Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MMT-3946: Bug: Current UI for RevisionList does not indicate to user that a revision has been deleted #1323

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions static/src/js/components/RevisionList/RevisionList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,29 @@ const RevisionList = () => {
const buildDescriptionCell = useCallback((cellData, rowData) => {
const published = rowData.revisionId === concept.revisionId

return (
(published) ? (
const { revisionId, userId } = rowData
// Temporary Solution from MMT-3946 until we can pass up a tombstone type instead
const isDeleted = userId === 'cmr'

let descriptionCellContent

if (published) {
descriptionCellContent = (
<EllipsisLink to={`/${type}/${conceptId}`}>
{[rowData.revisionId, ' - Published'].join('')}
{[revisionId, ' - Published'].join('')}
</EllipsisLink>
)
: (
<EllipsisLink to={`/${type}/${conceptId}/revisions/${rowData.revisionId}`}>
{[rowData.revisionId, ' - Revision'].join('')}
</EllipsisLink>
)
)
} else if (!published && isDeleted) {
descriptionCellContent = `${revisionId} - Deleted`
} else {
descriptionCellContent = (
<EllipsisLink to={`/${type}/${conceptId}/revisions/${rowData.revisionId}`}>
{[revisionId, ' - Revision'].join('')}
</EllipsisLink>
)
}

return descriptionCellContent
}, [])

const [restoreMutation] = useMutation(restoreRevisionMutations[derivedConceptType], {
Expand Down Expand Up @@ -97,11 +108,16 @@ const RevisionList = () => {
}

const buildActionCell = useCallback((cellData, rowData) => {
const { revisionId } = rowData
const { revisionId, userId } = 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'
mandyparson marked this conversation as resolved.
Show resolved Hide resolved

let actionCellContent

return (
revisionId !== currRevisionId && (
if (!isPublished && !isDeleted) {
actionCellContent = (
<Button
className="btn btn-link"
type="button"
Expand All @@ -111,7 +127,13 @@ const RevisionList = () => {
Revert to this revision
</Button>
)
)
} else if (!isPublished && isDeleted) {
actionCellContent = 'deleted'
} else {
actionCellContent = null
}

return actionCellContent
})

const columns = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
} from 'react-router-dom'

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

import RevisionList from '../RevisionList'
import ErrorBoundary from '../../ErrorBoundary/ErrorBoundary'
Expand Down Expand Up @@ -118,6 +121,37 @@ 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,3 +3304,43 @@ 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'
}
}
}
}