Skip to content

Commit

Permalink
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Browse files Browse the repository at this point in the history
…TS-9786_no_create_permissions_dialog_2
  • Loading branch information
sjorobekov committed Dec 20, 2024
2 parents 218ab11 + 69b954c commit f43618c
Show file tree
Hide file tree
Showing 38 changed files with 840 additions and 443 deletions.
4 changes: 4 additions & 0 deletions src/@types/nodekit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ export interface SharedAppContextParams {
) => Promise<ResolveEntryByLinkComponentResponse>;
};

sources: {
reqBody: Request['body'];
};

getAppLayoutSettings: (req: Request, res: Response, name?: string) => AppLayoutSettings;
landingPageSettings?: LandingPageSettings;

Expand Down
3 changes: 2 additions & 1 deletion src/i18n-keysets/dash.widget-dialog.edit/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
"button_params-setup": "Configure",
"button_save": "Save",
"context_autoheight-availability-hint": "Available only for charts with \"Table\" and \"Markdown\" types",
"context_fill-description": "Enter description",
"context_fill-title": "Enter title",
"context_filtering-other-charts": "This option enables you to apply filtering from this chart to other charts on the dashboard",
"context_filtering-usage-limitations": "<link>More about filtration</link>",
"context_hint-display-info": "The hint appears in the widget title if the title is enabled",
"field_autoheight": "Auto height",
"field_background": "Background",
"field_background-enable": "Enable",
"field_description": "Description",
"field_enable-filtering-other-charts": "Enable",
"field_hint": "Hint",
"field_param-name": "Name",
"field_param-value": "Value",
"field_params": "Parameters",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n-keysets/dash.widget-dialog.edit/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
"button_params-setup": "Настроить",
"button_save": "Сохранить",
"context_autoheight-availability-hint": "Доступно для чартов типа \"Таблица\" и \"Markdown\"",
"context_fill-description": "Введите описание",
"context_fill-title": "Введите заголовок",
"context_filtering-other-charts": "Опция позволяет применить фильтрацию из этого чарта к другим чартам на дашборде",
"context_filtering-usage-limitations": "<link>Подробнее о фильтрации</link>",
"context_hint-display-info": "Подсказка показывается в заголовке виджета, если он включён",
"field_autoheight": "Автовысота",
"field_background": "Фон",
"field_background-enable": "Включить",
"field_description": "Описание",
"field_enable-filtering-other-charts": "Включить",
"field_hint": "Подсказка",
"field_param-name": "Имя",
"field_param-value": "Значение",
"field_params": "Параметры",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,15 +646,6 @@ export class DataFetcher {
userTargetUriUi = sourceConfig.uiEndpoint + croppedTargetUri;
}

if (sourceConfig.adapter) {
return sourceConfig.adapter({
targetUri: croppedTargetUri,
sourceName,
req,
ctx,
});
}

if (sourceConfig.adapterWithContext) {
return sourceConfig.adapterWithContext({
targetUri: croppedTargetUri,
Expand All @@ -675,7 +666,9 @@ export class DataFetcher {
if (sourceType === 'charts') {
const incomingHeader = originalReqHeaders.xChartsFetcherVia || '';

const scriptName = req.body.params ? '/editor/' + req.body.params.name : req.body.path;
const {reqBody} = ctx.get('sources');

const scriptName = reqBody.params ? '/editor/' + reqBody.params.name : reqBody.path;

if (incomingHeader && !Array.isArray(incomingHeader)) {
const circular = incomingHeader.split(',').some((someScriptName) => {
Expand Down Expand Up @@ -733,7 +726,7 @@ export class DataFetcher {

const sourceAuthorizationHeaders = getSourceAuthorizationHeaders({
req,
chartsEngine,
ctx,
sourceConfig,
subrequestHeaders,
});
Expand Down
15 changes: 0 additions & 15 deletions src/server/components/charts-engine/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,6 @@ export type SourceConfig = {
preprocess?: (url: string) => string;
allowedMethods?: ('GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE')[];

/**
* @deprecated
**/
adapter?: ({
targetUri,
sourceName,
req,
ctx,
}: {
targetUri: string;
sourceName: string;
req: Request;
ctx: AppContext;
}) => unknown;

adapterWithContext?: ({
targetUri,
sourceName,
Expand Down
6 changes: 3 additions & 3 deletions src/server/registry/units/common/functions-map.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type {Request, Response} from '@gravity-ui/expresskit';
import type {AppContext} from '@gravity-ui/nodekit';

import type {Palette} from '../../../../shared/constants/colors';
import type {GetEntryByKeyResponse} from '../../../../shared/schema';
import {makeFunctionTemplate} from '../../../../shared/utils/makeFunctionTemplate';
import type {ChartsEngine} from '../../../components/charts-engine';
import type {SourceConfig} from '../../../components/charts-engine/types';

export const commonFunctionsMap = {
getAvailablePalettesMap: makeFunctionTemplate<() => Record<string, Palette>>(),
getSourceAuthorizationHeaders:
makeFunctionTemplate<
(args: {
chartsEngine: ChartsEngine;
req: Request;
req?: Request;
ctx: AppContext;
sourceConfig: SourceConfig;
subrequestHeaders: Record<string, string>;
}) => Record<string, string>
Expand Down
3 changes: 3 additions & 0 deletions src/shared/types/dash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ export interface DashTabItemWidgetTab {
id: string;
title: string;
description: string;
hint?: string;
enableHint?: boolean;
enableDescription?: boolean;
chartId: string;
isDefault: boolean;
params: StringParams;
Expand Down
4 changes: 4 additions & 0 deletions src/ui/components/DashKit/plugins/Widget/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export type CurrentTab = {
id: string;
title: string;
description: string;
displayedTitle?: string | React.ReactNode;
hint?: string;
enableHint?: boolean;
enableDescription?: boolean;
chartId: string;
isDefault: boolean;
params: StringParams;
Expand Down
8 changes: 8 additions & 0 deletions src/ui/components/DialogChartWidget/DialogChartWidget.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
margin-bottom: var(--g-spacing-2);
}

&__settings-container {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 5px;
gap: 8px;
}

&__checkbox {
margin-block-start: var(--g-spacing-2);
}
Expand Down
138 changes: 98 additions & 40 deletions src/ui/components/DialogChartWidget/DialogChartWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import {FormRow, HelpPopover} from '@gravity-ui/components';
import {Checkbox, Dialog, Flex, Link, Popup, Text, TextArea, TextInput} from '@gravity-ui/uikit';
import {Checkbox, Dialog, Flex, Link, Popup, Text, TextInput} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';
import {i18n} from 'i18n';
import type {CustomCommands, Spec} from 'immutability-helper';
Expand All @@ -21,6 +21,7 @@ import {Collapse} from 'ui/components/Collapse/Collapse';
import {Interpolate} from 'ui/components/Interpolate';
import {DL} from 'ui/constants/common';

import {registry} from '../../registry';
import NavigationInput from '../../units/dash/components/NavigationInput/NavigationInput';
import {ParamsSettings} from '../../units/dash/components/ParamsSettings/ParamsSettings';
import {
Expand Down Expand Up @@ -111,6 +112,7 @@ const INPUT_FILTERING_ID = 'chartFilteringField';
const INPUT_NAME_ID = 'chartNameField';
const INPUT_DESCRIPTION_ID = 'chartDescriptionField';
const INPUT_AUTOHEIGHT_ID = 'chartAutoheightField';
const INPUT_HINT_ID = 'chartHintField';

// TODO: put in defaultPath navigation key from entry
class DialogChartWidget extends React.PureComponent<
Expand All @@ -133,6 +135,9 @@ class DialogChartWidget extends React.PureComponent<
background: {
color: 'transparent',
},
enableHint: false,
hint: '',
enableDescription: false,
},
],
} as DashTabItemWidget['data'],
Expand Down Expand Up @@ -214,6 +219,19 @@ class DialogChartWidget extends React.PureComponent<
return Boolean(this.props.openedItemId);
}

handleUpdateField = (field: keyof DashTabItemWidgetTab, value: string | boolean) => {
const {data, tabIndex} = this.state;
this.setState({
data: update(data, {
tabs: {
[tabIndex]: {
[field]: {$set: value},
},
},
}),
});
};

onApply = () => {
const isValidateParamTitle = Utils.isEnabledFeature(
Feature.DashBoardWidgetParamsStrictValidation,
Expand Down Expand Up @@ -342,16 +360,25 @@ class DialogChartWidget extends React.PureComponent<
};

onAutoHeightRadioButtonChange = () => {
const {data, tabIndex} = this.state;
const currentCondition = this.state.data.tabs[tabIndex].autoHeight;
const currentCondition = this.state.data.tabs[this.state.tabIndex].autoHeight;

this.setState({
data: update(data, {
tabs: {
[tabIndex]: {autoHeight: {$set: !currentCondition}},
},
}),
});
this.handleUpdateField('autoHeight', !currentCondition);
};

handleUpdateEnableDesc = (val: boolean) => {
this.handleUpdateField('enableDescription', val);
};

handleUpdateEnableHint = (val: boolean) => {
this.handleUpdateField('enableHint', val);
};

handleUpdateDescription = (val: string) => {
this.handleUpdateField('description', val);
};

handleUpdateHint = (val: string) => {
this.handleUpdateField('hint', val);
};

handleBackgroundColorSelected = (color: string) => {
Expand All @@ -371,16 +398,8 @@ class DialogChartWidget extends React.PureComponent<
};

handleChangeFiltering = () => {
const {data, tabIndex} = this.state;
const currentCondition = this.state.data.tabs[tabIndex].enableActionParams;

this.setState({
data: update(data, {
tabs: {
[tabIndex]: {enableActionParams: {$set: !currentCondition}},
},
}),
});
const currentCondition = this.state.data.tabs[this.state.tabIndex].enableActionParams;
this.handleUpdateField('enableActionParams', !currentCondition);
};

updateTabMenu = ({items, selectedItemIndex, action}: UpdateState<DashTabItemWidgetTab>) => {
Expand Down Expand Up @@ -564,7 +583,21 @@ class DialogChartWidget extends React.PureComponent<
/>
);

const {title, chartId, description, autoHeight, background} = data.tabs[tabIndex];
const {
title,
chartId,
description,
autoHeight,
background,
hint,
enableHint,
enableDescription,
} = data.tabs[tabIndex];

const hasDesc =
enableDescription === undefined ? Boolean(description) : Boolean(enableDescription);

const {MarkdownControl} = registry.common.components.getAll();

return (
<React.Fragment>
Expand Down Expand Up @@ -641,25 +674,50 @@ class DialogChartWidget extends React.PureComponent<
fieldId={INPUT_DESCRIPTION_ID}
label={i18n('dash.widget-dialog.edit', 'field_description')}
>
<TextArea
id={INPUT_DESCRIPTION_ID}
size="m"
className={b('textarea')}
value={description}
placeholder={i18n('dash.widget-dialog.edit', 'context_fill-description')}
onUpdate={(value) =>
this.setState({
data: update(data, {
tabs: {
[tabIndex]: {
description: {$set: value},
},
},
}),
})
}
rows={3}
/>
<div className={b('settings-container')}>
<Checkbox
onUpdate={this.handleUpdateEnableDesc}
checked={hasDesc}
size="m"
className={b('checkbox')}
/>
{hasDesc && (
<MarkdownControl
key={`md-desc-tab-${tabIndex}`}
value={description || ''}
onChange={this.handleUpdateDescription}
disabled={!enableDescription}
/>
)}
</div>
</FormRow>
<FormRow
className={b('row')}
fieldId={INPUT_HINT_ID}
label={i18n('dash.widget-dialog.edit', 'field_hint')}
labelHelpPopover={
<HelpPopover
className={b('help-tooltip')}
content={i18n('dash.widget-dialog.edit', 'context_hint-display-info')}
/>
}
>
<div className={b('settings-container')}>
<Checkbox
onUpdate={this.handleUpdateEnableHint}
checked={Boolean(enableHint)}
size="m"
className={b('checkbox')}
/>
{Boolean(enableHint) && (
<MarkdownControl
key={`md-hint-tab-${tabIndex}`}
value={hint || ''}
onChange={this.handleUpdateHint}
disabled={!enableHint}
/>
)}
</div>
</FormRow>
{enableAutoheight && (
<FormRow
Expand Down
Loading

0 comments on commit f43618c

Please sign in to comment.