Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions src/services/v2/edge-storage/edge-storage-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class EdgeStorageService extends BaseService {
body
})

this.queryClient.removeQueries({ queryKey: queryKeys.edgeStorage.buckets.all() })
this.queryClient.invalidateQueries({ queryKey: queryKeys.edgeStorage.buckets.all() })

return data
}
Expand Down Expand Up @@ -99,7 +99,23 @@ export class EdgeStorageService extends BaseService {
body: { workloads_access: bucket.workloads_access }
})

this.queryClient.removeQueries({ queryKey: queryKeys.edgeStorage.buckets.all() })
// Update cache with new value from API response
this.queryClient.setQueriesData({ queryKey: queryKeys.edgeStorage.buckets.all() }, (cached) => {
if (!cached?.body) return cached
return {
...cached,
body: cached.body.map((cachedBucket) =>
cachedBucket.name === bucket.name
? { ...cachedBucket, workloadsAccess: bucket.workloads_access }
: cachedBucket
)
}
})

// Invalidate to trigger refetch if needed
this.queryClient.invalidateQueries({
queryKey: queryKeys.edgeStorage.buckets.all()
})

return data
}
Expand All @@ -110,7 +126,7 @@ export class EdgeStorageService extends BaseService {
url: `${this.baseURL}/buckets/${bucketName}`
})

this.queryClient.removeQueries({ queryKey: queryKeys.edgeStorage.buckets.all() })
await this.queryClient.invalidateQueries({ queryKey: queryKeys.edgeStorage.buckets.all() })

return `Bucket "${bucketName}" has been deleted successfully`
}
Expand Down Expand Up @@ -384,6 +400,15 @@ export class EdgeStorageService extends BaseService {
{ persist: firstPage && !skipCache, skipCache }
)
}

getBucketFromCache = (bucketName) => {
return super.getFromCache({
queryKey: queryKeys.edgeStorage.buckets.all(),
id: bucketName,
fieldName: 'name',
listPath: 'body'
})
}
createCredential = async (credential = {}) => {
const body = this.adapter?.transformCreateEdgeStorageCredential?.(credential)
const { data } = await this.http.request({
Expand All @@ -392,7 +417,7 @@ export class EdgeStorageService extends BaseService {
body
})

this.queryClient.removeQueries({ queryKey: queryKeys.edgeStorage.credentials.all() })
this.queryClient.invalidateQueries({ queryKey: queryKeys.edgeStorage.credentials.all() })

return data
}
Expand All @@ -402,7 +427,7 @@ export class EdgeStorageService extends BaseService {
url: `${this.baseURL}/credentials/${credentialId}`
})

this.queryClient.removeQueries({ queryKey: queryKeys.edgeStorage.credentials.all() })
this.queryClient.invalidateQueries({ queryKey: queryKeys.edgeStorage.credentials.all() })
}
}
export const edgeStorageService = new EdgeStorageService()
4 changes: 2 additions & 2 deletions src/views/EdgeStorage/ListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -583,11 +583,11 @@
})

const totalRecords = computed(() => {
return fileData.value.length
return fileData.value?.length
})

const filterData = computed(() => {
let filteredData = fileData.value.filter((item) => {
let filteredData = fileData.value?.filter((item) => {
return item.name.toLowerCase().includes(fileSearchTerm.value.toLowerCase())
})

Expand Down
7 changes: 7 additions & 0 deletions src/views/EdgeStorage/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@
}

const loadService = ({ id }) => {
const cachedBucket = edgeStorageService.getBucketFromCache(id)
if (cachedBucket) {
return {
name: cachedBucket.name,
workloads_access: cachedBucket.workloadsAccess
}
}
const bucket = findBucketById(id)

return {
Expand Down
Loading