Skip to content

Commit d2a602c

Browse files
authored
MMT-4024: As a user, I can view past revisions of my Visualizations from PublishPreview (#1378)
* MMT-4024: View Past Revisions * MMT-4024: Fixing published issue * MMT-4024: Minor fix
1 parent 5140ae9 commit d2a602c

File tree

7 files changed

+88
-35
lines changed

7 files changed

+88
-35
lines changed

static/src/js/components/RevisionList/RevisionList.jsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import React, { useCallback } from 'react'
1+
import React, {
2+
useCallback,
3+
useMemo,
4+
useState
5+
} from 'react'
26
import { useMutation, useSuspenseQuery } from '@apollo/client'
37
import { useParams } from 'react-router'
48
import Button from 'react-bootstrap/Button'
@@ -33,6 +37,8 @@ const RevisionList = () => {
3337

3438
const derivedConceptType = getConceptTypeByConceptId(conceptId)
3539

40+
const [publishedRevisionId, setPublishedRevisionId] = useState(null)
41+
3642
const { data } = useSuspenseQuery(conceptTypeQueries[derivedConceptType], {
3743
variables: {
3844
params: {
@@ -42,12 +48,12 @@ const RevisionList = () => {
4248
})
4349

4450
const { [derivedConceptType.toLowerCase()]: concept } = data
45-
const { revisions, revisionId: conceptRevisionId } = concept
51+
const { revisions } = concept
4652
const { count, items } = revisions
4753

4854
const buildDescriptionCell = useCallback((cellData, rowData) => {
4955
const { revisionId: rowDataRevisionId } = rowData
50-
const isPublished = rowDataRevisionId === conceptRevisionId
56+
const isPublished = rowDataRevisionId === publishedRevisionId
5157

5258
let descriptionCellContent
5359

@@ -66,7 +72,7 @@ const RevisionList = () => {
6672
}
6773

6874
return descriptionCellContent
69-
}, [])
75+
}, [publishedRevisionId])
7076

7177
const [restoreMutation] = useMutation(restoreRevisionMutations[derivedConceptType], {
7278
refetchQueries: [{
@@ -104,8 +110,7 @@ const RevisionList = () => {
104110

105111
const buildActionCell = useCallback((cellData, rowData) => {
106112
const { revisionId: rowDataRevisionId } = rowData
107-
const { revisionId: currRevisionId } = concept
108-
const isPublished = rowDataRevisionId === currRevisionId
113+
const isPublished = rowDataRevisionId === publishedRevisionId
109114

110115
let actionCellContent
111116

@@ -125,7 +130,7 @@ const RevisionList = () => {
125130
}
126131

127132
return actionCellContent
128-
})
133+
}, [handleRevert, publishedRevisionId])
129134

130135
const columns = [
131136
{
@@ -153,11 +158,22 @@ const RevisionList = () => {
153158
}
154159
]
155160

161+
// Ensures items are sorted when items array changes as opposed to every render
162+
const sortedItems = useMemo(() => {
163+
const sorted = [...items].sort((a, b) => new Date(b.revisionDate) - new Date(a.revisionDate))
164+
// Set the published revision ID to the first (most recent) revision
165+
if (sorted.length > 0) {
166+
setPublishedRevisionId(sorted[0].revisionId)
167+
}
168+
169+
return sorted
170+
}, [items])
171+
156172
return (
157173
<Table
158174
id="revision-results-table"
159175
columns={columns}
160-
data={items}
176+
data={sortedItems}
161177
generateCellKey={({ revisionId }, dataKey) => `column_${dataKey}_${conceptId}_${revisionId}`}
162178
generateRowKey={({ revisionId }) => `row_${conceptId}_${revisionId}`}
163179
noDataMessage="No results"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('RevisionList component', () => {
107107
const row2Cells = within(row2).queryAllByRole('cell')
108108
expect(row1Cells).toHaveLength(4)
109109
expect(row1Cells[0].textContent).toBe('8 - Published')
110-
expect(row1Cells[1].textContent).toBe('Tuesday, February 1, 2000 6:00 PM')
110+
expect(row1Cells[1].textContent).toBe('Monday, February 28, 2000 6:00 PM')
111111
expect(row1Cells[2].textContent).toBe('admin')
112112
expect(row1Cells[3].textContent).toBe('')
113113

static/src/js/components/RevisionList/__tests__/__mocks__/revisionResults.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const collectionRevisions = {
1515
data: {
1616
collection: {
1717
abstract: "The 2012 Environmental Performance Index (EPI) ranks 132 countries on 22 performance indicators in the following 10 policy categories: environmental burden of disease, water (effects on human health), air pollution (effects on human health), air pollution (ecosystem effects), water resources (ecosystem effects), biodiversity and habitat, forestry, fisheries, agriculture and climate change. These categories track performance and progress on two broad policy objectives, environmental health and ecosystem vitality. Each indicator has an associated environmental public health or ecosystem sustainability target. The EPI's proximity-to-target methodology facilitates cross-country comparisons among economic and regional peer groups.\n\n\n\n\nThe Pilot Trend Environmental Performance Index (Trend EPI) ranks countries on the change in their environmental performance over the last decade. As a complement to the EPI, the Trend EPI shows who is improving and who is declining over time.\n\n\n\n\nThe 2012 EPI and Pilot Trend EPI were formally released in Davos, Switzerland, at the annual meeting of the World Economic Forum on January 27, 2012. These are the result of collaboration between the Yale Center for Environmental Law and Policy (YCELP) and the Columbia University Center for International Earth Science Information Network (CIESIN). The Interactive Website for the 2012 EPI is at http://epi.yale.edu/.",
18+
associationDetails: [],
1819
accessConstraints: {
1920
description: 'None'
2021
},
@@ -1569,66 +1570,68 @@ export const collectionRevisions = {
15691570
userId: 'admin',
15701571
variables: {
15711572
count: 0,
1573+
cursor: '',
15721574
items: null,
15731575
__typename: 'VariableList'
15741576
},
15751577
versionDescription: null,
15761578
versionId: '2012.00',
1579+
visualizations: [],
15771580
revisions: {
15781581
count: 8,
15791582
items: [
15801583
{
15811584
conceptId: 'C1200000104-MMT_2',
1582-
revisionDate: '2000-02-01T18:00:00.000Z',
1585+
revisionDate: '2000-02-28T18:00:00.000Z',
15831586
revisionId: '8',
15841587
userId: 'admin',
15851588
__typename: 'Collection'
15861589
},
15871590
{
15881591
conceptId: 'C1200000104-MMT_2',
1589-
revisionDate: '2024-04-24T16:37:11.849Z',
1592+
revisionDate: '2000-02-27T18:00:00.000Z',
15901593
revisionId: '7',
15911594
userId: 'admin',
15921595
__typename: 'Collection'
15931596
},
15941597
{
15951598
conceptId: 'C1200000104-MMT_2',
1596-
revisionDate: '2024-04-24T16:30:34.542Z',
1599+
revisionDate: '2000-02-26T18:00:00.000Z',
15971600
revisionId: '6',
15981601
userId: 'admin',
15991602
__typename: 'Collection'
16001603
},
16011604
{
16021605
conceptId: 'C1200000104-MMT_2',
1603-
revisionDate: '2024-04-24T16:25:36.563Z',
1606+
revisionDate: '2000-02-24T18:00:00.000Z',
16041607
revisionId: '5',
16051608
userId: 'admin',
16061609
__typename: 'Collection'
16071610
},
16081611
{
16091612
conceptId: 'C1200000104-MMT_2',
1610-
revisionDate: '2024-04-24T04:55:11.745Z',
1613+
revisionDate: '2000-02-23T18:00:00.000Z',
16111614
revisionId: '4',
16121615
userId: 'admin',
16131616
__typename: 'Collection'
16141617
},
16151618
{
16161619
conceptId: 'C1200000104-MMT_2',
1617-
revisionDate: '2024-04-24T03:38:28.988Z',
1620+
revisionDate: '2000-02-22T18:00:00.000Z',
16181621
revisionId: '3',
16191622
userId: 'admin',
16201623
__typename: 'Collection'
16211624
},
16221625
{
16231626
conceptId: 'C1200000104-MMT_2',
1624-
revisionDate: '2024-04-24T03:24:08.375Z',
1627+
revisionDate: '2000-02-21T18:00:00.000Z',
16251628
revisionId: '2',
16261629
userId: 'admin',
16271630
__typename: 'Collection'
16281631
},
16291632
{
16301633
conceptId: 'C1200000104-MMT_2',
1631-
revisionDate: '2024-04-24T03:23:24.368Z',
1634+
revisionDate: '2000-02-20T18:00:00.000Z',
16321635
revisionId: '1',
16331636
userId: 'admin',
16341637
__typename: 'Collection'
@@ -1672,6 +1675,7 @@ export const revertCollectionRevision = {
16721675
data: {
16731676
collection: {
16741677
abstract: "The 2012 Environmental Performance Index (EPI) ranks 132 countries on 22 performance indicators in the following 10 policy categories: environmental burden of disease, water (effects on human health), air pollution (effects on human health), air pollution (ecosystem effects), water resources (ecosystem effects), biodiversity and habitat, forestry, fisheries, agriculture and climate change. These categories track performance and progress on two broad policy objectives, environmental health and ecosystem vitality. Each indicator has an associated environmental public health or ecosystem sustainability target. The EPI's proximity-to-target methodology facilitates cross-country comparisons among economic and regional peer groups.\n\n\n\n\nThe Pilot Trend Environmental Performance Index (Trend EPI) ranks countries on the change in their environmental performance over the last decade. As a complement to the EPI, the Trend EPI shows who is improving and who is declining over time.\n\n\n\n\nThe 2012 EPI and Pilot Trend EPI were formally released in Davos, Switzerland, at the annual meeting of the World Economic Forum on January 27, 2012. These are the result of collaboration between the Yale Center for Environmental Law and Policy (YCELP) and the Columbia University Center for International Earth Science Information Network (CIESIN). The Interactive Website for the 2012 EPI is at http://epi.yale.edu/.",
1678+
associationDetails: [],
16751679
accessConstraints: {
16761680
description: 'None'
16771681
},
@@ -3225,73 +3229,75 @@ export const revertCollectionRevision = {
32253229
userId: 'admin',
32263230
variables: {
32273231
count: 0,
3232+
cursor: '',
32283233
items: null,
32293234
__typename: 'VariableList'
32303235
},
32313236
versionDescription: null,
32323237
versionId: '2012.00',
3238+
visualizations: [],
32333239
revisions: {
32343240
count: 9,
32353241
items: [
32363242
{
32373243
conceptId: 'C1200000104-MMT_2',
3238-
revisionDate: '2000-02-01',
3244+
revisionDate: '2000-02-28T18:00:00.000Z',
32393245
revisionId: '9',
32403246
userId: 'admin',
32413247
__typename: 'Collection'
32423248
},
32433249
{
32443250
conceptId: 'C1200000104-MMT_2',
3245-
revisionDate: '2000-02-01',
3251+
revisionDate: '2000-02-27T18:00:00.000Z',
32463252
revisionId: '8',
32473253
userId: 'admin',
32483254
__typename: 'Collection'
32493255
},
32503256
{
32513257
conceptId: 'C1200000104-MMT_2',
3252-
revisionDate: '2000-02-01T18:00:00.000Z',
3258+
revisionDate: '2000-02-26T18:00:00.000Z',
32533259
revisionId: '7',
32543260
userId: 'admin',
32553261
__typename: 'Collection'
32563262
},
32573263
{
32583264
conceptId: 'C1200000104-MMT_2',
3259-
revisionDate: '2000-02-01T18:00:00.000Z',
3265+
revisionDate: '2000-02-25T18:00:00.000Z',
32603266
revisionId: '6',
32613267
userId: 'admin',
32623268
__typename: 'Collection'
32633269
},
32643270
{
32653271
conceptId: 'C1200000104-MMT_2',
3266-
revisionDate: '2000-02-01T18:00:00.000Z',
3272+
revisionDate: '2000-02-24T18:00:00.000Z',
32673273
revisionId: '5',
32683274
userId: 'admin',
32693275
__typename: 'Collection'
32703276
},
32713277
{
32723278
conceptId: 'C1200000104-MMT_2',
3273-
revisionDate: '2000-02-01T18:00:00.000Z',
3279+
revisionDate: '2000-02-23T18:00:00.000Z',
32743280
revisionId: '4',
32753281
userId: 'admin',
32763282
__typename: 'Collection'
32773283
},
32783284
{
32793285
conceptId: 'C1200000104-MMT_2',
3280-
revisionDate: '2000-02-01T18:00:00.000Z',
3286+
revisionDate: '2000-02-22T18:00:00.000Z',
32813287
revisionId: '3',
32823288
userId: 'admin',
32833289
__typename: 'Collection'
32843290
},
32853291
{
32863292
conceptId: 'C1200000104-MMT_2',
3287-
revisionDate: '2000-02-01T18:00:00.000Z',
3293+
revisionDate: '2000-02-21T18:00:00.000Z',
32883294
revisionId: '2',
32893295
userId: 'admin',
32903296
__typename: 'Collection'
32913297
},
32923298
{
32933299
conceptId: 'C1200000104-MMT_2',
3294-
revisionDate: '2000-02-01T18:00:00.000Z',
3300+
revisionDate: '2000-02-20T18:00:00.000Z',
32953301
revisionId: '1',
32963302
userId: 'admin',
32973303
__typename: 'Collection'

static/src/js/constants/restoreRevisionMutations.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import { RESTORE_COLLECTION_REVISION } from '../operations/mutations/restoreColl
22
import { RESTORE_SERVICE_REVISION } from '../operations/mutations/restoreServiceRevision'
33
import { RESTORE_TOOL_REVISION } from '../operations/mutations/restoreToolRevision'
44
import { RESTORE_VARIABLE_REVISION } from '../operations/mutations/restoreVariableRevision'
5+
import {
6+
RESTORE_VISUALIZATION_REVISION
7+
} from '../operations/mutations/restoreVisualizationRevision'
58

69
const restoreRevisionMutations = {
710
Collection: RESTORE_COLLECTION_REVISION,
811
Service: RESTORE_SERVICE_REVISION,
912
Tool: RESTORE_TOOL_REVISION,
10-
Variable: RESTORE_VARIABLE_REVISION
13+
Variable: RESTORE_VARIABLE_REVISION,
14+
Visualization: RESTORE_VISUALIZATION_REVISION
1115
}
1216

1317
export default restoreRevisionMutations
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { gql } from '@apollo/client'
2+
3+
export const RESTORE_VISUALIZATION_REVISION = gql`
4+
mutation RestoreVariableRevision (
5+
$conceptId: String!
6+
$revisionId: String!
7+
) {
8+
restoreVisualizationRevision (
9+
conceptId: $conceptId
10+
revisionId: $revisionId
11+
) {
12+
conceptId
13+
revisionId
14+
}
15+
}
16+
`
17+
// Example Variables:
18+
// {
19+
// "conceptId": "VIS1200000098-MMT_2",
20+
// "revisionId": "1"
21+
// }

static/src/js/operations/queries/getCollection.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,6 @@ export const GET_COLLECTION = gql`
117117
url
118118
}
119119
}
120-
visualizations {
121-
count
122-
items {
123-
conceptId
124-
name
125-
type: visualizationType
126-
}
127-
}
128120
ummMetadata
129121
useConstraints
130122
userId
@@ -138,6 +130,14 @@ export const GET_COLLECTION = gql`
138130
}
139131
versionDescription
140132
versionId
133+
visualizations {
134+
count
135+
items {
136+
conceptId
137+
name
138+
type: visualizationType
139+
}
140+
}
141141
}
142142
}
143143
`

static/src/js/operations/queries/getVisualization.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ export const GET_VISUALIZATION = gql`
1616
revisionId
1717
revisions {
1818
count
19+
items {
20+
conceptId
21+
revisionDate
22+
revisionId
23+
userId
24+
}
1925
}
2026
collections (params: $collectionsParams) {
2127
count

0 commit comments

Comments
 (0)