Skip to content

Commit

Permalink
Controls groups title (#1975)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaryaLari authored and kuzmadom committed Dec 26, 2024
1 parent 1d7f730 commit 4691994
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/shared/types/dash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ export interface DashTabItemGroupControl extends DashTabItemBase {
}

export interface DashTabItemGroupControlData {
showGroupName: boolean;
groupName?: string;
autoHeight: boolean;
buttonApply: boolean;
buttonReset: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
align-items: flex-end;
}

&__controls-title {
display: block;
width: 100%;
}

&__control-container {
display: contents;
position: relative;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import {type Plugin, type PluginWidgetProps, type SettingsProps} from '@gravity-ui/dashkit';
import type {Config, StateAndParamsMetaData} from '@gravity-ui/dashkit/helpers';
import {getItemsParams, pluginGroupControlBaseDL} from '@gravity-ui/dashkit/helpers';
import {Loader} from '@gravity-ui/uikit';
import {Loader, Text} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';
import {I18n} from 'i18n';
import debounce from 'lodash/debounce';
Expand Down Expand Up @@ -836,6 +836,11 @@ class GroupControl extends React.PureComponent<PluginGroupControlProps, PluginGr

return (
<div className={b('controls')}>
{controlData.showGroupName && controlData.groupName && (
<Text variant="subheader-2" className={b('controls-title')}>
{controlData.groupName}
</Text>
)}
{controlData.group?.map((item: DashTabItemControlSingle) =>
this.renderControl(item),
)}
Expand Down
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, List} from '@gravity-ui/uikit';
import {Checkbox, Dialog, Flex, List, TextInput} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';
import DialogManager from 'components/DialogManager/DialogManager';
import {I18n} from 'i18n';
Expand All @@ -26,6 +26,7 @@ export type ExtendedSettingsDialogProps = {
onClose: () => void;

enableAutoheightDefault?: boolean;
showSelectorsGroupTitle?: boolean;
};

export type OpenDialogExtendedSettingsArgs = {
Expand All @@ -45,6 +46,7 @@ const resetAutoValues = (group: SelectorDialogState[]) =>
const DialogExtendedSettings = ({
onClose,
enableAutoheightDefault,
showSelectorsGroupTitle,
}: ExtendedSettingsDialogProps) => {
const selectorsGroup = useSelector(selectSelectorsGroup);
const [itemsState, setItemsState] = React.useState(selectorsGroup.group);
Expand Down Expand Up @@ -145,6 +147,30 @@ const DialogExtendedSettings = ({

const isMultipleSelectors = selectorsGroup.group?.length > 1;

const handleChangeShowGroupName = React.useCallback(
(value) => {
dispatch(
updateSelectorsGroup({
...selectorsGroup,
showGroupName: value,
}),
);
},
[dispatch, selectorsGroup],
);

const handleChangeGroupName = React.useCallback(
(value) => {
dispatch(
updateSelectorsGroup({
...selectorsGroup,
groupName: value,
}),
);
},
[dispatch, selectorsGroup],
);

const handleChangeAutoHeight = React.useCallback(
(value) => {
dispatch(
Expand Down Expand Up @@ -218,6 +244,23 @@ const DialogExtendedSettings = ({
/>
<Dialog.Body className={b('body')}>
<FormSection title={i18n('label_group-parameters')}>
{showSelectorsGroupTitle && (
<FormRow className={b('row')} label={i18n('label_group-name')}>
<Flex gap={2}>
<Checkbox
className={b('checkbox')}
checked={selectorsGroup.showGroupName}
onUpdate={handleChangeShowGroupName}
size="l"
/>
<TextInput
disabled={!selectorsGroup.showGroupName}
value={selectorsGroup.groupName}
onUpdate={handleChangeGroupName}
/>
</Flex>
</FormRow>
)}
<FormRow
className={b('row')}
label={
Expand Down
3 changes: 3 additions & 0 deletions src/ui/components/DialogGroupControl/DialogGroupControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const i18n = I18n.keyset('dash.group-controls-dialog.edit');

export type DialogGroupControlFeaturesProps = {
enableAutoheightDefault?: boolean;
showSelectorsGroupTitle?: boolean;
};

export type DialogGroupControlProps = {
Expand All @@ -40,6 +41,7 @@ export const DialogGroupControl: React.FC<DialogGroupControlProps> = ({
navigationPath,
changeNavigationPath,
enableAutoheightDefault,
showSelectorsGroupTitle,
}) => {
const {id, draftId} = useSelector(selectSelectorDialog);

Expand Down Expand Up @@ -73,6 +75,7 @@ export const DialogGroupControl: React.FC<DialogGroupControlProps> = ({
sidebar={
<GroupControlSidebar
enableAutoheightDefault={enableAutoheightDefault}
showSelectorsGroupTitle={showSelectorsGroupTitle}
handleCopyItem={handleCopyItem}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ const handlePasteItems = (pasteConfig: CopiedConfigData | null) => {
export const GroupControlSidebar: React.FC<{
handleCopyItem: (itemIndex: number) => void;
enableAutoheightDefault?: boolean;
}> = ({enableAutoheightDefault, handleCopyItem}) => {
showSelectorsGroupTitle?: boolean;
}> = ({enableAutoheightDefault, handleCopyItem, showSelectorsGroupTitle}) => {
const selectorsGroup = useSelector(selectSelectorsGroup);
const activeSelectorIndex = useSelector(selectActiveSelectorIndex);

Expand Down Expand Up @@ -127,6 +128,7 @@ export const GroupControlSidebar: React.FC<{
props: {
onClose: handleClosePlacementDialog,
enableAutoheightDefault,
showSelectorsGroupTitle,
},
}),
);
Expand Down
2 changes: 2 additions & 0 deletions src/ui/store/actions/controlDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ export const applyGroupControlDialog = ({
: false;

const data = {
showGroupName: selectorsGroup.showGroupName,
groupName: selectorsGroup.groupName,
autoHeight,
buttonApply: selectorsGroup.buttonApply,
buttonReset: selectorsGroup.buttonReset,
Expand Down
14 changes: 12 additions & 2 deletions src/ui/store/reducers/controlDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export function getSelectorDialogInitialState(

export function getGroupSelectorDialogInitialState(): SelectorsGroupDialogState {
return {
showGroupName: false,
autoHeight: false,
buttonApply: false,
buttonReset: false,
Expand Down Expand Up @@ -345,8 +346,15 @@ export function controlDialog(

case UPDATE_SELECTORS_GROUP: {
const {selectorsGroup} = state;
const {group, autoHeight, buttonApply, buttonReset, updateControlsOnChange} =
action.payload;
const {
group,
autoHeight,
buttonApply,
buttonReset,
updateControlsOnChange,
showGroupName,
groupName,
} = action.payload;

// if the number of selectors has increased from 1 to several, we enable autoHeight
const updatedAutoHeight =
Expand All @@ -361,6 +369,8 @@ export function controlDialog(
buttonApply,
buttonReset,
updateControlsOnChange,
showGroupName,
groupName,
},
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/ui/store/typings/controlDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export type SelectorDialogValidation = {
};

export type SelectorsGroupDialogState = {
showGroupName: boolean;
groupName?: string;
autoHeight: boolean;
buttonApply: boolean;
buttonReset: boolean;
Expand Down

0 comments on commit 4691994

Please sign in to comment.