Skip to content

Commit 419a51d

Browse files
Support base operations with selectors globality (#3061)
1 parent 4e8001a commit 419a51d

File tree

46 files changed

+1878
-442
lines changed

Some content is hidden

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

46 files changed

+1878
-442
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: false,
8+
production: false,
9+
},
10+
});

src/server/components/sdk/dash.ts

Lines changed: 22 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,23 @@ function validateData(data: DashData) {
165165
allTabsIds.add(tabId);
166166
}
167167

168+
globalItems?.forEach(({id: itemId, type, data}) => {
169+
allItemsIds.add(itemId);
170+
currentItemsIds.add(itemId);
171+
172+
// to avoid isIdUniq check
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+
168185
items.forEach(({id: itemId, type, data}) => {
169186
if (isIdUniq(itemId)) {
170187
allItemsIds.add(itemId);
@@ -190,10 +207,12 @@ function validateData(data: DashData) {
190207
}
191208
});
192209

210+
const allItemsLength = items.length + (globalItems?.length ?? 0);
211+
193212
// checking that layout has all the ids from item, i.e. positions are set for all elements
194213
if (
195-
items.length !== layout.length ||
196-
items.length !==
214+
allItemsLength !== layout.length ||
215+
allItemsLength !==
197216
intersection(
198217
Array.from(currentItemsIds),
199218
layout.map(({i}) => i),

src/shared/types/dash.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import type {ItemDropProps} from '@gravity-ui/dashkit';
22

33
import type {Operations} from '../modules';
44

5+
export type ImpactType = 'allTabs' | 'currentTab' | 'selectedTabs' | 'asGroup';
6+
export type ImpactTabsIds = string[] | null | undefined;
7+
58
import type {
69
ClientChartsConfig,
710
Dictionary,
@@ -126,6 +129,7 @@ export interface DashTab {
126129
aliases: DashTabAliases;
127130
connections: DashTabConnection[];
128131
settings?: DashTabSettings;
132+
globalItems?: DashTabItem[];
129133
}
130134

131135
export type DashSettingsGlobalParams = Record<string, string | string[]>;
@@ -222,19 +226,24 @@ export interface DashTabItemControl extends DashTabItemBase {
222226
defaults: StringParams;
223227
}
224228

225-
export interface DashTabItemControlData {
229+
export interface DashTabItemControlBaseData {
226230
id: string;
227231
title: string;
228-
sourceType: DashTabItemControlSourceType;
229-
source:
230-
| DashTabItemControlDataset['source']
231-
| DashTabItemControlManual['source']
232-
| DashTabItemControlExternal['source'];
233232
placementMode?: 'auto' | '%' | 'px';
234233
autoHeight?: boolean;
235234
width?: string;
236235
defaults?: StringParams;
237236
namespace: string;
237+
impactType?: ImpactType;
238+
impactTabsIds?: ImpactTabsIds;
239+
}
240+
241+
export interface DashTabItemControlData extends DashTabItemControlBaseData {
242+
sourceType: DashTabItemControlSourceType;
243+
source:
244+
| DashTabItemControlDataset['source']
245+
| DashTabItemControlManual['source']
246+
| DashTabItemControlExternal['source'];
238247
}
239248

240249
export type DashTabItemControlSingle = DashTabItemControlDataset | DashTabItemControlManual;
@@ -336,15 +345,19 @@ export interface DashTabItemGroupControl extends DashTabItemBase {
336345
defaults: StringParams;
337346
}
338347

339-
export interface DashTabItemGroupControlData {
348+
export interface DashTabItemGroupControlBaseData {
340349
showGroupName: boolean;
341350
groupName?: string;
342351
autoHeight: boolean;
343352
buttonApply: boolean;
344353
buttonReset: boolean;
354+
impactType?: ImpactType;
355+
impactTabsIds?: ImpactTabsIds;
345356

346357
updateControlsOnChange?: boolean;
358+
}
347359

360+
export interface DashTabItemGroupControlData extends DashTabItemGroupControlBaseData {
348361
group: DashTabItemControlSingle[];
349362
}
350363

src/shared/types/feature.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export enum Feature {
100100
EnableMobileFixedHeader = 'EnableMobileFixedHeader',
101101
/** enabled redesign/moving to drawers existing settings */
102102
EnableCommonChartDashSettings = 'EnableCommonChartDashSettings',
103+
/** Enable a setting in the Selector settings dialog that allows you to make the selector pass-through for all or several tabs */
104+
EnableGlobalSelectors = 'EnableGlobalSelectors',
103105
/** enables new dash & widgets settings */
104106
EnableNewDashSettings = 'EnableNewDashSettings',
105107
/** Shows updated settings page */

src/shared/zod-schemas/dash.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ const controlSchema = z
116116
namespace: z.literal(DASH_DEFAULT_NAMESPACE),
117117
title: z.string().min(1),
118118
sourceType: z.enum(DashTabItemControlSourceType),
119+
// TODO(global selectors): uncomment when flag will be enabled
120+
// fields that regulate which tabs the selector will be displayed on
121+
// 'allTabs' = global selectors
122+
// 'currentTab' = regular selector that is visible only on one tab
123+
// 'selectedTabs' + impactTabsIds = selector is visible on the selected tabs
124+
// impactType: z.enum(['allTabs', 'currentTab', 'selectedTabs']).optional(),
125+
// impactTabsIds: z.array(z.string()).optional(),
119126
})
120127
.and(
121128
z.discriminatedUnion('sourceType', [
@@ -147,6 +154,13 @@ const groupControlItemsSchema = z
147154
defaults: z.record(z.any(), z.any()),
148155
placementMode: z.enum(CONTROLS_PLACEMENT_MODE).optional(),
149156
width: z.string().optional(),
157+
// TODO(global selectors): uncomment when flag will be enabled
158+
// fields that regulate which tabs the selector will be displayed on
159+
// 'allTabs' = global selectors
160+
// 'currentTab' = regular selector that is visible only on one tab
161+
// 'selectedTabs' + impactTabsIds = selector is visible on the selected tabs
162+
// impactType: z.enum(['allTabs', 'currentTab', 'selectedTabs']).optional(),
163+
// impactTabsIds: z.array(z.string()).optional(),
150164
})
151165
.and(
152166
z.discriminatedUnion('sourceType', [
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React from 'react';
2+
3+
import {I18n} from 'i18n';
4+
import {useSelector} from 'react-redux';
5+
import {DashTabItemControlSourceType} from 'shared';
6+
import {selectSelectorDialog, selectSelectorsGroup} from 'ui/store/selectors/controlDialog';
7+
8+
import {ConnectionSettings} from './ConnectionSettings/ConnectionSettings';
9+
import {DatasetSelectorSettings} from './DatasetSelectorSettings/DatasetSelectorSettings';
10+
import {ImpactTypeSelect} from './ImpactTypeSelect/ImpactTypeSelect';
11+
import {ParameterNameInput} from './ParameterNameInput/ParameterNameInput';
12+
13+
const i18n = I18n.keyset('dash.control-dialog.edit');
14+
15+
export const CommonGroupSettingsSection = ({
16+
navigationPath,
17+
changeNavigationPath,
18+
enableGlobalSelectors,
19+
className,
20+
}: {
21+
navigationPath: string | null;
22+
changeNavigationPath: (newNavigationPath: string) => void;
23+
enableGlobalSelectors?: boolean;
24+
className?: string;
25+
}) => {
26+
const {sourceType} = useSelector(selectSelectorDialog);
27+
const {group, impactType, impactTabsIds} = useSelector(selectSelectorsGroup);
28+
29+
const hasMultipleSelectors = group.length > 1;
30+
31+
switch (sourceType) {
32+
case DashTabItemControlSourceType.Manual:
33+
return (
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+
<ImpactTypeSelect
42+
groupImpactType={impactType}
43+
groupImpactTabsIds={impactTabsIds}
44+
hasMultipleSelectors={hasMultipleSelectors}
45+
/>
46+
)}
47+
</React.Fragment>
48+
);
49+
case DashTabItemControlSourceType.Connection:
50+
return (
51+
<ConnectionSettings
52+
rowClassName={className}
53+
changeNavigationPath={changeNavigationPath}
54+
navigationPath={navigationPath}
55+
enableGlobalSelectors={enableGlobalSelectors}
56+
/>
57+
);
58+
default:
59+
return (
60+
<DatasetSelectorSettings
61+
rowClassName={className}
62+
navigationPath={navigationPath}
63+
changeNavigationPath={changeNavigationPath}
64+
enableGlobalSelectors={enableGlobalSelectors}
65+
/>
66+
);
67+
}
68+
};

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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ 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

7+
import {ImpactTypeSelect} from '../ImpactTypeSelect/ImpactTypeSelect';
78
import {ParameterNameInput} from '../ParameterNameInput/ParameterNameInput';
89

910
import {ConnectionSelector} from './components/ConnectionSelector/ConnectionSelector';
@@ -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 {impactType, impactTabsIds, group} = useSelector(selectSelectorsGroup);
2428

2529
return (
2630
<React.Fragment>
@@ -38,6 +42,13 @@ export const ConnectionSettings = ({
3842
<QueryTypeControl connectionQueryTypes={connectionQueryTypes} />
3943
</React.Fragment>
4044
)}
45+
{enableGlobalSelectors && (
46+
<ImpactTypeSelect
47+
groupImpactType={impactType}
48+
groupImpactTabsIds={impactTabsIds}
49+
hasMultipleSelectors={group.length > 1}
50+
/>
51+
)}
4152
</React.Fragment>
4253
);
4354
};

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

Whitespace-only changes.

0 commit comments

Comments
 (0)