-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
InstallDependencies.vue
110 lines (95 loc) · 2.75 KB
/
InstallDependencies.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<template>
<WizardLayout
:next="allDependenciesInstalled ? t('setupPage.step.continue') : t('setupWizard.installDependencies.waitForInstall')"
:can-navigate-forward="allDependenciesInstalled"
:back-fn="props.backFn"
:next-fn="confirmInstalled"
class="max-w-[640px] relative"
:main-button-variant="allDependenciesInstalled ? 'indigo-dark' : 'disabled'"
:skip-fn="!allDependenciesInstalled ? confirmInstalled : undefined"
>
<template
v-if="allDependenciesInstalled && showSuccessAlert"
#accessory
>
<Alert
v-model="showSuccessAlert"
class="w-full"
:icon="CircleCheck"
:title="t('setupWizard.installDependencies.installationAlertSuccess')"
status="success"
dismissible
/>
</template>
<ManualInstall :gql="props.gql" />
</WizardLayout>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
import WizardLayout from './WizardLayout.vue'
import ManualInstall from './ManualInstall.vue'
import Alert from '@cy/components/Alert.vue'
import { gql } from '@urql/core'
import type { InstallDependenciesFragment } from '../generated/graphql'
import CircleCheck from '~icons/cy/circle-check_x16.svg'
import {
InstallDependencies_ScaffoldFilesDocument,
Wizard_InstalledPackagesDocument,
} from '../generated/graphql'
import { useI18n } from '@cy/i18n'
import { useMutation, useQuery } from '@urql/vue'
import { useIntervalFn } from '@vueuse/core'
gql`
mutation InstallDependencies_scaffoldFiles {
scaffoldTestingType {
...ScaffoldedFiles
}
}
`
gql`
fragment InstallDependencies on Query {
...ManualInstall
wizard {
packagesToInstall {
id
package
}
}
}
`
gql`
fragment Wizard_InstalledPackages_Data on Query {
...InstallDependencies
}
`
gql`
query Wizard_InstalledPackages {
...Wizard_InstalledPackages_Data
}`
const queryInstalled = useQuery({
query: Wizard_InstalledPackagesDocument,
})
const props = defineProps<{
gql: InstallDependenciesFragment
backFn: () => void
}>()
const checkForInstalledDependencies = (wizard) => {
return wizard?.packagesToInstall?.every((pkg) => pkg.satisfied) || false
}
const allDependenciesInstalled = ref(checkForInstalledDependencies(props.gql.wizard))
const showSuccessAlert = ref(true)
if (!allDependenciesInstalled.value) {
const intervalQueryTrigger = useIntervalFn(async () => {
const res = await queryInstalled.executeQuery({ requestPolicy: 'network-only' })
if (checkForInstalledDependencies(res.data.value?.wizard)) {
intervalQueryTrigger.pause()
allDependenciesInstalled.value = true
}
}, 1000)
}
const { t } = useI18n()
const mutation = useMutation(InstallDependencies_ScaffoldFilesDocument)
const confirmInstalled = () => {
mutation.executeMutation({})
}
</script>