Skip to content

Commit 78d7489

Browse files
committed
feat: Changed the constants to variables under account/settings
1 parent 664266b commit 78d7489

File tree

13 files changed

+528
-55
lines changed

13 files changed

+528
-55
lines changed
Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,54 @@
1+
import { useSelector } from 'react-redux';
2+
import store, { RootState } from 'store/store';
3+
4+
// The values below are managed in the settings tab, reading from the store
15
// util/gitlab.ts
2-
export const GROUP_NAME = 'DTaaS';
3-
export const DT_DIRECTORY = 'digital_twins';
4-
export const COMMON_LIBRARY_PROJECT_ID = 3;
6+
export const useGroupName = (): string => {
7+
// Reads GROUP_NAME from the Redux store.
8+
const GROUP_NAME = useSelector(
9+
(state: RootState) => state.settings.GROUP_NAME,
10+
);
11+
return GROUP_NAME;
12+
};
13+
14+
// Non-hook version for use in classes and other non-React contexts
15+
export const getGroupName = (): string => store.getState().settings.GROUP_NAME;
16+
17+
export const useDTDirectory = (): string => {
18+
// Reads DT_DIRECTORY from the Redux store.
19+
const DT_DIRECTORY = useSelector(
20+
(state: RootState) => state.settings.DT_DIRECTORY,
21+
);
22+
return DT_DIRECTORY;
23+
};
24+
25+
// Non-hook version for use in classes and other non-React contexts
26+
export const getDTDirectory = (): string =>
27+
store.getState().settings.DT_DIRECTORY;
28+
29+
export const useCommonLibraryProjectId = (): number => {
30+
// Reads COMMON_LIBRARY_PROJECT_ID from the Redux store.
31+
const COMMON_LIBRARY_PROJECT_ID = useSelector(
32+
(state: RootState) => state.settings.COMMON_LIBRARY_PROJECT_ID,
33+
);
34+
return COMMON_LIBRARY_PROJECT_ID;
35+
};
36+
37+
// Non-hook version for use in classes and other non-React contexts
38+
export const getCommonLibraryProjectId = (): number =>
39+
store.getState().settings.COMMON_LIBRARY_PROJECT_ID;
540

641
// util/digitalTwin.ts
7-
export const RUNNER_TAG = 'linux';
42+
export const useRunnerTag = (): string => {
43+
// Reads RUNNER_TAG from the Redux store.
44+
const RUNNER_TAG = useSelector(
45+
(state: RootState) => state.settings.RUNNER_TAG,
46+
);
47+
return RUNNER_TAG;
48+
};
49+
50+
// Non-hook version for use in classes and other non-React contexts
51+
export const getRunnerTag = (): string => store.getState().settings.RUNNER_TAG;
852

953
// route/digitaltwins/execute/pipelineChecks.ts
1054
export const MAX_EXECUTION_TIME = 10 * 60 * 1000;

client/src/preview/util/digitalTwin.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { getAuthority } from 'util/envUtil';
55
import { FileState } from 'preview/store/file.slice';
66
import { LibraryConfigFile } from 'preview/store/libraryConfigFiles.slice';
7-
import { RUNNER_TAG } from 'model/backend/gitlab/constants';
7+
import { getRunnerTag } from 'model/backend/gitlab/constants';
88
import GitlabInstance from './gitlab';
99
import {
1010
isValidInstance,
@@ -86,7 +86,8 @@ class DigitalTwin {
8686
}
8787

8888
private async triggerPipeline() {
89-
const variables = { DTName: this.DTName, RunnerTag: RUNNER_TAG };
89+
const runnerTag = getRunnerTag();
90+
const variables = { DTName: this.DTName, RunnerTag: runnerTag };
9091
return this.gitlabInstance.api.PipelineTriggerTokens.trigger(
9192
this.gitlabInstance.projectId!,
9293
'main',
@@ -96,39 +97,41 @@ class DigitalTwin {
9697
}
9798

9899
async execute(): Promise<number | null> {
100+
const runnerTag = getRunnerTag();
99101
if (!isValidInstance(this)) {
100-
logError(this, RUNNER_TAG, 'Missing projectId or triggerToken');
102+
logError(this, runnerTag, 'Missing projectId or triggerToken');
101103
return null;
102104
}
103105

104106
try {
105107
const response = await this.triggerPipeline();
106-
logSuccess(this, RUNNER_TAG);
108+
logSuccess(this, runnerTag);
107109
this.pipelineId = response.id;
108110
return this.pipelineId;
109111
} catch (error) {
110-
logError(this, RUNNER_TAG, String(error));
112+
logError(this, runnerTag, String(error));
111113
return null;
112114
}
113115
}
114116

115117
async stop(projectId: number, pipeline: string): Promise<void> {
118+
const runnerTag = getRunnerTag();
116119
const pipelineId =
117120
pipeline === 'parentPipeline' ? this.pipelineId : this.pipelineId! + 1;
118121
try {
119122
await this.gitlabInstance.api.Pipelines.cancel(projectId, pipelineId!);
120123
this.gitlabInstance.logs.push({
121124
status: 'canceled',
122125
DTName: this.DTName,
123-
runnerTag: RUNNER_TAG,
126+
runnerTag,
124127
});
125128
this.lastExecutionStatus = 'canceled';
126129
} catch (error) {
127130
this.gitlabInstance.logs.push({
128131
status: 'error',
129132
error: new Error(String(error)),
130133
DTName: this.DTName,
131-
runnerTag: RUNNER_TAG,
134+
runnerTag,
132135
});
133136
this.lastExecutionStatus = 'error';
134137
}

client/src/preview/util/fileHandler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable no-await-in-loop */
33

44
import { FileState } from 'preview/store/file.slice';
5-
import { COMMON_LIBRARY_PROJECT_ID } from 'model/backend/gitlab/constants';
5+
import { getCommonLibraryProjectId } from 'model/backend/gitlab/constants';
66
import GitlabInstance from './gitlab';
77
import { IFile } from './ifile';
88
import { FileType } from './DTAssets';
@@ -44,7 +44,7 @@ class FileHandler implements IFile {
4444
commonProject?: boolean,
4545
): Promise<void> {
4646
const projectToUse = commonProject
47-
? COMMON_LIBRARY_PROJECT_ID
47+
? getCommonLibraryProjectId()
4848
: this.gitlabInstance.projectId;
4949
await this.gitlabInstance.api.RepositoryFiles.create(
5050
projectToUse!,
@@ -81,7 +81,7 @@ class FileHandler implements IFile {
8181
async getFileContent(filePath: string, isPrivate?: boolean): Promise<string> {
8282
const projectToUse =
8383
isPrivate === false
84-
? COMMON_LIBRARY_PROJECT_ID
84+
? getCommonLibraryProjectId()
8585
: this.gitlabInstance.projectId;
8686

8787
const response = await this.gitlabInstance.api.RepositoryFiles.show(
@@ -123,7 +123,7 @@ class FileHandler implements IFile {
123123
): Promise<string[]> {
124124
const projectToUse = isPrivate
125125
? this.gitlabInstance.projectId
126-
: COMMON_LIBRARY_PROJECT_ID;
126+
: getCommonLibraryProjectId();
127127

128128
try {
129129
const response =
@@ -162,7 +162,7 @@ class FileHandler implements IFile {
162162
): Promise<string[]> {
163163
const projectToUse = isPrivate
164164
? this.gitlabInstance.projectId
165-
: COMMON_LIBRARY_PROJECT_ID;
165+
: getCommonLibraryProjectId();
166166

167167
const shouldBeRecursive = filePath.includes('common/');
168168

client/src/preview/util/gitlab.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Camelize, Gitlab, JobSchema } from '@gitbeaker/rest';
22
import {
3-
GROUP_NAME,
4-
DT_DIRECTORY,
5-
COMMON_LIBRARY_PROJECT_ID,
3+
getGroupName,
4+
getDTDirectory,
5+
getCommonLibraryProjectId,
66
} from 'model/backend/gitlab/constants';
77
import { Asset } from '../components/asset/Asset';
88

@@ -63,7 +63,7 @@ class GitlabInstance {
6363
async getProjectId(): Promise<number | null> {
6464
let projectId: number | null = null;
6565

66-
const group = await this.api.Groups.show(GROUP_NAME);
66+
const group = await this.api.Groups.show(getGroupName());
6767
const projects = await this.api.Groups.allProjects(group.id);
6868
const project = projects.find((proj) => proj.name === this.username);
6969

@@ -86,13 +86,15 @@ class GitlabInstance {
8686

8787
async getDTSubfolders(projectId: number): Promise<Asset[]> {
8888
const files = await this.api.Repositories.allRepositoryTrees(projectId, {
89-
path: DT_DIRECTORY,
89+
path: getDTDirectory(),
9090
recursive: false,
9191
});
9292

9393
const subfolders: Asset[] = await Promise.all(
9494
files
95-
.filter((file) => file.type === 'tree' && file.path !== DT_DIRECTORY)
95+
.filter(
96+
(file) => file.type === 'tree' && file.path !== getDTDirectory(),
97+
)
9698
.map(async (file) => ({
9799
name: file.name,
98100
path: file.path,
@@ -113,7 +115,7 @@ class GitlabInstance {
113115
throw new Error(`Invalid asset type: ${type}`);
114116
}
115117

116-
const projectToUse = isPrivate ? projectId : COMMON_LIBRARY_PROJECT_ID;
118+
const projectToUse = isPrivate ? projectId : getCommonLibraryProjectId();
117119

118120
const files = await this.api.Repositories.allRepositoryTrees(projectToUse, {
119121
path: mappedPath,
File renamed without changes.

client/src/route/auth/AccountTabData.tsx renamed to client/src/route/account/AccountTabData.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import { useAuth } from 'react-oidc-context';
33
import { TabData } from 'components/tab/subcomponents/TabRender';
4+
import SettingsForm from './SettingsForm'; // Import the SettingsForm component
45

56
function ListGroups(groups: string[]): React.ReactNode[] {
67
const boldGroups = groups.map((group) =>
@@ -80,6 +81,8 @@ function SettingsTab() {
8081
<a href={profileUrl}>SSO OAuth Provider.</a>
8182
</b>
8283
</p>
84+
85+
<SettingsForm />
8386
</div>
8487
);
8588
}

0 commit comments

Comments
 (0)