diff --git a/app/packs/src/apps/mydb/elements/details/vessels/VesselDetails.js b/app/packs/src/apps/mydb/elements/details/vessels/VesselDetails.js
index dfc6b1d443..5b947a99b1 100644
--- a/app/packs/src/apps/mydb/elements/details/vessels/VesselDetails.js
+++ b/app/packs/src/apps/mydb/elements/details/vessels/VesselDetails.js
@@ -4,6 +4,7 @@ import ElementActions from 'src/stores/alt/actions/ElementActions';
import ElementCollectionLabels from 'src/apps/mydb/elements/labels/ElementCollectionLabels';
import { observer } from 'mobx-react';
import DetailActions from 'src/stores/alt/actions/DetailActions';
+import CollectionUtils from 'src/models/collection/CollectionUtils';
import PropTypes from 'prop-types';
import UIStore from 'src/stores/alt/stores/UIStore';
import UserStore from 'src/stores/alt/stores/UserStore';
@@ -12,16 +13,19 @@ import VesselProperties from 'src/apps/mydb/elements/details/vessels/propertiesT
import VesselAttachmentsContainer from "src/apps/mydb/elements/details/vessels/attachmentsTab/VesselAttachmentsContainer";
function VesselDetails({ vesselItem, toggleFullScreen }) {
-
const isReadOnly = () => {
const { currentCollection, isSync } = UIStore.getState();
const { currentUser } = UserStore.getState();
+ return CollectionUtils.isReadOnly(
+ currentCollection,
+ currentUser.id,
+ isSync
+ );
};
const context = useContext(StoreContext);
const [activeTab, setActiveTab] = useState('tab1');
const [readOnly, setReadOnly] = useState(isReadOnly());
-
useEffect(() => {
context.vesselDetailsStore.convertVesselToModel(vesselItem);
setReadOnly(isReadOnly());
@@ -68,7 +72,6 @@ function VesselDetails({ vesselItem, toggleFullScreen }) {
const { vesselDetailsStore } = context;
const mobXItem = vesselDetailsStore.getVessel(vesselItem.id);
const disabled = false;
- // if (disabled) { return null; }
const action = closeAfterClick
? () => { handleSubmit(vesselItem); DetailActions.close(vesselItem, true); }
diff --git a/app/packs/src/apps/mydb/elements/details/vessels/attachmentsTab/AttachmentsModal.js b/app/packs/src/apps/mydb/elements/details/vessels/attachmentsTab/AttachmentsModal.js
deleted file mode 100644
index 6898eddd4b..0000000000
--- a/app/packs/src/apps/mydb/elements/details/vessels/attachmentsTab/AttachmentsModal.js
+++ /dev/null
@@ -1,130 +0,0 @@
-/* eslint-disable react/function-component-definition */
-import React, { useState, useRef } from 'react';
-import PropTypes from 'prop-types';
-import {
- Modal, Button,
-} from 'react-bootstrap';
-import AttachmentsModalContent from 'src/apps/mydb/elements/details/vessels/attachmentsTab/AttachmentsModalContent';
-
-const AttachmentsModal = ({
- show, onHide, onChange, readOnly = false, disabled = false, kind = null, datasetContainer,
-}) => {
- const datasetInput = useRef(null);
- const [isNameEditing, setIsNameEditing] = useState(false);
- const [localName, setLocalName] = useState(datasetContainer.name);
-
- const handleSave = () => {
- if (datasetInput.current) {
- datasetInput.current.handleSave();
- const updatedAttachments = datasetInput.current.getUpdatedAttachments();
- const updatedDatasetContainer = {
- ...datasetContainer,
- attachments: updatedAttachments,
- name: localName,
- };
- onChange(updatedDatasetContainer);
- onHide();
- }
- };
-
- const handleModalClose = (event) => {
- if (event && event.type === 'keydown' && event.key === 'Escape') {
- handleSave();
- } else {
- onHide();
- }
- };
-
- const handleNameChange = (newName) => {
- setLocalName(newName);
- };
-
- const toggleNameEditing = () => {
- setIsNameEditing((prev) => !prev);
- };
-
- if (show) {
- return (
- (disabled ? onHide() : handleModalClose())}
- >
-
-
- {isNameEditing ? (
-
- {
- if (event.key === 'Enter') {
- handleNameChange(event.target.value);
- toggleNameEditing();
- }
- }}
- onChange={(e) => { handleNameChange(e.target.value); }}
- />
-
- ) : (
-
- {localName}
- {!readOnly && (
-
- )}
-
- )}
-
-
-
-
-
-
-
-
- Changes are kept for this session. Remember to save the element itself to persist changes.
-
-
-
-
-
- );
- }
- return null;
-};
-
-AttachmentsModal.propTypes = {
- show: PropTypes.bool.isRequired,
- datasetContainer: PropTypes.shape({
- name: PropTypes.string.isRequired,
- extended_metadata: PropTypes.shape({
- instrument: PropTypes.string,
- }),
- }).isRequired,
- onHide: PropTypes.func.isRequired,
- onChange: PropTypes.func.isRequired,
- readOnly: PropTypes.bool,
- disabled: PropTypes.bool,
- kind: PropTypes.string,
-};
-
-export default AttachmentsModal;
diff --git a/app/packs/src/apps/mydb/elements/details/vessels/attachmentsTab/AttachmentsModalContent.js b/app/packs/src/apps/mydb/elements/details/vessels/attachmentsTab/AttachmentsModalContent.js
deleted file mode 100644
index bd632e80cc..0000000000
--- a/app/packs/src/apps/mydb/elements/details/vessels/attachmentsTab/AttachmentsModalContent.js
+++ /dev/null
@@ -1,177 +0,0 @@
-/* eslint-disable react/display-name */
-/* eslint-disable arrow-body-style */
-import React, { useImperativeHandle, forwardRef, useState } from 'react';
-import PropTypes from 'prop-types';
-import { Button, ButtonToolbar } from 'react-bootstrap';
-import Dropzone from 'react-dropzone';
-import SaveEditedImageWarning from 'src/apps/mydb/elements/details/researchPlans/SaveEditedImageWarning';
-import {
- downloadButton,
- removeButton,
- annotateButton,
- formatFileSize,
- attachmentThumbnail,
-} from 'src/apps/mydb/elements/list/AttachmentList';
-import { formatDate } from 'src/utilities/timezoneHelper';
-import ImageAnnotationModalSVG from 'src/apps/mydb/elements/details/researchPlans/ImageAnnotationModalSVG';
-import { observer } from 'mobx-react';
-
-const classifyAttachments = (attachments) => {
- return {
- Pending: attachments.filter((attachment) => attachment.is_pending && !attachment.is_deleted) || [],
- Original: attachments.filter((attachment) => !attachment.is_pending && !attachment.is_deleted) || [],
- };
-};
-
-const AttachmentsModalContent = forwardRef(({ datasetContainer, onChange, readOnly }, ref) => {
- const [attachments, setAttachments] = useState([...datasetContainer.attachments]);
- const [attachmentGroups, setAttachmentGroups] = useState(classifyAttachments(datasetContainer.attachments));
- const [imageEditModalShown, setImageEditModalShown] = useState(false);
- const [chosenAttachment, setChosenAttachment] = useState(null);
-
- const updateAttachments = (newAttachments) => {
- setAttachments(newAttachments);
- setAttachmentGroups(classifyAttachments(newAttachments));
- onChange({ ...datasetContainer, attachments: newAttachments });
- };
-
- useImperativeHandle(ref, () => ({
- handleSave: () => {
- const savedAttachments = attachments.map((attachment) => ({
- ...attachment,
- is_pending: false,
- }));
- setAttachments(savedAttachments);
- setAttachmentGroups(classifyAttachments(savedAttachments));
- onChange({ ...datasetContainer, attachments: savedAttachments });
- },
- getUpdatedAttachments: () => attachments,
- }));
-
- const handleFileDrop = (files) => {
- const newAttachments = files.map((file) => ({
- id: Date.now(),
- filename: file.name,
- filesize: file.size,
- is_pending: true,
- is_deleted: false,
- }));
-
- const updatedAttachments = [...attachments, ...newAttachments];
- updateAttachments(updatedAttachments);
- };
-
- const handleAttachmentRemove = (attachment) => {
- const updatedAttachments = attachments.map((a) => (a.id === attachment.id ? { ...a, is_deleted: true } : a));
- updateAttachments(updatedAttachments);
- };
-
- const handleUndo = (attachment) => {
- const updatedAttachments = attachments.map((a) => (a.id === attachment.id ? { ...a, is_deleted: false } : a));
- updateAttachments(updatedAttachments);
- };
-
- const renderAttachmentRow = (attachment) => (
-
- {attachmentThumbnail(attachment)}
-
- {attachment.is_deleted ?
{attachment.filename} : attachment.filename}
-
-
- Created:
- {' '}
-
- {formatDate(attachment.created_at || Date.now())}
- {' '}
-
-
-
|
-
- Size:
-
- {formatFileSize(attachment.filesize)}
-
-
-
-
-
- {attachment.is_deleted ? (
-
- ) : (
-
- {downloadButton(attachment)}
- {annotateButton(attachment, () => {
- setImageEditModalShown(true);
- setChosenAttachment(attachment);
- })}
- {removeButton(attachment, handleAttachmentRemove, readOnly)}
-
- )}
-
- {attachment.updatedAnnotation &&
}
-
- );
-
- const renderGroup = (attachments, title) => (
-
-
- {title}
-
- {attachments.map((attachment) => renderAttachmentRow(attachment))}
-
- );
-
- const renderAttachments = () => (
-
- {imageEditModalShown && (
-
setImageEditModalShown(false)}
- handleOnClose={() => setImageEditModalShown(false)}
- />
- )}
-
-
- Drop files here, or click to upload.
-
-
- {attachmentGroups.Pending.length === 0 && attachmentGroups.Original.length === 0 ? (
- There are currently no attachments.
- ) : (
- <>
- {attachmentGroups.Pending.length > 0
- && renderGroup(attachmentGroups.Pending, 'Pending')}
- {attachmentGroups.Original.length > 0
- && renderGroup(attachmentGroups.Original, 'Original')}
- >
- )}
-
- );
- return {renderAttachments()}
;
-});
-
-AttachmentsModalContent.propTypes = {
- datasetContainer: PropTypes.shape({
- attachments: PropTypes.arrayOf(
- PropTypes.shape({
- id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
- filename: PropTypes.string.isRequired,
- filesize: PropTypes.number.isRequired,
- is_deleted: PropTypes.bool,
- })
- ),
- }).isRequired,
- onChange: PropTypes.func.isRequired,
- readOnly: PropTypes.bool,
- disabled: PropTypes.bool,
-};
-
-export default observer(AttachmentsModalContent);
diff --git a/app/packs/src/apps/mydb/elements/details/vessels/propertiesTab/VesselProperties.js b/app/packs/src/apps/mydb/elements/details/vessels/propertiesTab/VesselProperties.js
index cef794edc4..3c37fdf6d3 100644
--- a/app/packs/src/apps/mydb/elements/details/vessels/propertiesTab/VesselProperties.js
+++ b/app/packs/src/apps/mydb/elements/details/vessels/propertiesTab/VesselProperties.js
@@ -6,19 +6,16 @@ import PropTypes from 'prop-types';
import { StoreContext } from 'src/stores/mobx/RootStore';
import VesselProperty from 'src/apps/mydb/elements/details/vessels/propertiesTab/VesselProperty';
import VesselName from 'src/apps/mydb/elements/details/vessels/propertiesTab/VesselName';
-// import InvalidPropertyWarning from 'src/apps/mydb/elements/details/cellLines/propertiesTab/InvalidPropertyWarning';
const VesselProperties = ({ item, readOnly }) => {
const { vesselDetailsStore } = useContext(StoreContext);
const vesselId = item.id;
- // const vesselItem = vesselDetailsStore.vessels.get(vesselId);
const vesselItem = vesselDetailsStore.getVessel(vesselId);
return (
- {/* */}
Common vessel properties
@@ -31,27 +28,27 @@ const VesselProperties = ({ item, readOnly }) => {
label="Details"
value={vesselItem?.details || ''}
onChange={(e) => vesselDetailsStore.changeDetails(vesselId, e.target.value)}
- // readOnly={readOnly}
+ readOnly={readOnly}
optional
/>
vesselDetailsStore.changeMaterialType(vesselId, e.target.value)}
- // readOnly={readOnly}
+ readOnly={readOnly}
/>
vesselDetailsStore.changeVesselType(vesselId, e.target.value)}
- // readOnly={readOnly}
+ readOnly={readOnly}
optional
/>
vesselDetailsStore.changeVolumeAmount(vesselId, parseFloat(e.target.value))}
- // readOnly={readOnly}
+ readOnly={readOnly}
isNumeric
optional
/>
@@ -59,14 +56,14 @@ const VesselProperties = ({ item, readOnly }) => {
label="Volume unit"
value={vesselItem?.volumeUnit || ''}
onChange={(e) => vesselDetailsStore.changeVolumeUnit(vesselId, e.target.value)}
- // readOnly={readOnly}
+ readOnly={readOnly}
optional
/>
vesselDetailsStore.changeWeightAmount(vesselId, parseFloat(e.target.value))}
- // readOnly={readOnly}
+ readOnly={readOnly}
isNumeric
optional
/>
@@ -82,7 +79,6 @@ const VesselProperties = ({ item, readOnly }) => {
- {/* */}
Item specific vessel properties
diff --git a/app/packs/src/apps/mydb/elements/details/vessels/propertiesTab/VesselProperty.js b/app/packs/src/apps/mydb/elements/details/vessels/propertiesTab/VesselProperty.js
index 20803aed27..4dcfb60399 100644
--- a/app/packs/src/apps/mydb/elements/details/vessels/propertiesTab/VesselProperty.js
+++ b/app/packs/src/apps/mydb/elements/details/vessels/propertiesTab/VesselProperty.js
@@ -1,40 +1,32 @@
/* eslint-disable react/function-component-definition */
-import React, {useState} from 'react';
+import React from 'react';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react';
import { Row, Col, Form } from 'react-bootstrap';
-const VesselProperty = ({ label, value, onChange, readOnly, isNumeric = false, optional = false }) => {
- const [typing, setTyping] = useState(false);
+const VesselProperty = ({ label, value, onChange, readOnly, isNumeric = false, optional = false }) => (
+
+ {label}
+
+ {
+ onChange(e);
+ }}
+ />
+
+
+);
- const handleButtonClick = () => {
- setTimeout(() => { setTyping(true) }, 1000);
- };
-
- return (
-
- {label}
-
- {
- onChange(e);
- }}
- />
-
-
- );
+VesselProperty.propTypes = {
+ label: PropTypes.string.isRequired,
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
+ onChange: PropTypes.func.isRequired,
+ readOnly: PropTypes.bool.isRequired,
+ isNumeric: PropTypes.bool,
+ optional: PropTypes.bool
};
-// VesselProperty.propTypes = {
-// label: PropTypes.string.isRequired,
-// value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
-// onChange: PropTypes.func.isRequired,
-// readOnly: PropTypes.bool.isRequired,
-// isNumeric: PropTypes.bool,
-// optional: PropTypes.bool
-// };
-
export default observer(VesselProperty);
diff --git a/app/packs/src/apps/mydb/elements/list/vessel/VesselEntry.js b/app/packs/src/apps/mydb/elements/list/vessel/VesselEntry.js
index 786e368da4..49405a6b50 100644
--- a/app/packs/src/apps/mydb/elements/list/vessel/VesselEntry.js
+++ b/app/packs/src/apps/mydb/elements/list/vessel/VesselEntry.js
@@ -1,3 +1,6 @@
+/* eslint-disable no-use-before-define */
+/* eslint-disable jsx-a11y/no-static-element-interactions */
+/* eslint-disable jsx-a11y/click-events-have-key-events */
import React, { useState } from 'react';
import UIStore from 'src/stores/alt/stores/UIStore';
import VesselItemEntry from 'src/apps/mydb/elements/list/vessel/VesselItemEntry';
@@ -7,71 +10,55 @@ import { elementShowOrNew } from 'src/utilities/routesUtils';
import Aviator from 'aviator';
import ChevronIcon from 'src/components/common/ChevronIcon';
-const VesselEntry = ({ vesselItems }) => {
+function VesselEntry({ vesselItems }) {
const [detailedInformation, setDetailedInformation] = useState(false);
const [showEntries, setShowEntries] = useState(true);
const getBorderStyle = () =>
- showEntries
+ (showEntries
? 'list-container title-panel p-3'
- : 'list-container title-panel p-3 cell-line-group-bottom-border';
-
- const renderItemEntries = () =>
- showEntries
- ? vesselItems.map((vesselItem) => (
-
- ))
- : [];
-
- const findThumbnailAttachment = (container) => {
- if (!container || !container.children) return null;
-
- for (const child of container.children) {
- if (child.attachments?.length) {
- const thumbnail = child.attachments.find((attachment) => attachment.preview);
- console.log('thumbnail', thumbnail);
- if (thumbnail) return thumbnail;
- }
- const nestedThumbnail = findThumbnailAttachment(child);
- if (nestedThumbnail) return nestedThumbnail;
- }
-
- return null;
- };
-
-
- const renderNameHeader = (firstVesselItem) => {
+ : 'list-container title-panel p-3 cell-line-group-bottom-border');
+
+ const renderItemEntries = () => (showEntries
+ ? vesselItems.map((vesselItem) => (
+
+ ))
+ : []);
+
+ const findThumbnailAttachment = (container) => {
+ if (!container || !container.children) return null;
+
+ for (const child of container.children) {
+ if (child.attachments?.length) {
+ const thumbnail = child.attachments.find((attachment) => attachment.preview);
+ if (thumbnail) return thumbnail;
+ }
+ const nestedThumbnail = findThumbnailAttachment(child);
+ if (nestedThumbnail) return nestedThumbnail;
+ }
+
+ return null;
+ };
+
+ const renderNameHeader = (firstVesselItem) => {
const thumbnail = findThumbnailAttachment(firstVesselItem.container);
const imgSrc = thumbnail ? thumbnail.preview : null;
- console.log(imgSrc);
-
return (
{imgSrc ? (
) : (
-
+
)}
@@ -86,18 +73,18 @@ const VesselEntry = ({ vesselItems }) => {
);
};
-
const renderDetailedInfos = (firstVesselItem) => {
if (!detailedInformation) return null;
return (
- {renderProperty('Name', firstVesselItem.vesselName)}
- {renderProperty('Vessel type', firstVesselItem.vesselType)}
- {renderProperty('Material type', firstVesselItem.materialType)}
- {renderProperty('Volume amount', firstVesselItem.volumeAmount)}
- {renderProperty('Volume unit', firstVesselItem.volumeUnit)}
+ {renderProperty('Name', firstVesselItem.vessel_template.name)}
+ {renderProperty('Details', firstVesselItem.vessel_template.details)}
+ {renderProperty('Vessel type', firstVesselItem.vessel_template.vessel_type)}
+ {renderProperty('Material type', firstVesselItem.vessel_template.material_type)}
+ {renderProperty('Volume amount', firstVesselItem.vessel_template.volume_amount)}
+ {renderProperty('Volume unit', firstVesselItem.vessel_template.volume_unit)}
);
};
@@ -106,11 +93,11 @@ const VesselEntry = ({ vesselItems }) => {
Show detailed information about the material
- }
+ )}
>
);
-};
+}
VesselEntry.propTypes = {
vesselItems: PropTypes.arrayOf(
diff --git a/app/packs/src/stores/mobx/VesselDetailsStore.jsx b/app/packs/src/stores/mobx/VesselDetailsStore.jsx
index 8dace1eea5..d8cc30ac5c 100644
--- a/app/packs/src/stores/mobx/VesselDetailsStore.jsx
+++ b/app/packs/src/stores/mobx/VesselDetailsStore.jsx
@@ -56,38 +56,6 @@ export const VesselDetailsStore = types
container.children = container.children || [];
return container;
},
- initializeContainer(vesselId) {
- const vessel = self.vessels.get(vesselId);
- if (!vessel) {
- console.error(`Vessel not found in store for id: ${vesselId}`);
- return;
- }
- if (!vessel.container) {
- vessel.container = { children: [] };
- } else if (!Array.isArray(vessel.container.children)) {
- vessel.container.children = [];
- }
- },
- addContainerToVessel(vesselId) {
- console.log("Adding container to vessel:", vesselId);
- const vessel = self.vessels.get(vesselId);
- if (!vessel) {
- console.error("Vessel not found");
- return;
- }
- const newContainer = self.addEmptyContainer(vesselId);
- vessel.container.children.push(newContainer);
- vessel.markChanged(true);
- },
- updateVesselContainer(vesselId, updatedContainer) {
- const vessel = self.vessels.get(vesselId);
- if (!vessel) {
- console.error("Vessel not found");
- return;
- }
- vessel.container = updatedContainer;
- vessel.markChanged(true);
- },
changeVesselName(id, newName) {
self.vessels.get(id).changed = true;
self.vessels.get(id).vesselName = newName;
@@ -177,7 +145,6 @@ export const VesselDetailsStore = types
if (item === undefined) {
throw new Error(`No vessel with id found: ${id}`);
}
- //name vs vesselName to be verified
item.vesselName = properties.name;
item.details = properties.details || '';
item.materialDetails = properties.material_details || '';
@@ -193,14 +160,4 @@ export const VesselDetailsStore = types
getVessel(id) {
return self.vessels.get(id);
},
- checkInputValidity(id) {
- const result = [];
- const item = self.vessels.get(id);
- if (item.name.trim() === '') { result.push('name'); }
- // if (item.source.trim() === '') { result.push('source'); }
- if (item.unit.trim() === '') { result.push('unit'); }
- if (!item.isAmountValid()) { result.push('amount'); }
- // if (!Number.isInteger(item.passage) || item.passage === 0) { result.push('passage'); }
- return result;
- }
}));