From 8310c50a1026f118f09b9b04930ce37fbbc86ccd Mon Sep 17 00:00:00 2001 From: deetz99 Date: Tue, 20 Aug 2024 16:52:11 -0700 Subject: [PATCH 1/6] filter table results --- .../app/composables/useAffiliations.ts | 112 +++++++++++++----- .../app/locales/en-CA.ts | 10 +- .../app/locales/fr-CA.ts | 10 +- .../app/pages/index.vue | 71 ++++++----- 4 files changed, 134 insertions(+), 69 deletions(-) diff --git a/business-registry-dashboard/app/composables/useAffiliations.ts b/business-registry-dashboard/app/composables/useAffiliations.ts index 1f8e8fd..074fc63 100644 --- a/business-registry-dashboard/app/composables/useAffiliations.ts +++ b/business-registry-dashboard/app/composables/useAffiliations.ts @@ -3,15 +3,18 @@ export const useAffiliations = () => { const { t } = useI18n() // const { getAffiliationInvitations } = useAffiliationInvitations() - const affiliations = (reactive({ + const affiliations = reactive({ filters: { isActive: false, - filterPayload: {} - } as AffiliationFilterParams, + businessName: '', + businessNumber: '', + type: '', + status: '' + }, loading: false, results: [] as Business[], count: 0 - }) as unknown) as AffiliationState + }) // TODO: handle affiliation invitations // async function handleAffiliationInvitations (affiliatedEntities: Business[]): Promise { @@ -72,6 +75,7 @@ export const useAffiliations = () => { } entity.nameRequest = buildNameRequestObject(nr) } + affiliations.results.push(entity) affiliations.count = affiliations.results.length // TODO: add affilaition invites to business object @@ -97,30 +101,16 @@ export const useAffiliations = () => { affiliations.loading = false affiliations.results = [] affiliations.count = 0 - affiliations.filters.filterPayload = {} - affiliations.filters.isActive = false + resetFilters() } - // const updateFilter = (filterField?: string, value?: any) => { - // if (filterField) { - // if (value) { - // affiliations.filters.filterPayload[filterField] = value - // affiliations.filters.isActive = true - // } else { - // delete affiliations.filters.filterPayload[filterField] - // } - // } - // if (Object.keys(affiliations.filters.filterPayload).length === 0) { - // affiliations.filters.isActive = false - // } else { - // affiliations.filters.isActive = true - // } - // } - - // const clearAllFilters = () => { - // affiliations.filters.filterPayload = {} - // affiliations.filters.isActive = false - // } + function resetFilters () { + affiliations.filters.businessName = '' + affiliations.filters.businessNumber = '' + affiliations.filters.type = '' + affiliations.filters.status = '' + affiliations.filters.isActive = false + } const nameColumn = { key: 'legalName', label: 'Name' } const actionColumn = { key: 'actions', label: 'Actions' } @@ -177,6 +167,67 @@ export const useAffiliations = () => { ] } + const filteredResults = computed(() => { + let results = affiliations.results + + if (affiliations.filters.businessName) { + results = results.filter((result) => { + const businessName = affiliationName(result) + return businessName.toLowerCase().includes(affiliations.filters.businessName.toLowerCase()) + }) + } + + if (affiliations.filters.businessNumber) { + results = results.filter((result) => { + const businessNumber = number(result) + return businessNumber.toLowerCase().includes(affiliations.filters.businessNumber.toLowerCase()) + }) + } + + if (affiliations.filters.type) { + results = results.filter((result) => { + const type = affiliationType(result) + return type.includes(affiliations.filters.type) + }) + } + + if (affiliations.filters.status) { + results = results.filter((result) => { + const status = affiliationStatus(result) + return status.includes(affiliations.filters.status) + }) + } + + return results + }) + + const statusOptions = computed(() => { + const optionSet = new Set() + + affiliations.results.forEach((item) => { + optionSet.add(affiliationStatus(item)) + }) + + return Array.from(optionSet) + }) + + const typeOptions = computed(() => { + const optionSet = new Set() + + affiliations.results.forEach((item) => { + optionSet.add(affiliationType(item)) + }) + + return Array.from(optionSet) + }) + + const hasFilters = computed(() => { + return affiliations.filters.businessName !== '' || + affiliations.filters.businessNumber !== '' || + affiliations.filters.type !== '' || + affiliations.filters.status !== '' + }) + return { getAffiliatedEntities, affiliations, @@ -184,8 +235,11 @@ export const useAffiliations = () => { visibleColumns, optionalColumns, selectedColumns, - setColumns - // clearAllFilters, - // updateFilter, + setColumns, + filteredResults, + statusOptions, + typeOptions, + hasFilters, + resetFilters } } diff --git a/business-registry-dashboard/app/locales/en-CA.ts b/business-registry-dashboard/app/locales/en-CA.ts index f03bede..9c1eb8d 100644 --- a/business-registry-dashboard/app/locales/en-CA.ts +++ b/business-registry-dashboard/app/locales/en-CA.ts @@ -111,7 +111,8 @@ export default { show: 'Help with Starting and Managing a Business', hide: 'Hide Help' }, - moreOptions: 'More Options' + moreOptions: 'More Options', + clearFilters: 'Clear Filters' }, currency: { cad: 'CAD', @@ -216,7 +217,8 @@ export default { addresses: 'Addresses', directors: 'Directors', confirm: 'Confirm', - select: 'Select' + select: 'Select', + none: 'None' }, page: { notFound: { @@ -292,7 +294,7 @@ export default { } }, legalType: { - aria: 'Filter by legal type, {count} selected', + aria: 'Filter by legal type, current filter: {filter}', placeholder: 'Type', selected: '{count} selected', clear: { @@ -301,7 +303,7 @@ export default { } }, busStates: { - aria: 'Filter by business status, {count} selected', + aria: 'Filter by business status, current filter: {filter}', placeholder: 'Status', selected: '{count} selected', clear: { diff --git a/business-registry-dashboard/app/locales/fr-CA.ts b/business-registry-dashboard/app/locales/fr-CA.ts index dcdfb0e..e1f49e4 100644 --- a/business-registry-dashboard/app/locales/fr-CA.ts +++ b/business-registry-dashboard/app/locales/fr-CA.ts @@ -111,7 +111,8 @@ export default { show: "Aide à la Création et à la Gestion d'une Entreprise", hide: "Masquer l'Aide" }, - moreOptions: "Plus d'options" + moreOptions: "Plus d'options", + clearFilters: 'Effacer les Filtres' }, currency: { cad: 'CAD', @@ -216,7 +217,8 @@ export default { addresses: 'Adresses', directors: 'Directeurs', confirm: 'Confirmer', - select: 'Sélectionner' + select: 'Sélectionner', + none: 'Aucun' }, page: { notFound: { @@ -292,7 +294,7 @@ export default { } }, legalType: { - aria: 'Filtrer par type juridique, {count} sélectionnés', + aria: 'Filtre par type juridique, filtre actuel: {filter}', placeholder: 'Taper', selected: '{count} sélectionnés', clear: { @@ -301,7 +303,7 @@ export default { } }, busStates: { - aria: "Filtrer par statut d'entreprise, {count} sélectionnés", + aria: "Filtrer par statut d'entreprise, filtre actuel: {filter}", placeholder: 'Statut', selected: '{count} sélectionnés', clear: { diff --git a/business-registry-dashboard/app/pages/index.vue b/business-registry-dashboard/app/pages/index.vue index ded60a3..6e7b4df 100644 --- a/business-registry-dashboard/app/pages/index.vue +++ b/business-registry-dashboard/app/pages/index.vue @@ -20,16 +20,13 @@ const { visibleColumns, optionalColumns, selectedColumns, - setColumns - // clearAllFilters, - // updateFilter, + setColumns, + filteredResults, + typeOptions, + statusOptions, + hasFilters, + resetFilters } = useAffiliations() - -const busTypes = ['BC Sole Proprietorship', 'Name Request', 'Incorporation Application', 'Registration'] -const selectedTypes = ref([]) - -const busStates = ['Active', 'Expired', 'Draft'] -const selectedStates = ref([]) @@ -294,14 +300,15 @@ const selectedStates = ref([]) name="i-mdi-check" aria-hidden="true" /> - {{ $t('table.affiliation.cell.name.approved', { name: nrName.name }) }} - {{ $t('table.affiliation.cell.name.rejected', { name: nrName.name }) }} + {{ $t('table.affiliation.cell.name.approved', { name: nrName.name }) }} + {{ $t('table.affiliation.cell.name.rejected', { name: nrName.name }) }} + {{ nrName.name }} Date: Wed, 21 Aug 2024 10:19:13 -0700 Subject: [PATCH 2/6] add comments, update filter computeds --- .../app/composables/useAffiliations.ts | 41 ++++++++----------- .../app/pages/index.vue | 1 + 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/business-registry-dashboard/app/composables/useAffiliations.ts b/business-registry-dashboard/app/composables/useAffiliations.ts index 074fc63..4d7b466 100644 --- a/business-registry-dashboard/app/composables/useAffiliations.ts +++ b/business-registry-dashboard/app/composables/useAffiliations.ts @@ -1,11 +1,10 @@ export const useAffiliations = () => { const accountStore = useConnectAccountStore() - const { t } = useI18n() + const { t, locale } = useI18n() // const { getAffiliationInvitations } = useAffiliationInvitations() const affiliations = reactive({ filters: { - isActive: false, businessName: '', businessNumber: '', type: '', @@ -89,6 +88,7 @@ export const useAffiliations = () => { } } + // load new affiliations when user changes accounts watch( [() => accountStore.currentAccount.id], async () => { @@ -109,20 +109,23 @@ export const useAffiliations = () => { affiliations.filters.businessNumber = '' affiliations.filters.type = '' affiliations.filters.status = '' - affiliations.filters.isActive = false } + // label required for columns type but overwritten in header slot, i18n not required const nameColumn = { key: 'legalName', label: 'Name' } const actionColumn = { key: 'actions', label: 'Actions' } + // optional table columns, i18n required because this is also used to populate the 'columns to show' dropdown const optionalColumns = [ { key: 'identifier', label: t('labels.number') }, { key: 'legalType', label: t('labels.type') }, { key: 'state', label: t('labels.status') } ] + // default user selectedColumns columns = optionalColumns const selectedColumns = ref([...optionalColumns]) + // default visible columns as all columns const visibleColumns = ref([ nameColumn, ...optionalColumns, @@ -131,9 +134,11 @@ export const useAffiliations = () => { const { width } = useWindowSize() + // update default columns on page width change watchDebounced( width, (newVal) => { + resetFilters() // reset filters so active filters do not get hidden when screen size changes if (newVal < 640) { // Mobile view visibleColumns.value = [nameColumn, actionColumn] @@ -156,9 +161,10 @@ export const useAffiliations = () => { ] } }, - { debounce: 500, immediate: true } + { debounce: 100, immediate: true } ) + // used to update columns @change on the 'columns to show' dropdown function setColumns () { visibleColumns.value = [ nameColumn, @@ -173,14 +179,14 @@ export const useAffiliations = () => { if (affiliations.filters.businessName) { results = results.filter((result) => { const businessName = affiliationName(result) - return businessName.toLowerCase().includes(affiliations.filters.businessName.toLowerCase()) + return businessName.toLocaleLowerCase(locale.value).includes(affiliations.filters.businessName.toLocaleLowerCase(locale.value)) }) } if (affiliations.filters.businessNumber) { results = results.filter((result) => { const businessNumber = number(result) - return businessNumber.toLowerCase().includes(affiliations.filters.businessNumber.toLowerCase()) + return businessNumber.toLocaleLowerCase(locale.value).includes(affiliations.filters.businessNumber.toLocaleLowerCase(locale.value)) }) } @@ -201,31 +207,18 @@ export const useAffiliations = () => { return results }) + // create status filter options relevant to affiliations.results const statusOptions = computed(() => { - const optionSet = new Set() - - affiliations.results.forEach((item) => { - optionSet.add(affiliationStatus(item)) - }) - - return Array.from(optionSet) + return Array.from(new Set(affiliations.results.map(affiliationStatus))) }) + // create type filter options relevant to affiliations.results const typeOptions = computed(() => { - const optionSet = new Set() - - affiliations.results.forEach((item) => { - optionSet.add(affiliationType(item)) - }) - - return Array.from(optionSet) + return Array.from(new Set(affiliations.results.map(affiliationType))) }) const hasFilters = computed(() => { - return affiliations.filters.businessName !== '' || - affiliations.filters.businessNumber !== '' || - affiliations.filters.type !== '' || - affiliations.filters.status !== '' + return Object.values(affiliations.filters).some(value => value !== '') }) return { diff --git a/business-registry-dashboard/app/pages/index.vue b/business-registry-dashboard/app/pages/index.vue index 6e7b4df..442ecf7 100644 --- a/business-registry-dashboard/app/pages/index.vue +++ b/business-registry-dashboard/app/pages/index.vue @@ -148,6 +148,7 @@ const { const { t } = useI18n() const accountStore = useConnectAccountStore() +const nrWebUrl = useRuntimeConfig().public.nrURL useHead({ title: t('page.home.title') @@ -10,10 +11,7 @@ definePageMeta({ order: 0 }) -const selected = ref('reg') - -const config = useRuntimeConfig() -const nrWebUrl = config.public.nrURL +const searchType = ref('reg') const { affiliations, @@ -72,25 +70,25 @@ const { }" >