Skip to content

Commit

Permalink
feat: add verbose map to get /dataset/ endpoint (apache#23655)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lily Kuang authored and sebastianliebscher committed Apr 28, 2023
1 parent c2650a0 commit 6e61ba2
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ import { noOp } from 'src/utils/common';
import DrillByChart from './DrillByChart';

const chart = chartQueries[sliceId];
const dataset = {
changed_on_humanized: '01-01-2001',
created_on_humanized: '01-01-2001',
description: 'desc',
table_name: 'my_dataset',
owners: [
{
first_name: 'Sarah',
last_name: 'Connor',
},
],
columns: [
{
column_name: 'gender',
},
{ column_name: 'name' },
],
};

const setup = (overrides: Record<string, any> = {}, result?: any) =>
render(
Expand All @@ -31,6 +49,7 @@ const setup = (overrides: Record<string, any> = {}, result?: any) =>
onContextMenu={noOp}
inContextMenu={false}
result={result}
dataset={dataset}
/>,
{
useRedux: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import {
css,
ContextMenuFilters,
} from '@superset-ui/core';
import { Dataset } from '../types';

interface DrillByChartProps {
formData: BaseFormData & { [key: string]: any };
result: QueryData[];
dataset: Dataset;
onContextMenu: (
offsetX: number,
offsetY: number,
Expand All @@ -39,6 +41,7 @@ interface DrillByChartProps {
export default function DrillByChart({
formData,
result,
dataset,
onContextMenu,
inContextMenu,
}: DrillByChartProps) {
Expand All @@ -56,6 +59,7 @@ export default function DrillByChart({
disableErrorBoundary
chartType={formData.viz_type}
enableNoResults
datasource={dataset}
formData={formData}
queriesData={result}
hooks={hooks}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
cachedSupersetGet,
supersetGetCache,
} from 'src/utils/cachedSupersetGet';
import { useVerboseMap } from 'src/hooks/apiResources/datasets';
import { MenuItemTooltip } from '../DisabledMenuItemTooltip';
import DrillByModal from './DrillByModal';
import { getSubmenuYOffset } from '../utils';
Expand Down Expand Up @@ -115,6 +116,7 @@ export const DrillByMenuItems = ({
?.behaviors.find(behavior => behavior === Behavior.DRILL_BY),
[formData.viz_type],
);
const verboseMap = useVerboseMap(dataset);

useEffect(() => {
if (handlesDimensionContextMenu && hasDrillBy) {
Expand Down Expand Up @@ -270,7 +272,7 @@ export const DrillByMenuItems = ({
drillByConfig={drillByConfig}
formData={formData}
onHideModal={closeModal}
dataset={dataset!}
dataset={{ ...dataset!, verbose_map: verboseMap }}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ export default function DrillByModal({
)}
{drillByDisplayMode === DrillByType.Chart && chartDataResult && (
<DrillByChart
dataset={dataset}
formData={drilledFormData}
result={chartDataResult}
onContextMenu={onContextMenu}
Expand Down
4 changes: 3 additions & 1 deletion superset-frontend/src/components/Chart/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Column } from '@superset-ui/core';
import { Column, Metric } from '@superset-ui/core';

export enum DrillByType {
Chart,
Expand All @@ -41,4 +41,6 @@ export type Dataset = {
last_name: string;
}[];
columns?: Column[];
metrics?: Metric[];
verbose_map?: Record<string, string>;
};
32 changes: 32 additions & 0 deletions superset-frontend/src/hooks/apiResources/datasets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable no-underscore-dangle */
/**
* 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 { Column, Metric, ensureIsArray } from '@superset-ui/core';
import { Dataset } from 'src/components/Chart/types';

export const useVerboseMap = (dataset?: Dataset) => {
const verbose_map = {};
ensureIsArray(dataset?.columns).forEach((column: Column) => {
verbose_map[column.column_name] = column.verbose_name || column.column_name;
});
ensureIsArray(dataset?.metrics).forEach((metric: Metric) => {
verbose_map[metric.metric_name] = metric.verbose_name || metric.metric_name;
});
return verbose_map;
};

0 comments on commit 6e61ba2

Please sign in to comment.