diff --git a/contentcuration/contentcuration/frontend/administration/pages/Channels/ChannelTable.vue b/contentcuration/contentcuration/frontend/administration/pages/Channels/ChannelTable.vue index 34b2ef0870..e139cbfcab 100644 --- a/contentcuration/contentcuration/frontend/administration/pages/Channels/ChannelTable.vue +++ b/contentcuration/contentcuration/frontend/administration/pages/Channels/ChannelTable.vue @@ -5,13 +5,13 @@ {{ `${$formatNumber(count)} ${count === 1 ? 'channel' : 'channels'}` }} @@ -45,8 +44,8 @@ { - if (channelTypeFilter.value === 'kolibriStudio') { + if (channelTypeFilter.value === ChannelTypeFilter.KOLIBRI_LIBRARY) { return { live: { label: 'Live', params: {} }, cheffed: { label: 'Sushi chef', params: { cheffed: true } }, }; - } else if (channelTypeFilter.value === 'community') { + } else if (channelTypeFilter.value === ChannelTypeFilter.COMMUNITY_LIBRARY) { return { live: { label: 'Live', params: { community_library_live: true } }, needsReview: { label: 'Needs review', params: { - community_library_live: false, - latest_community_library_submission_status: ['PENDING', 'REJECTED'], + latest_community_library_submission_status: [ + CommunityLibraryStatus.PENDING, + CommunityLibraryStatus.REJECTED, + ], }, }, published: { label: 'Published', params: {} }, cheffed: { label: 'Sushi chef', params: { cheffed: true } }, }; - } else if (channelTypeFilter.value === 'unlisted') { + } else if (channelTypeFilter.value === ChannelTypeFilter.UNLISTED) { return { - live: { label: 'Live', params: {} }, - draft: { label: 'Draft', params: { published: false } }, - published: { label: 'Published', params: { published: true } }, - cheffed: { label: 'Sushi chef', params: { cheffed: true } }, + live: { label: 'Live', params: { deleted: false } }, + draft: { label: 'Draft', params: { published: false, deleted: false } }, + published: { label: 'Published', params: { published: true, deleted: false } }, + cheffed: { label: 'Sushi chef', params: { cheffed: true, deleted: false } }, + deleted: { label: 'Deleted', params: { deleted: true } }, + }; + } else if (channelTypeFilter.value === ChannelTypeFilter.ALL) { + return { + live: { label: 'Live', params: { deleted: false } }, + published: { label: 'Published', params: { published: true, deleted: false } }, + draft: { label: 'Draft', params: { published: false, deleted: false } }, + cheffed: { label: 'Sushi chef', params: { cheffed: true, deleted: false } }, + deleted: { label: 'Deleted', params: { deleted: true } }, }; } return {}; @@ -230,7 +258,9 @@ } = useFilter({ name: 'channelType', filterMap: channelTypeFilterMap, + defaultValue: ChannelTypeFilter.ALL, }); + // Temporal wrapper, must be removed after migrating to KSelect const channelTypeFilter = computed({ get: () => _channelTypeFilter.value.value || undefined, @@ -281,10 +311,14 @@ fetchQueryParams: keywordSearchFetchQueryParams, } = useKeywordSearch(); - watch(channelTypeFilter, () => { - const options = channelStatusOptions.value; - channelStatusFilter.value = options.length ? options[0].value : null; - }); + watch( + channelTypeFilter, + () => { + const options = channelStatusOptions.value; + channelStatusFilter.value = options.length ? options[0].value : null; + }, + { immediate: true }, + ); const filterFetchQueryParams = computed(() => { return { diff --git a/contentcuration/contentcuration/frontend/administration/pages/Channels/__tests__/channelTable.spec.js b/contentcuration/contentcuration/frontend/administration/pages/Channels/__tests__/channelTable.spec.js index f0e17e9366..c35516a05b 100644 --- a/contentcuration/contentcuration/frontend/administration/pages/Channels/__tests__/channelTable.spec.js +++ b/contentcuration/contentcuration/frontend/administration/pages/Channels/__tests__/channelTable.spec.js @@ -55,8 +55,8 @@ describe('channelTable', () => { }); describe('filters', () => { it('changing channel type filter should set query params', async () => { - wrapper.vm.channelTypeFilter = 'community'; - expect(router.currentRoute.query.channelType).toBe('community'); + wrapper.vm.channelTypeFilter = 'communityLibrary'; + expect(router.currentRoute.query.channelType).toBe('communityLibrary'); }); it('changing language filter should set query params', () => { wrapper.vm.languageFilter = 'en'; @@ -72,7 +72,7 @@ describe('channelTable', () => { expect(router.currentRoute.query.keywords).toBe('keyword test'); }); it('changing channel type filter should reset channel status filter', async () => { - wrapper.vm.channelTypeFilter = 'community'; + wrapper.vm.channelTypeFilter = 'communityLibrary'; wrapper.vm.channelStatusFilter = 'published'; await wrapper.vm.$nextTick(); wrapper.vm.channelTypeFilter = 'unlisted'; diff --git a/contentcuration/contentcuration/frontend/shared/composables/useFilter.js b/contentcuration/contentcuration/frontend/shared/composables/useFilter.js index fbc07698c9..2dd713bba9 100644 --- a/contentcuration/contentcuration/frontend/shared/composables/useFilter.js +++ b/contentcuration/contentcuration/frontend/shared/composables/useFilter.js @@ -34,9 +34,10 @@ import { useQueryParams } from './useQueryParams'; * @param {Object} params The parameters for the filter. * @param {string} params.name The name of the filter used in query params. * @param {Object} params.filterMap A map of available filters. + * @param {string|null} [params.defaultValue] Optional default value if query param is not set. * @returns {UseFilterReturn} */ -export function useFilter({ name, filterMap }) { +export function useFilter({ name, filterMap, defaultValue = null }) { const route = useRoute(); const { updateQueryParams } = useQueryParams(); @@ -44,7 +45,7 @@ export function useFilter({ name, filterMap }) { get: () => { const routeFilter = route.query[name]; const filterOption = options.value.find(option => option.value === routeFilter); - return filterOption || {}; + return filterOption || options.value.find(option => option.value === defaultValue) || {}; }, set: value => { updateQueryParams({