Skip to content

Commit dd54ec2

Browse files
authored
Rename palettes (#2817)
1 parent 0db5bea commit dd54ec2

File tree

20 files changed

+614
-84
lines changed

20 files changed

+614
-84
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"label_classic20-palette": "Classic 20",
3-
"label_datalens-neo-20-palette": "Neo 20",
4-
"label_default20-palette": "Default 20",
5-
"label_emerald20-palette": "Emerald 20",
6-
"label_golden20-palette": "Golden 20",
7-
"label_neutral20-palette": "Neutral 20",
8-
"label_oceanic20-palette": "Oceanic 20",
9-
"label_traffic-light9-palette": "Traffic Light 9"
2+
"label_classic20": "Classic 20",
3+
"label_datalens-neo-20": "Neo 20",
4+
"label_default20": "Default 20",
5+
"label_emerald20": "Emerald 20",
6+
"label_golden20": "Golden 20",
7+
"label_neutral20": "Neutral 20",
8+
"label_oceanic20": "Oceanic 20",
9+
"label_traffic-light9": "Traffic Light 9"
1010
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"label_classic20-palette": "Classic 20",
3-
"label_datalens-neo-20-palette": "Neo 20",
4-
"label_default20-palette": "Default 20",
5-
"label_emerald20-palette": "Emerald 20",
6-
"label_golden20-palette": "Golden 20",
7-
"label_neutral20-palette": "Neutral 20",
8-
"label_oceanic20-palette": "Oceanic 20",
9-
"label_traffic-light9-palette": "Traffic Light 9"
2+
"label_classic20": "Classic 20",
3+
"label_datalens-neo-20": "Neo 20",
4+
"label_default20": "Default 20",
5+
"label_emerald20": "Emerald 20",
6+
"label_golden20": "Golden 20",
7+
"label_neutral20": "Neutral 20",
8+
"label_oceanic20": "Oceanic 20",
9+
"label_traffic-light9": "Traffic Light 9"
1010
}

src/shared/constants/colors/types.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
export const AUTO_PALETTE_ID = 'auto';
22

33
export const GRADIENT_PALETTE_ID = {
4-
EMERALD_20: 'emerald20-palette',
5-
GOLDEN_20: 'golden20-palette',
6-
NEUTRAL_20: 'neutral20-palette',
7-
OCEANIC_20: 'oceanic20-palette',
8-
TRAFFIC_LIGHT_9: 'traffic-light9-palette',
4+
EMERALD_20: 'emerald20',
5+
GOLDEN_20: 'golden20',
6+
NEUTRAL_20: 'neutral20',
7+
OCEANIC_20: 'oceanic20',
8+
TRAFFIC_LIGHT_9: 'traffic-light9',
99
} as const;
1010

1111
export const COMMON_PALETTE_ID = {
12-
CLASSIC_20: 'classic20-palette',
13-
DEFAULT_20: 'default20-palette',
14-
DATALENS_NEO_20: 'datalens-neo-20-palette',
12+
CLASSIC_20: 'classic20',
13+
DEFAULT_20: 'default20',
14+
DATALENS_NEO_20: 'datalens-neo-20',
1515
...GRADIENT_PALETTE_ID,
1616
} as const;
1717

src/shared/modules/config/ql/mapQlConfigToLatestVersion.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {mapV1ConfigToV2} from './v2/mapV1ConfigToV2';
77
import {mapV2ConfigToV3} from './v3/mapV2ConfigToV3';
88
import {mapV3ConfigToV4} from './v4/mapV3ConfigToV4';
99
import {mapV4ConfigToV5} from './v5/mapV4ConfigToV5';
10+
import {mapV5ConfigToV6} from './v6/mapV5ConfigToV6';
1011

1112
type MapQlConfigToLatestVersionOptions = {
1213
i18n: GetTranslationFn;
@@ -38,5 +39,9 @@ export const mapQlConfigToLatestVersion = (
3839
config = mapV4ConfigToV5(config);
3940
}
4041

42+
if (config.version === QlConfigVersions.V5) {
43+
config = mapV5ConfigToV6(config);
44+
}
45+
4146
return config;
4247
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import cloneDeep from 'lodash/cloneDeep';
2+
3+
import type {QlConfigV5} from '../../../../types/config/ql/v5';
4+
import type {QlConfigV6} from '../../../../types/config/ql/v6';
5+
import {QlConfigVersions} from '../../../../types/ql/versions';
6+
7+
function getNewPaletteId(value: string) {
8+
return value?.replace('-palette', '');
9+
}
10+
11+
function replacePalettesField(item: unknown) {
12+
if (item && typeof item === 'object') {
13+
if ('metricFontColorPalette' in item) {
14+
item.metricFontColorPalette = getNewPaletteId(item.metricFontColorPalette as string);
15+
} else if ('palette' in item) {
16+
item.palette = getNewPaletteId(item.palette as string);
17+
} else {
18+
Object.values(item).forEach(replacePalettesField);
19+
}
20+
}
21+
}
22+
23+
export const mapV5ConfigToV6 = (config: QlConfigV5): QlConfigV6 => {
24+
const newConfig = cloneDeep(config);
25+
replacePalettesField(newConfig);
26+
27+
return {
28+
...newConfig,
29+
version: QlConfigVersions.V6,
30+
};
31+
};

src/shared/modules/config/wizard/__test__/mapChartsConfigToLatestVersion.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ describe('mapChartsConfigToLatestVersion', () => {
88

99
const result = mapChartsConfigToLatestVersion(mockedConfigWithNumericVersion);
1010

11-
expect(result).toEqual({version: ChartsConfigVersion.V13});
11+
expect(result).toEqual({version: ChartsConfigVersion.V14});
1212
});
1313
});

src/shared/modules/config/wizard/mapChartsConfigToLatestVersion.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {mapV1ConfigToV2} from './v1/mapV1ConfigToV2';
55
import {mapV10ConfigToV11} from './v10/mapV10ConfigToV11';
66
import {mapV11ConfigToV12} from './v11/mapV11ConfigToV12';
77
import {mapV12ConfigToV13} from './v12/mapV12ConfigToV13';
8+
import {mapV13ConfigToV14} from './v13/mapV13ConfigToV14';
89
import {mapV2ConfigToV3} from './v2/mapV2ConfigToV3';
910
import {mapV3ConfigToV4, migrateDatetime} from './v3/mapV3ConfigToV4';
1011
import {mapV4ConfigToV5} from './v4/mapV4ConfigToV5';
@@ -78,5 +79,9 @@ export const mapChartsConfigToLatestVersion = (
7879
config = mapV12ConfigToV13(config);
7980
}
8081

82+
if (config.version === ChartsConfigVersion.V13) {
83+
config = mapV13ConfigToV14(config);
84+
}
85+
8186
return config as ChartsConfig;
8287
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import cloneDeep from 'lodash/cloneDeep';
2+
3+
import {ChartsConfigVersion} from '../../../../types';
4+
import type {V13ChartsConfig} from '../../../../types/config/wizard/v13';
5+
import type {V14ChartsConfig} from '../../../../types/config/wizard/v14';
6+
7+
function getNewPaletteId(value: string) {
8+
return value?.replace('-palette', '');
9+
}
10+
11+
function replacePalettesField(item: unknown) {
12+
if (item && typeof item === 'object') {
13+
if ('metricFontColorPalette' in item) {
14+
item.metricFontColorPalette = getNewPaletteId(item.metricFontColorPalette as string);
15+
} else if ('palette' in item) {
16+
item.palette = getNewPaletteId(item.palette as string);
17+
} else {
18+
Object.values(item).forEach(replacePalettesField);
19+
}
20+
}
21+
}
22+
23+
export const mapV13ConfigToV14 = (config: V13ChartsConfig): V14ChartsConfig => {
24+
const newConfig = cloneDeep(config);
25+
replacePalettesField(newConfig);
26+
27+
return {
28+
...newConfig,
29+
version: ChartsConfigVersion.V14,
30+
};
31+
};

src/shared/types/config/ql/index.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,51 @@ import type {QlConfigV1} from './v1';
44
import type {QlConfigV2} from './v2';
55
import type {QlConfigV3} from './v3';
66
import type {QlConfigV4} from './v4';
7+
import type {QlConfigV5} from './v5';
78
import type {
8-
QLParamIntervalV5,
9-
QLParamV5,
10-
QLPreviewTableDataColumnV5,
11-
QLPreviewTableDataRowV5,
12-
QLPreviewTableDataV5,
13-
QLQueryV5,
14-
QLRequestParamV5,
15-
QLResultEntryMetadataDataColumnOrGroupV5,
16-
QLResultEntryMetadataDataColumnV5,
17-
QLResultEntryMetadataDataGroupV5,
18-
QlConfigV5,
19-
} from './v5';
20-
21-
export type QlConfig = QlConfigV5;
9+
QLParamIntervalV6,
10+
QLParamV6,
11+
QLPreviewTableDataColumnV6,
12+
QLPreviewTableDataRowV6,
13+
QLPreviewTableDataV6,
14+
QLQueryV6,
15+
QLRequestParamV6,
16+
QLResultEntryMetadataDataColumnOrGroupV6,
17+
QLResultEntryMetadataDataColumnV6,
18+
QLResultEntryMetadataDataGroupV6,
19+
QlConfigV6,
20+
} from './v6';
21+
22+
export type QlConfig = QlConfigV6;
2223

2324
export type QlPreviousConfig =
2425
| QLEntryDataShared
26+
| QlConfigV5
2527
| QlConfigV4
2628
| QlConfigV3
2729
| QlConfigV2
2830
| QlConfigV1;
2931

3032
export type QlExtendedConfig = QlConfig | QlPreviousConfig;
3133

32-
export type QLConfigQuery = QLQueryV5;
34+
export type QLConfigQuery = QLQueryV6;
3335

34-
export type QlConfigResultEntryMetadataDataGroup = QLResultEntryMetadataDataGroupV5;
36+
export type QlConfigResultEntryMetadataDataGroup = QLResultEntryMetadataDataGroupV6;
3537

36-
export type QlConfigResultEntryMetadataDataColumn = QLResultEntryMetadataDataColumnV5;
38+
export type QlConfigResultEntryMetadataDataColumn = QLResultEntryMetadataDataColumnV6;
3739

38-
export type QlConfigParamInterval = QLParamIntervalV5;
40+
export type QlConfigParamInterval = QLParamIntervalV6;
3941

40-
export type QlConfigParam = QLParamV5;
42+
export type QlConfigParam = QLParamV6;
4143

42-
export type QlConfigRequestParam = QLRequestParamV5;
44+
export type QlConfigRequestParam = QLRequestParamV6;
4345

44-
export type QlConfigResultEntryMetadataDataColumnOrGroup = QLResultEntryMetadataDataColumnOrGroupV5;
46+
export type QlConfigResultEntryMetadataDataColumnOrGroup = QLResultEntryMetadataDataColumnOrGroupV6;
4547

46-
export type QlConfigPreviewTableDataColumn = QLPreviewTableDataColumnV5;
48+
export type QlConfigPreviewTableDataColumn = QLPreviewTableDataColumnV6;
4749

48-
export type QlConfigPreviewTableDataRow = QLPreviewTableDataRowV5;
50+
export type QlConfigPreviewTableDataRow = QLPreviewTableDataRowV6;
4951

50-
export type QlConfigPreviewTableData = QLPreviewTableDataV5;
52+
export type QlConfigPreviewTableData = QLPreviewTableDataV6;
5153

5254
export type MonitoringPreset = MonitoringPresetV1 | MonitoringPresetV2;

src/shared/types/config/ql/v6.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import type {QLChartType} from '../../../constants';
2+
import type {QlConfigVersions} from '../../ql/versions';
3+
import type {
4+
CommonSharedExtraSettings,
5+
Field,
6+
PointSizeConfig,
7+
ShapesConfig,
8+
Shared,
9+
} from '../../wizard';
10+
11+
export interface QLResultEntryMetadataDataGroupV6 {
12+
group: boolean;
13+
undragable: boolean;
14+
name: string;
15+
capacity?: number;
16+
size: number;
17+
id?: string;
18+
allowedTypes?: string[];
19+
pseudo?: boolean;
20+
}
21+
22+
export interface QLResultEntryMetadataDataColumnV6 {
23+
typeName: string;
24+
25+
// biType -- a new type compatible with Field and general visualization section
26+
biType?: string;
27+
28+
name: string;
29+
id?: string;
30+
undragable?: boolean;
31+
pseudo?: boolean;
32+
}
33+
34+
export interface QLParamIntervalV6 {
35+
from: string | undefined;
36+
to: string | undefined;
37+
}
38+
39+
export interface QLParamV6 {
40+
name: string;
41+
type: string;
42+
defaultValue: string | string[] | QLParamIntervalV6 | undefined;
43+
overridenValue?: string | string[] | QLParamIntervalV6;
44+
}
45+
46+
// Description of the request parameters.
47+
export interface QLRequestParamV6 {
48+
type_name: string;
49+
value: string | string[];
50+
}
51+
52+
export type QLResultEntryMetadataDataColumnOrGroupV6 =
53+
| QLResultEntryMetadataDataGroupV6
54+
| QLResultEntryMetadataDataColumnV6;
55+
56+
interface QLEntryDataSharedConnectionV6 {
57+
entryId: string;
58+
type: string;
59+
}
60+
61+
export interface QLQueryV6 {
62+
value: string;
63+
hidden?: boolean;
64+
params: QLParamV6[];
65+
queryName: string;
66+
}
67+
68+
export interface QlConfigV6 {
69+
version: QlConfigVersions.V6;
70+
// The type of template used to generate a chart at the ChartsEngine level, a low-level thing
71+
type: string;
72+
73+
// Chart type should be selected in UI
74+
chartType: QLChartType;
75+
queryValue: string;
76+
queries: QLQueryV6[];
77+
extraSettings?: CommonSharedExtraSettings;
78+
visualization: Shared['visualization'] & {highchartsId?: string};
79+
geopointsConfig?: PointSizeConfig;
80+
params: QLParamV6[];
81+
connection: QLEntryDataSharedConnectionV6;
82+
order?: QLResultEntryMetadataDataColumnOrGroupV6[] | null;
83+
preview?: boolean;
84+
85+
colors: Field[];
86+
colorsConfig?: any;
87+
labels: Field[];
88+
tooltips: Field[];
89+
shapes: Field[];
90+
shapesConfig?: ShapesConfig;
91+
92+
available?: Field[];
93+
}
94+
95+
export interface QLPreviewTableDataColumnV6 {
96+
name: string;
97+
}
98+
99+
export interface QLPreviewTableDataRowV6 {
100+
[key: string]: number | string | null;
101+
}
102+
103+
export interface QLPreviewTableDataV6 {
104+
columns?: QLPreviewTableDataColumnV6[];
105+
data?: QLPreviewTableDataRowV6[];
106+
}

0 commit comments

Comments
 (0)