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
45 changes: 26 additions & 19 deletions src/components/bundle/BundleCompareSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ const props = withDefaults(defineProps<{
noResultsLabel: string
disabled?: boolean
showSpinner?: boolean
compareMode?: 'manifest' | 'dependencies'
}>(), {
modelValue: null,
disabled: false,
showSpinner: false,
compareMode: 'manifest',
})

const emit = defineEmits<{
Expand Down Expand Up @@ -74,17 +76,26 @@ function selectCompareVersion(option: VersionRow | null) {
emit('update:modelValue', option)
}

// The manifest tab compares per-file manifest entries (manifest_count), while the
// dependencies tab compares native_packages. Only offer bundles that actually carry
// the data the current tab diffs on, so gate the candidate list per mode.
function buildCompareBaseQuery() {
const query = supabase
.from('app_versions')
.select('id, name, created_at, manifest_count, app_id')
.eq('app_id', props.appId)
return props.compareMode === 'dependencies'
? query.not('native_packages', 'is', null)
: query.gt('manifest_count', 0)
}

async function loadLatestCompareVersions() {
if (!props.appId || !props.currentVersionId) {
latestCompareVersions.value = []
return
}
const requestId = ++latestCompareRequestId.value
const { data, error } = await supabase
.from('app_versions')
.select('id, name, created_at, manifest_count, app_id')
.eq('app_id', props.appId)
.gt('manifest_count', 0)
const { data, error } = await buildCompareBaseQuery()
.neq('id', props.currentVersionId)
.order('created_at', { ascending: false })
.limit(5)
Expand Down Expand Up @@ -191,11 +202,7 @@ async function loadPreferredCompareVersions() {
return

const uniqueIds = [...new Set(preferredHistory.map(entry => entry.versionId))]
const { data: versions, error } = await supabase
.from('app_versions')
.select('id, name, created_at, manifest_count, app_id')
.eq('app_id', props.appId)
.gt('manifest_count', 0)
const { data: versions, error } = await buildCompareBaseQuery()
.in('id', uniqueIds)

if (requestId !== preferredCompareRequestId)
Expand Down Expand Up @@ -225,19 +232,17 @@ async function searchCompareVersions(term: string) {

const requestId = ++compareSearchRequestId.value
compareSearchLoading.value = true
const baseQuery = supabase
.from('app_versions')
.select('id, name, created_at, manifest_count, app_id')
.eq('app_id', props.appId)
.gt('manifest_count', 0)
.neq('id', props.currentVersionId)

// Each chain must start from its own builder: the Supabase query builder is
// mutable and returns `this`, so reusing one instance across concurrent
// chains would leak filters between the requests.
const numericId = Number(term)
let data: VersionRow[] | null = null
let error: unknown = null

if (Number.isNaN(numericId)) {
const response = await baseQuery
const response = await buildCompareBaseQuery()
.neq('id', props.currentVersionId)
.ilike('name', `%${term}%`)
.order('created_at', { ascending: false })
.limit(5)
Expand All @@ -250,11 +255,13 @@ async function searchCompareVersions(term: string) {
}
else {
const [nameResponse, idResponse] = await Promise.all([
baseQuery
buildCompareBaseQuery()
.neq('id', props.currentVersionId)
.ilike('name', `%${term}%`)
.order('created_at', { ascending: false })
.limit(5),
baseQuery
buildCompareBaseQuery()
.neq('id', props.currentVersionId)
.eq('id', numericId)
.order('created_at', { ascending: false })
.limit(5),
Expand Down
1 change: 1 addition & 0 deletions src/pages/app/[app].bundle.[bundle].dependencies.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ watchEffect(async () => {
v-model="selectedCompareVersion"
:app-id="packageId"
:current-version-id="id"
compare-mode="dependencies"
:label="t('dependencies-compare-label')"
:none-label="t('dependencies-compare-none')"
:latest-label="t('dependencies-compare-latest')"
Expand Down
Loading