Skip to content

Commit 68271f2

Browse files
authored
Use pretty type value for artifacts. Leverage v2 api (#567)
* Use pretty type value for artifacts. Leverage v2 api that includes engagement and project name * remove get engagement by id for other widgets that now get that info from v2 api * remove unused import. update browser list
1 parent e80169e commit 68271f2

File tree

9 files changed

+33
-70
lines changed

9 files changed

+33
-70
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/dashboard/widgets/dw_last_artifact.tsx

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,17 @@ import {
1010
} from '@patternfly/react-core';
1111
import {ReactComponent as CubesIcon} from '../../../assets/images/cubes.svg';
1212
import { Table, TableBody, TableHeader } from '@patternfly/react-table';
13-
import { Artifact, Engagement } from '../../../schemas/engagement';
13+
import { Artifact } from '../../../schemas/engagement';
1414
import { LinkOrSpan } from '../../link_or_span/link_or_span';
1515
import { Link } from 'react-router-dom';
1616
import CustomRowWrapper from '../../../components/custom_row_wrapper/custom_row_wrapper';
1717
export interface DwLastArtifactsProps {
1818
artifacts: Artifact[];
19-
engagements: Partial<Engagement>[];
2019
}
2120
const columns = ['Artifact', 'Type', 'Engagement'];
2221
export const DwLastArtifacts = ({
2322
artifacts = [],
24-
engagements = [],
2523
}: DwLastArtifactsProps) => {
26-
const engagementsById = artifacts.reduce(
27-
(acc, curr) => ({
28-
...acc,
29-
[curr.engagement_uuid]: engagements.find(
30-
e => e.uuid === curr.engagement_uuid
31-
),
32-
}),
33-
{}
34-
);
3524
const rows = artifacts.map(artifact => {
3625
return [
3726
{
@@ -41,13 +30,13 @@ export const DwLastArtifacts = ({
4130
</LinkOrSpan>
4231
),
4332
},
44-
artifact?.type,
33+
artifact?.pretty_type,
4534
{
4635
title: (
4736
<Link to={`/app/engagements/${artifact.engagement_uuid}#artifacts`}>
48-
{engagementsById[artifact.engagement_uuid]?.customer_name +
37+
{artifact?.customer_name +
4938
' — ' +
50-
engagementsById[artifact.engagement_uuid]?.project_name}
39+
artifact?.project_name}
5140
</Link>
5241
),
5342
},

src/components/dashboard/widgets/dw_last_demo.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,14 @@ import {ReactComponent as BroadcastIcon} from '../../../assets/images/broadcast-
1111
import { Table, TableHeader, TableBody } from '@patternfly/react-table';
1212
import React from 'react';
1313
import { Link } from 'react-router-dom';
14-
import { Artifact, Engagement } from '../../../schemas/engagement';
14+
import { Artifact } from '../../../schemas/engagement';
1515
import { LinkOrSpan } from '../../link_or_span/link_or_span';
1616
import CustomRowWrapper from '../../../components/custom_row_wrapper/custom_row_wrapper';
1717
export interface DwLastDemoProps {
1818
demos: Artifact[];
19-
engagements: Partial<Engagement>[];
2019
}
2120
const columns = ['Demo', 'Engagement'];
22-
export function DwLastDemo({ demos = [], engagements = [] }: DwLastDemoProps) {
23-
const engagementsById = demos.reduce(
24-
(acc, curr) => ({
25-
...acc,
26-
[curr.engagement_uuid]: engagements.find(
27-
e => e.uuid === curr.engagement_uuid
28-
),
29-
}),
30-
{}
31-
);
21+
export function DwLastDemo({ demos = [] }: DwLastDemoProps) {
3222
const rows = demos.map(demo => {
3323
return [
3424
{
@@ -39,8 +29,7 @@ export function DwLastDemo({ demos = [], engagements = [] }: DwLastDemoProps) {
3929
{
4030
title: (
4131
<Link to={`/app/engagements/${demo.engagement_uuid}`}>
42-
{engagementsById[demo.engagement_uuid]?.customer_name}&nbsp;—&nbsp;
43-
{engagementsById[demo.engagement_uuid]?.project_name}
32+
{demo?.customer_name}&nbsp;—&nbsp;{demo?.project_name}
4433
</Link>
4534
),
4635
},

src/components/dashboard/widgets/dw_last_weekly_report.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,17 @@ import {ReactComponent as HeartbeatIcon} from '../../../assets/images/heart-rate
1111
import { Table, TableHeader, TableBody } from '@patternfly/react-table';
1212
import React from 'react';
1313
import { Link } from 'react-router-dom';
14-
import { Artifact, Engagement } from '../../../schemas/engagement';
14+
import { Artifact } from '../../../schemas/engagement';
1515
import { LinkOrSpan } from '../../link_or_span/link_or_span';
1616
import CustomRowWrapper from '../../../components/custom_row_wrapper/custom_row_wrapper';
1717

1818
export interface DwLastWeeklyReportProps {
1919
artifacts: Artifact[];
20-
engagements: Partial<Engagement>[];
2120
}
2221
const columns = ['Weekly Report', 'Engagement'];
2322
export function DwLastWeeklyReport({
2423
artifacts = [],
25-
engagements = [],
2624
}: DwLastWeeklyReportProps) {
27-
const engagementsById = artifacts.reduce(
28-
(acc, curr) => ({
29-
...acc,
30-
[curr.engagement_uuid]: engagements.find(
31-
e => e.uuid === curr.engagement_uuid
32-
),
33-
}),
34-
{}
35-
);
3625
const rows = artifacts.map(artifact => {
3726
return [
3827
{
@@ -45,9 +34,9 @@ export function DwLastWeeklyReport({
4534
{
4635
title: (
4736
<Link to={`/app/engagements/${artifact.engagement_uuid}`}>
48-
{engagementsById[artifact.engagement_uuid]?.customer_name}
37+
{artifact?.customer_name}
4938
&nbsp;—&nbsp;
50-
{engagementsById[artifact.engagement_uuid]?.project_name}
39+
{artifact?.project_name}
5140
</Link>
5241
),
5342
},

src/hocs/with_artifacts.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useEffect } from 'react';
22
import { useArtifacts } from '../hooks/use_artifacts';
33
import { Artifact, Engagement } from '../schemas/engagement';
44

@@ -12,40 +12,31 @@ type ArtifactsComponent<P> = React.FunctionComponent<
1212
export function withArtifacts<P>(
1313
WrappedComponent: ArtifactsComponent<P>,
1414
fetcher: () => Promise<Artifact[]>,
15-
fetchEngagementById: (id: string) => Promise<Partial<Engagement>>
1615
) {
1716
return (
1817
<ArtifactFetcher
1918
component={WrappedComponent}
2019
fetcher={fetcher}
21-
getEngagementById={fetchEngagementById}
2220
/>
2321
);
2422
}
2523

2624
interface ArtifactFetcherProps<P> {
2725
component: ArtifactsComponent<P>;
2826
fetcher: () => Promise<Artifact[]>;
29-
getEngagementById: (id: string) => Promise<Partial<Engagement>>;
3027
}
3128

3229
const ArtifactFetcher = (props: ArtifactFetcherProps<any>) => {
33-
const { component: WrappedComponent, getEngagementById } = props;
30+
const { component: WrappedComponent } = props;
3431
const [artifacts, fetchArtifacts] = useArtifacts(props.fetcher);
35-
const [engagements, setEngagements] = useState([]);
3632
useEffect(() => {
3733
fetchArtifacts();
3834
}, [fetchArtifacts]);
39-
useEffect(() => {
40-
Promise.all(
41-
artifacts.map(artifact => getEngagementById(artifact.engagement_uuid))
42-
).then(engagements => setEngagements(engagements));
43-
}, [artifacts, getEngagementById]);
35+
useEffect(() => {}, [artifacts]);
4436
return (
4537
<WrappedComponent
4638
{...props}
4739
artifacts={artifacts}
48-
engagements={engagements}
4940
/>
5041
);
5142
};

src/mocks/engagement_mocks.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import faker from 'faker';
44
export const mockEngagementUseCase = (): EngagementUseCase => {
55
return {
66
id: faker.random.uuid(),
7+
engagement_uuid: "1",
78
description: faker.lorem.sentences(2),
89
};
910
};
@@ -13,6 +14,8 @@ export const mockEngagementArtifact = (useStaticData = false): Artifact => {
1314
uuid: useStaticData ? '1' : faker.random.uuid(),
1415
linkAddress: useStaticData ? 'https://example.com' : faker.internet.url(),
1516
title: useStaticData ? 'An engagement artifact' : faker.lorem.words(3),
17+
customer_name: useStaticData ? "Customer A1" : faker.lorem.words(2),
18+
project_name: useStaticData ? "Residency B1" : faker.lorem.words(2),
1619
type: 'demo',
1720
description: useStaticData
1821
? 'Artifact Description'

src/packages/api_v1_sdk/apiv1_artifact_service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,18 @@ export class Apiv1ArtifactService implements ArtifactService {
5353
uuid: apiResponseObject['uuid'],
5454
title: apiResponseObject['title'],
5555
type: apiResponseObject['type'],
56+
pretty_type: apiResponseObject['pretty_type'],
5657
engagement_uuid: apiResponseObject['engagement_uuid'],
58+
customer_name: apiResponseObject['customer_name'],
59+
project_name: apiResponseObject['project_name'],
5760
};
5861
};
5962
async getArtifacts(filter: ArtifactFilter = {}): Promise<Artifact[]> {
6063
const queryString = this.buildQueryString(filter);
6164
const { data } = await this.axios.get(
6265
`/engagements/artifacts?${queryString}`,
6366
{
64-
headers: { "Accept-version": "v1" }
67+
headers: { "Accept-version": "v2" }
6568
}
6669
);
6770
const artifacts = data.map(this.apiResponseToArtifact);

src/routes/dashboard/index.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,13 @@ export function Dashboard() {
322322
regions: selectedRegions,
323323
sortOrder: 'DESC',
324324
sortFields: 'updated',
325-
}),
326-
engagementService.getEngagementById
325+
})
327326
)}
328327
</GridItem>
329328
<GridItem sm={12} xl={12} xl2={6}>
330329
{withArtifacts(
331330
({ artifacts, engagements }) => (
332-
<DwLastDemo demos={artifacts} engagements={engagements} />
331+
<DwLastDemo demos={artifacts} />
333332
),
334333
() =>
335334
artifactService.getArtifacts({
@@ -341,8 +340,7 @@ export function Dashboard() {
341340
regions: selectedRegions,
342341
sortOrder: 'DESC',
343342
sortFields: 'updated',
344-
}),
345-
engagementService.getEngagementById
343+
})
346344
)}
347345
</GridItem>
348346
<GridItem sm={12} xl={12} xl2={6}>
@@ -358,9 +356,7 @@ export function Dashboard() {
358356
regions: selectedRegions,
359357
sortOrder: 'DESC',
360358
sortFields: 'updated',
361-
}),
362-
363-
engagementService.getEngagementById
359+
})
364360
)}
365361
</GridItem>
366362
</Grid>

src/schemas/engagement.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ export interface Artifact {
7070
linkAddress: string;
7171
title: string;
7272
type: string;
73+
pretty_type?: string;
7374
description: string;
7475
engagement_uuid?: string;
76+
project_name?: string;
77+
customer_name?: string;
7578
}
7679

7780
export interface EngagementOverview {

0 commit comments

Comments
 (0)