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

Enable markup and markdown in fields without using the flag #1554

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 0 additions & 10 deletions src/server/components/features/features-list/MarkupInLabels.ts

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type {
import {
AxisMode,
AxisNullsMode,
Feature,
PlaceholderId,
getActualAxisModeForField,
getFakeTitleOrTitle,
Expand Down Expand Up @@ -68,13 +67,10 @@ export function prepareBarX(args: PrepareFunctionArgs) {
usedColors,
ChartEditor,
disableDefaultSorting = false,
features,
} = args;
const {data, order} = resultData;
const widgetConfig = ChartEditor.getWidgetConfig();
const isActionParamsEnable = widgetConfig?.actionParams?.enable;
const isMarkdownFieldsEnabled = features[Feature.WizardMarkdownFields];
const isMarkupLabelsEnabled = features[Feature.MarkupInLabels];

const xPlaceholder = placeholders.find((p) => p.id === PlaceholderId.X);
const x: ServerField | undefined = xPlaceholder?.items[0];
Expand Down Expand Up @@ -124,8 +120,8 @@ export function prepareBarX(args: PrepareFunctionArgs) {

const labelItem = labels?.[0];
const labelsLength = labels && labels.length;
const isMarkdownLabel = isMarkdownFieldsEnabled && isMarkdownField(labelItem);
const isMarkupLabel = isMarkupLabelsEnabled && isMarkupField(labelItem);
const isMarkdownLabel = isMarkdownField(labelItem);
const isMarkupLabel = isMarkupField(labelItem);

const segmentField = segments[0];
const segmentIndexInOrder = getSegmentsIndexInOrder(order, segmentField, idToTitle);
Expand Down Expand Up @@ -257,7 +253,7 @@ export function prepareBarX(args: PrepareFunctionArgs) {
segmentIndexInOrder,
layers: shared.visualization?.layers,
colorMode,
convertMarkupToString: !isMarkupLabelsEnabled,
convertMarkupToString: false,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
import {
AxisMode,
AxisNullsMode,
Feature,
getActualAxisModeForField,
getFakeTitleOrTitle,
isDateField,
Expand Down Expand Up @@ -57,13 +56,10 @@ export function prepareBarYData({
layerChartMeta,
usedColors,
disableDefaultSorting = false,
features,
}: PrepareFunctionArgs) {
const {data, order} = resultData;
const widgetConfig = ChartEditor.getWidgetConfig();
const isActionParamsEnable = widgetConfig?.actionParams?.enable;
const isMarkdownFieldsEnabled = features[Feature.WizardMarkdownFields];
const isMarkupLabelsEnabled = features[Feature.MarkupInLabels];

const xPlaceholder = placeholders[0];
const x: ServerField | undefined = placeholders[0].items[0];
Expand Down Expand Up @@ -111,8 +107,8 @@ export function prepareBarYData({
isGradientMode({colorField: colorItem, colorFieldDataType, colorsConfig});

const labelItem = labels?.[0];
const isMarkdownLabel = isMarkdownFieldsEnabled && isMarkdownField(labelItem);
const isMarkupLabel = isMarkupLabelsEnabled && isMarkupField(labelItem);
const isMarkdownLabel = isMarkdownField(labelItem);
const isMarkupLabel = isMarkupField(labelItem);

const isColorItemExist = Boolean(colorItem && colorItem.type !== 'PSEUDO');
const isColorizeByMeasure = isMeasureField(colorItem);
Expand Down Expand Up @@ -239,7 +235,7 @@ export function prepareBarYData({
segmentIndexInOrder: -1,
layers: shared.visualization?.layers,
colorMode,
convertMarkupToString: !isMarkupLabelsEnabled,
convertMarkupToString: false,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export const linesColoredByFieldWithPostfixResult = {
{x: 1, y: 844, dataLabels: {enabled: false}, label: ''},
{x: 2, y: 429, dataLabels: {enabled: false}, label: ''},
],
dataLabels: {enabled: false},
dataLabels: {enabled: false, useHTML: false},
legendTitle: '2 014 г. в.',
drillDownFilterValue: '2014',
colorGuid: 'd0ab8220-16e9-4320-b6da-1ca12163d956',
Expand All @@ -415,7 +415,7 @@ export const linesColoredByFieldWithPostfixResult = {
{x: 1, y: 2789, dataLabels: {enabled: false}, label: ''},
{x: 2, y: 9667, dataLabels: {enabled: false}, label: ''},
],
dataLabels: {enabled: false},
dataLabels: {enabled: false, useHTML: false},
legendTitle: '2 015 г. в.',
drillDownFilterValue: '2015',
colorGuid: 'd0ab8220-16e9-4320-b6da-1ca12163d956',
Expand All @@ -438,7 +438,7 @@ export const linesColoredByFieldWithPostfixResult = {
{x: 1, y: 4969, dataLabels: {enabled: false}, label: ''},
{x: 2, y: 3535, dataLabels: {enabled: false}, label: ''},
],
dataLabels: {enabled: false},
dataLabels: {enabled: false, useHTML: false},
legendTitle: '2 016 г. в.',
drillDownFilterValue: '2016',
colorGuid: 'd0ab8220-16e9-4320-b6da-1ca12163d956',
Expand All @@ -461,7 +461,7 @@ export const linesColoredByFieldWithPostfixResult = {
{x: 1, y: 1564, dataLabels: {enabled: false}, label: ''},
{x: 2, y: 14646, dataLabels: {enabled: false}, label: ''},
],
dataLabels: {enabled: false},
dataLabels: {enabled: false, useHTML: false},
legendTitle: '2 017 г. в.',
drillDownFilterValue: '2017',
colorGuid: 'd0ab8220-16e9-4320-b6da-1ca12163d956',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {Field, HighchartsSeriesCustomObject} from '../../../../../../../sha
import {
AxisMode,
AxisNullsMode,
Feature,
PlaceholderId,
WizardVisualizationId,
getActualAxisModeForField,
Expand Down Expand Up @@ -62,12 +61,9 @@ export function prepareLineData(args: PrepareFunctionArgs) {
layerChartMeta,
usedColors,
disableDefaultSorting = false,
features,
} = args;
const widgetConfig = ChartEditor.getWidgetConfig();
const isActionParamsEnable = widgetConfig?.actionParams?.enable;
const isMarkdownFieldsEnabled = features[Feature.WizardMarkdownFields];
const isMarkupLabelsEnabled = features[Feature.MarkupInLabels];

const xPlaceholder = placeholders.find((p) => p.id === PlaceholderId.X);
const xField = xPlaceholder?.items[0];
Expand Down Expand Up @@ -116,8 +112,8 @@ export function prepareLineData(args: PrepareFunctionArgs) {

const labelItem = labels?.[0];
const labelsLength = labels && labels.length;
const isMarkdownLabel = isMarkdownFieldsEnabled && isMarkdownField(labelItem);
const isMarkupLabel = isMarkupLabelsEnabled && isMarkupField(labelItem);
const isMarkdownLabel = isMarkdownField(labelItem);
const isMarkupLabel = isMarkupField(labelItem);

const segmentField = segments[0];
const segmentIndexInOrder = getSegmentsIndexInOrder(order, segmentField, idToTitle);
Expand Down Expand Up @@ -263,7 +259,7 @@ export function prepareLineData(args: PrepareFunctionArgs) {
segmentIndexInOrder,
layers: shared.visualization?.layers,
colorMode,
convertMarkupToString: !isMarkupLabelsEnabled,
convertMarkupToString: false,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export const piePrepareForQLResult = {
name: 'iznos',
pointConflict: true,
tooltip: {chartKitFormatting: true, chartKitPrecision: 2},
dataLabels: {chartKitFormatting: true, chartKitPrecision: 0},
dataLabels: {chartKitFormatting: true, chartKitPrecision: 0, useHTML: false},
data: [
{
name: 'Кирпич',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {ExtendedSeriesLineOptions} from '../../../../../../../shared';
import {
DATASET_FIELD_TYPES,
Feature,
MINIMUM_FRACTION_DIGITS,
PlaceholderId,
getDistinctValue,
Expand Down Expand Up @@ -97,12 +96,9 @@ export function preparePieData(args: PrepareFunctionArgs) {
ChartEditor,
disableDefaultSorting = false,
shared,
features,
} = args;
const {data, order, totals} = resultData;
const widgetConfig = ChartEditor.getWidgetConfig();
const isMarkdownFieldsEnabled = features[Feature.WizardMarkdownFields];
const isMarkupLabelsEnabled = features[Feature.MarkupInLabels];

const measure = placeholders.find((p) => p.id === PlaceholderId.Measures)?.items[0];
let colorField = placeholders.find((p) => p.id === PlaceholderId.Colors)?.items[0];
Expand Down Expand Up @@ -131,8 +127,8 @@ export function preparePieData(args: PrepareFunctionArgs) {
const labelIndex = labelField
? findIndexInOrder(order, labelField, idToTitle[labelField.guid])
: -1;
const isMarkdownLabel = isMarkdownFieldsEnabled && isMarkdownField(labelItem);
const isMarkupLabel = isMarkupLabelsEnabled && isMarkupField(labelItem);
const isMarkdownLabel = isMarkdownField(labelItem);
const isMarkupLabel = isMarkupField(labelItem);

const measureIndex = findIndexInOrder(order, measure, idToTitle[measure.guid]);
const measureDataType = idToDataType[measure.guid] || measure.data_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export function prepareScatter(options: PrepareFunctionArgs): PrepareScatterResu
features,
shared,
} = options;
const isMarkdownFieldsEnabled = features[Feature.WizardMarkdownFields];
const widgetConfig = ChartEditor.getWidgetConfig();
const isActionParamsEnable = widgetConfig?.actionParams?.enable;
const {data, order} = resultData;
Expand Down Expand Up @@ -183,7 +182,7 @@ export function prepareScatter(options: PrepareFunctionArgs): PrepareScatterResu
});
} else {
let value: string | WrappedMarkdown = xValue as string;
if (isMarkdownField(x) && isMarkdownFieldsEnabled) {
if (isMarkdownField(x)) {
value = wrapMarkdownValue(value);
} else if (shouldEscapeUserValue) {
value = escape(value);
Expand Down Expand Up @@ -237,7 +236,7 @@ export function prepareScatter(options: PrepareFunctionArgs): PrepareScatterResu
} else {
let yLabel: string | WrappedMarkdown =
yValue && shouldEscapeUserValue ? escape(yValue as string) : (yValue as string);
if (isMarkdownField(x) && isMarkdownFieldsEnabled) {
if (isMarkdownField(x)) {
yLabel = wrapMarkdownValue(String(yLabel));
}

Expand Down Expand Up @@ -272,7 +271,7 @@ export function prepareScatter(options: PrepareFunctionArgs): PrepareScatterResu
}

if (isStringField(z)) {
if (isMarkdownField(z) && isMarkdownFieldsEnabled) {
if (isMarkdownField(z)) {
formattedZValue = wrapMarkdownValue(zValueRaw as string);
} else if (shouldEscapeUserValue) {
formattedZValue = escape(formattedZValue as string);
Expand Down Expand Up @@ -315,7 +314,7 @@ export function prepareScatter(options: PrepareFunctionArgs): PrepareScatterResu
const colorValue =
values[i] && shouldEscapeUserValue ? escape(String(values[i])) : values[i];
let colorLabel: string | null | WrappedMarkdown = colorValue;
if (isMarkdownField(color) && isMarkdownFieldsEnabled) {
if (isMarkdownField(color)) {
colorLabel = wrapMarkdownValue(String(colorValue));
}

Expand Down Expand Up @@ -352,7 +351,7 @@ export function prepareScatter(options: PrepareFunctionArgs): PrepareScatterResu
const i = findIndexInOrder(order, shape, cTitle);
const shapeValue = escape(values[i] as string) || '';
let shapeLabel: WrappedMarkdown | string = shapeValue;
if (isMarkdownField(shape) && isMarkdownFieldsEnabled) {
if (isMarkdownField(shape)) {
shapeLabel = wrapMarkdownValue(String(shapeValue));
}

Expand Down Expand Up @@ -410,7 +409,7 @@ export function prepareScatter(options: PrepareFunctionArgs): PrepareScatterResu
});
}

if ((isMarkdownField(color) || isMarkdownField(shape)) && isMarkdownFieldsEnabled) {
if (isMarkdownField(color) || isMarkdownField(shape)) {
graphs.forEach((g) => {
g.name = wrapMarkdownValue(g.name as string);
});
Expand All @@ -421,13 +420,13 @@ export function prepareScatter(options: PrepareFunctionArgs): PrepareScatterResu
if (!xIsNumber && !xIsDate) {
categories = xCategories;

if (isMarkdownField(x) && isMarkdownFieldsEnabled) {
if (isMarkdownField(x)) {
categories = categories?.map((c) => wrapMarkdownValue(c as string));
}
}

const hasMarkdown = [x, y, z, size, color, shape].some((field) => isMarkdownField(field));
if (isMarkdownFieldsEnabled && hasMarkdown) {
if (hasMarkdown) {
ChartEditor.updateConfig({useMarkdown: true});
}

Expand Down
8 changes: 2 additions & 6 deletions src/server/modes/charts/plugins/datalens/preparers/treemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ function prepareTreemap({
features,
ChartEditor,
}: PrepareFunctionArgs) {
const isMarkdownFieldsEnabled = features[Feature.WizardMarkdownFields];
// Dimensions
const d = placeholders[0].items;
const dTypes = d.map((item) => item.data_type);
const useMarkdown = isMarkdownFieldsEnabled && d?.some(isMarkdownField);
const useMarkdown = d?.some(isMarkdownField);

// Measures
const m = placeholders[1].items;
Expand Down Expand Up @@ -141,10 +140,7 @@ function prepareTreemap({
const treemapId =
dPath.length >= 1 ? `id_${dPath[0]}/${value}` : `id_${dPath.join()}${value}`;

const name =
isMarkdownField(item) && isMarkdownFieldsEnabled
? wrapMarkdownValue(value as string)
: value;
const name = isMarkdownField(item) ? wrapMarkdownValue(value as string) : value;

const treemapItem: TreemapItem = {
id: treemapId,
Expand Down
4 changes: 0 additions & 4 deletions src/shared/types/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,8 @@ export enum Feature {
NewSandbox_75p = 'NewSandbox_75p',
NewSandbox_100p = 'NewSandbox_100p',
SandboxEngineSelectSwitch = 'SandboxEngineSelectSwitch',
/** Allow markdown in chart fields. */
WizardMarkdownFields = 'WizardMarkdownFields',
EnableEmbedsInDialogShare = 'EnableEmbedsInDialogShare',
EnableEntryMenuItemShare = 'EnableEntryMenuItemShare',
/** Render markup in chart dataLabels. */
MarkupInLabels = 'MarkupInLabels',
}

export type FeatureConfig = Record<string, boolean>;
11 changes: 2 additions & 9 deletions src/ui/constants/visualizations/pie.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {BucketPaint, ChartPie, LayoutColumns3} from '@gravity-ui/icons';
import type {Field, GraphShared, Placeholder} from 'shared';
import {Feature, PlaceholderId, WizardVisualizationId, isMarkupField} from 'shared';
import {PlaceholderId, WizardVisualizationId} from 'shared';
import {prepareFieldToMeasureTransformation} from 'units/wizard/utils/visualization';

import Utils from '../../utils/utils';
import {ITEM_TYPES, PRIMITIVE_DATA_TYPES, PRIMITIVE_DATA_TYPES_AND_HIERARCHY} from '../misc';

import {prepareFieldToDimensionTransformation} from './utils';
Expand All @@ -28,13 +27,7 @@ export const PIE_VISUALIZATION: GraphShared['visualization'] = {

return selectedItems.some((selectedItem) => selectedItem.guid === item.guid);
},
checkAllowedLabels: (item: Field) => {
if (isMarkupField(item)) {
return Utils.isEnabledFeature(Feature.MarkupInLabels);
}

return ITEM_TYPES.ALL.has(item.type);
},
checkAllowedLabels: (item: Field) => ITEM_TYPES.ALL.has(item.type),
availableLabelModes: ['absolute', 'percent'],
placeholders: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@ import type {
Placeholder,
TableFieldBackgroundSettings,
} from 'shared';
import {
Feature,
PlaceholderId,
WizardVisualizationId,
getDefaultFormatting,
isPseudoField,
} from 'shared';
import {PlaceholderId, WizardVisualizationId, getDefaultFormatting, isPseudoField} from 'shared';
import type {TableSubTotalsSettings} from 'shared/types/wizard/sub-totals';
import {setExtraSettings} from 'ui/units/wizard/actions/widget';
import {
getDefaultSubTotalsSettings,
isSubTotalsAvailableInDialogField,
} from 'ui/units/wizard/components/Dialogs/DialogField/utils/subTotals';
import Utils from 'ui/utils';
import type {Optional} from 'utility-types';

import type {
Expand Down Expand Up @@ -468,7 +461,6 @@ class DialogField extends React.PureComponent<DialogFieldInnerProps, DialogField
private renderMarkdownSettings() {
const {item, placeholderId, visualization} = this.props;
const canTransformToMarkdown =
Utils.isEnabledFeature(Feature.WizardMarkdownFields) &&
item?.data_type === DATASET_FIELD_TYPES.STRING &&
canUseStringAsMarkdown(visualization.id as WizardVisualizationId, placeholderId);

Expand Down
Loading
Loading