Skip to content

Commit fee0809

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

File tree

37 files changed

+437
-320
lines changed

37 files changed

+437
-320
lines changed

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

Lines changed: 0 additions & 63 deletions
This file was deleted.

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

Lines changed: 0 additions & 178 deletions
This file was deleted.

0 commit comments

Comments
 (0)