Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 10 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -31,6 +31,7 @@ import {
Behavior,
Column,
ContextMenuFilters,
Metric,
css,
ensureIsArray,
getChartMetadataRegistry,
Expand Down Expand Up @@ -123,7 +124,16 @@ export const DrillByMenuItems = ({
endpoint: `/api/v1/dataset/${datasetId}`,
})
.then(({ json: { result } }) => {
setDataset(result);
const verbose_map = {};
ensureIsArray(result.columns).forEach((column: Column) => {
verbose_map[column.column_name] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move that to a separate file/hook? Like useVerboseMap?
The we could call it in DrillByChart like const verboseMap = useVerboseMap(dataset) and pass dataset to SuperChart like { ...dataset, verbose_map: verboseMap }
WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And since that hook might have a more generic purpose, we could place it in src/hooks or src/utils instead of drill by directories

column.verbose_name || column.column_name;
});
ensureIsArray(result.metrics).forEach((metric: Metric) => {
verbose_map[metric.metric_name] =
metric.verbose_name || metric.metric_name;
});
setDataset({ ...result, verbose_map });
setColumns(
ensureIsArray(result.columns)
.filter(column => column.groupby)
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