Skip to content

Commit cdb0eb8

Browse files
authored
Tenant setting to select the default palette (#2917)
1 parent d7490ad commit cdb0eb8

File tree

16 files changed

+105
-13
lines changed

16 files changed

+105
-13
lines changed

dev/env/opensource/development.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ ZITADEL_COOKIE_SECRET=!@OUVOF$@E@%F^&@$*ER!F
1818

1919
SERVICE_CLIENT_ID=charts
2020
SERVICE_CLIENT_SECRET=uvdZDsiZJslDj8bKbTlKR43oMHqEiNGppxhMjCQWqQXkHUmGpW2iuLYNJ5tdmmlL
21+
22+
US_MASTER_TOKEN=us-master-token

src/server/components/charts-engine/components/processor/worker-chart-builder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export const getWizardChartBuilder = async (
5454
const defaultColorPaletteId = getDefaultColorPaletteId({
5555
ctx: app.nodekit.ctx,
5656
tenantSettings,
57-
palettes,
5857
});
5958

6059
// Nothing happens here - just for compatibility with the editor

src/server/components/features/features-list/EnableTenantSettingPalettes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {createFeatureConfig} from '../utils';
44
export default createFeatureConfig({
55
name: Feature.EnableTenantSettingPalettes,
66
state: {
7-
development: false,
8-
production: false,
7+
development: true,
8+
production: true,
99
},
1010
});

src/server/components/features/features-list/NewDefaultPalette.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {createFeatureConfig} from '../utils';
44
export default createFeatureConfig({
55
name: Feature.NewDefaultPalette,
66
state: {
7-
development: false,
8-
production: false,
7+
development: true,
8+
production: true,
99
},
1010
});

src/server/components/layout/opensource-layout-config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import type {RenderParams} from '@gravity-ui/app-layout';
22

3-
import type {AppEnvironment, AppInstallation, DLGlobalData, DLUser} from '../../../shared';
3+
import type {
4+
AppEnvironment,
5+
AppInstallation,
6+
DLGlobalData,
7+
DLUser,
8+
TenantSettings,
9+
} from '../../../shared';
410
import {FALLBACK_LANGUAGES, Feature, Language, USER_SETTINGS_KEY} from '../../../shared';
511
import type {AppLayoutSettings, GetLayoutConfig} from '../../types/app-layout';
612
import {addTranslationsScript} from '../../utils/language';
@@ -71,6 +77,10 @@ export const getOpensourceLayoutConfig: GetLayoutConfig = async (args) => {
7177
// applying new favicon from rebranding
7278
const faviconUrl = isRebrandingEnabled ? '/os-favicon.ico' : config.faviconUrl;
7379

80+
const tenantSettings: TenantSettings = {
81+
defaultColorPaletteId: res.locals.tenantDefaultColorPaletteId,
82+
};
83+
7484
const DL: DLGlobalData = {
7585
user,
7686
userSettings,
@@ -96,6 +106,7 @@ export const getOpensourceLayoutConfig: GetLayoutConfig = async (args) => {
96106
docsUrl: config.docsUrl,
97107
orderedAuthRoles: config.orderedAuthRoles,
98108
authSignupDisabled: req.ctx.config.authSignupDisabled,
109+
tenantSettings,
99110
...appLayoutSettings.DL,
100111
};
101112
const renderConfig: RenderParams<{DL: DLGlobalData}> = {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type {NextFunction, Request, Response} from '@gravity-ui/expresskit';
2+
import {REQUEST_ID_PARAM_NAME} from '@gravity-ui/nodekit';
3+
4+
import {onFail} from '../callbacks';
5+
import {registry} from '../registry';
6+
import type {DatalensGatewaySchemas} from '../types/gateway';
7+
8+
export function getTenantSettingsMiddleware() {
9+
async function resolveTenantSettings(req: Request, res: Response, next: NextFunction) {
10+
const {ctx} = req;
11+
12+
const requestId = req.ctx.get(REQUEST_ID_PARAM_NAME);
13+
const currentTenantId = 'common';
14+
15+
const {gatewayApi} = registry.getGatewayApi<DatalensGatewaySchemas>();
16+
const {getAuthArgsUSPrivate} = registry.common.auth.getAll();
17+
const authArgsUSPrivate = getAuthArgsUSPrivate(req, res);
18+
19+
const tenantDetailsResponce = await gatewayApi.usPrivate._getTenantDetails({
20+
ctx,
21+
headers: req.headers,
22+
requestId: requestId ?? '',
23+
authArgs: authArgsUSPrivate,
24+
args: {tenantId: currentTenantId},
25+
});
26+
const resolvedTenant = tenantDetailsResponce.responseData;
27+
res.locals.tenantDefaultColorPaletteId = resolvedTenant.settings?.defaultColorPaletteId;
28+
29+
next();
30+
}
31+
32+
return function resolveTenantSettingsMiddleware(
33+
req: Request,
34+
res: Response,
35+
next: NextFunction,
36+
) {
37+
resolveTenantSettings(req, res, next)
38+
.catch((error) => {
39+
req.ctx.logError('TENANT_RESOLVED_FAILED', error);
40+
onFail(req, res);
41+
})
42+
.catch((error) => next(error));
43+
};
44+
}

src/server/modes/charts/plugins/datalens/js/helpers/colors/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const getChartColorsConfig = ({
2323
const fallbackColors = selectServerPalette({
2424
palette: colorsConfig.palette,
2525
availablePalettes,
26+
customColorPalettes: loadedColorPalettes,
2627
defaultColorPaletteId,
2728
});
2829

src/server/modes/charts/plugins/datalens/preparers/pie/gravity-charts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function prepareD3Pie(args: PrepareFunctionArgs) {
5656
return {
5757
...item,
5858
value: item.y,
59-
color: String(item.color),
59+
color: item.color,
6060
formattedValue: getFormattedValue(String(item.y), {
6161
...measure,
6262
data_type: idToDataType[measure.guid],

src/server/modes/opensource/routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {getZitadelRoutes} from '../../components/zitadel/routes';
1212
import {ping} from '../../controllers/ping';
1313
import {workbooksTransferController} from '../../controllers/workbook-transfer';
1414
import {getConnectorIconsMiddleware} from '../../middlewares';
15+
import {getTenantSettingsMiddleware} from '../../middlewares/tenant-settings';
1516
import type {ExtendedAppRouteDescription} from '../../types/controllers';
1617
import {getConfiguredRoute} from '../../utils/routes';
1718
import {applyPluginRoutes} from '../charts/init-charts-engine';
@@ -119,6 +120,7 @@ function getDataLensRoutes({
119120
authArgs: getAuthArgs(req, res),
120121
}),
121122
}),
123+
getTenantSettingsMiddleware(),
122124
],
123125
ui: true,
124126
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {entriesActions} from './entries';
2+
import {tenantActions} from './tenant';
23

34
export const actions = {
45
...entriesActions,
6+
...tenantActions,
57
};

0 commit comments

Comments
 (0)