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(viz-gallery): add 'feature' tag and fuzzy search weighting #18662

Merged
merged 19 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -44,6 +44,11 @@ export interface ChartMetadataConfig {
exampleGallery?: ExampleImage[];
tags?: string[];
category?: string | null;
label?: {
name: string;
description: string;
};
searchWeight?: number;
}

export default class ChartMetadata {
Expand Down Expand Up @@ -79,6 +84,13 @@ export default class ChartMetadata {

category: string | null;

label?: {
name: string;
description: string;
};

searchWeight: number;

constructor(config: ChartMetadataConfig) {
const {
name,
Expand All @@ -96,6 +108,8 @@ export default class ChartMetadata {
exampleGallery = [],
tags = [],
category = null,
label,
searchWeight = 0,
} = config;

this.name = name;
Expand All @@ -122,6 +136,8 @@ export default class ChartMetadata {
this.exampleGallery = exampleGallery;
this.tags = tags;
this.category = category;
this.label = label;
this.searchWeight = searchWeight;
}

canBeAnnotationType(type: string): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ const metadata = new ChartMetadata({
],
thumbnail,
useLegacyApi: true,
label: {
name: t('verified'),
description: t(
'This chart was tested and verified, so the overall experience should be stable.',
Copy link
Member

Choose a reason for hiding this comment

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

I understand that a label is very flexible, but do we actually want such high flexibility? If this were, say, an enum of VERIFIED, DEPRECATED, ... , it could be used for more programmatic things. For example, rather than using a searchWeight that has to be the same for all verified charts, the logic in the gallery's sort function could sort by the value of this enum. And having this text duplicated in every verified plugin doesn't really seem ideal to me.

We already have a boolean field deprecated, so if we did switch this to an enum we would probably want to... deprecate the deprecated field.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for this inputs!This makes sense. @rusackas I think we can unify it into an enum and influence the search results based on the definition of this field.

),
},
searchWeight: 0.5,
});

export default class WorldMapChartPlugin extends ChartPlugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ const metadata = new ChartMetadata({
],
thumbnail,
useLegacyApi: true,
label: {
name: t('verified'),
description: t(
'This chart was tested and verified, so the overall experience should be stable.',
),
},
searchWeight: 0.5,
});

export default class DistBarChartPlugin extends ChartPlugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ const metadata = new ChartMetadata({
t('Description'),
],
thumbnail,
label: {
name: t('verified'),
description: t(
'This chart was tested and verified, so the overall experience should be stable.',
),
},
searchWeight: 0.5,
});

export default class BigNumberTotalChartPlugin extends ChartPlugin<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ const metadata = new ChartMetadata({
t('Trend'),
],
thumbnail,
label: {
name: t('verified'),
description: t(
'This chart was tested and verified, so the overall experience should be stable.',
),
},
searchWeight: 0.5,
});

export default class BigNumberWithTrendlineChartPlugin extends ChartPlugin<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ export default class EchartsPieChartPlugin extends ChartPlugin<
t('ECharts'),
],
thumbnail,
label: {
name: t('verified'),
description: t(
'This chart was tested and verified, so the overall experience should be stable.',
),
},
searchWeight: 0.5,
}),
transformProps,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ export default class EchartsAreaChartPlugin extends ChartPlugin<
t('Popular'),
],
thumbnail,
label: {
name: t('verified'),
description: t(
'This chart was tested and verified, so the overall experience should be stable.',
),
},
searchWeight: 0.5,
}),
transformProps: areaTransformProps,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export default class EchartsTimeseriesBarChartPlugin extends ChartPlugin<
t('Popular'),
],
thumbnail,
label: {
name: t('verified'),
description: t(
'This chart was tested and verified, so the overall experience should be stable.',
),
},
searchWeight: 0.5,
}),
transformProps: barTransformProps,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ export default class EchartsTimeseriesLineChartPlugin extends ChartPlugin<
t('Popular'),
],
thumbnail,
label: {
name: t('verified'),
description: t(
'This chart was tested and verified, so the overall experience should be stable.',
),
},
searchWeight: 0.5,
}),
transformProps: lineTransformProps,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ export default class EchartsTimeseriesScatterChartPlugin extends ChartPlugin<
t('Popular'),
],
thumbnail,
label: {
name: t('verified'),
description: t(
'This chart was tested and verified, so the overall experience should be stable.',
),
},
searchWeight: 0.5,
}),
transformProps: scatterTransformProps,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ export default class PivotTableChartPlugin extends ChartPlugin<
name: t('Pivot Table v2'),
tags: [t('Additive'), t('Report'), t('Tabular'), t('Popular')],
thumbnail,
label: {
name: t('verified'),
description: t(
'This chart was tested and verified, so the overall experience should be stable.',
),
},
searchWeight: 0.5,
});

super({
Expand Down
7 changes: 7 additions & 0 deletions superset-frontend/plugins/plugin-chart-table/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ const metadata = new ChartMetadata({
t('Description'),
],
thumbnail,
label: {
name: t('verified'),
description: t(
'This chart was tested and verified, so the overall experience should be stable.',
),
},
searchWeight: 0.5,
});

export default class TableChartPlugin extends ChartPlugin<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
SupersetTheme,
useTheme,
} from '@superset-ui/core';
import { Collapse, Input } from 'src/common/components';
import { Collapse, Input, Tooltip } from 'src/common/components';
import Label from 'src/components/Label';
import { usePluginContext } from 'src/components/DynamicPlugins';
import Icons from 'src/components/Icons';
Expand Down Expand Up @@ -309,6 +309,7 @@ const Examples = styled.div`
const thumbnailContainerCss = (theme: SupersetTheme) => css`
cursor: pointer;
width: ${theme.gridUnit * THUMBNAIL_GRID_UNITS}px;
position: relative;

img {
min-width: ${theme.gridUnit * THUMBNAIL_GRID_UNITS}px;
Expand All @@ -332,6 +333,38 @@ const thumbnailContainerCss = (theme: SupersetTheme) => css`
}
`;

const BetaBadge = styled.div`
stephenLYZ marked this conversation as resolved.
Show resolved Hide resolved
${({ theme }) => `
border: 1px solid #1985a0;
stephenLYZ marked this conversation as resolved.
Show resolved Hide resolved
box-sizing: border-box;
border-radius: 4px;
stephenLYZ marked this conversation as resolved.
Show resolved Hide resolved
background: #ffffff;
stephenLYZ marked this conversation as resolved.
Show resolved Hide resolved
line-height: ${theme.gridUnit * 2.5}px;
color: #1985a0;
stephenLYZ marked this conversation as resolved.
Show resolved Hide resolved
font-size: 12px;
stephenLYZ marked this conversation as resolved.
Show resolved Hide resolved
font-weight: 500;
stephenLYZ marked this conversation as resolved.
Show resolved Hide resolved
text-align: center;
padding: ${theme.gridUnit * 0.5}px ${theme.gridUnit}px;
text-transform: uppercase;
cursor: pointer;

div {
transform: scale(0.83,0.83);
}
`}
`;

const ThumbnailBadgeWrapper = styled.div`
position: absolute;
right: ${({ theme }) => theme.gridUnit}px;
top: ${({ theme }) => theme.gridUnit * 19}px;
`;

const TitleBadgeWrapper = styled.div`
display: inline-block !important;
margin-left: ${({ theme }) => theme.gridUnit * 2}px;
`;

function vizSortFactor(entry: VizEntry) {
if (typesWithDefaultOrder.has(entry.key)) {
return DEFAULT_ORDER.indexOf(entry.key);
Expand Down Expand Up @@ -377,6 +410,13 @@ const Thumbnail: React.FC<ThumbnailProps> = ({
>
{type.name}
</div>
{type.label && (
<ThumbnailBadgeWrapper>
<BetaBadge>
<div>{type.label.name}</div>
</BetaBadge>
</ThumbnailBadgeWrapper>
)}
</div>
);
};
Expand Down Expand Up @@ -544,7 +584,12 @@ export default function VizTypeGallery(props: VizTypeGalleryProps) {
if (searchInputValue.trim() === '') {
return [];
}
return fuse.search(searchInputValue).map(result => result.item);
return fuse
.search(searchInputValue)
.map(result => result.item)
.sort(
(a, b) => (b.value?.searchWeight || 0) - (a.value?.searchWeight || 0),
);
}, [searchInputValue, fuse]);

const focusSearch = useCallback(() => {
Expand Down Expand Up @@ -738,9 +783,23 @@ export default function VizTypeGallery(props: VizTypeGalleryProps) {
<SectionTitle
css={css`
grid-area: viz-name;
position: relative;
`}
>
{selectedVizMetadata?.name}
{selectedVizMetadata?.label && (
<Tooltip
id="viz-badge-tooltip"
placement="top"
title={selectedVizMetadata?.label.description}
>
<TitleBadgeWrapper>
<BetaBadge>
<div>{selectedVizMetadata.label.name}</div>
</BetaBadge>
</TitleBadgeWrapper>
</Tooltip>
)}
</SectionTitle>
<TagsWrapper>
{selectedVizMetadata?.tags.map(tag => (
Expand Down