From 1bdacdb74707e8cd7f43b0b735a838bb5291ec08 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Wed, 15 Jan 2025 16:10:18 +0100 Subject: [PATCH] Add functionality to delete credential groups in UI --- .../src/components/Tool/ToolCredentials.vue | 14 ++++++ .../Credentials/ManageToolCredentials.vue | 10 +++++ .../User/Credentials/ServiceCredentials.vue | 43 +++++++++++++++++-- client/src/stores/userCredentials.ts | 38 ++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) diff --git a/client/src/components/Tool/ToolCredentials.vue b/client/src/components/Tool/ToolCredentials.vue index b19cb56ed689..68e425894693 100644 --- a/client/src/components/Tool/ToolCredentials.vue +++ b/client/src/components/Tool/ToolCredentials.vue @@ -143,6 +143,19 @@ async function onSavedCredentials(providedCredentials: CreateSourceCredentialsPa } } +async function onDeleteCredentialsGroup(reference: string, groupName: string) { + busyMessage.value = "Updating your credentials..."; + isBusy.value = true; + try { + userCredentialsStore.deleteCredentialsGroupForTool(props.toolId, reference, groupName); + } catch (error) { + // TODO: Implement error handling. + console.error("Error deleting user credentials group", error); + } finally { + isBusy.value = false; + } +} + checkUserCredentials(); @@ -197,6 +210,7 @@ checkUserCredentials(); :tool-version="props.toolVersion" :tool-credentials-definition="credentialsDefinition" :user-tool-credentials="userCredentials" + @delete-credentials-group="onDeleteCredentialsGroup" @save-credentials="onSavedCredentials" /> diff --git a/client/src/components/User/Credentials/ManageToolCredentials.vue b/client/src/components/User/Credentials/ManageToolCredentials.vue index 0eb4c70c4039..51b1c639e2b7 100644 --- a/client/src/components/User/Credentials/ManageToolCredentials.vue +++ b/client/src/components/User/Credentials/ManageToolCredentials.vue @@ -28,6 +28,7 @@ const providedCredentials = ref(initializeCreden const emit = defineEmits<{ (e: "save-credentials", credentials: CreateSourceCredentialsPayload): void; + (e: "delete-credentials-group", reference: string, groupName: string): void; }>(); function saveCredentials() { @@ -103,6 +104,14 @@ function onNewCredentialsSet(credential: ServiceCredentialPayload, newSet: Servi } } +function onDeleteCredentialsGroup(reference: string, groupName: string) { + const credentialFound = providedCredentials.value.credentials.find((c) => c.reference === reference); + if (credentialFound) { + credentialFound.groups = credentialFound.groups.filter((g) => g.name !== groupName); + emit("delete-credentials-group", reference, groupName); + } +} + function onCurrentSetChange(credential: ServiceCredentialPayload, newSet: ServiceGroupPayload) { const credentialFound = providedCredentials.value.credentials.find((c) => c.reference === credential.reference); if (credentialFound) { @@ -133,6 +142,7 @@ function getServiceCredentialsDefinition(reference: string): ServiceCredentialsD :credential-payload="credential" class="mb-2" @new-credentials-set="onNewCredentialsSet" + @delete-credentials-group="onDeleteCredentialsGroup" @update-current-set="onCurrentSetChange" /> diff --git a/client/src/components/User/Credentials/ServiceCredentials.vue b/client/src/components/User/Credentials/ServiceCredentials.vue index 25e662bfcae9..6528d8becebf 100644 --- a/client/src/components/User/Credentials/ServiceCredentials.vue +++ b/client/src/components/User/Credentials/ServiceCredentials.vue @@ -1,4 +1,6 @@