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
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ const { extensions, filterTerm = '' } = defineProps<{
}>()

const { $gettext } = useGettext()
const sortBy = ref<keyof ExtensionInfo>('name')
type SortField = 'name' | 'status'

const sortBy = ref<SortField>('name')
const sortDir = ref<SortDir>(SortDir.Asc)

const filteredExtensions = computed(() => {
Expand All @@ -90,14 +92,19 @@ const filteredExtensions = computed(() => {

const items = computed(() => {
return [...unref(filteredExtensions)].sort((a, b) => {
const c = (a[unref(sortBy)] || '').toString()
const d = (b[unref(sortBy)] || '').toString()
const field = unref(sortBy)
if (field === 'status') {
const result = Number(b.loaded) - Number(a.loaded)
return unref(sortDir) === SortDir.Desc ? -result : result
}
const c = (a[field] || '').toString()
const d = (b[field] || '').toString()
return unref(sortDir) === SortDir.Desc ? d.localeCompare(c) : c.localeCompare(d)
})
})

function handleSort(event: { sortBy: string; sortDir: SortDir }) {
sortBy.value = event.sortBy as keyof ExtensionInfo
sortBy.value = event.sortBy as SortField
sortDir.value = event.sortDir
}

Expand All @@ -121,6 +128,7 @@ const fields = computed(() => [
name: 'status',
title: $gettext('Status'),
type: 'slot',
sortable: true,
width: 'shrink' as const
}
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ describe('ExtensionsList', () => {
])
})

it('sorts by status ascending and descending', () => {
const { wrapper } = getWrapper({
extensions: [
{ name: 'Alpha', version: '1.0.0', loaded: false },
{ name: 'Beta', version: '1.0.0', loaded: true }
]
})

;(wrapper.vm as any).handleSort({ sortBy: 'status', sortDir: SortDir.Asc })
expect((wrapper.vm as any).items.map((item: { name: string }) => item.name)).toEqual([
'Beta',
'Alpha'
])
;(wrapper.vm as any).handleSort({ sortBy: 'status', sortDir: SortDir.Desc })
expect((wrapper.vm as any).items.map((item: { name: string }) => item.name)).toEqual([
'Alpha',
'Beta'
])
})

it('highlights the matching part of app names', () => {
const ocTableStub = {
props: ['data'],
Expand Down
Loading