Skip to content

Commit

Permalink
Fix rebase control dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
goshander committed Jan 24, 2024
1 parent 50be1ba commit de351d4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {createFeatureConfig} from '../utils';
export default createFeatureConfig({
name: Feature.GroupControls,
state: {
development: true,
development: false,
production: false,
},
});
2 changes: 1 addition & 1 deletion src/ui/components/DashKit/DashKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const getConfiguredDashKit = () => {
? getSdk().bi.getPublicDistinctsApiV2
: getSdk().bi.getDistinctsApiV2,
}),
pluginGroupControl,
...(Utils.isEnabledFeature(Feature.GroupControls) ? [pluginGroupControl] : []),
widgetPlugin,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const getWidgetRowText = (item: DashTabItem) => {
});
break;
case DashTabItemType.GroupControl:
// TODO fix only one element widget order
Object.values(item.data.items).forEach((controlItem: DashTabItemControlData) => {
widgetTabs.push(controlItem.title);
});
Expand Down
33 changes: 24 additions & 9 deletions src/ui/units/dash/store/actions/dashTyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {PluginTitleProps} from '@gravity-ui/dashkit/build/esm/plugins/Title/Titl
import {i18n} from 'i18n';
import {DatalensGlobalState, URL_QUERY, sdk} from 'index';
import isEmpty from 'lodash/isEmpty';
import {Dispatch} from 'redux';
import {
DATASET_FIELD_TYPES,
DashTab,
DashTabItem,
DashTabItemControlData,
DashTabItemControlSourceType,
DashTabItemType,
Dataset,
DatasetFieldType,
EntryUpdateMode,
Expand All @@ -36,7 +38,7 @@ import {DashUpdateStatus} from '../../typings/dash';
import * as actionTypes from '../constants/dashActionTypes';

import {closeDialog as closeDashDialog, deleteLock, purgeData, save, setLock} from './dash';
import {getBeforeCloseDialogItemAction} from './helpers';
import {getBeforeCloseDialogItemAction, getExtendedItemDataAction} from './helpers';

import {DashDispatch} from './index';

Expand Down Expand Up @@ -490,7 +492,7 @@ const getItemDataSource = (selectorDialog: SelectorDialogState): ItemDataSource
};

const getControlValidation = (selectorDialog: SelectorDialogState) => {
const {title, sourceType, datasetFieldId, fieldName} = selectorDialog;
const {title, sourceType, datasetFieldId, fieldName, defaultValue, required} = selectorDialog;

const validation: SelectorDialogValidation = {};

Expand All @@ -506,6 +508,10 @@ const getControlValidation = (selectorDialog: SelectorDialogState) => {
validation.datasetFieldId = i18n('dash.control-dialog.edit', 'validation_required');
}

if (required && (!defaultValue || !defaultValue?.length)) {
validation.defaultValue = i18n('dash.control-dialog.edit', 'validation_required');
}

return validation;
};

Expand Down Expand Up @@ -561,21 +567,26 @@ export const applyControl2Dialog = () => {
}

const defaults = getControlDefaultsForField(selectorDialog.defaults, selectorDialog);

const data = {
title,
sourceType,
autoHeight,
source: getItemDataSource(selectorDialog),
};
const getExtendedItemData = getExtendedItemDataAction();
const itemData = dispatch(getExtendedItemData({data, defaults}));

const itemType =
getState().dash.openedDialog === DashTabItemType.GroupControl
? DashTabItemType.Control
: undefined;

dispatch(
setItemData({
data: {
title,
sourceType,
autoHeight,
source: getItemDataSource(selectorDialog),
},
data: itemData.data,
type: itemType,
defaults,
defaults: itemData.defaults,
}),
);

Expand Down Expand Up @@ -640,6 +651,10 @@ export const applyGroupControlDialog = () => {
),
};

// TODO what is getExtendedItemData from single control?
// const getExtendedItemData = getExtendedItemDataAction();
// const itemData = dispatch(getExtendedItemData({data, defaults}));

dispatch(
setItemData({
data,
Expand Down
4 changes: 4 additions & 0 deletions src/ui/units/dash/store/reducers/dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export function getSelectorDialogFromData(data, defaults) {
innerTitle: data.source.innerTitle,
showInnerTitle: data.source.showInnerTitle,
id: getRandomKey(),
required: data.source.required,
};
}

Expand Down Expand Up @@ -137,6 +138,7 @@ export function getSelectorGroupDialogFromData(data, defaults) {
innerTitle: item.source.innerTitle,
showInnerTitle: item.source.showInnerTitle,
id: getRandomKey(),
required: item.source.required,
placementMode: item.placementMode,
width: item.width,
}))
Expand Down Expand Up @@ -413,6 +415,8 @@ function dash(state = initialState, action) {
} else if (openedDialog === 'group_control') {
newState.selectorsGroup = getSelectorGroupDialogFromData(data, defaults);
newState.selectorDialog = newState.selectorsGroup.items[0];
} else {
newState.selectorDialog = getSelectorDialogFromData(data, defaults);
}

newState.openedDialog = openedDialog;
Expand Down

0 comments on commit de351d4

Please sign in to comment.