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
feat: add control grouping functionality #485
Merged
villebro
merged 13 commits into
apache-superset:master
from
preset-io:villebro/autogroup-controls
May 20, 2020
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
63614fc
feat: add control grouping functionality
villebro ef65ac3
implement controlGroups on WordCloud
villebro af9f20d
fix tests
villebro 0b2020c
break up into smaller packages and add unit tests
villebro c6f1424
fix test
villebro 1e42e85
address comments
villebro 7d9672c
rename controlGroup to queryField
villebro e6cff17
move import
villebro e42de00
fix word cloud test
villebro 900fb66
fix a few remaining references to control groups
villebro d3bd3c8
Rename funcs
villebro 9e52a4c
Simplify extractQueryFields
villebro 511e3e7
fix
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
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.
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.
ditto on
unknown
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.
Actually, are the items in ResidualFormData a
QueryFormDataMetric
?buildGroupedControlData
seems to imply that.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.
Yes, I was also puzzled by this.
ResidualFormData
(in retrospect should beQueryFormResidualData
) is currently expected to contain either column names (string
) or metrics (QueryFormDataMetric
which is the same asstring | AdhocMetric
). When these are combined, the union is reduced tostring | AdhocMetric
which is the same asQueryFormDataMetric
. I'm tempted to removeQueryFormDataMetric
and just pass aroundQueryFormResidualData
, which can later be split intoQueryFormDataMetric
andQueryFormDataColumn
when that need arises (Down the line we'll need to addAdhocColumn
which is a column with a SQL expression). I will actually do that, we'll see how it looks.