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 272
chore: add shared plugin controls utilities #389
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
62c48b5
add shared controls utilities
suddjian 1386bef
accidentally yarn lock
suddjian 90695fe
bring in date formatting fix
suddjian 931fac4
turn off no-plusplus rule
suddjian 87d04f3
address PR feedback, reorganize modules a bit
suddjian c92e1f0
turn off no-plusplus
suddjian 0ba89ab
bring in new external changes
suddjian b9b35e6
superset-ui packages should be peer dependencies
suddjian d5e70aa
add tests for ported in code
suddjian 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,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'], | ||
]; |
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'; |
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,57 @@ | ||
/** | ||
* 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'], | ||
['slice_id', 'cache_timeout', 'url_params', 'time_range_endpoints'], | ||
], | ||
}; | ||
|
||
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'), | ||
expanded: true, | ||
controlSetRows: [['annotation_layers']], | ||
}; |
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
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.
These should be
peerDependencies
. (translation
needs to be a singleton.validator
not necessariliy, but I have been making all@superset-ui/xxx
peerDependencies
by convention to avoid having multiple copies of some singleton by mistake)