-
Notifications
You must be signed in to change notification settings - Fork 14k
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(generic-x-axis): add x sorting on series limit metric #23274
Merged
villebro
merged 8 commits into
apache:master
from
villebro:villebro/sort-x-hidden-metric
Mar 6, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
665c061
feat(plugin-chart-echarts): add sorting on series limit metric
villebro 338b5cb
lint
villebro 0215120
add extra_metrics to chart schema
villebro 2ce33cd
deflake state behavior and clean up tooltips
villebro 36f1ae8
simplify
villebro 85de269
use verbose name
villebro af0517f
use verbose name
villebro 6252762
refactor
villebro 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
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
38 changes: 38 additions & 0 deletions
38
...t-frontend/packages/superset-ui-chart-controls/src/operators/utils/extractExtraMetrics.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,38 @@ | ||
/** | ||
* 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 { | ||
getMetricLabel, | ||
QueryFormData, | ||
QueryFormMetric, | ||
} from '@superset-ui/core'; | ||
|
||
export function extractExtraMetrics( | ||
formData: QueryFormData, | ||
): QueryFormMetric[] { | ||
const { groupby, timeseries_limit_metric, x_axis_sort } = formData; | ||
const extra_metrics: QueryFormMetric[] = []; | ||
if ( | ||
!(groupby || []).length && | ||
timeseries_limit_metric && | ||
getMetricLabel(timeseries_limit_metric) === x_axis_sort | ||
) { | ||
extra_metrics.push(timeseries_limit_metric); | ||
} | ||
return extra_metrics; | ||
} |
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
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
94 changes: 94 additions & 0 deletions
94
...tend/packages/superset-ui-chart-controls/test/operators/utils/extractExtraMetrics.test.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,94 @@ | ||
/** | ||
* 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 { QueryFormData, QueryFormMetric } from '@superset-ui/core'; | ||
import { extractExtraMetrics } from '@superset-ui/chart-controls'; | ||
|
||
const baseFormData: QueryFormData = { | ||
datasource: 'dummy', | ||
viz_type: 'table', | ||
metrics: ['a', 'b'], | ||
columns: ['foo', 'bar'], | ||
limit: 100, | ||
metrics_b: ['c', 'd'], | ||
columns_b: ['hello', 'world'], | ||
limit_b: 200, | ||
}; | ||
|
||
const metric: QueryFormMetric = { | ||
expressionType: 'SQL', | ||
sqlExpression: 'case when 1 then 1 else 2 end', | ||
label: 'foo', | ||
}; | ||
|
||
test('returns empty array if relevant controls missing', () => { | ||
expect( | ||
extractExtraMetrics({ | ||
...baseFormData, | ||
}), | ||
).toEqual([]); | ||
}); | ||
|
||
test('returns empty array if x_axis_sort is not same as timeseries_limit_metric', () => { | ||
expect( | ||
extractExtraMetrics({ | ||
...baseFormData, | ||
timeseries_limit_metric: 'foo', | ||
x_axis_sort: 'bar', | ||
}), | ||
).toEqual([]); | ||
}); | ||
|
||
test('returns correct column if sort columns match', () => { | ||
expect( | ||
extractExtraMetrics({ | ||
...baseFormData, | ||
timeseries_limit_metric: 'foo', | ||
x_axis_sort: 'foo', | ||
}), | ||
).toEqual(['foo']); | ||
}); | ||
|
||
test('handles adhoc metrics correctly', () => { | ||
expect( | ||
extractExtraMetrics({ | ||
...baseFormData, | ||
timeseries_limit_metric: metric, | ||
x_axis_sort: 'foo', | ||
}), | ||
).toEqual([metric]); | ||
|
||
expect( | ||
extractExtraMetrics({ | ||
...baseFormData, | ||
timeseries_limit_metric: metric, | ||
x_axis_sort: 'bar', | ||
}), | ||
).toEqual([]); | ||
}); | ||
|
||
test('returns empty array if groupby populated', () => { | ||
expect( | ||
extractExtraMetrics({ | ||
...baseFormData, | ||
groupby: ['bar'], | ||
timeseries_limit_metric: 'foo', | ||
x_axis_sort: 'foo', | ||
}), | ||
).toEqual([]); | ||
}); |
Oops, something went wrong.
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.
removed due to this hook being flaky (has been disabled on many other similar controls, too)