[Manager] Fix reactivity of node pack version options dropdown (#3557)

This commit is contained in:
Christian Byrne
2025-04-22 21:45:46 +08:00
committed by GitHub
parent d8f4dc95bb
commit 11f909436c

View File

@@ -10,7 +10,7 @@
<ProgressSpinner class="w-8 h-8 mb-2" />
{{ $t('manager.loadingVersions') }}
</div>
<div v-else-if="allVersionOptions.length === 0" class="py-2">
<div v-else-if="versionOptions.length === 0" class="py-2">
<NoResultsPlaceholder
:title="$t('g.noResultsFound')"
:message="$t('manager.tryAgainLater')"
@@ -23,7 +23,7 @@
v-model="selectedVersion"
option-label="label"
option-value="value"
:options="allVersionOptions"
:options="versionOptions"
:highlight-on-select="false"
class="my-3 w-full max-h-[50vh] border-none shadow-none"
>
@@ -58,11 +58,11 @@
</template>
<script setup lang="ts">
import { useAsyncState, whenever } from '@vueuse/core'
import { whenever } from '@vueuse/core'
import Button from 'primevue/button'
import Listbox from 'primevue/listbox'
import ProgressSpinner from 'primevue/progressspinner'
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { onMounted, onUnmounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import ContentDivider from '@/components/common/ContentDivider.vue'
@@ -119,47 +119,53 @@ const fetchVersions = async () => {
return (await registryService.getPackVersions(nodePack.id)) || []
}
const {
isLoading: isLoadingVersions,
state: versions,
execute: startFetchVersions
} = useAsyncState(fetchVersions, [])
const versionOptions = ref<
{
value: string
label: string
}[]
>([])
const specialOptions = computed(() => {
const options = [
const isLoadingVersions = ref(false)
const onNodePackChange = async () => {
isLoadingVersions.value = true
// Fetch versions from the registry
const versions = await fetchVersions()
const availableVersionOptions = versions
.map((version) => ({
value: version.version ?? '',
label: version.version ?? ''
}))
.filter((option) => option.value)
// Add Latest option
const defaultVersions = [
{
value: SelectedVersion.LATEST,
label: t('manager.latestVersion')
}
]
// Only include nightly option if there is a repo
// Add Nightly option if there is a non-empty `repository` field
if (nodePack.repository?.length) {
options.push({
defaultVersions.push({
value: SelectedVersion.NIGHTLY,
label: t('manager.nightlyVersion')
})
}
return options
})
const versionOptions = computed(() =>
versions.value.map((version) => ({
value: version.version,
label: version.version
}))
)
const allVersionOptions = computed(() => [
...specialOptions.value,
...versionOptions.value
])
versionOptions.value = [...defaultVersions, ...availableVersionOptions]
isLoadingVersions.value = false
}
whenever(
() => nodePack.id,
() => startFetchVersions(),
{ deep: true }
() => nodePack,
() => {
void onNodePackChange()
},
{ deep: true, immediate: true }
)
const handleSubmit = async () => {