|
| 1 | +import { FilterConfigType } from '@/shared/modules/filters/types/FilterConfig'; |
| 2 | +import { itemLabelRendererByType } from '@/shared/modules/filters/config/itemLabelRendererByType'; |
| 3 | +import { |
| 4 | + MultiSelectAsyncFilterConfig, |
| 5 | + MultiSelectAsyncFilterOptions, MultiSelectAsyncFilterValue, |
| 6 | +} from '@/shared/modules/filters/types/filterTypes/MultiSelectAsyncFilterConfig'; |
| 7 | +import { OrganizationService } from '@/modules/organization/organization-service'; |
| 8 | +import { DEFAULT_ORGANIZATION_FILTERS } from '@/modules/organization/store/constants'; |
| 9 | + |
| 10 | +const organizations: MultiSelectAsyncFilterConfig = { |
| 11 | + id: 'organizations', |
| 12 | + label: 'Organization', |
| 13 | + iconClass: 'ri-community-line', |
| 14 | + type: FilterConfigType.MULTISELECT_ASYNC, |
| 15 | + options: { |
| 16 | + remoteMethod: (query) => OrganizationService.listAutocomplete(query, 10) |
| 17 | + .then((data: any[]) => data.map((organization) => ({ |
| 18 | + label: organization.label, |
| 19 | + value: organization.id, |
| 20 | + logo: organization.logo, |
| 21 | + }))), |
| 22 | + remotePopulateItems: (ids: string[]) => OrganizationService.listAutocomplete({ |
| 23 | + filter: { |
| 24 | + and: [ |
| 25 | + ...DEFAULT_ORGANIZATION_FILTERS, |
| 26 | + { |
| 27 | + id: { in: ids }, |
| 28 | + }, |
| 29 | + ], |
| 30 | + }, |
| 31 | + orderBy: null, |
| 32 | + limit: ids.length, |
| 33 | + offset: 0, |
| 34 | + }) |
| 35 | + .then(({ rows }: any) => rows.map((organization: any) => ({ |
| 36 | + label: organization.displayName, |
| 37 | + value: organization.id, |
| 38 | + logo: organization.logo, |
| 39 | + }))), |
| 40 | + }, |
| 41 | + itemLabelRenderer(value: MultiSelectAsyncFilterValue, options: MultiSelectAsyncFilterOptions, data: any): string { |
| 42 | + return itemLabelRendererByType[FilterConfigType.MULTISELECT_ASYNC]('Organization', value, options, data); |
| 43 | + }, |
| 44 | + apiFilterRenderer({ value, include }: MultiSelectAsyncFilterValue): any[] { |
| 45 | + const filter = { |
| 46 | + or: value.map((id) => ({ organizations: { eq: id } })), |
| 47 | + }; |
| 48 | + return [ |
| 49 | + (include ? filter : { not: filter }), |
| 50 | + ]; |
| 51 | + }, |
| 52 | +}; |
| 53 | + |
| 54 | +export default organizations; |
0 commit comments