From 02739fc60e7d596c95cb1e3baf610381537f91a9 Mon Sep 17 00:00:00 2001 From: Arnav Shekaran Date: Mon, 25 Sep 2023 17:01:10 +1300 Subject: [PATCH] =?UTF-8?q?Reusing=20ListContainer=20rather=20than=20exten?= =?UTF-8?q?ding=20it=20=F0=9F=94=81=F0=9F=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - adding a readOnly parameter for items that can be edited such as assigned scenarios/scenes - adjust styles so can have two ListContainers on the page - formatting code --- frontend/src/components/ListContainer.js | 88 ++----------------- .../containers/pages/ScenarioSelectionPage.js | 33 +++++-- .../src/styling/ListContainer.module.scss | 4 +- .../styling/ScenarioSelectionPage.module.scss | 3 + 4 files changed, 38 insertions(+), 90 deletions(-) create mode 100644 frontend/src/styling/ScenarioSelectionPage.module.scss diff --git a/frontend/src/components/ListContainer.js b/frontend/src/components/ListContainer.js index bff0feff..869579e2 100644 --- a/frontend/src/components/ListContainer.js +++ b/frontend/src/components/ListContainer.js @@ -43,7 +43,6 @@ import useStyles from "./component.styles"; */ export default function ListContainer({ data, // could be scenarios or scenes data - assignedScenarios, onItemSelected, onItemDoubleClick, wide, @@ -52,11 +51,18 @@ export default function ListContainer({ sceneSelectionPage, scenarioId, invalidNameId, + readOnly, // for scenes/scenarios that can't be edited/deleted by user }) { const classes = useStyles(); const [selected, setSelected] = useState(); const columns = wide ? 5 : 4; + if (readOnly) { + data = data.map((item) => { + return { ...item, isAssigned: true }; + }); + } + /** Function which executes when an image in the image list is clicked. */ const onItemClick = (event, item) => { if (event.detail === 2) { @@ -80,8 +86,6 @@ export default function ListContainer({ wide ? styles.scenarioListContainerWide : styles.scenarioListContainer } > - {!sceneSelectionPage &&

Created scenarios

} - {addCard ? ( ) : null} + {data && data.length > 0 ? data.map((item) => ( - - {assignedScenarios ? ( - <> - {!sceneSelectionPage &&

Assigned scenarios

} - - - {addCard ? ( - - - - ) : null} - - {assignedScenarios && assignedScenarios.length > 0 - ? assignedScenarios.map(({ _id, name }) => ( - - onItemClick(event, { _id, isAssigned: true }) - } - onContextMenu={() => - onItemRightClick({ _id, isAssigned: true }) - } - > -
- - {sceneSelectionPage ? ( - - ) : ( - - )} - - -
- - {invalidNameId === _id && ( - invalid null name - )} -
- )) - : null} -
- - ) : null} ); diff --git a/frontend/src/containers/pages/ScenarioSelectionPage.js b/frontend/src/containers/pages/ScenarioSelectionPage.js index 31c5b679..78469294 100644 --- a/frontend/src/containers/pages/ScenarioSelectionPage.js +++ b/frontend/src/containers/pages/ScenarioSelectionPage.js @@ -1,13 +1,15 @@ import React, { useContext, useEffect, useState } from "react"; import { useHistory } from "react-router-dom"; +import "styling/ScenarioSelectionPage.module.scss"; + import MenuItem from "@material-ui/core/MenuItem"; -import ContextMenu from "../../components/ContextMenu"; -import SideBar from "../../components/SideBar"; -import ListContainer from "../../components/ListContainer"; -import ScreenContainer from "../../components/ScreenContainer"; -import ScenarioContext from "../../context/ScenarioContext"; -import { usePut, useDelete } from "../../hooks/crudHooks"; -import AuthenticationContext from "../../context/AuthenticationContext"; +import ContextMenu from "components/ContextMenu"; +import SideBar from "components/SideBar"; +import ListContainer from "components/ListContainer"; +import ScreenContainer from "components/ScreenContainer"; +import ScenarioContext from "context/ScenarioContext"; +import { usePut, useDelete } from "hooks/crudHooks"; +import AuthenticationContext from "context/AuthenticationContext"; import AccessLevel from "../../enums/route.access.level"; /** @@ -132,14 +134,29 @@ export default function ScenarioSelectionPage({ data = null }) { "" )} + +

Created scenarios

+ +

Assigned scenarios

+ {assignedScenarios && assignedScenarios.length ? ( + {}} + onItemBlur={() => {}} + invalidNameId={invalidNameId} + readOnly + /> + ) : ( +

You have no assigned scenarios

+ )} ); diff --git a/frontend/src/styling/ListContainer.module.scss b/frontend/src/styling/ListContainer.module.scss index d562ad84..42310838 100644 --- a/frontend/src/styling/ListContainer.module.scss +++ b/frontend/src/styling/ListContainer.module.scss @@ -1,7 +1,7 @@ .scenarioListContainer { width: 85vw; - height: 100vh; - overflow-y: scroll; + // height: 100vh; + overflow-y: auto; overflow-x: hidden; padding-right: 30px; padding-left: 30px; diff --git a/frontend/src/styling/ScenarioSelectionPage.module.scss b/frontend/src/styling/ScenarioSelectionPage.module.scss new file mode 100644 index 00000000..adb48a70 --- /dev/null +++ b/frontend/src/styling/ScenarioSelectionPage.module.scss @@ -0,0 +1,3 @@ +h1 { + margin-left: 15px; +} \ No newline at end of file