From 7ab476d317447e7e9c00bb165eab0f09c0ca3c2a Mon Sep 17 00:00:00 2001 From: Aditya Khatri Date: Thu, 19 Sep 2024 17:00:45 +0545 Subject: [PATCH] Fix type issues --- .../PillarAnalysisRow/index.tsx | 7 +- .../AnalysisEditModal/index.tsx | 64 +++++++++---------- app/views/AnalysisDashboard/index.tsx | 8 +-- 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/app/views/AnalysisDashboard/AnalysisEditModal/PillarAnalysisRow/index.tsx b/app/views/AnalysisDashboard/AnalysisEditModal/PillarAnalysisRow/index.tsx index 0417e27d6..2cd2ab648 100644 --- a/app/views/AnalysisDashboard/AnalysisEditModal/PillarAnalysisRow/index.tsx +++ b/app/views/AnalysisDashboard/AnalysisEditModal/PillarAnalysisRow/index.tsx @@ -19,7 +19,7 @@ import { import _ts from '#ts'; import { MatrixPillar } from '../utils'; -import { AnalysisPillar, UserMembersType } from '..'; +import { AnalysisPillarForm, UserMembersType } from '..'; import styles from './styles.css'; @@ -29,14 +29,14 @@ const labelSelector = (d: MatrixPillar) => d.altTitle ?? d.title; const userKeySelector = (user: UserMembersType) => user.member.id; const userLabelSelector = (user: UserMembersType) => user.member?.displayName ?? ''; -type Value = PartialForm +type Value = PartialForm const defaultValue: Value = { filters: [], }; export interface Props { className?: string; - error: Error | undefined; + error: Error | undefined; index: number; matrixPillars?: MatrixPillar[]; onChange: (value: SetValueArg, index: number) => void; @@ -100,6 +100,7 @@ function PillarAnalysisRow(props: Props) { onChange={onFieldChange} options={matrixPillars} placeholder={_ts('analysis.editModal', 'matrixPillarsPlaceholder')} + // FIXME: Need to fix value={value.filters} disabled={pending} optionsPopupClassName={styles.optionsPopup} diff --git a/app/views/AnalysisDashboard/AnalysisEditModal/index.tsx b/app/views/AnalysisDashboard/AnalysisEditModal/index.tsx index ac115c945..9e31d3c2d 100644 --- a/app/views/AnalysisDashboard/AnalysisEditModal/index.tsx +++ b/app/views/AnalysisDashboard/AnalysisEditModal/index.tsx @@ -1,7 +1,6 @@ import React, { useCallback, useContext, - useEffect, useMemo, } from 'react'; import { @@ -171,15 +170,19 @@ const USER_MEMBERS = gql` type PartialForm = RawPartialForm; export type AnalysisPillar = NonNullable['analysisUpdate']>['result']>['pillars']>[number]; +export type AnalysisPillarForm = Omit & { + assignee: string, + filters: MatrixPillar['uniqueId'][], +}; export type UserMembersType = NonNullable['userMembers']>['results']>[number]; -const analysisPillarKeySelector = (analysis: AnalysisPillar) => analysis.clientId; +const analysisPillarKeySelector = (analysis: AnalysisPillarForm) => analysis.clientId; type FormType = { title?: string; - teamLead?: UserMembersType; + teamLead?: string; startDate?: string; endDate: string; - analysisPillar?: AnalysisPillar[]; + analysisPillar?: AnalysisPillarForm[]; } type PartialFormType = PartialForm; @@ -309,7 +312,6 @@ function AnalysisEditModal(props: AnalysisEditModalProps) { const alert = useAlert(); const { - data: analysisDetailData, loading: analysisDetailLoading, } = useQuery( ANALYSIS_DETAIL, @@ -318,34 +320,32 @@ function AnalysisEditModal(props: AnalysisEditModalProps) { projectId, analysisId: analysisToEdit, }, - skip: !analysisToEdit, + onCompleted: (response) => { + const { + analysis, + } = response?.project || {}; + if (!analysis) { + return; + } + + const formData: PartialForm = { + title: analysis.title, + startDate: analysis?.startDate || undefined, + endDate: analysis?.endDate, + teamLead: analysis.teamLead.id, + analysisPillar: analysis.pillars?.map((pillar: AnalysisPillar) => ({ + analysisId: pillar.analysisId, + clientId: pillar.clientId, + title: pillar.title, + assignee: pillar.assignee.id, + filters: pillar.filters?.map((item) => item.unique_id) as MatrixPillar['uniqueId'][], + })), + }; + setValue(formData); + }, }, ); - useEffect(() => { - if (analysisDetailData?.project?.analysis && analysisToEdit) { - const analysis = analysisDetailData.project.analysis; - const formData: PartialForm = { - title: analysis.title, - startDate: analysis?.startDate || undefined, - endDate: analysis?.endDate, - teamLead: analysis.teamLead.id, - analysisPillar: analysis.pillars?.map((pillar: AnalysisPillar) => ({ - analysisId: pillar.analysisId, - clientId: pillar.clientId, - title: pillar.title, - assignee: pillar.assignee.id, - filters: pillar.filters, - })), - }; - setValue(formData); - } - }, [ - analysisDetailData, - analysisToEdit, - setValue, - ]); - const variables = useMemo( (): UserMembersQueryVariables | undefined => ( (project) ? ({ @@ -421,7 +421,7 @@ function AnalysisEditModal(props: AnalysisEditModalProps) { const rowRendererParams: ( key: string, - data: Partial, + data: Partial, index: number, ) => PillarAnalysisProps = React.useCallback( (id, data, index) => ({ @@ -531,7 +531,7 @@ function AnalysisEditModal(props: AnalysisEditModalProps) { name="teamLead" options={usersListResponse?.project?.userMembers?.results} placeholder={_ts('analysis.editModal', 'teamLeadPlaceholder')} - value={value.teamLead?.id} + value={value.teamLead} error={error?.teamLead} onChange={setFieldValue} disabled={pending} diff --git a/app/views/AnalysisDashboard/index.tsx b/app/views/AnalysisDashboard/index.tsx index af26d9c63..932a3f77a 100644 --- a/app/views/AnalysisDashboard/index.tsx +++ b/app/views/AnalysisDashboard/index.tsx @@ -223,7 +223,7 @@ function AnalysisDashboard(props: AnalysisDashboardProps) { project, } = useContext(ProjectContext); - const activeProject = project?.id ? +project.id : undefined; + const activeProject = project?.id ? project.id : undefined; const [ showAnalysisAddModal, @@ -233,7 +233,7 @@ function AnalysisDashboard(props: AnalysisDashboardProps) { const alert = useAlert(); - const [activePage, setActivePage] = useState(); + const [activePage, setActivePage] = useState(1); const [analysisToEdit, setAnalysisToEdit] = useState(); const [dateRangeFilter, setDateRangeFilter] = useState(undefined); @@ -560,11 +560,11 @@ function AnalysisDashboard(props: AnalysisDashboardProps) { messageShown /> - {showAnalysisAddModal && activeProject && ( + {showAnalysisAddModal && activeProject && analysisToEdit && ( )}