-
Notifications
You must be signed in to change notification settings - Fork 14k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(generic-x-axis): add x sorting on series limit metric (#23274)
- Loading branch information
Showing
11 changed files
with
294 additions
and
76 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
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.