Skip to content

Commit e240471

Browse files
kejaulinsaurL
authored andcommitted
FEATURE: Delete a reference (closes #3).
Co-authored-by: Lucas Sauron <lucas.sauron@utt.fr>
1 parent b17184a commit e240471

3 files changed

Lines changed: 52 additions & 4 deletions

File tree

frontend/src/components/OpenedDocuments.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import DiscreeteDropdown from './DiscreeteDropdown';
1010
import InviteEditorsAction from '../menu-items/InviteEditorsAction';
1111
import BreakIntoPassagesAction from '../menu-items/BreakIntoPassagesAction';
1212
import DeleteDocumentAction from '../menu-items/DeleteDocumentAction';
13+
import DeleteReferenceToDocumentAction from '../menu-items/DeleteReferenceToDocumentAction';
1314
import EditRawDocumentAction from '../menu-items/EditRawDocumentAction';
1415
import Bookmark from './Bookmark';
1516
import LicenseCompatibility from './LicenseCompatibility';
1617
import { InfoCircle } from 'react-bootstrap-icons';
1718

18-
function OpenedDocuments({id, margin, metadata, parallelDocuments, rawEditMode, setRawEditMode, backend, user, setLastUpdate}) {
19+
function OpenedDocuments({id, margin, metadata, parallelDocuments, rawEditMode, setRawEditMode, backend, user, setLastUpdate, content}) {
1920
const marginMetadata = metadata.getDocument(margin);
2021
const marginLicense = marginMetadata?.dc_license;
2122
const sourceMetadata = metadata.focusedDocument;
@@ -25,7 +26,7 @@ function OpenedDocuments({id, margin, metadata, parallelDocuments, rawEditMode,
2526
<Col className="lectern" {...{xs}} >
2627
<Row className ="runningHead">
2728
<RunningHeadSource {...{id, metadata, parallelDocuments, backend, user}} />
28-
<RunningHeadMargin {...{parallelDocuments, margin, setRawEditMode, backend, setLastUpdate}}
29+
<RunningHeadMargin {...{id, parallelDocuments, margin, setRawEditMode, backend, setLastUpdate, content}}
2930
metadata={marginMetadata}
3031
/>
3132
</Row>
@@ -91,7 +92,7 @@ function RunningHeadSource({id, metadata, parallelDocuments, backend, user}) {
9192
);
9293
}
9394

94-
function RunningHeadMargin({metadata, parallelDocuments, margin, setRawEditMode, backend, setLastUpdate}) {
95+
function RunningHeadMargin({id, metadata, parallelDocuments, margin, setRawEditMode, backend, setLastUpdate, content}) {
9596
const isFromScratch = parallelDocuments.isFromScratch;
9697
if (Object.keys(metadata).length) return (
9798
<Col xs={5} className="scholium position-relative">
@@ -101,6 +102,7 @@ function RunningHeadMargin({metadata, parallelDocuments, margin, setRawEditMode,
101102
<BreakIntoPassagesAction {...{parallelDocuments, margin, backend, setLastUpdate}} />
102103
<EditRawDocumentAction {...{setRawEditMode}} />
103104
<DeleteDocumentAction {...{metadata, isFromScratch, backend, setLastUpdate}} />
105+
<DeleteReferenceToDocumentAction {...{id, margin, backend, metadata, content, setLastUpdate}} />
104106
</DiscreeteDropdown>
105107
<Metadata editable={true} {...{backend, metadata, setLastUpdate}} />
106108
<Type editable={true} {...{backend, metadata}}/>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { useState } from 'react';
2+
import { useNavigate } from 'react-router-dom';
3+
import { Modal, Button } from 'react-bootstrap';
4+
import DiscreeteDropdown from '../components/DiscreeteDropdown';
5+
6+
function DeleteReferenceToDocumentAction({id, margin, backend, metadata, content, setLastUpdate}) {
7+
const [show, setShow] = useState(false);
8+
const navigate = useNavigate();
9+
const handleClick = () => {
10+
setShow(false);
11+
metadata.links = metadata.links.filter(link => ![id, ...new Set([...content.filter((row) => row.value.isPartOf === id).map(({id, value}) => value._id || id)])].includes(link.object));
12+
backend.putDocument({...metadata})
13+
.then(x => setLastUpdate(x.rev))
14+
.then(() => navigate('/' + margin + '#' + margin))
15+
.catch(console.error);
16+
};
17+
18+
const disabled = (metadata.links && metadata.links.length > 0 ? false : true);
19+
return (
20+
<>
21+
<DiscreeteDropdown.Item onClick={() => setShow(true)} {...{disabled}}>
22+
Delete reference...
23+
</DiscreeteDropdown.Item>
24+
<Modal show={show} onHide={() => setShow(false)}>
25+
<Modal.Body>
26+
Are you sure you want to delete the link between this glose and the
27+
focused document?
28+
Both documents will be preserved but in case of a &quot;quotation link&quot;,
29+
the quoted contents will be removed from the glose.
30+
This action cannot be undone.
31+
</Modal.Body>
32+
<Modal.Footer>
33+
<Button variant="secondary" onClick={() => setShow(false)}>
34+
Cancel
35+
</Button>
36+
<Button variant="primary" onClick={handleClick}>
37+
Delete reference
38+
</Button>
39+
</Modal.Footer>
40+
</Modal>
41+
</>
42+
);
43+
}
44+
45+
export default DeleteReferenceToDocumentAction;
46+

frontend/src/routes/Lectern.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function Lectern({backend, user}) {
6262
<Row>
6363
<OpenedDocuments
6464
hasSources={metadata.forwardLinkedDocuments.length > 0}
65-
{...{id, margin, metadata, parallelDocuments, user, rawEditMode, setRawEditMode, backend, setLastUpdate}}
65+
{...{id, margin, metadata, parallelDocuments, user, rawEditMode, setRawEditMode, backend, setLastUpdate, content}}
6666
/>
6767
<References active={!margin}
6868
{...{metadata, user, createOn, setLastUpdate, backend}}

0 commit comments

Comments
 (0)