Skip to content

Commit

Permalink
Mmt 3946b: Reverting changes from MMT-3946 (#1328)
Browse files Browse the repository at this point in the history
* MMT-3946b: Removing logic from MMT-3946

* MMT-3946b: Linting
  • Loading branch information
mandyparson authored Dec 4, 2024
1 parent 53c2a92 commit 30375f8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 95 deletions.
31 changes: 11 additions & 20 deletions static/src/js/components/RevisionList/RevisionList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,25 @@ const RevisionList = () => {
})

const { [derivedConceptType.toLowerCase()]: concept } = data
const { revisions } = concept
const { revisions, revisionId: conceptRevisionId } = concept
const { count, items } = revisions

const buildDescriptionCell = useCallback((cellData, rowData) => {
const published = rowData.revisionId === concept.revisionId

const { revisionId, userId } = rowData
// Temporary Solution from MMT-3946 until we can pass up a tombstone type instead
const isDeleted = userId === 'cmr'
const { revisionId: rowDataRevisionId } = rowData
const isPublished = rowDataRevisionId === conceptRevisionId

let descriptionCellContent

if (published) {
if (isPublished) {
descriptionCellContent = (
<EllipsisLink to={`/${type}/${conceptId}`}>
{[revisionId, ' - Published'].join('')}
{[rowDataRevisionId, ' - Published'].join('')}
</EllipsisLink>
)
} else if (!published && isDeleted) {
descriptionCellContent = `${revisionId} - Deleted`
} else {
descriptionCellContent = (
<EllipsisLink to={`/${type}/${conceptId}/revisions/${rowData.revisionId}`}>
{[revisionId, ' - Revision'].join('')}
<EllipsisLink to={`/${type}/${conceptId}/revisions/${rowDataRevisionId}`}>
{[rowDataRevisionId, ' - Revision'].join('')}
</EllipsisLink>
)
}
Expand Down Expand Up @@ -108,27 +103,23 @@ const RevisionList = () => {
}

const buildActionCell = useCallback((cellData, rowData) => {
const { revisionId, userId } = rowData
const { revisionId: rowDataRevisionId } = rowData
const { revisionId: currRevisionId } = concept
const isPublished = revisionId === currRevisionId
// Temporary Solution from MMT-3946 until we can pass up a tombstone type instead
const isDeleted = userId === 'cmr'
const isPublished = rowDataRevisionId === currRevisionId

let actionCellContent

if (!isPublished && !isDeleted) {
if (!isPublished) {
actionCellContent = (
<Button
className="btn btn-link"
type="button"
variant="link"
onClick={() => { handleRevert(revisionId) }}
onClick={() => { handleRevert(rowDataRevisionId) }}
>
Revert to this revision
</Button>
)
} else if (!isPublished && isDeleted) {
actionCellContent = 'deleted'
} else {
actionCellContent = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import {
} from 'react-router-dom'

import userEvent from '@testing-library/user-event'
import {
collectionRevisions,
collectionRevisionsWithDeletedRevision
} from './__mocks__/revisionResults'
import { collectionRevisions } from './__mocks__/revisionResults'

import RevisionList from '../RevisionList'
import ErrorBoundary from '../../ErrorBoundary/ErrorBoundary'
Expand Down Expand Up @@ -121,37 +118,6 @@ describe('RevisionList component', () => {
})
})

// Temporary solution from MMT-3946. We are determining that a revision has been deleted if its userId === cmr
describe('when there is a revision with userid === cmr', () => {
test('renders the revisions and indicates which of them has been deleted', async () => {
setup({ overrideMocks: [collectionRevisionsWithDeletedRevision] })

expect(screen.queryByText('Loading...'))

const tableRows = await screen.findAllByRole('row')
expect(tableRows.length).toEqual(3)

const date = new Date(2000, 1, 1, 13)
vi.setSystemTime(date)
const rows = screen.queryAllByRole('row')
const row1 = rows[1]
const row2 = rows[2]

const row1Cells = within(row1).queryAllByRole('cell')
const row2Cells = within(row2).queryAllByRole('cell')
expect(row1Cells).toHaveLength(4)
expect(row1Cells[0].textContent).toBe('8 - Published')
expect(row1Cells[1].textContent).toBe('Tuesday, February 1, 2000 6:00 PM')
expect(row1Cells[2].textContent).toBe('admin')
expect(row1Cells[3].textContent).toBe('')

expect(row2Cells).toHaveLength(4)
expect(row2Cells[0].textContent).toBe('7 - Deleted')
expect(row2Cells[2].textContent).toBe('cmr')
expect(row2Cells[3].textContent).toBe('deleted')
})
})

describe('when reverting to a revision results in a success', () => {
test('should call restore to revision mutation', async () => {
const { user } = setup({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3304,43 +3304,3 @@ export const revertCollectionRevision = {
}
}
}

// We are considering 'deleted' when userId === 'cmr' for now. Will come back better solution has been created
export const collectionRevisionsWithDeletedRevision = {
request: {
query: GET_COLLECTION,
variables: {
params: {
conceptId: 'C1200000104-MMT_2'
}
}
},
result: {
data: {
collection: {
revisionId: '8',
revisions: {
count: 8,
items: [
{
conceptId: 'C1200000104-MMT_2',
revisionDate: '2000-02-01T18:00:00.000Z',
revisionId: '8',
userId: 'admin',
__typename: 'Collection'
},
{
conceptId: 'C1200000104-MMT_2',
revisionDate: '2024-04-24T16:37:11.849Z',
revisionId: '7',
userId: 'cmr',
__typename: 'Collection'
}
],
__typename: 'CollectionRevisionList'
},
__typename: 'Collection'
}
}
}
}

0 comments on commit 30375f8

Please sign in to comment.