-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cross-filters): Add scoping for cross filters (#13625)
* feat: cross filter modal * refactor: add charts metadata * refactor: add charts metadata * feat: cross filters scoping * fix: fix CR notes * test: fix test * lint: fix lint
- Loading branch information
Showing
26 changed files
with
457 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { Dispatch } from 'redux'; | ||
import { makeApi } from '@superset-ui/core'; | ||
import { ChartConfiguration, DashboardInfo } from '../reducers/types'; | ||
|
||
export const DASHBOARD_INFO_UPDATED = 'DASHBOARD_INFO_UPDATED'; | ||
|
||
// updates partially changed dashboard info | ||
export function dashboardInfoChanged(newInfo: { metadata: any }) { | ||
return { type: DASHBOARD_INFO_UPDATED, newInfo }; | ||
} | ||
export const SET_CHART_CONFIG_BEGIN = 'SET_CHART_CONFIG_BEGIN'; | ||
export interface SetChartConfigBegin { | ||
type: typeof SET_CHART_CONFIG_BEGIN; | ||
chartConfiguration: ChartConfiguration; | ||
} | ||
export const SET_CHART_CONFIG_COMPLETE = 'SET_CHART_CONFIG_COMPLETE'; | ||
export interface SetChartConfigComplete { | ||
type: typeof SET_CHART_CONFIG_COMPLETE; | ||
chartConfiguration: ChartConfiguration; | ||
} | ||
export const SET_CHART_CONFIG_FAIL = 'SET_CHART_CONFIG_FAIL'; | ||
export interface SetChartConfigFail { | ||
type: typeof SET_CHART_CONFIG_FAIL; | ||
chartConfiguration: ChartConfiguration; | ||
} | ||
export const setChartConfiguration = ( | ||
chartConfiguration: ChartConfiguration, | ||
) => async (dispatch: Dispatch, getState: () => any) => { | ||
dispatch({ | ||
type: SET_CHART_CONFIG_BEGIN, | ||
chartConfiguration, | ||
}); | ||
const { id, metadata } = getState().dashboardInfo; | ||
|
||
// TODO extract this out when makeApi supports url parameters | ||
const updateDashboard = makeApi< | ||
Partial<DashboardInfo>, | ||
{ result: DashboardInfo } | ||
>({ | ||
method: 'PUT', | ||
endpoint: `/api/v1/dashboard/${id}`, | ||
}); | ||
|
||
try { | ||
const response = await updateDashboard({ | ||
json_metadata: JSON.stringify({ | ||
...metadata, | ||
chart_configuration: chartConfiguration, | ||
}), | ||
}); | ||
dispatch( | ||
dashboardInfoChanged({ | ||
metadata: JSON.parse(response.result.json_metadata), | ||
}), | ||
); | ||
dispatch({ | ||
type: SET_CHART_CONFIG_COMPLETE, | ||
chartConfiguration, | ||
}); | ||
} catch (err) { | ||
dispatch({ type: SET_CHART_CONFIG_FAIL, chartConfiguration }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...rset-frontend/src/dashboard/components/CrossFilterScopingModal/CrossFilterScopingForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React, { FC } from 'react'; | ||
import { FormInstance } from 'antd/lib/form'; | ||
import FilterScope from '../nativeFilters/FiltersConfigModal/FiltersConfigForm/FilterScope/FilterScope'; | ||
import { setCrossFilterFieldValues } from './utils'; | ||
import { Scope } from '../nativeFilters/types'; | ||
import { useForceUpdate } from '../nativeFilters/FiltersConfigModal/FiltersConfigForm/utils'; | ||
import { CrossFilterScopingFormType } from './types'; | ||
|
||
type CrossFilterScopingFormProps = { | ||
scope: Scope; | ||
form: FormInstance<CrossFilterScopingFormType>; | ||
}; | ||
|
||
const CrossFilterScopingForm: FC<CrossFilterScopingFormProps> = ({ | ||
form, | ||
scope, | ||
}) => { | ||
const forceUpdate = useForceUpdate(); | ||
const formScope = form.getFieldValue('scope'); | ||
const formScoping = form.getFieldValue('scoping'); | ||
return ( | ||
<FilterScope | ||
updateFormValues={(values: any) => { | ||
setCrossFilterFieldValues(form, { | ||
...values, | ||
}); | ||
}} | ||
scope={scope} | ||
formScope={formScope} | ||
forceUpdate={forceUpdate} | ||
formScoping={formScoping} | ||
/> | ||
); | ||
}; | ||
|
||
export default CrossFilterScopingForm; |
97 changes: 97 additions & 0 deletions
97
...set-frontend/src/dashboard/components/CrossFilterScopingModal/CrossFilterScopingModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { t } from '@superset-ui/core'; | ||
import React, { FC } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { StyledModal } from 'src/common/components/Modal'; | ||
import Button from 'src/components/Button'; | ||
import { Form } from 'src/common/components'; | ||
import { setChartConfiguration } from 'src/dashboard/actions/dashboardInfo'; | ||
import { ChartConfiguration } from 'src/dashboard/reducers/types'; | ||
import CrossFilterScopingForm from './CrossFilterScopingForm'; | ||
import { CrossFilterScopingFormType } from './types'; | ||
import { StyledForm } from '../nativeFilters/FiltersConfigModal/FiltersConfigModal'; | ||
|
||
type CrossFilterScopingModalProps = { | ||
chartId: number; | ||
isOpen: boolean; | ||
onClose: () => void; | ||
}; | ||
|
||
const CrossFilterScopingModal: FC<CrossFilterScopingModalProps> = ({ | ||
isOpen, | ||
chartId, | ||
onClose, | ||
}) => { | ||
const dispatch = useDispatch(); | ||
const [form] = Form.useForm<CrossFilterScopingFormType>(); | ||
const chartConfig = useSelector<any, ChartConfiguration>( | ||
({ dashboardInfo }) => dashboardInfo?.metadata?.chart_configuration, | ||
); | ||
const scope = chartConfig?.[chartId]?.crossFilters?.scope; | ||
const handleSave = () => { | ||
dispatch( | ||
setChartConfiguration({ | ||
...chartConfig, | ||
[chartId]: { crossFilters: { scope: form.getFieldValue('scope') } }, | ||
}), | ||
); | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<StyledModal | ||
visible={isOpen} | ||
maskClosable={false} | ||
title={t('Cross Filter Scoping')} | ||
width="55%" | ||
destroyOnClose | ||
onCancel={onClose} | ||
onOk={handleSave} | ||
centered | ||
data-test="cross-filter-scoping-modal" | ||
footer={ | ||
<> | ||
<Button | ||
key="cancel" | ||
buttonStyle="secondary" | ||
data-test="cross-filter-scoping-modal-cancel-button" | ||
onClick={onClose} | ||
> | ||
{t('Cancel')} | ||
</Button> | ||
<Button | ||
key="submit" | ||
buttonStyle="primary" | ||
onClick={handleSave} | ||
data-test="cross-filter-scoping-modal-save-button" | ||
> | ||
{t('Save')} | ||
</Button> | ||
</> | ||
} | ||
> | ||
<StyledForm preserve={false} form={form} layout="vertical"> | ||
<CrossFilterScopingForm form={form} scope={scope} /> | ||
</StyledForm> | ||
</StyledModal> | ||
); | ||
}; | ||
|
||
export default CrossFilterScopingModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
superset-frontend/src/dashboard/components/CrossFilterScopingModal/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { FormInstance } from 'antd/lib/form'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const setCrossFilterFieldValues = ( | ||
form: FormInstance, | ||
values: object, | ||
) => { | ||
form.setFieldsValue({ | ||
...values, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.