Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add email option to members identities filter list #1478

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
48 changes: 45 additions & 3 deletions frontend/src/modules/member/config/filters/identities/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
} from '@/shared/modules/filters/types/filterTypes/MultiSelectFilterConfig';
import { CrowdIntegrations } from '@/integrations/integrations-config';
import { itemLabelRendererByType } from '@/shared/modules/filters/config/itemLabelRendererByType';
import { apiFilterRendererByType } from '@/shared/modules/filters/config/apiFilterRendererByType';

const identities: MultiSelectFilterConfig = {
id: 'identities',
Expand All @@ -17,6 +16,10 @@ const identities: MultiSelectFilterConfig = {
options: [
{
options: [
{
label: 'Email',
value: 'emails',
},
...(CrowdIntegrations.enabledConfigs.map((platform) => ({
label: (platform as any).name,
value: platform.platform,
Expand All @@ -28,8 +31,47 @@ const identities: MultiSelectFilterConfig = {
itemLabelRenderer(value: MultiSelectFilterValue, options: MultiSelectFilterOptions): string {
return itemLabelRendererByType[FilterConfigType.MULTISELECT]('Identities', value, options);
},
apiFilterRenderer(value: MultiSelectFilterValue): any[] {
return apiFilterRendererByType[FilterConfigType.MULTISELECT]('identities', value);
apiFilterRenderer({ value, include }: MultiSelectFilterValue): any[] {
const platformIdentities = value.filter((identity) => identity !== 'emails');

const emailFilter = value.filter((identity) => identity === 'emails');

// Initialize an empty filter
let filter = {};

// Handle the conditions
if (platformIdentities.length > 0 && emailFilter.length === 0) {
// Only platforms selected
filter = {
or: platformIdentities.map((identity) => ({
identities: { eq: identity },
})),
};
} else if (platformIdentities.length === 0 && emailFilter.length > 0) {
// Only emails selected
filter = {
emails: { ne: null },
};
} else if (platformIdentities.length > 0 && emailFilter.length > 0) {
// Both platforms and emails selected
filter = {
// [
or: [
{
or:
platformIdentities.map((identity) => ({
identities: { eq: identity },
})),
},

{ emails: { ne: null } },
],
};
}

return [
(include ? filter : { not: filter }),
];
},
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/member/config/filters/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const memberFilters: Record<string, FilterConfig> = {
};

export const memberSearchFilter: SearchFilterConfig = {
placeholder: 'Search contacts',
placeholder: 'Search contact\'s name or email',
apiFilterRenderer(value: string): any[] {
const trimmedValue = trimAndReduceSpaces(value);
return [
Expand Down
Loading