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

Html in the Wizard (for string fields) #1868

Merged
merged 13 commits into from
Dec 9, 2024
4 changes: 3 additions & 1 deletion src/i18n-keysets/wizard/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
"label_holidays": "Holidays on the chart",
"label_horizontal": "Horizontal",
"label_hour": "Hour",
"label_html": "HTML",
"label_ignore": "Ignore",
"label_integer": "Integer",
"label_invalid-name": "The chart with the specified name already exists",
Expand All @@ -193,8 +194,9 @@
"label_logarithmic": "Logarithmic",
"label_manual": "Manual",
"label_markdown": "Markdown",
"label_markdown-tooltip": "The field value will be formatted according to the Markdown language",
"label_markup": "Markup",
"label_markup-type": "Markup type",
"label_markup-type-tooltip": "The field value will be formatted according to the selected markup language",
"label_max": "Maximum",
"label_message-link-copied": "Link copied",
"label_min": "Minimum",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n-keysets/wizard/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
"label_holidays": "Выходные на графике",
"label_horizontal": "Горизонтальные",
"label_hour": "Час",
"label_html": "HTML",
"label_ignore": "Не отображать",
"label_integer": "Целое число",
"label_invalid-name": "Чарт с таким именем уже сущестует",
Expand All @@ -193,8 +194,9 @@
"label_logarithmic": "Логарифмическая",
"label_manual": "Вручную",
"label_markdown": "Markdown",
"label_markdown-tooltip": "Значение поля будет отформатировано в соответствии с разметкой Markdown",
"label_markup": "Разметка",
"label_markup-type": "Разметка",
"label_markup-type-tooltip": "Значение поля будет отформатировано в соответствии с выбранным языком разметки",
"label_max": "Максимум",
"label_message-link-copied": "Ссылка скопирована",
"label_min": "Минимум",
Expand Down
10 changes: 10 additions & 0 deletions src/server/components/features/features-list/HtmlInWizard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {Feature} from '../../../../shared';
import {createFeatureConfig} from '../utils';

export default createFeatureConfig({
name: Feature.HtmlInWizard,
state: {
development: false,
production: false,
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getXAxisMode,
isDateField,
isDimensionField,
isHtmlField,
isMarkdownField,
isMarkupField,
isMeasureField,
Expand Down Expand Up @@ -114,6 +115,7 @@ export function prepareBarX(args: PrepareFunctionArgs) {
const labelsLength = labels && labels.length;
const isMarkdownLabel = isMarkdownField(labelItem);
const isMarkupLabel = isMarkupField(labelItem);
const isHtmlLabel = isHtmlField(labelItem);

const segmentField = segments[0];
const segmentIndexInOrder = getSegmentsIndexInOrder(order, segmentField, idToTitle);
Expand Down Expand Up @@ -332,7 +334,10 @@ export function prepareBarX(args: PrepareFunctionArgs) {
id: line.id,
title: line.title || 'Null',
tooltip: line.tooltip,
dataLabels: {...line.dataLabels, useHTML: isMarkdownLabel || isMarkupLabel},
dataLabels: {
...line.dataLabels,
useHTML: isMarkdownLabel || isMarkupLabel || isHtmlLabel,
},
data: categories
.map((category, i) => {
const lineData = line.data[category];
Expand Down Expand Up @@ -385,6 +390,7 @@ export function prepareBarX(args: PrepareFunctionArgs) {
point.label = getLabelValue(innerLabels?.[category], {
isMarkdownLabel,
isMarkupLabel,
isHtmlLabel,
});

if (isActionParamsEnable) {
Expand Down Expand Up @@ -485,6 +491,10 @@ export function prepareBarX(args: PrepareFunctionArgs) {
ChartEditor.updateConfig({useMarkup: true});
}

if (isHtmlLabel) {
ChartEditor.updateConfig({useHtml: true});
}

if (isXCategoryAxis) {
return {
graphs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getFakeTitleOrTitle,
getXAxisMode,
isDateField,
isHtmlField,
isMarkdownField,
isMarkupField,
isMeasureField,
Expand Down Expand Up @@ -99,6 +100,7 @@ export function prepareBarYData({
const labelItem = labels?.[0];
const isMarkdownLabel = isMarkdownField(labelItem);
const isMarkupLabel = isMarkupField(labelItem);
const isHtmlLabel = isHtmlField(labelItem);

const isColorItemExist = Boolean(colorItem && colorItem.type !== 'PSEUDO');
const isColorizeByMeasure = isMeasureField(colorItem);
Expand Down Expand Up @@ -312,7 +314,7 @@ export function prepareBarYData({
dataLabels: {
enabled: Boolean(labelItem),
...line.dataLabels,
useHTML: isMarkdownLabel || isMarkupLabel,
useHTML: isMarkdownLabel || isMarkupLabel || isHtmlLabel,
},
data: categories
.map((category, i) => {
Expand Down Expand Up @@ -353,6 +355,7 @@ export function prepareBarYData({
point.label = getLabelValue(innerLabels?.[category], {
isMarkdownLabel,
isMarkupLabel,
isHtmlLabel,
});

if (isActionParamsEnable) {
Expand Down Expand Up @@ -448,6 +451,10 @@ export function prepareBarYData({
ChartEditor.updateConfig({useMarkup: true});
}

if (isHtmlLabel) {
ChartEditor.updateConfig({useHtml: true});
}

if (isXCategoryAxis) {
return {
graphs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
} from '../../../../../../../shared';
import {
Feature,
MARKUP_TYPE,
MINIMUM_FRACTION_DIGITS,
WRAPPED_MARKDOWN_KEY,
getFakeTitleOrTitle,
Expand Down Expand Up @@ -335,7 +336,7 @@ function prepareGeopoint(options: PrepareFunctionArgs, {isClusteredPoints = fals
);
const text = itemTitle ? `${itemTitle}: ${value}` : value;

if (tooltipField?.isMarkdown) {
if (tooltipField?.markupType === MARKUP_TYPE.markdown) {
pointData[WRAPPED_MARKDOWN_KEY] = text;
} else {
pointData.text = shouldEscapeUserValue ? escape(text) : text;
Expand Down Expand Up @@ -369,10 +370,14 @@ function prepareGeopoint(options: PrepareFunctionArgs, {isClusteredPoints = fals
});
});

if (tooltips.some((item) => item.isMarkdown)) {
if (tooltips.some((item) => item.markupType === MARKUP_TYPE.markdown)) {
ChartEditor.updateConfig({useMarkdown: true});
}

if (tooltips.some((item) => item.markupType === MARKUP_TYPE.html)) {
ChartEditor.updateConfig({useHtml: true});
}

let mapOptions: GeopointMapOptions = {
opacity: ALPHA,
showCustomLegend: true,
Expand Down
14 changes: 12 additions & 2 deletions src/server/modes/charts/plugins/datalens/preparers/geopolygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import type {
} from '../../../../../../shared';
import {
DATASET_FIELD_TYPES,
MARKUP_TYPE,
MINIMUM_FRACTION_DIGITS,
WRAPPED_MARKDOWN_KEY,
getFakeTitleOrTitle,
isHtmlField,
isMarkdownField,
} from '../../../../../../shared';
import {wrapHtml} from '../../../../../../shared/utils/ui-sandbox';
import {hexToRgb} from '../utils/color-helpers';
import {GEO_MAP_LAYERS_LEVEL} from '../utils/constants';
import type {Coordinate} from '../utils/geo-helpers';
Expand Down Expand Up @@ -241,16 +244,23 @@ function prepareGeopolygon(options: PrepareFunctionArgs) {
const itemTitle = shouldUseFieldTitle ? getFakeTitleOrTitle(tooltip as ServerField) : '';
const tooltipText = itemTitle ? `${itemTitle}: ${formattedText}` : formattedText;
const isMarkupField = tooltip?.data_type === DATASET_FIELD_TYPES.MARKUP;
const useHtml = isHtmlField(tooltip);

if (isMarkupField || isMarkdownField(tooltip)) {
if (isMarkupField || isMarkdownField(tooltip) || useHtml) {
polygon.properties.rawText = true;
}

if (useHtml) {
ChartEditor.updateConfig({useHtml: true});
}

let tooltipData;
if (isMarkupField) {
tooltipData = {key: itemTitle, value: formattedText};
} else if (tooltip?.isMarkdown) {
} else if (tooltip?.markupType === MARKUP_TYPE.markdown) {
tooltipData = {[WRAPPED_MARKDOWN_KEY]: tooltipText};
} else if (tooltip?.markupType === MARKUP_TYPE.html) {
tooltipData = {text: wrapHtml(tooltipText)};
} else {
tooltipData = {text: tooltipText};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getFakeTitleOrTitle,
getXAxisMode,
isDateField,
isHtmlField,
isMarkdownField,
isMarkupField,
isMeasureField,
Expand Down Expand Up @@ -109,6 +110,7 @@ export function prepareLineData(args: PrepareFunctionArgs) {
const labelsLength = labels && labels.length;
const isMarkdownLabel = isMarkdownField(labelItem);
const isMarkupLabel = isMarkupField(labelItem);
const isHtmlLabel = isHtmlField(labelItem);

const segmentField = segments[0];
const segmentIndexInOrder = getSegmentsIndexInOrder(order, segmentField, idToTitle);
Expand Down Expand Up @@ -345,7 +347,10 @@ export function prepareLineData(args: PrepareFunctionArgs) {
id: line.id,
title: line.title || 'Null',
tooltip: line.tooltip,
dataLabels: {...line.dataLabels, useHTML: isMarkdownLabel || isMarkupLabel},
dataLabels: {
...line.dataLabels,
useHTML: isMarkdownLabel || isMarkupLabel || isHtmlLabel,
},
data: categories
.map((category, i) => {
const lineData = line.data[category];
Expand Down Expand Up @@ -415,6 +420,7 @@ export function prepareLineData(args: PrepareFunctionArgs) {
point.label = getLabelValue(innerLabels?.[category], {
isMarkdownLabel,
isMarkupLabel,
isHtmlLabel,
});

if (isActionParamsEnable) {
Expand Down Expand Up @@ -532,6 +538,10 @@ export function prepareLineData(args: PrepareFunctionArgs) {
ChartEditor.updateConfig({useMarkup: true});
}

if (isHtmlLabel) {
ChartEditor.updateConfig({useHtml: true});
}

if (isXCategoryAxis) {
return {
graphs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getDistinctValue,
getFakeTitleOrTitle,
isFieldHierarchy,
isHtmlField,
isMarkdownField,
isMarkupField,
isMeasureValue,
Expand All @@ -14,6 +15,7 @@ import {
wrapMarkupValue,
} from '../../../../../../../shared';
import {wrapMarkdownValue} from '../../../../../../../shared/utils/markdown';
import {wrapHtml} from '../../../../../../../shared/utils/ui-sandbox';
import type {ChartColorsConfig} from '../../types';
import type {ColorValue} from '../../utils/color-helpers';
import {getColorsByMeasureField, getThresholdValues} from '../../utils/color-helpers';
Expand Down Expand Up @@ -129,6 +131,7 @@ export function preparePieData(args: PrepareFunctionArgs) {
: -1;
const isMarkdownLabel = isMarkdownField(labelItem);
const isMarkupLabel = isMarkupField(labelItem);
const isHtmlLabel = isHtmlField(labelItem);

const measureIndex = findIndexInOrder(order, measure, idToTitle[measure.guid]);
const measureDataType = idToDataType[measure.guid] || measure.data_type;
Expand Down Expand Up @@ -183,7 +186,7 @@ export function preparePieData(args: PrepareFunctionArgs) {
? MINIMUM_FRACTION_DIGITS
: 0,
}),
useHTML: isMarkdownLabel || isMarkupLabel,
useHTML: (isMarkdownLabel || isMarkupLabel || isHtmlLabel) ?? undefined,
},
};

Expand Down Expand Up @@ -248,6 +251,8 @@ export function preparePieData(args: PrepareFunctionArgs) {
point.label = wrapMarkdownValue(labelValue);
} else if (labelValue && isMarkupLabel) {
point.label = wrapMarkupValue(labelValue);
} else if (labelValue && isHtmlLabel) {
point.label = wrapHtml(labelValue);
} else {
point.label = getFormattedValue(labelValue, {
...labelField,
Expand Down Expand Up @@ -302,6 +307,10 @@ export function preparePieData(args: PrepareFunctionArgs) {
ChartEditor.updateConfig({useMarkup: true});
}

if (isHtmlLabel) {
ChartEditor.updateConfig({useHtml: true});
}

return {graphs: [pie], totals: totals.find((value) => value), label: labelField, measure};
}

Expand Down
Loading
Loading