Skip to content

Commit

Permalink
Support accent setting for selectors (#1925)
Browse files Browse the repository at this point in the history
Co-authored-by: datalens-weblate-robot <[email protected]>
Co-authored-by: Darya Tikhonova <[email protected]>
Co-authored-by: Matthew Casserly <[email protected]>
  • Loading branch information
4 people authored Dec 16, 2024
1 parent e5c259a commit 2d5e359
Show file tree
Hide file tree
Showing 20 changed files with 217 additions and 89 deletions.
2 changes: 2 additions & 0 deletions src/i18n-keysets/dash.control-dialog.edit/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"error_unsupported-connection": "Connection not supported",
"field_acceptable-values": "Possible values",
"field_autoheight": "Auto height",
"field_color-accent": "Color accent",
"field_color-accent-note": "Use this option to highlight important selectors",
"field_connection": "Connection",
"field_control": "Selector",
"field_dataset": "Dataset",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n-keysets/dash.control-dialog.edit/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"error_unsupported-connection": "Подключение не поддерживается",
"field_acceptable-values": "Возможные значения",
"field_autoheight": "Автовысота",
"field_color-accent": "Цветовой акцент",
"field_color-accent-note": "Используйте опцию для выделения цветом важных селекторов",
"field_connection": "Подключение",
"field_control": "Селектор",
"field_dataset": "Датасет",
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 @@ -231,6 +231,8 @@ export enum TitlePlacementOption {
Top = 'top',
}

export type AccentTypeValue = 'info' | null;

export interface DashTabItemControlElementBase {
showTitle: boolean;
titlePlacement?: TitlePlacementOption;
Expand All @@ -242,6 +244,7 @@ export interface DashTabItemControlElementBase {
required?: boolean;
showHint?: boolean;
hint?: string;
accentType?: AccentTypeValue;
}

export interface DashTabItemControlElementSelect extends DashTabItemControlElementBase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
.control2-appearance-section {
&__operation-container {
&__setting-container {
display: flex;
align-items: center;
min-height: var(--gc-form-row-field-height);
}

&__operation-checkbox {
&__setting-checkbox {
margin-right: 8px;

&_top {
align-self: flex-start;
margin-top: 4px;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react';

import {FormRow, HelpPopover} from '@gravity-ui/components';
import {Checkbox} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';
import {I18n} from 'i18n';
import {useDispatch, useSelector} from 'react-redux';
import {setSelectorDialogItem} from 'ui/store/actions/controlDialog';
import {
selectIsControlConfigurationDisabled,
selectSelectorDialog,
} from 'ui/store/selectors/controlDialog';

import '../../AppearanceSection.scss';

const b = block('control2-appearance-section');

const i18n = I18n.keyset('dash.control-dialog.edit');

export const ColorAccentRow = () => {
const dispatch = useDispatch();
const {accentType} = useSelector(selectSelectorDialog);
const isFieldDisabled = useSelector(selectIsControlConfigurationDisabled);

const handleaccentTypeUpdate = React.useCallback(
(enableAccent) => {
const updatedType = enableAccent ? 'info' : null;

dispatch(
setSelectorDialogItem({
accentType: updatedType,
}),
);
},
[dispatch],
);

const label = (
<React.Fragment>
<span>{i18n('field_color-accent')}</span>
<HelpPopover
placement={['bottom', 'top']}
offset={{top: -1, left: 5}}
content={i18n('field_color-accent-note')}
/>
</React.Fragment>
);

return (
<FormRow label={label}>
<div className={b('setting-container')}>
<Checkbox
disabled={isFieldDisabled}
onUpdate={handleaccentTypeUpdate}
checked={Boolean(accentType)}
size="l"
className={b('setting-checkbox')}
/>
</div>
</FormRow>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ export const HintRow = () => {

return (
<FormRow label={i18n('field_hint')}>
<div className={b('operation-container')}>
<div className={b('setting-container')}>
<Checkbox
disabled={isFieldDisabled}
onUpdate={handleUpdateEnable}
checked={showHint}
size="l"
className={b('operation-checkbox', {top: true})}
className={b('setting-checkbox')}
/>
{showHint && (
<MarkdownControl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {I18n} from 'i18n';
import {useDispatch, useSelector} from 'react-redux';
import {ControlQA, DashTabItemControlSourceType, DialogControlQa} from 'shared';
import {setSelectorDialogItem} from 'ui/store/actions/controlDialog';
import {ELEMENT_TYPE} from 'ui/store/constants/controlDialog';
import {
selectIsControlConfigurationDisabled,
selectSelectorDialog,
Expand All @@ -31,11 +30,10 @@ const getHelpPopoverText = (sourceType: SelectorSourceType | undefined): string

export const InnerTitleRow = () => {
const dispatch = useDispatch();
const {elementType, showInnerTitle, innerTitle, sourceType} = useSelector(selectSelectorDialog);
const {showInnerTitle, innerTitle, sourceType} = useSelector(selectSelectorDialog);
const isFieldDisabled = useSelector(selectIsControlConfigurationDisabled);

const isInnerTitleDisabled = elementType === ELEMENT_TYPE.CHECKBOX || isFieldDisabled;
const isInnerTitleActive = (elementType !== ELEMENT_TYPE.CHECKBOX && showInnerTitle) ?? false;
const isInnerTitleActive = showInnerTitle ?? false;

const handleShowInnerTitleUpdate = React.useCallback((showInnerTitle: boolean) => {
dispatch(
Expand Down Expand Up @@ -66,13 +64,10 @@ export const InnerTitleRow = () => {

return (
<FormRow label={label}>
<div
className={b('operation-container')}
data-qa={DialogControlQa.appearanceInnerTitle}
>
<div className={b('setting-container')} data-qa={DialogControlQa.appearanceInnerTitle}>
<Checkbox
className={b('operation-checkbox')}
disabled={isInnerTitleDisabled}
className={b('setting-checkbox')}
disabled={isFieldDisabled}
checked={isInnerTitleActive}
qa={ControlQA.showInnerTitleCheckbox}
onUpdate={handleShowInnerTitleUpdate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const TitlePlacementRow = () => {

return (
<FormRow label={i18n('label_title-placement')}>
<div className={b('operation-container')}>
<div className={b('setting-container')}>
<RadioButton
options={TITLE_PLACEMENT_OPTIONS}
value={titlePlacement}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export const TitleRow = () => {

return (
<FormRow label={i18n('field_title')}>
<div className={b('operation-container')} data-qa={DialogControlQa.appearanceTitle}>
<div className={b('setting-container')} data-qa={DialogControlQa.appearanceTitle}>
<Checkbox
disabled={isFieldDisabled}
className={b('operation-checkbox')}
className={b('setting-checkbox')}
qa={ControlQA.showLabelCheckbox}
checked={showTitle}
onUpdate={handleShowTitleUpdate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type ControlItemSelectProps = {
renderOverlay?: () => React.ReactNode;
selectProps: Pick<
SelectControlProps,
'style' | 'innerLabel' | 'label' | 'limitLabel' | 'labelPlacement'
'style' | 'innerLabel' | 'label' | 'limitLabel' | 'labelPlacement' | 'accentType'
>;
};

Expand Down
3 changes: 2 additions & 1 deletion src/ui/components/DashKit/plugins/Control/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type React from 'react';

import type {StringParams} from '@gravity-ui/dashkit';
import type {TitlePlacementOption} from 'shared';
import type {AccentTypeValue, TitlePlacementOption} from 'shared';
import type {
GetDistinctsApiV2Args,
GetDistinctsApiV2InfoHeadersArg,
Expand Down Expand Up @@ -84,6 +84,7 @@ export interface SelectControlProps {
innerLabel: string;
labelPlacement?: TitlePlacementOption;
limitLabel?: boolean;
accentType?: AccentTypeValue;
param: string;
multiselect: boolean;
type: ControlType;
Expand Down
Loading

0 comments on commit 2d5e359

Please sign in to comment.