Skip to content

Commit 1f6da74

Browse files
committed
Add query for edit analysis dashboard
1 parent f1d79b4 commit 1f6da74

File tree

10 files changed

+227
-249
lines changed

10 files changed

+227
-249
lines changed

app/types/analysisModule.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ export interface PillarSummary {
4848
totalCount?: number | null | undefined;
4949
} | null | undefined;
5050
analyticalStatementCount: number;
51-
analyticalStatements: any[];
52-
assigneeDetails: any;
5351
}
5452

5553
export interface AnalysisElement {

app/types/user.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface User {
1616
}
1717

1818
export interface UserMini {
19-
id: number;
19+
id: string;
2020
email: string;
2121
displayName: string;
2222
}

app/views/AnalysisDashboard/Analysis/AnalysisCloneModal/index.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,6 @@ function AnalysisCloneModal(props: Props) {
8888

8989
const error = getErrorObject(riskyError);
9090

91-
/*
92-
const {
93-
pending: pendingAnalysisGet,
94-
} = useRequest<AnalysisElement>({
95-
url: `server://projects/${projectId}/analysis/${analysisId}/`,
96-
method: 'GET',
97-
onSuccess: (response) => {
98-
setValue({
99-
title: response.title,
100-
startDate: response.startDate,
101-
endDate: response.endDate,
102-
});
103-
},
104-
});
105-
*/
106-
10791
const {
10892
pending: pendingAnalysisClone,
10993
trigger: triggerAnalysisClone,

app/views/AnalysisDashboard/Analysis/AnalysisPillar/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ export interface Props {
3535
title: string;
3636
createdAt: string;
3737
onDelete: (value: number) => void;
38+
pendingPillarDelete: boolean;
3839
pillarId: PillarSummary['id']; projectId: string;
3940
className?: string;
4041
totalEntries: number;
41-
analyzedEntries?: number;
42+
analyzedEntries?: number | undefined;
4243
}
4344

4445
function AnalysisPillar(props: Props) {
@@ -53,6 +54,7 @@ function AnalysisPillar(props: Props) {
5354
statements,
5455
className,
5556
totalEntries,
57+
pendingPillarDelete,
5658
analyzedEntries = 0,
5759
} = props;
5860

@@ -72,6 +74,7 @@ function AnalysisPillar(props: Props) {
7274
}
7375

7476
const onDeleteConfirmClick = useCallback(() => {
77+
// TODO: Remove Number in pillarId
7578
onDelete(Number(pillarId));
7679
}, [onDelete, pillarId]);
7780

@@ -89,6 +92,8 @@ function AnalysisPillar(props: Props) {
8992
value: data.statement,
9093
}), []);
9194

95+
const disabled = pendingPillarDelete;
96+
9297
return (
9398
<Container
9499
className={_cs(styles.analysisPillar, className)}
@@ -109,7 +114,7 @@ function AnalysisPillar(props: Props) {
109114
analysisId,
110115
pillarAnalysisId: pillarId,
111116
}}
112-
disabled={undefined}
117+
disabled={disabled}
113118
variant="tertiary"
114119
icons={(
115120
<FiEdit2 />
@@ -123,7 +128,7 @@ function AnalysisPillar(props: Props) {
123128
onConfirm={onDeleteConfirmClick}
124129
title={_ts('analysis', 'deletePillarButtonTitle')}
125130
message={_ts('analysis', 'deletePillarConfirmMessage')}
126-
disabled={undefined}
131+
disabled={disabled}
127132
showConfirmationInitially={false}
128133
variant="secondary"
129134
>

app/views/AnalysisDashboard/Analysis/PillarAssignment/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import _ts from '#ts';
55

66
import styles from './styles.css';
77

8-
interface Props {
8+
export interface Props {
99
className?: string;
1010
assigneeName: string | null | undefined;
1111
pillarTitle: string;
@@ -36,13 +36,13 @@ function PillarAssignment(props: Props) {
3636
className={styles.assigneeName}
3737
title={isDefined(assigneeName) ? assigneeName : undefined}
3838
>
39-
{assigneeName}
39+
{ assigneeName }
4040
</div>
4141
<div
4242
className={styles.pillarTitle}
4343
title={pillarTitle}
4444
>
45-
{pillarTitle}
45+
{ pillarTitle }
4646
</div>
4747
<div
4848
className={_cs(
@@ -51,7 +51,7 @@ function PillarAssignment(props: Props) {
5151
)}
5252
title={statusLabel}
5353
>
54-
{statusLabel}
54+
{ statusLabel }
5555
</div>
5656
</div>
5757
);

app/views/AnalysisDashboard/Analysis/PillarList/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {
77
Kraken,
88
} from '@the-deep/deep-ui';
99

10-
import _ts from '#ts';
11-
1210
import { AnalysisSummaryQuery } from '#generated/types';
1311

1412
import AnalysisPillar, { Props as PillarComponentProps } from '../AnalysisPillar';
@@ -26,7 +24,7 @@ interface Props {
2624
activeProject: string;
2725
onAnalysisPillarDelete: () => void;
2826
analysisId: string;
29-
totalEntries: number;
27+
totalEntries: number | undefined;
3028
pillars: PillarSummary[] | null | undefined;
3129
pillarsPending: boolean;
3230
}
@@ -59,6 +57,7 @@ function AnalysisDetails(props: Props) {
5957
title: data.title,
6058
totalEntries,
6159
}), [
60+
onAnalysisPillarDelete,
6261
totalEntries,
6362
createdAt,
6463
analysisId,
@@ -71,7 +70,7 @@ function AnalysisDetails(props: Props) {
7170
className={_cs(className, styles.container)}
7271
spacing="none"
7372
contentClassName={styles.content}
74-
footerActions={((totalEntries ?? 0) / MAX_ITEMS_PER_PAGE) > 1 ? (
73+
footerActions={((pillars?.length ?? 0) / MAX_ITEMS_PER_PAGE) > 1 ? (
7574
<Pager
7675
activePage={activePage}
7776
itemsCount={pillars?.length ?? 0}

app/views/AnalysisDashboard/Analysis/index.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import {
4747

4848
import _ts from '#ts';
4949
import PillarAnalysisList from './PillarList';
50-
import PillarAssignment from './PillarAssignment';
50+
import PillarAssignment, { type Props as PillarAssignmentItemProps } from './PillarAssignment';
5151
import AnalysisCloneModal from './AnalysisCloneModal';
5252
import ReportsModal from '../ReportsModal';
5353

@@ -101,7 +101,7 @@ const barChartMargin = {
101101
const BAR_TICK_COUNT = 5;
102102
const MAX_BAR_SIZE = 16;
103103

104-
interface ComponentProps {
104+
export interface Props {
105105
analysisId: string;
106106
className?: string;
107107
title: string;
@@ -116,15 +116,15 @@ interface ComponentProps {
116116
pendingAnalysisDelete: boolean;
117117
pillars?: PillarSummary[] | null | undefined;
118118
pillarsPending: boolean;
119-
totalEntries: number;
120-
totalSources: number;
121-
analyzedEntries: number;
122-
analyzedLeads: number;
119+
totalEntries: number | undefined;
120+
totalSources: number | undefined;
121+
analyzedEntries: number | undefined;
122+
analyzedLeads: number | undefined;
123123
}
124124

125125
const pillarSummaryKeySelector = (item: PillarSummary) => (item.id);
126126

127-
function Analysis(props: ComponentProps) {
127+
function Analysis(props: Props) {
128128
const {
129129
title,
130130
className,
@@ -167,7 +167,7 @@ function Analysis(props: ComponentProps) {
167167
const alert = useAlert();
168168

169169
const pillarAssignmentRendererParams = useCallback(
170-
(_: string, data: PillarSummary) => ({
170+
(_: string, data: PillarSummary): PillarAssignmentItemProps => ({
171171
assigneeName: data.assignee?.displayName,
172172
pillarTitle: data.title,
173173
analyzedEntries: data.analyzedEntriesCount,
@@ -230,14 +230,16 @@ function Analysis(props: ComponentProps) {
230230
onDelete(analysisId);
231231
}, [analysisId, onDelete]);
232232

233-
const barChartData = useMemo(() => (
234-
pillars?.map((o) => ({
233+
const barChartData = useMemo(() => {
234+
if (!pillars || totalEntries === undefined) return [];
235+
236+
return pillars.map((o) => ({
235237
...o,
236238
percent: Math.round(
237239
((o.analyzedEntriesCount ?? 0) / (totalEntries === 0 ? 1 : totalEntries)) * 10000,
238240
) / 100,
239-
}))
240-
), [pillars, totalEntries]);
241+
}));
242+
}, [pillars, totalEntries]);
241243

242244
const disabled = pendingAnalysisDelete;
243245

@@ -249,6 +251,11 @@ function Analysis(props: ComponentProps) {
249251
const canTagEntry = project?.analysisFramework?.id
250252
&& project?.allowedPermissions?.includes('UPDATE_ENTRY');
251253

254+
const safeAnalyzedLeads = analyzedLeads ?? 0;
255+
const safeTotalSource = totalSources ?? 1;
256+
const safeAnalyzedEntries = analyzedEntries ?? 0;
257+
const safeTotalEntries = totalEntries ?? 1;
258+
252259
return (
253260
<ContainerCard
254261
className={_cs(className, styles.analysisItem)}
@@ -365,12 +372,12 @@ function Analysis(props: ComponentProps) {
365372
contentClassName={styles.overviewContent}
366373
>
367374
<ProgressLine
368-
progress={(analyzedLeads / totalSources) * 100}
375+
progress={(safeAnalyzedLeads / safeTotalSource) * 100}
369376
title={_ts('analysis', 'sourcesAnalyzedLabel')}
370377
variant="complement1"
371378
/>
372379
<ProgressLine
373-
progress={(analyzedEntries / totalEntries) * 100}
380+
progress={(safeAnalyzedEntries / safeTotalEntries) * 100}
374381
title={_ts('analysis', 'entriesAnalyzedLabel')}
375382
variant="complement2"
376383
/>
@@ -427,7 +434,7 @@ function Analysis(props: ComponentProps) {
427434
<ExpandableContainer
428435
className={styles.pillarAnalyses}
429436
headerClassName={styles.pillarAnalysesHeader}
430-
heading={_ts('analysis', 'pillarAnalysisCount', { count: pillars?.length })}
437+
heading={`Analysis ${pillars?.length}`}
431438
headingSize="extraSmall"
432439
alwaysMountedContent={false}
433440
contentClassName={styles.pillarAnalysisList}

app/views/AnalysisDashboard/AnalysisEditModal/PillarAnalysisRow/index.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,23 @@ import {
1818
} from '@togglecorp/toggle-form';
1919

2020
import _ts from '#ts';
21-
import { ProjectUserMembersQuery } from '#generated/types';
21+
import { UserMini } from '#types';
2222

2323
import { MatrixPillar } from '../utils';
2424

2525
import styles from './styles.css';
2626

27-
type UserMemberType = NonNullable<NonNullable<NonNullable<NonNullable<ProjectUserMembersQuery['project']>['userMembers']>['results']>>[number];
28-
2927
export interface PillarAnalysisFields {
3028
title: string;
31-
emailDisplay: UserMemberType;
29+
assignee: string;
3230
filters: MatrixPillar['uniqueId'][];
3331
}
3432

3533
const idSelector = (d: MatrixPillar) => d.uniqueId;
3634
const labelSelector = (d: MatrixPillar) => d.altTitle ?? d.title;
3735

38-
const userKeySelector = (u: UserMemberType) => u.id;
39-
const userLabelSelector = (u: UserMemberType) => u.member.emailDisplay;
36+
const userKeySelector = (u: UserMini) => u.id;
37+
const userLabelSelector = (u: UserMini) => u.displayName;
4038

4139
type Value = PartialForm<PillarAnalysisFields>
4240
const defaultValue: Value = {
@@ -50,7 +48,7 @@ export interface Props {
5048
matrixPillars?: MatrixPillar[];
5149
onChange: (value: SetValueArg<Value>, index: number) => void;
5250
onRemove: (index: number) => void;
53-
usersList: UserMemberType[];
51+
usersList: UserMini[];
5452
value: Value;
5553
pending: boolean;
5654
}
@@ -70,7 +68,6 @@ function PillarAnalysisRow(props: Props) {
7068

7169
const error = getErrorObject(riskyError);
7270

73-
console.info('value', value);
7471
const onFieldChange = useFormObject(index, onChange, defaultValue);
7572

7673
return (
@@ -87,15 +84,15 @@ function PillarAnalysisRow(props: Props) {
8784
/>
8885
<SelectInput
8986
className={styles.input}
90-
error={error?.emailDisplay}
87+
error={error?.assignee}
9188
keySelector={userKeySelector}
9289
label={_ts('analysis.editModal', 'pillarAnalysisAssigneeLabel')}
9390
labelSelector={userLabelSelector}
94-
name="emailDisplay"
91+
name="assignee"
9592
onChange={onFieldChange}
9693
options={usersList}
9794
placeholder={_ts('analysis.editModal', 'pillarAnalysisAssigneePlaceholder')}
98-
value={value.emailDisplay}
95+
value={value.assignee}
9996
disabled={pending}
10097
/>
10198
<MultiSelectInput

0 commit comments

Comments
 (0)