Skip to content

Commit

Permalink
Merge pull request #2491 from Inist-CNRS/feat/2330-delete-annotation
Browse files Browse the repository at this point in the history
Feat(annotation): Improve annotation detail layout and add support for deletion
  • Loading branch information
jonathanarnault authored Feb 7, 2025
2 parents 72cfdd9 + c015fa7 commit d047cda
Show file tree
Hide file tree
Showing 36 changed files with 2,036 additions and 767 deletions.
4 changes: 4 additions & 0 deletions cypress/e2e/phase_1/admin_display.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ describe('Home Page', () => {
cy.findByRole('gridcell', {
name: /newField/,
timeout: 1000,
}).trigger('mouseenter');

cy.findByRole('button', {
name: /edit-newField/,
}).click();

cy.get(`button[value="home"]`).should('not.have.class', 'Mui-selected');
Expand Down
165 changes: 151 additions & 14 deletions cypress/e2e/phase_4/annotation.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('Annotation', () => {
'Internal Comment',
'Administrator',
'Contributor',
'Comment',
'Contributor Comment',
'Submission date',
'Last modified on',
]);
Expand Down Expand Up @@ -162,33 +162,51 @@ describe('Annotation', () => {

cy.findByText('RoboCop').click();

cy.findByText('Annotation: RoboCop').should('be.visible');
cy.findByRole('heading', {
name: /^Annotation: uid:\//,
}).should('be.visible');
cy.findByRole('heading', {
name: 'RoboCop',
}).should('be.visible');

cy.findByLabelText('Field Id').should('have.text', '[bZE+]');
cy.findByLabelText('Field label').should('have.text', 'rating');
cy.findByLabelText('Field Internal Name').should(
cy.findByRole('region', { name: 'Contributor Comment' }).should(
'have.text',
'',
'Contributor CommentThis is another comment',
);

cy.findByLabelText('Contributor Comment:').should(
cy.findByRole('region', {
name: 'Contributor',
exact: true,
}).should(
'have.text',
'This is another comment',
'ContributorJane [email protected]',
);

cy.findByLabelText('Name').should('have.text', 'Jane Smith');
cy.findByRole('region', {
name: 'Contributor',
exact: true,
}).then((region) => {
cy.findByRole('link', {
name: '[email protected]',
container: region,
}).should(
'have.attr',
'href',
'mailto:[email protected]',
);
});

cy.findByLabelText('Email').should(
cy.findByLabelText('Submission date').should(
'have.text',
'[email protected]',
new Date().toLocaleDateString(),
);

cy.findByLabelText('Submission date').should(
cy.findByLabelText('Last modified on').should(
'have.text',
new Date().toLocaleDateString(),
);

cy.findByLabelText('Status').should('have.text', 'To Review');
cy.findByLabelText('Status').should('have.text', 'To Review');
cy.findByLabelText('Status').click();
cy.findByText('Validated').click();
cy.findByLabelText('Internal Comment *').type('Return applied');
Expand All @@ -198,7 +216,9 @@ describe('Annotation', () => {
'exist',
);

cy.findByText('Annotations').click();
cy.findByRole('link', {
name: 'Cancel',
}).click();

cy.wait(1000);
cy.findByRole('progressbar').should('not.exist');
Expand Down Expand Up @@ -250,6 +270,123 @@ describe('Annotation', () => {
name: `Add an annotation to Liste des films`,
}).should('not.exist');
});

it('should delete an annotation on resource field', () => {
cy.findByText('Search').click();
searchDrawer.search('Terminator 2');
searchDrawer.waitForLoading();
cy.findByTitle('Terminator 2').click();
annotation.createTitleAnnotation({
fieldLabel: 'actors',
comment: 'This is a comment',
authorName: 'John Doe',
authorEmail: '[email protected]',
});

cy.findByText('Search').click();
searchDrawer.search('RoboCop');
searchDrawer.waitForLoading();
cy.findByTitle('RoboCop').click();
annotation.createTitleAnnotation({
fieldLabel: 'rating',
comment: 'This is another comment',
authorName: 'Jane Smith',
authorEmail: '[email protected]',
});
cy.findByText('More').click();
menu.goToAdminDashboard();
cy.findByText('Annotations').click();

cy.findAllByRole('cell').then((cells) => {
const firstUri = cells[0].textContent;
const secondUri = cells[14].textContent;

expect(firstUri).to.match(/uid:\//);
expect(secondUri).to.match(/uid:\//);

expect(
cells.toArray().map((cell) => cell.textContent),
).to.deep.equal([
firstUri,
'RoboCop',
'rating',
'[bZE+]',
'',
'',
'',
'To Review',
'',
'',
'Jane Smith',
'This is another comment',
new Date().toLocaleDateString(),
new Date().toLocaleDateString(),
secondUri,
'Terminator 2',
'actors',
'[K8Lu]',
'',
'',
'',
'To Review',
'',
'',
'John Doe',
'This is a comment',
new Date().toLocaleDateString(),
new Date().toLocaleDateString(),
]);
});

cy.findByText('Terminator 2').click();

cy.findByRole('heading', {
name: /^Annotation: uid:\//,
}).should('be.visible');
cy.findByRole('heading', {
name: 'Terminator 2',
}).should('be.visible');

cy.findByRole('button', {
name: 'Delete the annotation',
}).click();

cy.findByRole('button', {
name: 'Delete',
}).click();

cy.findByRole('alert', {}).should(
'have.text',
'The annotation has been deleted.',
);

cy.wait(500);

cy.findAllByRole('cell').then((cells) => {
const firstUri = cells[0].textContent;

expect(firstUri).to.match(/uid:\//);

expect(
cells.toArray().map((cell) => cell.textContent),
).to.deep.equal([
firstUri,
'RoboCop',
'rating',
'[bZE+]',
'',
'',
'',
'To Review',
'',
'',
'Jane Smith',
'This is another comment',
new Date().toLocaleDateString(),
new Date().toLocaleDateString(),
]);
});
});
});
});

Expand Down
7 changes: 4 additions & 3 deletions cypress/support/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ function fillComment(comment) {
}

function fillAuthor({ authorName, authorEmail }) {
cy.findByRole('textbox', { name: 'Name *', timeout: 1500 }).type(
authorName,
);
cy.findByRole('textbox', {
name: 'Last name, First name *',
timeout: 1500,
}).type(authorName);

if (authorEmail) {
cy.findByRole('textbox', { name: /Email/, timeout: 1500 }).type(
Expand Down
52 changes: 38 additions & 14 deletions src/api/controller/api/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,8 @@ export async function getAnnotations(ctx) {
})),
};
}
/**
* @param {Koa.Context} ctx
*/
export async function getAnnotation(ctx, id) {
const annotation = await ctx.annotation.findOneById(id);

if (!annotation) {
ctx.response.status = 404;

return;
}

async function bindResourceAndFieldToAnnnotation(ctx, annotation) {
const [titleField, subResourceTitleFields] = await Promise.all([
ctx.field.findResourceTitle(),
ctx.field.findSubResourceTitles(),
Expand All @@ -272,8 +262,7 @@ export async function getAnnotation(ctx, id) {
? await ctx.field.findOneById(annotation.fieldId)
: null;

ctx.response.status = 200;
ctx.response.body = {
return {
...annotation,
field,
resource: resource
Expand All @@ -289,6 +278,25 @@ export async function getAnnotation(ctx, id) {
};
}

/**
* @param {Koa.Context} ctx
*/
export async function getAnnotation(ctx, id) {
const annotation = await ctx.annotation.findOneById(id);

if (!annotation) {
ctx.response.status = 404;

return;
}

ctx.response.status = 200;
ctx.response.body = await bindResourceAndFieldToAnnnotation(
ctx,
annotation,
);
}

/**
* @param {Koa.Context} ctx
*/
Expand All @@ -313,7 +321,22 @@ export async function updateAnnotation(ctx, id) {
}

ctx.response.status = 200;
ctx.response.body = { data: updatedAnnotation };
ctx.response.body = {
data: await bindResourceAndFieldToAnnnotation(ctx, updatedAnnotation),
};
}

export async function deleteAnnotation(ctx, id) {
const deletedCount = await ctx.annotation.deleteOneById(id);
if (deletedCount === 0) {
ctx.response.status = 404;
return;
}

ctx.response.status = 200;
ctx.response.body = {
success: true,
};
}

function getResourceTitle(resource, titleField, subResourceTitleFields) {
Expand All @@ -333,6 +356,7 @@ app.use(route.get('/', getAnnotations));
app.use(route.get('/:id', getAnnotation));
app.use(koaBodyParser());
app.use(route.put('/:id', updateAnnotation));
app.use(route.del('/:id', deleteAnnotation));
app.use(route.post('/', createAnnotation));

export default app;
Loading

0 comments on commit d047cda

Please sign in to comment.