From bd3a54608490bcc0837fb8f2877361666365f19b Mon Sep 17 00:00:00 2001 From: Jeff Sieu Date: Fri, 28 Oct 2022 14:08:08 +0800 Subject: [PATCH] [questions][fix] update roles typeahead --- .../questions/typeahead/RoleTypeahead.tsx | 10 ++- .../[questionId]/[questionSlug]/index.tsx | 16 ++++- apps/portal/src/pages/questions/browse.tsx | 67 ++++++++++--------- apps/portal/src/pages/questions/lists.tsx | 64 +++++++++--------- .../questions/relabelQuestionAggregates.ts | 26 +++++++ 5 files changed, 116 insertions(+), 67 deletions(-) create mode 100644 apps/portal/src/utils/questions/relabelQuestionAggregates.ts diff --git a/apps/portal/src/components/questions/typeahead/RoleTypeahead.tsx b/apps/portal/src/components/questions/typeahead/RoleTypeahead.tsx index d40d6678..60dd3ffa 100644 --- a/apps/portal/src/components/questions/typeahead/RoleTypeahead.tsx +++ b/apps/portal/src/components/questions/typeahead/RoleTypeahead.tsx @@ -1,13 +1,21 @@ -import { ROLES } from '~/utils/questions/constants'; +import { JobTitleLabels } from '~/components/shared/JobTitles'; import type { ExpandedTypeaheadProps } from './ExpandedTypeahead'; import ExpandedTypeahead from './ExpandedTypeahead'; +import type { FilterChoices } from '../filter/FilterSection'; export type RoleTypeaheadProps = Omit< ExpandedTypeaheadProps, 'label' | 'onQueryChange' | 'options' >; +const ROLES: FilterChoices = Object.entries(JobTitleLabels).map( + ([slug, label]) => ({ + id: slug, + label, + value: slug, + }), +); export default function RoleTypeahead(props: RoleTypeaheadProps) { return ( { + if (!aggregatedEncounters) { + return aggregatedEncounters; + } + + return relabelQuestionAggregates(aggregatedEncounters); + }, [aggregatedEncounters]); + const utils = trpc.useContext(); const { data: comments } = trpc.useQuery([ @@ -138,11 +148,11 @@ export default function QuestionPage() {
({ checked: true, id: role, - label: role, + label: JobTitleLabels[role as keyof typeof JobTitleLabels], value: role, })); }, [selectedRoles]); @@ -369,7 +371,7 @@ export default function QuestionsBrowsePage() { setSelectedRoles([...selectedRoles, option.value]); } else { setSelectedRoles( - selectedCompanies.filter((role) => role !== option.value), + selectedRoles.filter((role) => role !== option.value), ); } }} @@ -470,36 +472,37 @@ export default function QuestionsBrowsePage() {
{(questionsQueryData?.pages ?? []).flatMap( ({ data: questions }) => - questions.map((question) => ( - - )), + questions.map((question) => { + const { companyCounts, locationCounts, roleCounts } = + relabelQuestionAggregates( + question.aggregatedQuestionEncounters, + ); + + return ( + + ); + }), )}