Skip to content

Commit a64399e

Browse files
authored
MMT-3990: Adding Published and Draft Visualizations (#1355)
* MMT-3990: Adding Published and Draft Visualizations * MMT-3990: Removing Search Bar for now * MMT-3990: Adding comments and lint
1 parent 842face commit a64399e

File tree

18 files changed

+508
-148
lines changed

18 files changed

+508
-148
lines changed

static.config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"ummC": "1.18.3",
3030
"ummS": "1.5.3",
3131
"ummT": "1.2.0",
32-
"ummV": "1.9.0"
32+
"ummV": "1.9.0",
33+
"ummVis": "1.1.0"
3334
},
3435
"ummJsonSchemaUrl": "http://json-schema.org/draft-07/schema#",
3536
"edl": {

static/src/js/components/DraftList/DraftList.jsx

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import Col from 'react-bootstrap/Col'
99
import Row from 'react-bootstrap/Row'
1010

1111
import { DATE_FORMAT } from '@/js/constants/dateFormat'
12-
import conceptIdTypes from '@/js/constants/conceptIdTypes'
1312
import conceptTypeDraftsQueries from '@/js/constants/conceptTypeDraftsQueries'
1413
import constructDownloadableFile from '@/js/utils/constructDownloadableFile'
1514
import urlValueTypeToConceptTypeStringMap from '@/js/constants/urlValueToConceptStringMap'
@@ -58,7 +57,7 @@ const DraftList = () => {
5857

5958
let cellData = originalCellData
6059

61-
if (!cellData && draftType === conceptIdTypes.C) cellData = '<Blank Short Name>'
60+
if (!cellData && draftType === 'Collection') cellData = '<Blank Short Name>'
6261
if (!cellData) cellData = '<Blank Name>'
6362

6463
return (
@@ -71,7 +70,7 @@ const DraftList = () => {
7170
const buildEllipsisTextCell = useCallback((originalCellData) => {
7271
let cellData = originalCellData
7372

74-
if (!cellData && draftType === conceptIdTypes.C) cellData = '<Blank Entry Title>'
73+
if (!cellData && draftType === 'Collection') cellData = '<Blank Entry Title>'
7574
if (!cellData) cellData = '<Blank Long Name>'
7675

7776
return (
@@ -114,7 +113,23 @@ const DraftList = () => {
114113
dataAccessorFn: buildEllipsisTextCell
115114
}
116115
]
117-
const nonCollectionColumns = [
116+
117+
const visColumns = [
118+
{
119+
dataKey: 'previewMetadata.name',
120+
title: 'Name',
121+
className: 'col-auto',
122+
dataAccessorFn: buildPrimaryEllipsisLink
123+
},
124+
{
125+
dataKey: 'previewMetadata.title',
126+
title: 'Long Name',
127+
className: 'col-auto',
128+
dataAccessorFn: buildEllipsisTextCell
129+
}
130+
]
131+
132+
const defaultColumns = [
118133
{
119134
dataKey: 'ummMetadata.Name',
120135
title: 'Name',
@@ -147,9 +162,18 @@ const DraftList = () => {
147162
}
148163
]
149164

150-
const columns = draftType === conceptIdTypes.C
151-
? [...collectionColumns, ...commonColumns]
152-
: [...nonCollectionColumns, ...commonColumns]
165+
const getColumns = () => {
166+
switch (draftType) {
167+
case 'Collection':
168+
return [...collectionColumns, ...commonColumns]
169+
case 'Visualization':
170+
return [...visColumns, ...commonColumns]
171+
default:
172+
return [...defaultColumns, ...commonColumns]
173+
}
174+
}
175+
176+
const columns = getColumns()
153177

154178
return (
155179
<Row>

static/src/js/components/DraftList/__tests__/DraftList.test.jsx

Lines changed: 54 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@ import constructDownloadableFile from '@/js/utils/constructDownloadableFile'
1313

1414
import { GET_TOOL_DRAFTS } from '@/js/operations/queries/getToolDrafts'
1515
import { GET_COLLECTION_DRAFTS } from '@/js/operations/queries/getCollectionDrafts'
16+
import { GET_VISUALIZATION_DRAFTS } from '@/js/operations/queries/getVisualizationDrafts'
1617

1718
import ErrorBoundary from '@/js/components/ErrorBoundary/ErrorBoundary'
1819

20+
import {
21+
mockCollectionDrafts,
22+
mockToolDrafts,
23+
mockVisualizationDrafts
24+
} from './__mocks__/DraftListMocks'
25+
1926
import DraftList from '../DraftList'
2027

2128
vi.mock('react-bootstrap/Placeholder', () => ({ default: vi.fn() }))
@@ -27,124 +34,6 @@ vi.mock('react-router-dom', async () => ({
2734
useParams: vi.fn().mockImplementation(() => ({ draftType: 'tools' }))
2835
}))
2936

30-
const mockToolDrafts = {
31-
count: 3,
32-
items: [
33-
{
34-
conceptId: 'TD1200000092-MMT_2',
35-
revisionDate: '2023-12-08T17:56:09.385Z',
36-
revisionId: '1',
37-
ummMetadata: {
38-
Name: 'Tool TD1200000092 short name',
39-
LongName: 'Tool TD1200000092 long name'
40-
},
41-
name: 'Tool TD1200000092 short name',
42-
previewMetadata: {
43-
conceptId: 'TD1200000092-MMT_2',
44-
revisionId: '1',
45-
name: 'Tool TD1200000092 short name',
46-
longName: 'Tool TD1200000092 long name',
47-
__typename: 'Tool'
48-
},
49-
providerId: 'MMT_2',
50-
__typename: 'Draft'
51-
},
52-
{
53-
conceptId: 'TD1200000093-MMT_2',
54-
revisionDate: '2023-11-08T17:56:09.385Z',
55-
revisionId: '1',
56-
ummMetadata: {},
57-
previewMetadata: {
58-
conceptId: 'TD1200000093-MMT_2',
59-
revisionId: '1',
60-
name: null,
61-
longName: null,
62-
__typename: 'Tool'
63-
},
64-
providerId: 'MMT_2',
65-
__typename: 'Draft'
66-
},
67-
{
68-
conceptId: 'TD1200000094-MMT_2',
69-
revisionDate: '2023-10-08T17:56:09.385Z',
70-
revisionId: '1',
71-
ummMetadata: {
72-
Name: 'Tool TD1200000094 short name',
73-
LongName: 'Tool TD1200000094 long name'
74-
},
75-
previewMetadata: {
76-
conceptId: 'TD1200000094-MMT_2',
77-
revisionId: '1',
78-
name: null,
79-
longName: null,
80-
__typename: 'Tool'
81-
},
82-
providerId: 'MMT_2',
83-
__typename: 'Draft'
84-
}
85-
],
86-
__typename: 'DraftList'
87-
}
88-
89-
const mockCollectionDrafts = {
90-
count: 3,
91-
items: [
92-
{
93-
conceptId: 'CD1200000092-MMT_2',
94-
revisionDate: '2023-12-08T17:56:09.385Z',
95-
revisionId: '1',
96-
ummMetadata: {
97-
ShortName: 'Collection CD1200000092 short name',
98-
EntryTitle: 'Collection CD1200000092 entry title'
99-
},
100-
shortName: 'Collection CD1200000092 short name',
101-
previewMetadata: {
102-
conceptId: 'CD1200000092-MMT_2',
103-
revisionId: '1',
104-
shortName: 'Collection CD1200000092 short name',
105-
entryTitle: 'Collection CD1200000092 entry title',
106-
__typename: 'Collection'
107-
},
108-
providerId: 'MMT_2',
109-
__typename: 'Draft'
110-
},
111-
{
112-
conceptId: 'CD1200000093-MMT_2',
113-
revisionDate: '2023-11-08T17:56:09.385Z',
114-
revisionId: '1',
115-
ummMetadata: {},
116-
previewMetadata: {
117-
conceptId: 'CD1200000093-MMT_2',
118-
revisionId: '1',
119-
shortName: null,
120-
entryTitle: null,
121-
__typename: 'Collection'
122-
},
123-
providerId: 'MMT_2',
124-
__typename: 'Draft'
125-
},
126-
{
127-
conceptId: 'CD1200000094-MMT_2',
128-
revisionDate: '2023-10-08T17:56:09.385Z',
129-
revisionId: '1',
130-
ummMetadata: {
131-
ShortName: 'Collection CD1200000094 short name',
132-
EntryTitle: 'Collection CD1200000094 entry title'
133-
},
134-
previewMetadata: {
135-
conceptId: 'CD1200000094-MMT_2',
136-
revisionId: '1',
137-
shortName: null,
138-
entryTitle: null,
139-
__typename: 'Collection'
140-
},
141-
providerId: 'MMT_2',
142-
__typename: 'Draft'
143-
}
144-
],
145-
__typename: 'DraftList'
146-
}
147-
14837
const setup = ({ overrideMocks = false }) => {
14938
const mocks = [{
15039
request: {
@@ -335,4 +224,51 @@ describe('DraftList', () => {
335224
)
336225
})
337226
})
227+
228+
describe('when draft type Visualization is given', () => {
229+
test('renders Visualization draft list', async () => {
230+
useParams.mockImplementation(() => ({ draftType: 'visualizations' }))
231+
232+
setup({
233+
overrideMocks: [{
234+
request: {
235+
query: GET_VISUALIZATION_DRAFTS,
236+
variables: {
237+
params: {
238+
conceptType: 'Visualization',
239+
limit: 20,
240+
offset: 0,
241+
sortKey: ['-revision_date']
242+
}
243+
}
244+
},
245+
result: {
246+
data: {
247+
drafts: mockVisualizationDrafts
248+
}
249+
}
250+
}]
251+
})
252+
253+
const rows = await screen.findAllByRole('row')
254+
255+
expect(within(rows[1]).getByRole('cell', { name: 'Short Name 1' })).toBeInTheDocument()
256+
expect(within(rows[1]).getByRole('cell', { name: 'Long Name 1' })).toBeInTheDocument()
257+
expect(within(rows[1]).getByRole('cell', { name: 'Friday, April 25, 2025 5:26 PM' })).toBeInTheDocument()
258+
expect(within(rows[1]).getByRole('cell', { name: 'MMT_1' })).toBeInTheDocument()
259+
expect(within(rows[1]).getByRole('button', { name: /Download JSON/ })).toBeInTheDocument()
260+
261+
expect(within(rows[2]).getByRole('cell', { name: '<Blank Name>' })).toBeInTheDocument()
262+
expect(within(rows[2]).getByRole('cell', { name: '<Blank Long Name>' })).toBeInTheDocument()
263+
expect(within(rows[2]).getByRole('cell', { name: 'Thursday, May 15, 2025 10:30 AM' })).toBeInTheDocument()
264+
expect(within(rows[2]).getByRole('cell', { name: 'MMT_1' })).toBeInTheDocument()
265+
expect(within(rows[2]).getByRole('button', { name: /Download JSON/ })).toBeInTheDocument()
266+
267+
expect(within(rows[3]).getByRole('cell', { name: 'Short Name 3' })).toBeInTheDocument()
268+
expect(within(rows[3]).getByRole('cell', { name: 'Long Name 3' })).toBeInTheDocument()
269+
expect(within(rows[3]).getByRole('cell', { name: 'Thursday, June 5, 2025 2:45 PM' })).toBeInTheDocument()
270+
expect(within(rows[3]).getByRole('cell', { name: 'MMT_1' })).toBeInTheDocument()
271+
expect(within(rows[3]).getByRole('button', { name: /Download JSON/ })).toBeInTheDocument()
272+
})
273+
})
338274
})

0 commit comments

Comments
 (0)