This repository has been archived by the owner on Dec 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 271
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 (#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
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
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; | ||
} |
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; | ||
} |
This file was deleted.
Oops, something went wrong.
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
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'], | ||
}); | ||
}); | ||
}); |
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.
4ceacfb
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.
Successfully deployed to following URLs: