diff --git a/e2e/pages/form-builder-page.ts b/e2e/pages/form-builder-page.ts index 9fad386..59dfff6 100644 --- a/e2e/pages/form-builder-page.ts +++ b/e2e/pages/form-builder-page.ts @@ -37,6 +37,8 @@ export class FormBuilderPage { this.page.getByRole("button", { name: /start building/i }); readonly interactiveFormNameInput = () => this.page.getByRole("textbox", { name: /form name/i }); + readonly interactiveFormDescriptionInput = () => + this.page.getByRole("textbox", { name: /form description/i }); readonly createFormButton = () => this.page.getByRole("button", { name: /create form/i }); readonly addPageButton = () => @@ -91,6 +93,9 @@ export class FormBuilderPage { await this.interactiveBuilderTab().click(); await this.startBuildingButton().click(); await this.interactiveFormNameInput().fill("Covid-19 Screening"); + await this.interactiveFormDescriptionInput().fill( + "A test form for recording COVID-19 screening information" + ); await this.createFormButton().click(); await expect(this.page.getByText(/form created/i)).toBeVisible(); @@ -129,13 +134,11 @@ export class FormBuilderPage { await this.formNameInput().fill(formName); await this.formVersionInput().click(); await this.formVersionInput().fill("1.0"); - await this.formDescriptionInput().click(); - await this.formDescriptionInput().fill("this is test form description"); await this.formEncounterType().selectOption("Admission"); await this.formSaveButton().click(); } async searchForm(formName: string) { - await this.page.getByRole('searchbox').fill(formName); + await this.page.getByRole("searchbox").fill(formName); } } diff --git a/package.json b/package.json index 77ace9f..50212b7 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "test-e2e": "playwright test", "verify": "turbo lint typescript coverage", "coverage": "yarn test --coverage --passWithNoTests", - "prepare": "husky install", + "postinstall": "husky install", "extract-translations": "i18next 'src/**/*.component.tsx' --config ./i18next-parser.config.js", "ci:bump-form-engine-lib": "yarn up @openmrs/openmrs-form-engine-lib@next" }, diff --git a/src/components/action-buttons/action-buttons.component.tsx b/src/components/action-buttons/action-buttons.component.tsx index 3ed5c50..57ac4f9 100644 --- a/src/components/action-buttons/action-buttons.component.tsx +++ b/src/components/action-buttons/action-buttons.component.tsx @@ -14,9 +14,14 @@ import type { TFunction } from "react-i18next"; import type { RouteParams, Schema } from "../../types"; import { publishForm, unpublishForm } from "../../forms.resource"; import { useForm } from "../../hooks/useForm"; -import SaveFormModal from "../modals/save-form.component"; +import SaveFormModal from "../modals/save-form-modal.component"; import styles from "./action-buttons.scss"; +type ActionButtonsProps = { + schema: Schema; + t: TFunction; +}; + type Status = | "idle" | "publishing" @@ -25,11 +30,6 @@ type Status = | "unpublished" | "error"; -type ActionButtonsProps = { - schema: Schema; - t: TFunction; -}; - function ActionButtons({ schema, t }: ActionButtonsProps) { const { formUuid } = useParams(); const { form, mutate } = useForm(formUuid); diff --git a/src/components/form-editor/form-editor.component.tsx b/src/components/form-editor/form-editor.component.tsx index 2cf08b3..794fa70 100644 --- a/src/components/form-editor/form-editor.component.tsx +++ b/src/components/form-editor/form-editor.component.tsx @@ -171,7 +171,7 @@ const FormEditor: React.FC = () => { - + {t("preview", "Preview")} {t("interactiveBuilder", "Interactive Builder")} @@ -179,7 +179,6 @@ const FormEditor: React.FC = () => { diff --git a/src/components/interactive-builder/new-form-modal.component.tsx b/src/components/interactive-builder/new-form-modal.component.tsx index 2a5ad78..60b6555 100644 --- a/src/components/interactive-builder/new-form-modal.component.tsx +++ b/src/components/interactive-builder/new-form-modal.component.tsx @@ -8,6 +8,7 @@ import { ModalBody, ModalFooter, ModalHeader, + Stack, TextInput, } from "@carbon/react"; import { showToast, showNotification } from "@openmrs/esm-framework"; @@ -16,8 +17,8 @@ import type { Schema } from "../../types"; type NewFormModalProps = { schema: Schema; onSchemaChange: (schema: Schema) => void; - showModal: boolean; onModalChange: (showModal: boolean) => void; + showModal: boolean; }; const NewFormModal: React.FC = ({ @@ -28,11 +29,12 @@ const NewFormModal: React.FC = ({ }) => { const { t } = useTranslation(); const [formName, setFormName] = useState(""); + const [formDescription, setFormDescription] = useState(""); - const updateFormName = () => { + const updateSchema = (updates: Partial) => { try { - schema.name = formName; - onSchemaChange({ ...schema }); + const updatedSchema = { ...schema, ...updates }; + onSchemaChange(updatedSchema); showToast({ title: t("success", "Success!"), @@ -50,6 +52,17 @@ const NewFormModal: React.FC = ({ } }; + const handleCreateForm = () => { + if (formName) { + updateSchema({ + name: formName, + description: formDescription, + }); + + onModalChange(false); + } + }; + return ( = ({
event.preventDefault()}> - - setFormName(event.target.value)} - /> - + + + ) => + setFormName(event.target.value) + } + /> + + + ) => + setFormDescription(event.target.value) + } + /> + +
- diff --git a/src/components/modals/save-form.component.tsx b/src/components/modals/save-form-modal.component.tsx similarity index 89% rename from src/components/modals/save-form.component.tsx rename to src/components/modals/save-form-modal.component.tsx index 21d8129..2c9751f 100644 --- a/src/components/modals/save-form.component.tsx +++ b/src/components/modals/save-form-modal.component.tsx @@ -1,4 +1,4 @@ -import React, { SyntheticEvent, useCallback, useState } from "react"; +import React, { SyntheticEvent, useCallback, useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { useParams } from "react-router-dom"; import { @@ -29,7 +29,7 @@ import { import type { EncounterType, Resource, RouteParams, Schema } from "../../types"; import { useEncounterTypes } from "../../hooks/useEncounterTypes"; import { useForm } from "../../hooks/useForm"; -import styles from "./save-form.scss"; +import styles from "./save-form-modal.scss"; type FormGroupData = { name: string; @@ -56,18 +56,25 @@ const SaveFormModal: React.FC = ({ form, schema }) => { const [saveState, setSaveState] = useState(""); const [isSavingForm, setIsSavingForm] = useState(false); const [isInvalidVersion, setIsInvalidVersion] = useState(false); - const [name, setName] = useState(form?.name); - const [description, setDescription] = useState(form?.description); - const [encounterType, setEncounterType] = useState( - form?.encounterType?.uuid || "" - ); - const [version, setVersion] = useState(form?.version); + const [name, setName] = useState(""); + const [description, setDescription] = useState(""); + const [encounterType, setEncounterType] = useState(""); + const [version, setVersion] = useState(""); const clearDraftFormSchema = useCallback( () => localStorage.removeItem("formSchema"), [] ); + useEffect(() => { + if (schema) { + setName(schema.name); + setDescription(schema.description); + setEncounterType(schema.encounterType); + setVersion(schema.version); + } + }, [schema]); + const checkVersionValidity = (version: string) => { if (!version) return setIsInvalidVersion(false); @@ -297,27 +304,28 @@ const SaveFormModal: React.FC = ({ form, schema }) => { setName(event.target.value)} - placeholder="e.g. OHRI Express Care Patient Encounter Form" + placeholder={t( + "formNamePlaceholder", + "e.g. OHRI Express Care Patient Encounter Form" + )} required + value={name} /> {saveState === "update" ? ( ) : null} { checkVersionValidity(event.target.value); @@ -330,33 +338,38 @@ const SaveFormModal: React.FC = ({ form, schema }) => { "invalidVersionWarning", "Version can only start with with a number" )} + required + value={version} />