From 9ccc35d181017faf0fdf1d85e0848bc00ccce719 Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Date: Sat, 20 May 2023 16:00:41 +0530 Subject: [PATCH] fix: make custom search select handle undefined options (#1094) * fix: make search select handle undefined options * fix: kanban y-scroll --- .../analytics/custom-analytics/sidebar.tsx | 11 ++++-- .../core/board-view/single-board.tsx | 2 +- .../integration/github/import-data.tsx | 13 ++++--- .../integration/github/single-user-select.tsx | 35 ++++++++--------- .../integration/jira/import-users.tsx | 35 ++++++++--------- .../app/components/issues/select/assignee.tsx | 39 +++++++++---------- .../issues/sidebar-select/assignee.tsx | 39 +++++++++---------- .../issues/view-select/assignee.tsx | 39 +++++++++---------- apps/app/components/modules/select/lead.tsx | 33 ++++++++-------- .../app/components/modules/select/members.tsx | 33 ++++++++-------- .../modules/sidebar-select/select-lead.tsx | 33 ++++++++-------- .../modules/sidebar-select/select-members.tsx | 33 ++++++++-------- .../components/ui/custom-search-select.tsx | 12 +++--- apps/app/helpers/string.helper.ts | 2 +- 14 files changed, 179 insertions(+), 180 deletions(-) diff --git a/apps/app/components/analytics/custom-analytics/sidebar.tsx b/apps/app/components/analytics/custom-analytics/sidebar.tsx index 26eb66d12..e9a9d5d7f 100644 --- a/apps/app/components/analytics/custom-analytics/sidebar.tsx +++ b/apps/app/components/analytics/custom-analytics/sidebar.tsx @@ -152,7 +152,7 @@ export const AnalyticsSidebar: React.FC = ({ return (
-
+
{project.emoji ? ( {String.fromCodePoint(parseInt(project.emoji))} @@ -171,8 +171,13 @@ export const AnalyticsSidebar: React.FC = ({ {project?.name.charAt(0)} )} - {project.name} -
+
+ {project.name} + + ({project.identifier}) + +
+
diff --git a/apps/app/components/core/board-view/single-board.tsx b/apps/app/components/core/board-view/single-board.tsx index b50b978ce..a4f869cb3 100644 --- a/apps/app/components/core/board-view/single-board.tsx +++ b/apps/app/components/core/board-view/single-board.tsx @@ -99,7 +99,7 @@ export const SingleBoard: React.FC = ({
)} -
+
{groupedByIssues?.[groupTitle].map((issue, index) => ( = ({ handleStepChange, integration, control, watch }) => { const { projects } = useProjects(); - const options = - projects.map((project) => ({ - value: project.id, - query: project.name, - content:

{truncateText(project.name, 25)}

, - })) ?? []; + const options = projects + ? projects.map((project) => ({ + value: project.id, + query: project.name, + content:

{truncateText(project.name, 25)}

, + })) + : undefined; return (
diff --git a/apps/app/components/integration/github/single-user-select.tsx b/apps/app/components/integration/github/single-user-select.tsx index 14f913bff..53fbce476 100644 --- a/apps/app/components/integration/github/single-user-select.tsx +++ b/apps/app/components/integration/github/single-user-select.tsx @@ -44,24 +44,23 @@ export const SingleUserSelect: React.FC = ({ collaborator, index, users, workspaceSlug ? () => workspaceService.workspaceMembers(workspaceSlug.toString()) : null ); - const options = - members?.map((member) => ({ - value: member.member.email, - query: - (member.member.first_name && member.member.first_name !== "" - ? member.member.first_name - : member.member.email) + - " " + - member.member.last_name ?? "", - content: ( -
- - {member.member.first_name && member.member.first_name !== "" - ? member.member.first_name + "(" + member.member.email + ")" - : member.member.email} -
- ), - })) ?? []; + const options = members?.map((member) => ({ + value: member.member.email, + query: + (member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + : member.member.email) + + " " + + member.member.last_name ?? "", + content: ( +
+ + {member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + "(" + member.member.email + ")" + : member.member.email} +
+ ), + })); return (
diff --git a/apps/app/components/integration/jira/import-users.tsx b/apps/app/components/integration/jira/import-users.tsx index da14f7d15..80c0c4c9b 100644 --- a/apps/app/components/integration/jira/import-users.tsx +++ b/apps/app/components/integration/jira/import-users.tsx @@ -32,24 +32,23 @@ export const JiraImportUsers: FC = () => { const { workspaceMembers: members } = useWorkspaceMembers(workspaceSlug?.toString()); - const options = - members?.map((member) => ({ - value: member.member.email, - query: - (member.member.first_name && member.member.first_name !== "" - ? member.member.first_name - : member.member.email) + - " " + - member.member.last_name ?? "", - content: ( -
- - {member.member.first_name && member.member.first_name !== "" - ? member.member.first_name + " (" + member.member.email + ")" - : member.member.email} -
- ), - })) ?? []; + const options = members?.map((member) => ({ + value: member.member.email, + query: + (member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + : member.member.email) + + " " + + member.member.last_name ?? "", + content: ( +
+ + {member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + " (" + member.member.email + ")" + : member.member.email} +
+ ), + })); return (
diff --git a/apps/app/components/issues/select/assignee.tsx b/apps/app/components/issues/select/assignee.tsx index 1fead864e..2e1844a69 100644 --- a/apps/app/components/issues/select/assignee.tsx +++ b/apps/app/components/issues/select/assignee.tsx @@ -29,26 +29,25 @@ export const IssueAssigneeSelect: React.FC = ({ projectId, value = [], on : null ); - const options = - members?.map((member) => ({ - value: member.member.id, - query: - (member.member.first_name && member.member.first_name !== "" - ? member.member.first_name - : member.member.email) + - " " + - member.member.last_name ?? "", - content: ( -
- - {`${ - member.member.first_name && member.member.first_name !== "" - ? member.member.first_name - : member.member.email - } ${member.member.last_name ?? ""}`} -
- ), - })) ?? []; + const options = members?.map((member) => ({ + value: member.member.id, + query: + (member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + : member.member.email) + + " " + + member.member.last_name ?? "", + content: ( +
+ + {`${ + member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + : member.member.email + } ${member.member.last_name ?? ""}`} +
+ ), + })); return ( = ({ value, onChange, userAu : null ); - const options = - members?.map((member) => ({ - value: member.member.id, - query: - (member.member.first_name && member.member.first_name !== "" - ? member.member.first_name - : member.member.email) + - " " + - member.member.last_name ?? "", - content: ( -
- - {`${ - member.member.first_name && member.member.first_name !== "" - ? member.member.first_name - : member.member.email - } ${member.member.last_name ?? ""}`} -
- ), - })) ?? []; + const options = members?.map((member) => ({ + value: member.member.id, + query: + (member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + : member.member.email) + + " " + + member.member.last_name ?? "", + content: ( +
+ + {`${ + member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + : member.member.email + } ${member.member.last_name ?? ""}`} +
+ ), + })); const isNotAllowed = userAuth.isGuest || userAuth.isViewer; diff --git a/apps/app/components/issues/view-select/assignee.tsx b/apps/app/components/issues/view-select/assignee.tsx index 69726f9c5..48149c24f 100644 --- a/apps/app/components/issues/view-select/assignee.tsx +++ b/apps/app/components/issues/view-select/assignee.tsx @@ -43,26 +43,25 @@ export const ViewAssigneeSelect: React.FC = ({ : null ); - const options = - members?.map((member) => ({ - value: member.member.id, - query: - (member.member.first_name && member.member.first_name !== "" - ? member.member.first_name - : member.member.email) + - " " + - member.member.last_name ?? "", - content: ( -
- - {`${ - member.member.first_name && member.member.first_name !== "" - ? member.member.first_name - : member.member.email - } ${member.member.last_name ?? ""}`} -
- ), - })) ?? []; + const options = members?.map((member) => ({ + value: member.member.id, + query: + (member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + : member.member.email) + + " " + + member.member.last_name ?? "", + content: ( +
+ + {`${ + member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + : member.member.email + } ${member.member.last_name ?? ""}`} +
+ ), + })); return ( = ({ value, onChange }) => { : null ); - const options = - members?.map((member) => ({ - value: member.member.id, - query: - (member.member.first_name && member.member.first_name !== "" + const options = members?.map((member) => ({ + value: member.member.id, + query: + (member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + : member.member.email) + + " " + + member.member.last_name ?? "", + content: ( +
+ + {member.member.first_name && member.member.first_name !== "" ? member.member.first_name - : member.member.email) + - " " + - member.member.last_name ?? "", - content: ( -
- - {member.member.first_name && member.member.first_name !== "" - ? member.member.first_name - : member.member.email} -
- ), - })) ?? []; + : member.member.email} +
+ ), + })); const selectedOption = members?.find((m) => m.member.id === value)?.member; diff --git a/apps/app/components/modules/select/members.tsx b/apps/app/components/modules/select/members.tsx index 8d407f36a..c95331202 100644 --- a/apps/app/components/modules/select/members.tsx +++ b/apps/app/components/modules/select/members.tsx @@ -28,24 +28,23 @@ export const ModuleMembersSelect: React.FC = ({ value, onChange }) => { ? () => projectServices.projectMembers(workspaceSlug as string, projectId as string) : null ); - const options = - members?.map((member) => ({ - value: member.member.id, - query: - (member.member.first_name && member.member.first_name !== "" + const options = members?.map((member) => ({ + value: member.member.id, + query: + (member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + : member.member.email) + + " " + + member.member.last_name ?? "", + content: ( +
+ + {member.member.first_name && member.member.first_name !== "" ? member.member.first_name - : member.member.email) + - " " + - member.member.last_name ?? "", - content: ( -
- - {member.member.first_name && member.member.first_name !== "" - ? member.member.first_name - : member.member.email} -
- ), - })) ?? []; + : member.member.email} +
+ ), + })); return ( = ({ value, onChange }) => { : null ); - const options = - members?.map((member) => ({ - value: member.member.id, - query: - (member.member.first_name && member.member.first_name !== "" + const options = members?.map((member) => ({ + value: member.member.id, + query: + (member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + : member.member.email) + + " " + + member.member.last_name ?? "", + content: ( +
+ + {member.member.first_name && member.member.first_name !== "" ? member.member.first_name - : member.member.email) + - " " + - member.member.last_name ?? "", - content: ( -
- - {member.member.first_name && member.member.first_name !== "" - ? member.member.first_name - : member.member.email} -
- ), - })) ?? []; + : member.member.email} +
+ ), + })); const selectedOption = members?.find((m) => m.member.id === value)?.member; diff --git a/apps/app/components/modules/sidebar-select/select-members.tsx b/apps/app/components/modules/sidebar-select/select-members.tsx index 2f024913f..2481aaeed 100644 --- a/apps/app/components/modules/sidebar-select/select-members.tsx +++ b/apps/app/components/modules/sidebar-select/select-members.tsx @@ -29,24 +29,23 @@ export const SidebarMembersSelect: React.FC = ({ value, onChange }) => { : null ); - const options = - members?.map((member) => ({ - value: member.member.id, - query: - (member.member.first_name && member.member.first_name !== "" + const options = members?.map((member) => ({ + value: member.member.id, + query: + (member.member.first_name && member.member.first_name !== "" + ? member.member.first_name + : member.member.email) + + " " + + member.member.last_name ?? "", + content: ( +
+ + {member.member.first_name && member.member.first_name !== "" ? member.member.first_name - : member.member.email) + - " " + - member.member.last_name ?? "", - content: ( -
- - {member.member.first_name && member.member.first_name !== "" - ? member.member.first_name - : member.member.email} -
- ), - })) ?? []; + : member.member.email} +
+ ), + })); return (
diff --git a/apps/app/components/ui/custom-search-select.tsx b/apps/app/components/ui/custom-search-select.tsx index ebe1dfb45..ef0943377 100644 --- a/apps/app/components/ui/custom-search-select.tsx +++ b/apps/app/components/ui/custom-search-select.tsx @@ -9,11 +9,13 @@ import { CheckIcon, MagnifyingGlassIcon } from "@heroicons/react/24/outline"; type CustomSearchSelectProps = { value: any; onChange: any; - options: { - value: any; - query: string; - content: JSX.Element; - }[]; + options: + | { + value: any; + query: string; + content: JSX.Element; + }[] + | undefined; label?: string | JSX.Element; textAlignment?: "left" | "center" | "right"; height?: "sm" | "md" | "rg" | "lg"; diff --git a/apps/app/helpers/string.helper.ts b/apps/app/helpers/string.helper.ts index 1cdebf0bb..a13f149fc 100644 --- a/apps/app/helpers/string.helper.ts +++ b/apps/app/helpers/string.helper.ts @@ -89,7 +89,7 @@ export const cosineSimilarity = (a: string, b: string) => { }; export const generateRandomColor = (string: string): string => { - if (!string) return "var(--color-accent)"; + if (!string) return "rgb(var(--color-accent))"; string = `${string}`;