-
Notifications
You must be signed in to change notification settings - Fork 13.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(native-filters): add markers and number formatter to range filter #14981
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
superset-frontend/src/filters/components/Range/RangeFilterPlugin.stories.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,78 @@ | ||
/** | ||
* 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 from 'react'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { | ||
SuperChart, | ||
getChartTransformPropsRegistry, | ||
GenericDataType, | ||
} from '@superset-ui/core'; | ||
import RangeFilterPlugin from './index'; | ||
import transformProps from './transformProps'; | ||
|
||
new RangeFilterPlugin().configure({ key: 'filter_range' }).register(); | ||
|
||
getChartTransformPropsRegistry().registerValue('filter_range', transformProps); | ||
|
||
export default { | ||
title: 'Filter Plugins', | ||
}; | ||
|
||
export const range = ({ width, height }: { width: number; height: number }) => ( | ||
<SuperChart | ||
chartType="filter_range" | ||
width={width} | ||
height={height} | ||
queriesData={[{ data: [{ min: 10, max: 100 }] }]} | ||
filterState={{ value: [10, 70] }} | ||
formData={{ | ||
groupby: ['SP_POP_TOTL'], | ||
adhoc_filters: [], | ||
extra_filters: [], | ||
viz_type: 'filter_range', | ||
metrics: [ | ||
{ | ||
aggregate: 'MIN', | ||
column: { | ||
column_name: 'SP_POP_TOTL', | ||
id: 1, | ||
type_generic: GenericDataType.NUMERIC, | ||
}, | ||
expressionType: 'SIMPLE', | ||
hasCustomLabel: true, | ||
label: 'min', | ||
}, | ||
{ | ||
aggregate: 'MAX', | ||
column: { | ||
column_name: 'SP_POP_TOTL', | ||
id: 2, | ||
type_generic: GenericDataType.NUMERIC, | ||
}, | ||
expressionType: 'SIMPLE', | ||
hasCustomLabel: true, | ||
label: 'max', | ||
}, | ||
], | ||
}} | ||
hooks={{ | ||
setDataMask: action('setDataMask'), | ||
}} | ||
/> | ||
); |
121 changes: 121 additions & 0 deletions
121
superset-frontend/src/filters/components/Range/RangeFilterPlugin.test.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,121 @@ | ||
/** | ||
* 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 { AppSection, GenericDataType } from '@superset-ui/core'; | ||
import React from 'react'; | ||
import { render } from 'spec/helpers/testing-library'; | ||
import RangeFilterPlugin from './RangeFilterPlugin'; | ||
import transformProps from './transformProps'; | ||
|
||
const rangeProps = { | ||
formData: { | ||
datasource: '3__table', | ||
groupby: ['SP_POP_TOTL'], | ||
adhocFilters: [], | ||
extraFilters: [], | ||
extraFormData: {}, | ||
granularitySqla: 'ds', | ||
metrics: [ | ||
{ | ||
aggregate: 'MIN', | ||
column: { | ||
column_name: 'SP_POP_TOTL', | ||
id: 1, | ||
type_generic: GenericDataType.NUMERIC, | ||
}, | ||
expressionType: 'SIMPLE', | ||
hasCustomLabel: true, | ||
label: 'min', | ||
}, | ||
{ | ||
aggregate: 'MAX', | ||
column: { | ||
column_name: 'SP_POP_TOTL', | ||
id: 2, | ||
type_generic: GenericDataType.NUMERIC, | ||
}, | ||
expressionType: 'SIMPLE', | ||
hasCustomLabel: true, | ||
label: 'max', | ||
}, | ||
], | ||
rowLimit: 1000, | ||
showSearch: true, | ||
defaultValue: [10, 70], | ||
timeRangeEndpoints: ['inclusive', 'exclusive'], | ||
urlParams: {}, | ||
vizType: 'filter_range', | ||
inputRef: { current: null }, | ||
}, | ||
height: 20, | ||
hooks: {}, | ||
filterState: { value: [10, 70] }, | ||
queriesData: [ | ||
{ | ||
rowcount: 1, | ||
colnames: ['min', 'max'], | ||
coltypes: [GenericDataType.NUMERIC, GenericDataType.NUMERIC], | ||
data: [{ min: 10, max: 100 }], | ||
applied_filters: [], | ||
rejected_filters: [], | ||
}, | ||
], | ||
width: 220, | ||
behaviors: ['NATIVE_FILTER'], | ||
isRefreshing: false, | ||
appSection: AppSection.DASHBOARD, | ||
}; | ||
|
||
describe('RangeFilterPlugin', () => { | ||
const setDataMask = jest.fn(); | ||
const getWrapper = (props = {}) => | ||
render( | ||
// @ts-ignore | ||
<RangeFilterPlugin | ||
// @ts-ignore | ||
{...transformProps({ | ||
...rangeProps, | ||
formData: { ...rangeProps.formData, ...props }, | ||
})} | ||
setDataMask={setDataMask} | ||
/>, | ||
); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should call setDataMask with correct filter', () => { | ||
getWrapper(); | ||
expect(setDataMask).toHaveBeenCalledWith({ | ||
extraFormData: { | ||
filters: [ | ||
{ | ||
col: 'SP_POP_TOTL', | ||
op: '<=', | ||
val: 70, | ||
}, | ||
], | ||
}, | ||
filterState: { | ||
label: 'x ≤ 70', | ||
value: [10, 70], | ||
}, | ||
}); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaultValue
is now converted intofilterState
by the application, hence it doesn't need to be handled here