Skip to content

Commit 6802dbd

Browse files
atomicgamedeveloperMicrochesstprasadtalasila
authored
feat: Changes the Gitlab constants to user settings (#1249 and #1297)
- Converts hardcoded GitLab configuration into user settings. Uses browser LocalStorage to save settins across different user sessions. - Refactors and consolidates interfaces to backend - Updates tests to use mocks for the new constant getter functions --------- Co-authored-by: Neble <marcusnj123@gmail.com> Co-authored-by: Prasad Talasila <prasadtalasila@users.noreply.github.com> Co-authored-by: Marcus Jensen <79929209+Microchesst@users.noreply.github.com>
1 parent a4eae5b commit 6802dbd

File tree

132 files changed

+1740
-756
lines changed

Some content is hidden

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

132 files changed

+1740
-756
lines changed

client/jest.config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
"moduleNameMapper": {
3030
"^test/(.*)$": "<rootDir>/test/$1",
3131
"\\.(css|less|scss)$": "<rootDir>/test/__mocks__/styleMock.ts"
32-
}
32+
},
33+
"maxWorkers": 3
3334
}

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@into-cps-association/dtaas-web",
3-
"version": "0.8.4",
3+
"version": "0.9.0",
44
"description": "Web client for Digital Twin as a Service (DTaaS)",
55
"main": "index.tsx",
66
"author": "prasadtalasila <prasad.talasila@gmail.com> (http://prasad.talasila.in/)",

client/playwright.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default defineConfig({
2525
retries: process.env.CI ? 0 : 1, // Disable retries on Github actions for now as setup always fails
2626
timeout: process.env.CI ? 1000 : 60 * 1000,
2727
globalTimeout: 10 * 60 * 1000,
28+
workers: 3,
2829
testDir: './test/e2e/tests',
2930
testMatch: /.*\.test\.ts/,
3031
reporter: [
@@ -51,7 +52,7 @@ export default defineConfig({
5152
use: {
5253
baseURL: BASE_URI,
5354
screenshot: 'only-on-failure',
54-
trace: 'on-first-retry', // Wil not record trace on Github actions because of no retries
55+
trace: 'on-first-retry', // Will not record trace on Github actions because of no retries
5556
headless: true,
5657
},
5758
projects: [
@@ -81,4 +82,5 @@ export default defineConfig({
8182
],
8283
globalSetup: 'test/e2e/setup/global.setup.ts',
8384
globalTeardown: 'test/e2e/setup/global-teardown.ts',
85+
reportSlowTests: null,
8486
});

client/src/model/backend/gitlab/ARCHITECTURE.md renamed to client/src/model/backend/ARCHITECTURE.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ the backends are connected to key objects:
3232
await this.backend.api.createRepositoryFile(
3333
projectToUse,
3434
`${filePath}/${file.name}`,
35-
'main',
35+
getBranchName(),
3636
file.content,
3737
commitMessage,
3838
);
@@ -45,7 +45,7 @@ the backends are connected to key objects:
4545
The Instance is responsible for linking the DTaaS application to the selected backend.
4646
This entails keeping track of logs, project ids and keeping associated backend API
4747
instances for further operations as described below. The interface is described in
48-
`./UtilInterfaces.ts` with a concrete implementation being `./instance.ts`. It is
48+
`./backendInterfaces.ts` with a concrete implementation being `./instance.ts`. It is
4949
either created on an instance basis or passed from instance to instance when
5050
creating other instances. These then use the enriched project information to
5151
execute API commands, as demonstrated above. Detailed Logs are kept for any
@@ -55,7 +55,7 @@ Digital Twin executions, describing the success and job processing.
5555

5656
The Backend communicates directly with the backend server for pipeline execution,
5757
log retrieval, and or file management. The interface is described in
58-
`./UtilInterfaces.ts` with a concrete implementation being `./backend.ts`. It is
58+
`./backendInterfaces.ts` with a concrete implementation being `./backend.ts`. It is
5959
created before the Instance to be injected and may be initialized there. After
6060
this, it may be called through the Instance directly (e.g.
6161
`myInstance.api.cancelPipeline(...)`). It may contain a client field from a
@@ -179,8 +179,12 @@ to provide the desired backend implementation.
179179

180180
## Data Flow
181181

182-
The below class diagram shows how a backend (Gitlab) is used.
183-
![Class diagram over ./Preview/Util](./classDiagramOfPreviewUtil.png)
182+
The basic data flow consists of a bidirectional relationship between the backend
183+
and the application. The files can be created, deleted and triggered
184+
from the UI changing the state of the storage backend's files and running its pipelines
185+
on the execution backend, if they are seperated.
186+
Statuses on pipelines are intermittently retrieved and showcased to the user
187+
who also has the option to stop execution, as well as reading execution logs received.
184188

185189
## Extension Points
186190

client/src/model/backend/gitlab/IMPLEMENTATION.md renamed to client/src/model/backend/IMPLEMENTATION.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ and `BackendAPI` interfaces..
1515

1616
This class implements the Backend interface. Its primary responsibility is to
1717
create the backend API instance, and to obtain the private and common project IDs
18-
from the username and the group name defined in [constants.ts](./constants.ts).
18+
from the username and the group name defined in [constants.ts](./constants.ts)
19+
as well as in the settings.
1920
After this, it keeps track of execution log entries and gives high-level access
2021
to pipeline information and execution, job traces and ids for further processing
2122
by the Backend API, which has to be Gitlab. It is only dependent on its backend
@@ -91,7 +92,7 @@ Example:
9192
Please follow [config guide](../docs/admin/client/config.md) for setting up the
9293
configuration. You may also wish to change certain constants, like
9394
`COMMON_LIBRARY_PROJECT_NAME` and `DT_DIRECTORY` in the [constants](./constants.ts)
94-
file.
95+
file or in the settings tab.
9596

9697
<!--
9798
Maybe something about setting up the folder structure.

client/src/model/backend/gitlab/backend.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import { Gitlab } from '@gitbeaker/rest';
77
import {
88
BackendAPI,
99
ProjectId,
10-
Pipeline,
1110
RepositoryFile,
1211
RepositoryTreeItem,
1312
ProjectSummary,
1413
JobSummary,
15-
} from './UtilityInterfaces';
14+
} from 'model/backend/interfaces/backendInterfaces';
15+
import { Pipeline } from '../interfaces/execution';
16+
import { getBranchName } from './digitalTwinConfig/settingsUtility';
1617

1718
export class GitlabAPI implements BackendAPI {
1819
public client: InstanceType<typeof Gitlab>;
@@ -112,7 +113,7 @@ export class GitlabAPI implements BackendAPI {
112113
public async listRepositoryFiles(
113114
projectId: ProjectId,
114115
path = '',
115-
ref = 'main',
116+
ref = getBranchName(),
116117
recursive = false,
117118
): Promise<RepositoryTreeItem[]> {
118119
const items = await this.client.Repositories.allRepositoryTrees(projectId, {
-383 KB
Binary file not shown.

client/src/model/backend/gitlab/constants.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { FileType } from 'model/backend/interfaces/sharedInterfaces';
2+
3+
// Default project settings
4+
export const GROUP_NAME = 'DTaaS';
5+
export const DT_DIRECTORY = 'digital_twins';
6+
export const COMMON_LIBRARY_PROJECT_NAME = 'common';
7+
export const RUNNER_TAG = 'linux';
8+
export const BRANCH_NAME = 'master';
9+
10+
// Pipeline execution settings
11+
export const MAX_EXECUTION_TIME = 10 * 60 * 1000;
12+
export const PIPELINE_POLL_INTERVAL = 5 * 1000;
13+
14+
// Maps tabs to project folders (based on asset types)
15+
export enum AssetTypes {
16+
'Functions' = 'functions',
17+
'Models' = 'models',
18+
'Tools' = 'tools',
19+
'Data' = 'data',
20+
'Digital Twins' = 'digital_twins',
21+
'Digital Twin' = 'digital_twin',
22+
}
23+
24+
// Default initial files for new digital twins
25+
export const defaultFiles = [
26+
{ name: 'description.md', type: FileType.DESCRIPTION },
27+
{ name: 'README.md', type: FileType.DESCRIPTION },
28+
{ name: '.gitlab-ci.yml', type: FileType.CONFIGURATION },
29+
];
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import store from 'store/store';
2+
3+
/**
4+
* Non-hook getters for settings stored in the Redux store.
5+
*
6+
* - Default values are defined in ./constants.ts
7+
* - Hook variants are in util/settingsUseHooks.ts
8+
* - Settings can be overridden by the user in the Settings tab
9+
*/
10+
export const getGroupName = (): string => store.getState().settings.GROUP_NAME;
11+
export const getDTDirectory = (): string =>
12+
store.getState().settings.DT_DIRECTORY;
13+
export const getCommonLibraryProjectName = (): string =>
14+
store.getState().settings.COMMON_LIBRARY_PROJECT_NAME;
15+
export const getRunnerTag = (): string => store.getState().settings.RUNNER_TAG;
16+
export const getBranchName = (): string =>
17+
store.getState().settings.BRANCH_NAME;

0 commit comments

Comments
 (0)