feat: add verbose map to get /dataset/ endpoint (#23655)

This commit is contained in:
Lily Kuang 2023-04-26 10:17:32 -07:00 committed by GitHub
parent fa8f98472c
commit 369aafd9ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 62 additions and 2 deletions

View File

@ -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(
@ -31,6 +49,7 @@ const setup = (overrides: Record<string, any> = {}, result?: any) =>
onContextMenu={noOp}
inContextMenu={false}
result={result}
dataset={dataset}
/>,
{
useRedux: true,

View File

@ -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,
@ -39,6 +41,7 @@ interface DrillByChartProps {
export default function DrillByChart({
formData,
result,
dataset,
onContextMenu,
inContextMenu,
}: DrillByChartProps) {
@ -56,6 +59,7 @@ export default function DrillByChart({
disableErrorBoundary
chartType={formData.viz_type}
enableNoResults
datasource={dataset}
formData={formData}
queriesData={result}
hooks={hooks}

View File

@ -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';
@ -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) {
@ -270,7 +272,7 @@ export const DrillByMenuItems = ({
drillByConfig={drillByConfig}
formData={formData}
onHideModal={closeModal}
dataset={dataset!}
dataset={{ ...dataset!, verbose_map: verboseMap }}
/>
)}
</>

View File

@ -407,6 +407,7 @@ export default function DrillByModal({
)}
{drillByDisplayMode === DrillByType.Chart && chartDataResult && (
<DrillByChart
dataset={dataset}
formData={drilledFormData}
result={chartDataResult}
onContextMenu={onContextMenu}

View File

@ -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,
@ -41,4 +41,6 @@ export type Dataset = {
last_name: string;
}[];
columns?: Column[];
metrics?: Metric[];
verbose_map?: Record<string, string>;
};

View File

@ -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;
};