Line data Source code
1 : import { defineStore } from 'pinia'
2 : import { computed, ref } from 'vue'
3 :
4 : import type { ConflictDetectionResult } from '@/platform/customNodes/manager/types/conflictDetectionTypes'
5 :
6 2356 : export const useConflictDetectionStore = defineStore(
7 : 'conflictDetection',
8 : () => {
9 : // State
10 2355 : const conflictedPackages = ref<ConflictDetectionResult[]>([])
11 2355 : const isDetecting = ref(false)
12 2355 : const lastDetectionTime = ref<string | null>(null)
13 :
14 : // Getters
15 2355 : const hasConflicts = computed(() =>
16 : conflictedPackages.value.some((pkg) => pkg.has_conflict)
17 : )
18 :
19 2355 : const getConflictsForPackageByID = computed(
20 : () => (packageId: string) =>
21 : conflictedPackages.value.find((pkg) => pkg.package_id === packageId)
22 : )
23 :
24 2355 : const bannedPackages = computed(() =>
25 : conflictedPackages.value.filter((pkg) =>
26 : pkg.conflicts.some((conflict) => conflict.type === 'banned')
27 : )
28 : )
29 :
30 2355 : const securityPendingPackages = computed(() =>
31 : conflictedPackages.value.filter((pkg) =>
32 : pkg.conflicts.some((conflict) => conflict.type === 'pending')
33 : )
34 : )
35 :
36 : // Actions
37 0 : function setConflictedPackages(packages: ConflictDetectionResult[]) {
38 0 : conflictedPackages.value = [...packages]
39 : }
40 :
41 15 : function clearConflicts() {
42 15 : conflictedPackages.value = []
43 : }
44 :
45 0 : function setDetecting(detecting: boolean) {
46 0 : isDetecting.value = detecting
47 : }
48 :
49 0 : function setLastDetectionTime(time: string) {
50 0 : lastDetectionTime.value = time
51 : }
52 :
53 2355 : return {
54 : // State
55 : conflictedPackages,
56 : isDetecting,
57 : lastDetectionTime,
58 : // Getters
59 : hasConflicts,
60 : getConflictsForPackageByID,
61 : bannedPackages,
62 : securityPendingPackages,
63 : // Actions
64 : setConflictedPackages,
65 : clearConflicts,
66 : setDetecting,
67 : setLastDetectionTime
68 : }
69 : }
70 : )
|