Skip to content

Commit b820f31

Browse files
Support base operations with selectors globality
1 parent f3d019c commit b820f31

File tree

48 files changed

+1352
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1352
-104
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {Feature} from '../../../../shared';
2+
import {createFeatureConfig} from '../utils';
3+
4+
export default createFeatureConfig({
5+
name: Feature.EnableGlobalSelectors,
6+
state: {
7+
development: true,
8+
production: false,
9+
},
10+
});

src/server/components/sdk/dash.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function validateData(data: DashData) {
156156
return true;
157157
};
158158

159-
data.tabs.forEach(({id: tabId, title: tabTitle, items, layout, connections}) => {
159+
data.tabs.forEach(({id: tabId, title: tabTitle, items, layout, connections, globalItems}) => {
160160
const currentItemsIds: Set<string> = new Set();
161161
const currentWidgetTabsIds: Set<string> = new Set();
162162
const currentControlsIds: Set<string> = new Set();
@@ -165,6 +165,24 @@ function validateData(data: DashData) {
165165
allTabsIds.add(tabId);
166166
}
167167

168+
if (globalItems) {
169+
globalItems.forEach(({id: itemId, type, data}) => {
170+
allItemsIds.add(itemId);
171+
currentItemsIds.add(itemId);
172+
173+
if (type === DashTabItemType.Control || type === DashTabItemType.GroupControl) {
174+
// if it is group control all connections set on its items
175+
if ('group' in data) {
176+
data.group.forEach((widgetItem) => {
177+
currentControlsIds.add(widgetItem.id);
178+
});
179+
} else {
180+
currentControlsIds.add(itemId);
181+
}
182+
}
183+
});
184+
}
185+
168186
items.forEach(({id: itemId, type, data}) => {
169187
if (isIdUniq(itemId)) {
170188
allItemsIds.add(itemId);
@@ -190,10 +208,12 @@ function validateData(data: DashData) {
190208
}
191209
});
192210

211+
const allItemsLength = items.length + (globalItems?.length ?? 0);
212+
193213
// checking that layout has all the ids from item, i.e. positions are set for all elements
194214
if (
195-
items.length !== layout.length ||
196-
items.length !==
215+
allItemsLength !== layout.length ||
216+
allItemsLength !==
197217
intersection(
198218
Array.from(currentItemsIds),
199219
layout.map(({i}) => i),

src/shared/types/dash.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {ItemDropProps} from '@gravity-ui/dashkit';
22

3+
import type {TabsScope} from '../../ui/units/dash/typings/selectors';
34
import type {Operations} from '../modules';
45

56
import type {
@@ -125,6 +126,7 @@ export interface DashTab {
125126
aliases: DashTabAliases;
126127
connections: DashTabConnection[];
127128
settings?: DashTabSettings;
129+
globalItems?: DashTabItem[];
128130
}
129131

130132
export type DashSettingsGlobalParams = Record<string, string | string[]>;
@@ -232,6 +234,7 @@ export interface DashTabItemControlData {
232234
width?: string;
233235
defaults?: StringParams;
234236
namespace: string;
237+
tabsScope?: TabsScope;
235238
}
236239

237240
export type DashTabItemControlSingle = DashTabItemControlDataset | DashTabItemControlManual;
@@ -339,6 +342,7 @@ export interface DashTabItemGroupControlData {
339342
autoHeight: boolean;
340343
buttonApply: boolean;
341344
buttonReset: boolean;
345+
tabsScope?: TabsScope;
342346

343347
updateControlsOnChange?: boolean;
344348

src/shared/types/feature.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ export enum Feature {
103103

104104
EnableMobileFixedHeader = 'EnableMobileFixedHeader',
105105
EnableCommonChartDashSettings = 'EnableCommonChartDashSettings',
106+
/** Enable a setting in the Selector settings dialog that allows you to make the selector pass-through for all or several tabs */
107+
EnableGlobalSelectors = 'EnableGlobalSelectors',
106108
}
107109

108110
export type FeatureConfig = Record<string, boolean>;

src/shared/zod-schemas/dash.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const controlSchema = z
116116
namespace: z.literal(DASH_DEFAULT_NAMESPACE),
117117
title: z.string().min(1),
118118
sourceType: z.enum(DashTabItemControlSourceType),
119+
tabsScope: z.union([z.string(), z.array(z.string())]).optional(),
119120
})
120121
.and(
121122
z.discriminatedUnion('sourceType', [
@@ -147,6 +148,7 @@ const groupControlItemsSchema = z
147148
defaults: z.record(z.any(), z.any()),
148149
placementMode: z.enum(CONTROLS_PLACEMENT_MODE).optional(),
149150
width: z.string().optional(),
151+
tabsScope: z.union([z.string(), z.array(z.string())]).optional(),
150152
})
151153
.and(
152154
z.discriminatedUnion('sourceType', [

src/ui/components/ControlComponents/Sections/CommonSettingsSection/CommonSettingsSection.tsx renamed to src/ui/components/ControlComponents/Sections/CommonSettingsSection/CommonGroupSettingsSection.tsx

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,64 @@ import React from 'react';
33
import {I18n} from 'i18n';
44
import {useSelector} from 'react-redux';
55
import {DashTabItemControlSourceType} from 'shared';
6-
import {selectSelectorDialog} from 'ui/store/selectors/controlDialog';
6+
import {selectSelectorDialog, selectSelectorsGroup} from 'ui/store/selectors/controlDialog';
77

88
import {ConnectionSettings} from './ConnectionSettings/ConnectionSettings';
9-
import {DatasetSelector} from './DatasetSelector/DatasetSelector';
10-
import {ExternalSelectorSettings} from './ExternalSelectorSettings/ExternalSelectorSettings';
9+
import {DatasetSelectorSettings} from './DatasetSelectorSettings/DatasetSelectorSettings';
1110
import {ParameterNameInput} from './ParameterNameInput/ParameterNameInput';
11+
import {TabsScopeSelect} from './TabsScopeSelect/TabsScopeSelect';
1212

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

15-
export const CommonSettingsSection = ({
15+
export const CommonGroupSettingsSection = ({
1616
navigationPath,
1717
changeNavigationPath,
18-
enableAutoheightDefault,
18+
enableGlobalSelectors,
1919
className,
2020
}: {
2121
navigationPath: string | null;
2222
changeNavigationPath: (newNavigationPath: string) => void;
23-
enableAutoheightDefault?: boolean;
23+
enableGlobalSelectors?: boolean;
2424
className?: string;
2525
}) => {
2626
const {sourceType} = useSelector(selectSelectorDialog);
27+
const {group, tabsScope} = useSelector(selectSelectorsGroup);
28+
29+
const hasMultipleSelectors = group.length > 1;
2730

2831
switch (sourceType) {
29-
case DashTabItemControlSourceType.External:
30-
return (
31-
<ExternalSelectorSettings
32-
rowClassName={className}
33-
changeNavigationPath={changeNavigationPath}
34-
navigationPath={navigationPath}
35-
enableAutoheightDefault={enableAutoheightDefault}
36-
/>
37-
);
3832
case DashTabItemControlSourceType.Manual:
3933
return (
40-
<ParameterNameInput
41-
label={i18n('field_field-name')}
42-
note={i18n('field_field-name-note')}
43-
className={className}
44-
/>
34+
<React.Fragment>
35+
<ParameterNameInput
36+
label={i18n('field_field-name')}
37+
note={i18n('field_field-name-note')}
38+
className={className}
39+
/>
40+
{enableGlobalSelectors && (
41+
<TabsScopeSelect
42+
groupTabsScope={tabsScope}
43+
hasMultipleSelectors={hasMultipleSelectors}
44+
/>
45+
)}
46+
</React.Fragment>
4547
);
4648
case DashTabItemControlSourceType.Connection:
4749
return (
4850
<ConnectionSettings
4951
rowClassName={className}
5052
changeNavigationPath={changeNavigationPath}
5153
navigationPath={navigationPath}
54+
enableGlobalSelectors={enableGlobalSelectors}
5255
/>
5356
);
5457
default:
5558
return (
56-
<DatasetSelector
59+
<DatasetSelectorSettings
5760
rowClassName={className}
5861
navigationPath={navigationPath}
5962
changeNavigationPath={changeNavigationPath}
63+
enableGlobalSelectors={enableGlobalSelectors}
6064
/>
6165
);
6266
}

src/ui/components/ControlComponents/Sections/CommonSettingsSection/ConnectionSettings/ConnectionSettings.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import React from 'react';
22

33
import {I18n} from 'i18n';
44
import {useSelector} from 'react-redux';
5-
import {selectSelectorDialog} from 'ui/store/selectors/controlDialog';
5+
import {selectSelectorDialog, selectSelectorsGroup} from 'ui/store/selectors/controlDialog';
66

77
import {ParameterNameInput} from '../ParameterNameInput/ParameterNameInput';
8+
import {TabsScopeSelect} from '../TabsScopeSelect/TabsScopeSelect';
89

910
import {ConnectionSelector} from './components/ConnectionSelector/ConnectionSelector';
1011
import {QueryTypeControl} from './components/QueryTypeControl/QueryTypeControl';
@@ -15,12 +16,15 @@ export const ConnectionSettings = ({
1516
navigationPath,
1617
changeNavigationPath,
1718
rowClassName,
19+
enableGlobalSelectors,
1820
}: {
1921
navigationPath: string | null;
2022
changeNavigationPath: (newNavigationPath: string) => void;
2123
rowClassName?: string;
24+
enableGlobalSelectors?: boolean;
2225
}) => {
2326
const {connectionQueryTypes} = useSelector(selectSelectorDialog);
27+
const {tabsScope, group} = useSelector(selectSelectorsGroup);
2428

2529
return (
2630
<React.Fragment>
@@ -38,6 +42,12 @@ export const ConnectionSettings = ({
3842
<QueryTypeControl connectionQueryTypes={connectionQueryTypes} />
3943
</React.Fragment>
4044
)}
45+
{enableGlobalSelectors && (
46+
<TabsScopeSelect
47+
groupTabsScope={tabsScope}
48+
hasMultipleSelectors={group.length > 1}
49+
/>
50+
)}
4151
</React.Fragment>
4252
);
4353
};

src/ui/components/ControlComponents/Sections/CommonSettingsSection/DatasetSelector/DatasetSelector.scss

Whitespace-only changes.

src/ui/components/ControlComponents/Sections/CommonSettingsSection/DatasetSelector/DatasetSelector.tsx renamed to src/ui/components/ControlComponents/Sections/CommonSettingsSection/DatasetSelectorSettings/DatasetSelectorSettings.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,32 @@ import {
1515
import logger from 'ui/libs/logger';
1616
import {setLastUsedDatasetId, setSelectorDialogItem} from 'ui/store/actions/controlDialog';
1717
import {ELEMENT_TYPE} from 'ui/store/constants/controlDialog';
18-
import {selectOpenedItemMeta, selectSelectorDialog} from 'ui/store/selectors/controlDialog';
18+
import {
19+
selectOpenedItemMeta,
20+
selectSelectorDialog,
21+
selectSelectorsGroup,
22+
} from 'ui/store/selectors/controlDialog';
1923
import type {SelectorElementType, SetSelectorDialogItemArgs} from 'ui/store/typings/controlDialog';
2024

2125
import {DatasetField} from '../../Switchers/DatasetField/DatasetField';
2226
import {EntrySelector} from '../EntrySelector/EntrySelector';
27+
import {TabsScopeSelect} from '../TabsScopeSelect/TabsScopeSelect';
2328

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

2631
const getDatasetLink = (entryId: string) => `/datasets/${entryId}`;
2732

28-
function DatasetSelector(props: {
33+
function DatasetSelectorSettings(props: {
2934
navigationPath: string | null;
3035
changeNavigationPath: (newNavigationPath: string) => void;
3136
rowClassName?: string;
37+
enableGlobalSelectors?: boolean;
3238
}) {
3339
const dispatch = useDispatch();
3440
const {datasetId, datasetFieldId, isManualTitle, title, fieldType, validation} =
3541
useSelector(selectSelectorDialog);
3642
const {workbookId} = useSelector(selectOpenedItemMeta);
43+
const {tabsScope, group} = useSelector(selectSelectorsGroup);
3744
const [isInvalid, setIsInvalid] = React.useState(false);
3845

3946
const fetchDataset = React.useCallback((entryId: string) => {
@@ -53,7 +60,7 @@ function DatasetSelector(props: {
5360
})
5461
.catch((isInvalid) => {
5562
setIsInvalid(true);
56-
logger.logError('DatasetSelector: load dataset failed', isInvalid);
63+
logger.logError('DatasetSelectorSettings: load dataset failed', isInvalid);
5764
});
5865
}, []);
5966

@@ -171,8 +178,14 @@ function DatasetSelector(props: {
171178
/>
172179
</FieldWrapper>
173180
</FormRow>
181+
{props.enableGlobalSelectors && (
182+
<TabsScopeSelect
183+
hasMultipleSelectors={group.length > 1}
184+
groupTabsScope={tabsScope}
185+
></TabsScopeSelect>
186+
)}
174187
</React.Fragment>
175188
);
176189
}
177190

178-
export {DatasetSelector};
191+
export {DatasetSelectorSettings};

src/ui/components/ControlComponents/Sections/CommonSettingsSection/ExternalSelectorSettings/ExternalSelectorSettings.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {selectOpenedItemMeta, selectSelectorDialog} from 'ui/store/selectors/con
1515
import {EntryTypeNode} from 'ui/units/dash/modules/constants';
1616

1717
import {EntrySelector} from '../EntrySelector/EntrySelector';
18+
import {TabsScopeSelect} from '../TabsScopeSelect/TabsScopeSelect';
1819

1920
import './ExternalSelectorSettings.scss';
2021

@@ -32,6 +33,7 @@ const ExternalSelectorSettings: React.FC<{
3233
navigationPath: string | null;
3334
changeNavigationPath: (newNavigationPath: string) => void;
3435
enableAutoheightDefault?: boolean;
36+
enableGlobalSelectors?: boolean;
3537
rowClassName?: string;
3638
}> = (props) => {
3739
const dispatch = useDispatch();
@@ -121,6 +123,8 @@ const ExternalSelectorSettings: React.FC<{
121123
changeNavigationPath={props.changeNavigationPath}
122124
/>
123125

126+
{props.enableGlobalSelectors && <TabsScopeSelect />}
127+
124128
{!props.enableAutoheightDefault && (
125129
<FormRow
126130
label={i18n('dash.control-dialog.edit', 'field_autoheight')}

0 commit comments

Comments
 (0)