forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add control grouping functionality (apache#485)
* feat: add control grouping functionality * implement controlGroups on WordCloud * fix tests * break up into smaller packages and add unit tests * fix test * address comments * rename controlGroup to queryField * move import * fix word cloud test * fix a few remaining references to control groups * Rename funcs * Simplify extractQueryFields * fix
- Loading branch information
1 parent
bf64c8a
commit 2ea2c18
Showing
15 changed files
with
184 additions
and
134 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
30 changes: 30 additions & 0 deletions
30
...nd/temporary_superset_ui/superset-ui/packages/superset-ui-query/src/extractQueryFields.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,30 @@ | ||
import { QueryFields, QueryFormResidualData } from './types/QueryFormData'; | ||
import { QueryFieldData } from './types/Query'; | ||
|
||
export default function extractQueryFields( | ||
residualFormData: QueryFormResidualData, | ||
queryFields?: QueryFields, | ||
) { | ||
const queryFieldAliases: QueryFields = { | ||
/** These are predefined for backward compatibility */ | ||
metric: 'metrics', | ||
percent_metrics: 'metrics', | ||
metric_2: 'metrics', | ||
secondary_metric: 'metrics', | ||
x: 'metrics', | ||
y: 'metrics', | ||
size: 'metrics', | ||
...queryFields, | ||
}; | ||
const finalQueryFields: QueryFieldData = { | ||
columns: [], | ||
groupby: [], | ||
metrics: [], | ||
}; | ||
Object.entries(residualFormData).forEach(entry => { | ||
const [key, residualValue] = entry; | ||
const normalizedKey = queryFieldAliases[key] || key; | ||
finalQueryFields[normalizedKey] = (finalQueryFields[normalizedKey] || []).concat(residualValue); | ||
}); | ||
return finalQueryFields; | ||
} |
11 changes: 11 additions & 0 deletions
11
...ontend/temporary_superset_ui/superset-ui/packages/superset-ui-query/src/processGroupby.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,11 @@ | ||
import { QueryFormResidualDataValue } from './types/QueryFormData'; | ||
|
||
export default function processGroupby(groupby: QueryFormResidualDataValue[]): string[] { | ||
const groupbyList: string[] = []; | ||
groupby.forEach(value => { | ||
if (typeof value === 'string') { | ||
groupbyList.push(value); | ||
} | ||
}); | ||
return groupbyList; | ||
} |
25 changes: 0 additions & 25 deletions
25
...ontend/temporary_superset_ui/superset-ui/packages/superset-ui-query/src/processMetrics.ts
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
...frontend/temporary_superset_ui/superset-ui/packages/superset-ui-query/src/types/Metric.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
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
63 changes: 63 additions & 0 deletions
63
...porary_superset_ui/superset-ui/packages/superset-ui-query/test/extractQueryFields.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,63 @@ | ||
import extractQueryFields from '../src/extractQueryFields'; | ||
|
||
describe('extractQueryFields', () => { | ||
it('should return default object', () => { | ||
expect(extractQueryFields({})).toEqual({ | ||
columns: [], | ||
groupby: [], | ||
metrics: [], | ||
}); | ||
}); | ||
|
||
it('should group default metric controls to metrics', () => { | ||
expect(extractQueryFields({ metric: 'my_metric' }).metrics).toEqual(['my_metric']); | ||
}); | ||
|
||
it('should group custom metrics with default metrics', () => { | ||
expect( | ||
extractQueryFields( | ||
{ metric: 'metric_1', my_custom_metric: 'metric_2' }, | ||
{ my_custom_metric: 'metrics' }, | ||
).metrics, | ||
).toEqual(['metric_1', 'metric_2']); | ||
}); | ||
|
||
it('should extract columns', () => { | ||
expect(extractQueryFields({ columns: 'col_1' })).toEqual({ | ||
columns: ['col_1'], | ||
groupby: [], | ||
metrics: [], | ||
}); | ||
}); | ||
|
||
it('should extract groupby', () => { | ||
expect(extractQueryFields({ groupby: 'col_1' })).toEqual({ | ||
columns: [], | ||
groupby: ['col_1'], | ||
metrics: [], | ||
}); | ||
}); | ||
|
||
it('should extract custom groupby', () => { | ||
expect( | ||
extractQueryFields({ series: 'col_1', metric: 'metric_1' }, { series: 'groupby' }), | ||
).toEqual({ | ||
columns: [], | ||
groupby: ['col_1'], | ||
metrics: ['metric_1'], | ||
}); | ||
}); | ||
|
||
it('should merge custom groupby with default group', () => { | ||
expect( | ||
extractQueryFields( | ||
{ groupby: 'col_1', series: 'col_2', metric: 'metric_1' }, | ||
{ series: 'groupby' }, | ||
), | ||
).toEqual({ | ||
columns: [], | ||
groupby: ['col_1', 'col_2'], | ||
metrics: ['metric_1'], | ||
}); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
.../temporary_superset_ui/superset-ui/packages/superset-ui-query/test/processGroupby.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,12 @@ | ||
import processGroupby from '../src/processGroupby'; | ||
|
||
describe('processGroupby', () => { | ||
it('should handle array of strings', () => { | ||
expect(processGroupby(['foo', 'bar'])).toEqual(['foo', 'bar']); | ||
}); | ||
|
||
it('should exclude non-string values', () => { | ||
// @ts-ignore, change to @ts-expect-error when updated to TypeScript>=3.9 | ||
expect(processGroupby(['bar', 1, undefined, null, 'foo'])).toEqual(['bar', 'foo']); | ||
}); | ||
}); |
Oops, something went wrong.