Skip to content

Commit

Permalink
✨ Display & regenerate module & environment token value in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Lysoun committed Mar 5, 2024
1 parent af4d969 commit 68ddd53
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
8 changes: 5 additions & 3 deletions modules/ui/src/lib/components/atoms/A_button.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
export let label;
export let type = 'button';
export let label: string;
export let type: "button" | "submit" | "reset" = 'button';
// eslint-disable-next-line @typescript-eslint/no-empty-function
export let onClickAction: () => void = () => { }
</script>

<button {type}>{label}</button>
<button {type} on:click={onClickAction}>{label}</button>
3 changes: 3 additions & 0 deletions modules/ui/src/lib/domain/ModuleEnvironmentToken.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type ModuleEnvironmentToken = {
tokenValue: string
}
17 changes: 17 additions & 0 deletions modules/ui/src/lib/services/ModuleEnvironmentTokenService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type {ModuleEnvironmentToken} from '$lib/domain/ModuleEnvironmentToken';
import {Http} from '$lib/services/utils/HttpService';

export class ModuleEnvironmentTokenService {
private static baseUrl = '/api/v1/moduleEnvironmentTokens';

public static byModuleAndEnvironment = async (moduleRef: string, environmentRef: string): Promise<ModuleEnvironmentToken> => {
return Http.get<ModuleEnvironmentToken>(`${ModuleEnvironmentTokenService.baseUrl}/byModuleAndEnvironmentRef/${moduleRef}/${environmentRef}`);
}

public static regenerateToken = async (moduleRef: string, environmentRef: string): Promise<ModuleEnvironmentToken> => {
return Http.post<ModuleEnvironmentToken>(`${ModuleEnvironmentTokenService.baseUrl}/regenerateToken`, {
moduleRef: moduleRef,
environmentRef: environmentRef
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,67 @@
import {ExecutionMock} from "$lib/mocks/ExecutionMock";
import O_matrixScriptEnv from "$lib/components/organisms/O_matrix/O_matrixScriptEnv.svelte";
import M_error from "$lib/components/molecules/M_error.svelte";
import {ModuleEnvironmentTokenService} from '$lib/services/ModuleEnvironmentTokenService';
import type {ModuleEnvironmentToken} from '$lib/domain/ModuleEnvironmentToken';
import A_button from '$lib/components/atoms/A_button.svelte';
let project
let env
let modulePromise
let scriptEnvMatrix
let moduleEnvironmentTokenPromise: Promise<ModuleEnvironmentToken>
$: if($page.params?.project) {
ProjectService.byId($page.params.project).then(foundProject => {
project = foundProject
});
}
$: if($page.url.searchParams?.has('env')) {
EnvService.byId($page.url.searchParams?.get('env')).then(foundEnv => {
const environmentRef = $page.url.searchParams?.get('env');
$: if(environmentRef) {
EnvService.byId(environmentRef).then(foundEnv => {
env = foundEnv
});
}
$: if($page.params?.module) {
const moduleRef = $page.params?.module;
$: if(moduleRef) {
modulePromise = ModuleService.byId($page.params.module);
}
$: if(environmentRef && moduleRef) {
moduleEnvironmentTokenPromise = ModuleEnvironmentTokenService.byModuleAndEnvironment(
moduleRef,
environmentRef
)
}
$: if (project) {
scriptEnvMatrix = ExecutionMock.scriptEnvMatrixByProject(project.id)
}
export function regenerateToken() {
console.log('pouet');
moduleEnvironmentTokenPromise = ModuleEnvironmentTokenService.regenerateToken(
moduleRef,
environmentRef
)
}
</script>

{#await modulePromise}
<p>...waiting</p>
{:then module}
Module {module.name} du projet {#if project} {project.name} {/if} {#if env} sur l'environnement {env.name}{/if}

{#await moduleEnvironmentTokenPromise}
Chargement du token en cours...
{:then moduleEnvironmentToken}
Token : {moduleEnvironmentToken.tokenValue}
<A_button label="Régénérer token" onClickAction={regenerateToken}>
</A_button>
{/await}

<br>
<a href="{module.id}/edit">Editer</a>

Expand Down

0 comments on commit 68ddd53

Please sign in to comment.