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

3 - Delete a reference #119

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
17 changes: 17 additions & 0 deletions features/delete_reference.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#language: fr

Fonctionnalité: Supprimer les références existantes

Scénario: sans être connecté

Soit "Les fées : Conte" le document principal
Quand je vais supprimer les références
Alors je peux lire "Before editing this document, please log in first"

Scénario: être connecté

Soit "Les fées : Conte" le document principal
LIUC2H5OH marked this conversation as resolved.
Show resolved Hide resolved
Et une session active avec mon compte
Quand je vais supprimer les références
Alors La référence "Les fées (Charles Perrault),Contes des fées, 1886, All rights reserved" n'existe pas dans le document principal

4 changes: 4 additions & 0 deletions features/step_definitions/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@

Quand("je navigue vers le document suivant") do
click_on('->')
end

Quand("je vais supprimer les références") do
click_on_icon('delete_reference')
end
6 changes: 5 additions & 1 deletion features/step_definitions/outcome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@

Alors("{string} est le document affiché à l'écran") do |text|
expect(find('.runningHead')).to have_content text
end
end

Alors("La référence {string} n'existe pas dans le document principal") do |title|
expect(page).not_to have_content title
end
21 changes: 21 additions & 0 deletions frontend/src/DeleteReferenceButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Button from 'react-bootstrap/Button';
import {useNavigate} from 'react-router-dom';
import {XCircle} from 'react-bootstrap-icons';

function DeleteReferenceButton({doc, ref_id, setLastUpdate, backend}) {
const navigate = useNavigate();
let handleDelete = async () => {
let _id = doc._id;
doc.links = doc.links.filter(link => link.object.toString() !== ref_id.toString());
backend.putDocument(doc).then(() => {
setLastUpdate(_id);
navigate('/' + ref_id);
});
};

return (
<XCircle title="Delete this reference" className="icon delete_reference" onClick={handleDelete}/>
);
}

export default DeleteReferenceButton;
12 changes: 9 additions & 3 deletions frontend/src/DocumentsCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import BrowseTools from './BrowseTools';
import FutureDocument from './FutureDocument';
import FutureCollection from './FutureCollection';
import { TypeBadge } from './Type';
import DeleteReferenceButton from './DeleteReferenceButton';

function DocumentsCards({docs, expandable, byRow, createOn, setLastUpdate, backend}) {
function DocumentsCards({docs, expandable, byRow, isDeletable, createOn, setLastUpdate, backend}) {
return (
<Row className="gy-4">
{docs.map(x =>
<Col key={x._id} md={ byRow && (12 / byRow) }>
<DocumentCard doc={x} expandable={expandable} />
<DocumentCard doc={x} expandable={expandable} isDeletable={isDeletable} ref_id={createOn} {...{setLastUpdate, backend}}/>
</Col>
)}
{createOn &&
Expand All @@ -35,7 +36,7 @@ function DocumentsCards({docs, expandable, byRow, createOn, setLastUpdate, backe
);
}

function DocumentCard({doc, expandable}) {
function DocumentCard({doc, expandable, isDeletable, ref_id, setLastUpdate, backend}) {
const collectionId = useMemo(() => {
if (doc?.links?.length > 1) {
return doc.links.every((item) => {
Expand All @@ -48,6 +49,11 @@ function DocumentCard({doc, expandable}) {

return (
<Card className="h-100">
{isDeletable && (
<Card.Header className="d-flex justify-content-end">
<DeleteReferenceButton doc={doc} ref_id={ref_id} setLastUpdate={setLastUpdate} backend={backend}/>
</Card.Header>
)}
<Card.Body>
<BrowseTools
id={collectionId ? doc.links.length && windowWidth.current < 820 ? doc.links[0].object : doc._id : doc._id}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function References({scholiaMetadata, active, createOn, setLastUpdate, backend})
if (!active) return;
return (
<Col className="gloses" >
<DocumentsCards docs={scholiaMetadata} expandable={true} byRow={1}
<DocumentsCards docs={scholiaMetadata} expandable={true} byRow={1} isDeletable={true}
{...{createOn, setLastUpdate, backend}}
/>
</Col>
Expand Down