Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) Add description field to the interactive builder #176

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions e2e/pages/form-builder-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () =>
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
67 changes: 48 additions & 19 deletions src/components/interactive-builder/new-form-modal.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ModalBody,
ModalFooter,
ModalHeader,
Stack,
TextInput,
} from "@carbon/react";
import { showToast, showNotification } from "@openmrs/esm-framework";
Expand All @@ -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<NewFormModalProps> = ({
Expand All @@ -28,11 +29,12 @@ const NewFormModal: React.FC<NewFormModalProps> = ({
}) => {
const { t } = useTranslation();
const [formName, setFormName] = useState("");
const [formDescription, setFormDescription] = useState("");

const updateFormName = () => {
const updateSchema = (updates: Partial<Schema>) => {
try {
schema.name = formName;
onSchemaChange({ ...schema });
const updatedSchema = { ...schema, ...updates };
onSchemaChange(updatedSchema);

showToast({
title: t("success", "Success!"),
Expand All @@ -50,6 +52,17 @@ const NewFormModal: React.FC<NewFormModalProps> = ({
}
};

const handleCreateForm = () => {
if (formName) {
updateSchema({
name: formName,
description: formDescription,
});

onModalChange(false);
}
};

return (
<ComposedModal
open={showModal}
Expand All @@ -59,27 +72,43 @@ const NewFormModal: React.FC<NewFormModalProps> = ({
<ModalHeader title={t("createNewForm", "Create a new form")} />
<Form onSubmit={(event) => event.preventDefault()}>
<ModalBody>
<FormGroup legendText={""}>
<TextInput
id="formName"
labelText={t("formName", "Form name")}
value={formName}
onChange={(event) => setFormName(event.target.value)}
/>
</FormGroup>
<Stack gap={5}>
<FormGroup legendText={""}>
<TextInput
id="formName"
labelText={t("formName", "Form name")}
placeholder={t(
"formNamePlaceholder",
"What the form is called in the system"
)}
value={formName}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
setFormName(event.target.value)
}
/>
</FormGroup>
<FormGroup legendText={""}>
<TextInput
id="formDescription"
labelText={t("formDescription", "Form description")}
placeholder={t(
"formDescriptionPlaceholder",
"A short description of the form e.g. A form for collecting COVID-19 symptoms"
)}
value={formDescription}
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
setFormDescription(event.target.value)
}
/>
</FormGroup>
</Stack>
</ModalBody>
</Form>
<ModalFooter>
<Button kind="secondary" onClick={() => onModalChange(false)}>
{t("cancel", "Cancel")}
</Button>
<Button
disabled={!formName}
onClick={() => {
updateFormName();
onModalChange(false);
}}
>
<Button disabled={!formName} onClick={handleCreateForm}>
<span>{t("createForm", "Create Form")}</span>
</Button>
</ModalFooter>
Expand Down
Loading