feat(@xen-orchestra/rest-api): add reactivity on task store (#9271)

This commit is contained in:
Mathieu
2025-12-15 10:51:58 +01:00
committed by GitHub
parent 9f3872a5f1
commit a4ab2e8b06
4 changed files with 10 additions and 2 deletions

View File

@@ -632,6 +632,7 @@ export type XoTask = {
end?: number
id: Branded<'task'>
infos?: { data: unknown; message: string }[]
progress?: number
properties: {
method?: string
name?: string

View File

@@ -1,13 +1,17 @@
import { useXoCollectionState } from '@/composables/xo-collection-state/use-xo-collection-state.ts'
import { convertTaskToCore } from '@/utils/convert-task-to-core.util.ts'
import { watchCollectionWrapper } from '@/utils/sse.util'
import { defineRemoteResource } from '@core/packages/remote-resource/define-remote-resource.ts'
import type { XoTask } from '@vates/types'
import { computed } from 'vue'
const ONE_DAY = 24 * 60 * 60 * 1000
const taskFields: (keyof XoTask)[] = ['id', 'start', 'end', 'properties', 'status', 'progress', 'tasks'] as const
export const useXoTaskCollection = defineRemoteResource({
url: '/rest/v0/tasks?fields=id,start,end,properties,status,progress,tasks',
url: `/rest/v0/tasks?fields=${taskFields}`,
watchCollection: watchCollectionWrapper({ resource: 'task', fields: taskFields }),
initialData: () => [] as XoTask[],
state: (tasks, context) => {
const lastDayTasks = computed(() => {

View File

@@ -28,7 +28,7 @@ export function watchCollectionWrapper<T>({
handleWatching?: THandleWatching
predicate?: (receivedObj: T | T[], context: ResourceContext<any[]> | undefined) => boolean
}) {
const _getType: (obj: unknown) => string | undefined = getType ?? ((obj: any) => obj.type)
const _getType: (obj: unknown) => string | undefined = getType ?? ((obj: any) => obj.$subscription)
const _getIdentifier: (obj: unknown) => string | undefined = getIdentifier ?? ((obj: any) => obj.id)
if (handleDelete === undefined) {

View File

@@ -15,6 +15,7 @@
- **XO 6:**
- [i18n] Update Czech, Danish, Spanish, French, Italian, Dutch, Portuguese (Brazil), and Russian translations (PR [#9243](https://github.com/vatesfr/xen-orchestra/pull/9243))
- [Reactivity] Tasks are now reactive (PR [#9271](https://github.com/vatesfr/xen-orchestra/pull/9271))
### Bug fixes
@@ -39,8 +40,10 @@
<!--packages-start-->
- @vates/types minor
- @xen-orchestra/mixins minor
- @xen-orchestra/rest-api minor
- @xen-orchestra/web minor
- @xen-orchestra/web-core minor
<!--packages-end-->