From 4b414b10548b7f88b88d02f79c2be19800253092 Mon Sep 17 00:00:00 2001 From: Nar Cuenca Date: Thu, 22 May 2025 09:49:35 +0800 Subject: [PATCH 1/5] Enable button by default, remove none option and add error handling when clicking create without selecting a model --- .../components/CreateContentItemDialog.tsx | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/shell/components/CreateContentItemDialog.tsx b/src/shell/components/CreateContentItemDialog.tsx index b0832861b..03bcb2fe9 100644 --- a/src/shell/components/CreateContentItemDialog.tsx +++ b/src/shell/components/CreateContentItemDialog.tsx @@ -34,10 +34,8 @@ export const CreateContentItemDialog = ({ }: Props) => { const { data: models } = useGetContentModelsQuery(); const history = useHistory(); - const [selectedModel, setSelectedModel] = useState({ - label: "None", - ZUID: "", - }); + const [selectedModel, setSelectedModel] = useState(null); + const [hasError, setHasError] = useState(false); const sortedModels = useMemo(() => { if (models?.length) { @@ -65,8 +63,12 @@ export const CreateContentItemDialog = ({ }, [models, limitTo]); const onCreateClick = () => { - onClose(); - history.push("/content/" + selectedModel.ZUID + "/new"); + if (!selectedModel?.ZUID) { + setHasError(true); + } else { + onClose(); + history.push("/content/" + selectedModel.ZUID + "/new"); + } }; return ( @@ -101,6 +103,7 @@ export const CreateContentItemDialog = ({ Select Model } + renderInput={(params) => ( + + )} getOptionLabel={(option: any) => option.label} isOptionEqualToValue={(option, value) => option.ZUID === value.ZUID} - onChange={(event, newValue) => setSelectedModel(newValue)} + onChange={(event, newValue) => { + if (!!newValue?.ZUID) { + setHasError(false); + } + + setSelectedModel(newValue); + }} onKeyDown={(evt) => { if (evt.key.toLowerCase() === "enter" && !!selectedModel?.ZUID) { evt.preventDefault(); @@ -145,7 +159,6 @@ export const CreateContentItemDialog = ({ data-cy="create_new_content_item_btn" variant="contained" color="primary" - disabled={!selectedModel.ZUID} onClick={onCreateClick} > Create From a7c08c79474ae7c0faeedd773a81012b8d8a3cb4 Mon Sep 17 00:00:00 2001 From: Nar Cuenca Date: Thu, 22 May 2025 09:50:07 +0800 Subject: [PATCH 2/5] remove unused imports --- src/shell/components/CreateContentItemDialog.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/shell/components/CreateContentItemDialog.tsx b/src/shell/components/CreateContentItemDialog.tsx index 03bcb2fe9..38434227c 100644 --- a/src/shell/components/CreateContentItemDialog.tsx +++ b/src/shell/components/CreateContentItemDialog.tsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useState } from "react"; +import { useMemo, useState } from "react"; import { Box, Button, @@ -10,12 +10,9 @@ import { InputLabel, Autocomplete, Typography, - Avatar, } from "@mui/material"; import EditRoundedIcon from "@mui/icons-material/EditRounded"; import { useHistory } from "react-router"; -import { ThemeProvider } from "@mui/material/styles"; -import { theme } from "@zesty-io/material"; import { cloneDeep } from "lodash"; import { useGetContentModelsQuery } from "../services/instance"; From 497b4b88fdfad136ae437ac407477ec128e0857b Mon Sep 17 00:00:00 2001 From: Nar Cuenca Date: Thu, 22 May 2025 09:54:27 +0800 Subject: [PATCH 3/5] Add error handling for create item without model selection --- cypress/e2e/content/navigation.spec.js | 7 +++++++ src/shell/components/CreateContentItemDialog.tsx | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/content/navigation.spec.js b/cypress/e2e/content/navigation.spec.js index d130ed4b2..fcc3f08e1 100644 --- a/cypress/e2e/content/navigation.spec.js +++ b/cypress/e2e/content/navigation.spec.js @@ -19,6 +19,13 @@ describe("Navigation through content editor", () => { cy.get(".ModalAligner--ptdt-.Open--M5j6S button.Close--kVpCO").click(); }); + it("Should not navigate to the create item page if no model is selected", () => { + cy.getBySelector("create_new_content_item").should("exist").click(); + cy.getBySelector("create_new_content_item_btn").click({ force: true }); + cy.contains("Please select a Model to proceed.").should("exist"); + cy.getBySelector("discard_new_content_item_btn").should("exist").click(); + }); + it("Creates a new item from the menu", () => { cy.getBySelector("create_new_content_item").should("exist").click(); cy.getBySelector("create_new_content_item_dialog").should("exist"); diff --git a/src/shell/components/CreateContentItemDialog.tsx b/src/shell/components/CreateContentItemDialog.tsx index 38434227c..95cfec766 100644 --- a/src/shell/components/CreateContentItemDialog.tsx +++ b/src/shell/components/CreateContentItemDialog.tsx @@ -149,7 +149,11 @@ export const CreateContentItemDialog = ({ /> -