Dashboard and error handling

This commit is contained in:
2025-07-15 13:22:11 +02:00
parent 5ac4c987d3
commit 6a5149fd4c
27 changed files with 572 additions and 204 deletions

View File

@ -3,6 +3,7 @@ import { SshecretObjectType } from '@/api/types'
import type { SshecretObject } from '@/api/types'
import { SshecretAdmin } from '@/client'
import type { ClientQueryResult, Client, SecretView, ClientSecretGroupList, SecretListView, ClientSecretGroup } from '@/client'
import { assertSdkResponseOk } from '@/api/assertSdkResponseOk'
export const useTreeState = defineStore('treeState', {
state: () => ({
@ -55,12 +56,9 @@ export const useTreeState = defineStore('treeState', {
limit,
}
})
if (response.data) {
this.clients = response.data
return response.data.total_results
}
this.clients = null
return 0
const clientData = assertSdkResponseOk(response)
this.clients = clientData
return clientData.total_results
},
async queryClients(query: string, offset: number = 0, limit: number = 100): Promise<number> {
// Query or search. Result is the number of hits.
@ -74,30 +72,21 @@ export const useTreeState = defineStore('treeState', {
}
})
if (response.data) {
this.clients = response.data
return response.data.total_results
}
this.clients = null
return 0
const clientData = assertSdkResponseOk(response)
this.clients = clientData
return clientData.total_results
},
async getSecretNames(): Promise<boolean> {
// Get all secret names.
const response = await SshecretAdmin.getSecretNamesApiV1SecretsGet()
if (response.data) {
this.secrets = response.data
return true
}
return false
this.secrets = assertSdkResponseOk(response)
return true
},
async getSecretGroups(): Promise<boolean> {
const response = await SshecretAdmin.getSecretGroupsApiV1SecretsGroupsGet()
if (response.data) {
this.secretGroups = response.data
return true
}
return false
this.secretGroups = assertSdkResponseOk(response)
return true
},
async getClient(id: string | null = null): Promise<Client> {
if (!id && this.selected?.objectType === SshecretObjectType.Client) {
@ -115,24 +104,15 @@ export const useTreeState = defineStore('treeState', {
}
}
const response = await SshecretAdmin.getClientApiV1ClientsIdGet({ path: { id: id } })
if (response.data) {
return response.data
}
throw "Client not found"
return assertSdkResponseOk(response)
},
async getSecret(name: string): Promise<SecretView> {
const response = await SshecretAdmin.getSecretApiV1SecretsNameGet({ path: { name: name } })
if (response.data) {
return response.data
}
throw "Secret not found"
return assertSdkResponseOk(response)
},
async getGroup(path: string): Promise<ClientSecretGroup> {
const response = await SshecretAdmin.getSecretGroupApiV1SecretsGroupsGroupPathGet({ path: { group_path: path } })
if (response.data) {
return response.data
}
throw "Group not found"
return assertSdkResponseOk(response)
},
async getSelected(): Promise<Client | SecretView | ClientSecretGroup | null> {
if (!this.selected) {
@ -156,11 +136,9 @@ export const useTreeState = defineStore('treeState', {
if (clientIndex >= 0) {
console.log("found client at index: ", clientIndex, this.clients.clients[clientIndex])
const response = await SshecretAdmin.getClientApiV1ClientsIdGet({ path: { id: id } })
if (response.data) {
const newClient = response.data
this.clients.clients = this.clients.clients.map(c => c.id === id ? newClient : c)
return true
}
const newClient = assertSdkResponseOk(response)
this.clients.clients = this.clients.clients.map(c => c.id === id ? newClient : c)
return true
}
}
return false