Environment variables in admin panel (read only) - front (#10011)
Frontend for https://github.com/twentyhq/core-team-issues/issues/293 POC - https://github.com/twentyhq/twenty/pull/9903 --------- Co-authored-by: Félix Malfait <felix@twenty.com> Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
@ -33,9 +33,33 @@ jest.mock(
|
||||
);
|
||||
|
||||
jest.mock(
|
||||
'src/engine/core-modules/environment/constants/environment-variables-hidden-groups',
|
||||
'src/engine/core-modules/environment/constants/environment-variables-group-metadata',
|
||||
() => ({
|
||||
ENVIRONMENT_VARIABLES_HIDDEN_GROUPS: new Set(['HIDDEN_GROUP']),
|
||||
ENVIRONMENT_VARIABLES_GROUP_METADATA: {
|
||||
GROUP_1: {
|
||||
position: 100,
|
||||
description: '',
|
||||
},
|
||||
GROUP_2: {
|
||||
position: 200,
|
||||
description: '',
|
||||
},
|
||||
VISIBLE_GROUP: {
|
||||
position: 300,
|
||||
description: '',
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
jest.mock(
|
||||
'src/engine/core-modules/environment/constants/environment-variables-sub-group-metadata',
|
||||
() => ({
|
||||
ENVIRONMENT_VARIABLES_SUB_GROUP_METADATA: {
|
||||
SUBGROUP_1: {
|
||||
description: '',
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@ -262,9 +286,10 @@ describe('AdminPanelService', () => {
|
||||
const result = service.getEnvironmentVariablesGrouped();
|
||||
|
||||
expect(result).toEqual({
|
||||
groups: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
groupName: 'GROUP_1',
|
||||
groups: [
|
||||
{
|
||||
name: 'GROUP_1',
|
||||
description: '',
|
||||
variables: [
|
||||
{
|
||||
name: 'VAR_1',
|
||||
@ -275,7 +300,8 @@ describe('AdminPanelService', () => {
|
||||
],
|
||||
subgroups: [
|
||||
{
|
||||
subgroupName: 'SUBGROUP_1',
|
||||
name: 'SUBGROUP_1',
|
||||
description: '',
|
||||
variables: [
|
||||
{
|
||||
name: 'VAR_2',
|
||||
@ -286,9 +312,10 @@ describe('AdminPanelService', () => {
|
||||
],
|
||||
},
|
||||
],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
groupName: 'GROUP_2',
|
||||
},
|
||||
{
|
||||
name: 'GROUP_2',
|
||||
description: '',
|
||||
variables: [
|
||||
{
|
||||
name: 'VAR_3',
|
||||
@ -298,8 +325,8 @@ describe('AdminPanelService', () => {
|
||||
},
|
||||
],
|
||||
subgroups: [],
|
||||
}),
|
||||
]),
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
@ -324,7 +351,7 @@ describe('AdminPanelService', () => {
|
||||
const result = service.getEnvironmentVariablesGrouped();
|
||||
|
||||
const group = result.groups.find(
|
||||
(g) => g.groupName === ('GROUP_1' as EnvironmentVariablesGroup),
|
||||
(g) => g.name === ('GROUP_1' as EnvironmentVariablesGroup),
|
||||
);
|
||||
|
||||
expect(group?.variables[0].name).toBe('A_VAR');
|
||||
@ -340,34 +367,5 @@ describe('AdminPanelService', () => {
|
||||
groups: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('should exclude hidden groups from the output', () => {
|
||||
EnvironmentServiceGetAllMock.mockReturnValue({
|
||||
VAR_1: {
|
||||
value: 'value1',
|
||||
metadata: {
|
||||
group: 'HIDDEN_GROUP',
|
||||
description: 'Description 1',
|
||||
},
|
||||
},
|
||||
VAR_2: {
|
||||
value: 'value2',
|
||||
metadata: {
|
||||
group: 'VISIBLE_GROUP',
|
||||
description: 'Description 2',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const result = service.getEnvironmentVariablesGrouped();
|
||||
|
||||
expect(result.groups).toHaveLength(1);
|
||||
expect(result.groups[0].groupName).toBe('VISIBLE_GROUP');
|
||||
expect(result.groups).not.toContainEqual(
|
||||
expect.objectContaining({
|
||||
groupName: 'HIDDEN_GROUP',
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -12,8 +12,8 @@ import {
|
||||
AuthExceptionCode,
|
||||
} from 'src/engine/core-modules/auth/auth.exception';
|
||||
import { LoginTokenService } from 'src/engine/core-modules/auth/token/services/login-token.service';
|
||||
import { ENVIRONMENT_VARIABLES_GROUP_POSITION } from 'src/engine/core-modules/environment/constants/environment-variables-group-position';
|
||||
import { ENVIRONMENT_VARIABLES_HIDDEN_GROUPS } from 'src/engine/core-modules/environment/constants/environment-variables-hidden-groups';
|
||||
import { ENVIRONMENT_VARIABLES_GROUP_METADATA } from 'src/engine/core-modules/environment/constants/environment-variables-group-metadata';
|
||||
import { ENVIRONMENT_VARIABLES_SUB_GROUP_METADATA } from 'src/engine/core-modules/environment/constants/environment-variables-sub-group-metadata';
|
||||
import { EnvironmentVariablesGroup } from 'src/engine/core-modules/environment/enums/environment-variables-group.enum';
|
||||
import { EnvironmentVariablesSubGroup } from 'src/engine/core-modules/environment/enums/environment-variables-sub-group.enum';
|
||||
import { EnvironmentService } from 'src/engine/core-modules/environment/environment.service';
|
||||
@ -180,10 +180,6 @@ export class AdminPanelService {
|
||||
for (const [varName, { value, metadata }] of Object.entries(rawEnvVars)) {
|
||||
const { group, subGroup, description } = metadata;
|
||||
|
||||
if (ENVIRONMENT_VARIABLES_HIDDEN_GROUPS.has(group)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const envVar: EnvironmentVariable = {
|
||||
name: varName,
|
||||
description,
|
||||
@ -218,18 +214,23 @@ export class AdminPanelService {
|
||||
groupedData.entries(),
|
||||
)
|
||||
.sort((a, b) => {
|
||||
const positionA = ENVIRONMENT_VARIABLES_GROUP_POSITION[a[0]];
|
||||
const positionB = ENVIRONMENT_VARIABLES_GROUP_POSITION[b[0]];
|
||||
const positionA = ENVIRONMENT_VARIABLES_GROUP_METADATA[a[0]].position;
|
||||
const positionB = ENVIRONMENT_VARIABLES_GROUP_METADATA[b[0]].position;
|
||||
|
||||
return positionA - positionB;
|
||||
})
|
||||
.map(([groupName, data]) => ({
|
||||
groupName,
|
||||
.map(([name, data]) => ({
|
||||
name,
|
||||
description: ENVIRONMENT_VARIABLES_GROUP_METADATA[name].description,
|
||||
isHiddenOnLoad:
|
||||
ENVIRONMENT_VARIABLES_GROUP_METADATA[name].isHiddenOnLoad,
|
||||
variables: data.variables.sort((a, b) => a.name.localeCompare(b.name)),
|
||||
subgroups: Array.from(data.subgroups.entries())
|
||||
.sort((a, b) => a[0].localeCompare(b[0]))
|
||||
.map(([subgroupName, variables]) => ({
|
||||
subgroupName,
|
||||
.map(([name, variables]) => ({
|
||||
name,
|
||||
description:
|
||||
ENVIRONMENT_VARIABLES_SUB_GROUP_METADATA[name].description,
|
||||
variables,
|
||||
})),
|
||||
}));
|
||||
|
||||
@ -18,5 +18,11 @@ export class EnvironmentVariablesGroupData {
|
||||
subgroups: EnvironmentVariablesSubgroupData[];
|
||||
|
||||
@Field(() => EnvironmentVariablesGroup)
|
||||
groupName: EnvironmentVariablesGroup;
|
||||
name: EnvironmentVariablesGroup;
|
||||
|
||||
@Field(() => String, { defaultValue: '' })
|
||||
description: string;
|
||||
|
||||
@Field(() => Boolean, { defaultValue: false })
|
||||
isHiddenOnLoad: boolean;
|
||||
}
|
||||
|
||||
@ -14,5 +14,8 @@ export class EnvironmentVariablesSubgroupData {
|
||||
variables: EnvironmentVariable[];
|
||||
|
||||
@Field(() => EnvironmentVariablesSubGroup)
|
||||
subgroupName: EnvironmentVariablesSubGroup;
|
||||
name: EnvironmentVariablesSubGroup;
|
||||
|
||||
@Field(() => String, { defaultValue: '' })
|
||||
description: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user