-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(chart): add shared plugin controls utilities (#389)
* add shared controls utilities * accidentally yarn lock * bring in date formatting fix * turn off no-plusplus rule * address PR feedback, reorganize modules a bit * turn off no-plusplus * bring in new external changes * superset-ui packages should be peer dependencies * add tests for ported in code
- Loading branch information
1 parent
afed1a0
commit fb46642
Showing
10 changed files
with
699 additions
and
0 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
49 changes: 49 additions & 0 deletions
49
...temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/controls/D3Formatting.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,49 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
// D3 specific formatting config | ||
|
||
export const D3_FORMAT_DOCS = 'D3 format syntax: https://github.com/d3/d3-format'; | ||
|
||
// input choices & options | ||
export const D3_FORMAT_OPTIONS = [ | ||
['SMART_NUMBER', 'Adaptative formating'], | ||
['~g', 'Original value'], | ||
[',d', ',d (12345.432 => 12,345)'], | ||
['.1s', '.1s (12345.432 => 10k)'], | ||
['.3s', '.3s (12345.432 => 12.3k)'], | ||
[',.1%', ',.1% (12345.432 => 1,234,543.2%)'], | ||
['.3%', '.3% (12345.432 => 1234543.200%)'], | ||
['.4r', '.4r (12345.432 => 12350)'], | ||
[',.3f', ',.3f (12345.432 => 12,345.432)'], | ||
['+,', '+, (12345.432 => +12,345.432)'], | ||
['$,.2f', '$,.2f (12345.432 => $12,345.43)'], | ||
['DURATION', 'Duration in ms (66000 => 1m 6s)'], | ||
['DURATION_SUB', 'Duration in ms (100.40008 => 100ms 400µs 80ns)'], | ||
]; | ||
|
||
export const D3_TIME_FORMAT_OPTIONS = [ | ||
['smart_date', 'Adaptative formating'], | ||
['%d/%m/%Y', '%d/%m/%Y | 14/01/2019'], | ||
['%m/%d/%Y', '%m/%d/%Y | 01/14/2019'], | ||
['%Y-%m-%d', '%Y-%m-%d | 2019-01-14'], | ||
['%Y-%m-%d %H:%M:%S', '%Y-%m-%d %H:%M:%S | 2019-01-14 01:32:10'], | ||
['%d-%m-%Y %H:%M:%S', '%Y-%m-%d %H:%M:%S | 14-01-2019 01:32:10'], | ||
['%H:%M:%S', '%H:%M:%S | 01:32:10'], | ||
]; |
5 changes: 5 additions & 0 deletions
5
...ontend/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/controls/index.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,5 @@ | ||
import * as sectionsModule from './sections'; | ||
|
||
export const sections = sectionsModule; | ||
export * from './D3Formatting'; | ||
export * from './selectOptions'; |
109 changes: 109 additions & 0 deletions
109
...nd/temporary_superset_ui/superset-ui/packages/superset-ui-chart/src/controls/sections.tsx
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,109 @@ | ||
/** | ||
* 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 { t } from '@superset-ui/translation'; | ||
|
||
// A few standard controls sections that are used internally. | ||
// Not recommended for use in third-party plugins. | ||
|
||
export const druidTimeSeries = { | ||
label: t('Time'), | ||
expanded: true, | ||
description: t('Time related form attributes'), | ||
controlSetRows: [['time_range']], | ||
}; | ||
|
||
export const datasourceAndVizType = { | ||
label: t('Datasource & Chart Type'), | ||
expanded: true, | ||
controlSetRows: [ | ||
['datasource'], | ||
['viz_type'], | ||
[ | ||
{ | ||
name: 'slice_id', | ||
config: { | ||
type: 'HiddenControl', | ||
label: t('Chart ID'), | ||
hidden: true, | ||
description: t('The id of the active chart'), | ||
}, | ||
}, | ||
{ | ||
name: 'cache_timeout', | ||
config: { | ||
type: 'HiddenControl', | ||
label: t('Cache Timeout (seconds)'), | ||
hidden: true, | ||
description: t('The number of seconds before expiring the cache'), | ||
}, | ||
}, | ||
{ | ||
name: 'url_params', | ||
config: { | ||
type: 'HiddenControl', | ||
label: t('URL Parameters'), | ||
hidden: true, | ||
description: t('Extra parameters for use in jinja templated queries'), | ||
}, | ||
}, | ||
{ | ||
name: 'time_range_endpoints', | ||
config: { | ||
type: 'HiddenControl', | ||
label: t('Time range endpoints'), | ||
hidden: true, | ||
description: t('Time range endpoints (SIP-15)'), | ||
}, | ||
}, | ||
], | ||
], | ||
}; | ||
|
||
export const colorScheme = { | ||
label: t('Color Scheme'), | ||
controlSetRows: [['color_scheme', 'label_colors']], | ||
}; | ||
|
||
export const sqlaTimeSeries = { | ||
label: t('Time'), | ||
description: t('Time related form attributes'), | ||
expanded: true, | ||
controlSetRows: [['granularity_sqla'], ['time_range']], | ||
}; | ||
|
||
export const annotations = { | ||
label: t('Annotations and Layers'), | ||
tabOverride: 'data', | ||
expanded: true, | ||
controlSetRows: [ | ||
[ | ||
{ | ||
name: 'annotation_layers', | ||
config: { | ||
type: 'AnnotationLayerControl', | ||
label: '', | ||
default: [], | ||
description: 'Annotation Layers', | ||
renderTrigger: true, | ||
tabOverride: 'data', | ||
}, | ||
}, | ||
], | ||
], | ||
}; |
42 changes: 42 additions & 0 deletions
42
...emporary_superset_ui/superset-ui/packages/superset-ui-chart/src/controls/selectOptions.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,42 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
// helper functions for select controls | ||
|
||
export type Formattable = string | number; | ||
|
||
export type Formatted = [Formattable, string]; | ||
|
||
/** Turns an array of string/number options into options for a select input */ | ||
export function formatSelectOptions(options: Formattable[]): Formatted[] { | ||
return options.map(opt => [opt, opt.toString()]); | ||
} | ||
|
||
/** | ||
* outputs array of arrays | ||
* formatSelectOptionsForRange(1, 5) | ||
* returns [[1,'1'], [2,'2'], [3,'3'], [4,'4'], [5,'5']] | ||
*/ | ||
export function formatSelectOptionsForRange(start: number, end: number) { | ||
const options: Formatted[] = []; | ||
for (let i = start; i <= end; i++) { | ||
options.push([i, i.toString()]); | ||
} | ||
return options; | ||
} |
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
26 changes: 26 additions & 0 deletions
26
...ry_superset_ui/superset-ui/packages/superset-ui-chart/test/controls/selectOptions.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,26 @@ | ||
import { formatSelectOptions, formatSelectOptionsForRange } from '../../src'; | ||
|
||
describe('formatSelectOptions', () => { | ||
it('formats an array of options', () => { | ||
expect(formatSelectOptions([1, 5, 10, 25, 50, 'unlimited'])).toEqual([ | ||
[1, '1'], | ||
[5, '5'], | ||
[10, '10'], | ||
[25, '25'], | ||
[50, '50'], | ||
['unlimited', 'unlimited'], | ||
]); | ||
}); | ||
}); | ||
|
||
describe('formatSelectOptionsForRange', () => { | ||
it('generates select options from a range', () => { | ||
expect(formatSelectOptionsForRange(1, 5)).toEqual([ | ||
[1, '1'], | ||
[2, '2'], | ||
[3, '3'], | ||
[4, '4'], | ||
[5, '5'], | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.