Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
Clean up chart-control exports
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud committed Aug 28, 2020
1 parent af8785a commit c0f4e04
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 49 deletions.
34 changes: 19 additions & 15 deletions packages/superset-ui-core/src/chart-controls/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import * as constantsModule from './constants';
import * as sharedControlsModule from './shared-controls';
import * as sectionModules from './sections';

// explore all available shared controls
/**
* 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.
*/
export * from './utils';
export { default as sharedControls } from './shared-controls';

// `export * as x from 'y'` doesn't work for some reason
export const constants = constantsModule;
export const internalSharedControls = sharedControlsModule;
export const sections = sectionModules;
export { D3_FORMAT_DOCS, D3_FORMAT_OPTIONS, D3_TIME_FORMAT_OPTIONS } from './utils/D3Formatting';
export { formatSelectOptions, formatSelectOptionsForRange } from './utils/selectOptions';
export { default as mainMetric } from './utils/mainMetric';
export * from './utils/expandControlConfig';

export * from './components/InfoTooltipWithTrigger';
export * from './components/ColumnOption';
export * from './components/ColumnTypeLabel';
export * from './components/MetricOption';

// React control components
export * from './components/RadioButtonControl';

export * from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ import {
validateNonEmpty,
} from '../..';

import { formatSelectOptions } from '../utils/selectOptions';
import mainMetric from '../utils/mainMetric';
import { mainMetric, formatSelectOptions } from '../utils';
import { TIME_FILTER_LABELS } from '../constants';
import {
Metric,
SharedControlConfig,
ColumnMeta,
DatasourceMeta,
ExtraControlProps,
SelectControlConfig,
} from '../types';
Expand Down Expand Up @@ -165,15 +163,6 @@ const metric: SharedControlConfig<'MetricsControl'> = {
default: (c: Control) => mainMetric(c.savedMetrics),
};

export function columnChoices(datasource: DatasourceMeta) {
if (datasource?.columns) {
return datasource.columns
.map(col => [col.column_name, col.verbose_name || col.column_name])
.sort((opt1, opt2) => (opt1[1].toLowerCase() > opt2[1].toLowerCase() ? 1 : -1));
}
return [];
}

const datasourceControl: SharedControlConfig<'DatasourceControl'> = {
type: 'DatasourceControl',
label: t('Datasource'),
Expand Down Expand Up @@ -477,7 +466,7 @@ const label_colors: SharedControlConfig<'ColorMapControl'> = {
}),
};

export default {
const sharedControls = {
metrics,
metric,
datasource: datasourceControl,
Expand Down Expand Up @@ -506,3 +495,5 @@ export default {
color_scheme,
label_colors,
};

export default sharedControls;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* 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 { DatasourceMeta } from '../types';

/**
* Convert Dataource columns to column choices
*/
export default function columnChoices(datasource: DatasourceMeta) {
if (datasource?.columns) {
return datasource.columns
.map(col => [col.column_name, col.verbose_name || col.column_name])
.sort((opt1, opt2) => (opt1[1].toLowerCase() > opt2[1].toLowerCase() ? 1 : -1));
}
return [];
}
23 changes: 23 additions & 0 deletions packages/superset-ui-core/src/chart-controls/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* 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.
*/
export * from './selectOptions';
export * from './D3Formatting';
export * from './expandControlConfig';
export { default as mainMetric } from './mainMetric';
export { default as columnChoices } from './columnChoices';
4 changes: 1 addition & 3 deletions plugins/legacy-plugin-chart-event-flow/src/controlPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import {
t,
validateNonEmpty,
ColumnOption,
internalSharedControls,
formatSelectOptionsForRange,
columnChoices,
} from '@superset-ui/core';

const { columnChoices } = internalSharedControls;

export default {
controlPanelSections: [
{
Expand Down
4 changes: 1 addition & 3 deletions plugins/legacy-plugin-chart-heatmap/src/controlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
import {
t,
validateNonEmpty,
internalSharedControls,
formatSelectOptionsForRange,
formatSelectOptions,
columnChoices,
} from '@superset-ui/core';

const { columnChoices } = internalSharedControls;

const sortAxisChoices = [
['alpha_asc', t('Axis ascending')],
['alpha_desc', t('Axis descending')],
Expand Down
9 changes: 1 addition & 8 deletions plugins/legacy-plugin-chart-histogram/src/controlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import {
t,
validateNonEmpty,
formatSelectOptions,
internalSharedControls,
} from '@superset-ui/core';

const { columnChoices } = internalSharedControls;
import { t, validateNonEmpty, formatSelectOptions, columnChoices } from '@superset-ui/core';

export default {
controlPanelSections: [
Expand Down
4 changes: 1 addition & 3 deletions plugins/legacy-plugin-chart-map-box/src/controlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { t, formatSelectOptions, internalSharedControls } from '@superset-ui/core';

const { columnChoices } = internalSharedControls;
import { t, formatSelectOptions, columnChoices } from '@superset-ui/core';

export default {
controlPanelSections: [
Expand Down
22 changes: 18 additions & 4 deletions test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import { configure } from '@superset-ui/core';

configure();

/**
* 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.
*/
const caches = {};

class Cache {
Expand Down

0 comments on commit c0f4e04

Please sign in to comment.