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

use react components for ICardForm page one and two #31

Merged
merged 1 commit into from
Feb 16, 2022
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
17 changes: 15 additions & 2 deletions src/simplified/cardEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ interface ExpressionOption {
libraryIdentifier: string,
libraryUrl: string,
}

export interface pageOneProps {
fieldElements: JSX.Element[],
}

export interface pageTwoProps {
conditions: PlanDefinitionActionCondition[],
}

export interface ICardForm {
resourceType: FriendlyResourceListEntry;
textBoxFields: Map<string, textBoxProps>;
dropdownFields: Map<string, string[]>;
cardFieldLayout: cardLayout;
pageOne: (fieldElements: JSX.Element[]) => JSX.Element[];
pageTwo: (fieldElements: JSX.Element[]) => JSX.Element[];
pageOne: React.FunctionComponent<pageOneProps> | React.ComponentClass<pageOneProps>;
pageTwo: React.FunctionComponent<pageTwoProps> | React.ComponentClass<pageTwoProps>;
pageThree: (fieldElements: JSX.Element[]) => JSX.Element[];
}

Expand Down Expand Up @@ -176,12 +185,16 @@ export const CardEditor = (props: CardEditorProps) => {

const innerCardForm = getInnerCardForm();

// Read existing conditions
const pdConditions: PlanDefinitionActionCondition[] = [];

return (
<div>
<Form key={actResourceType.FHIR + "-form"} style={{ color: "#2a6b92" }} id="commonMetaDataForm" target="void" onSubmit={handleSaveResource}>
<OuterCardForm
sageNode={actNode}
fieldHandlers={fieldHandlers}
pdConditions={pdConditions}
resourceType={actResourceType}
elementList={fieldElementListForType(innerCardForm, fieldHandlers, actNode)}
innerCardForm={innerCardForm}
Expand Down
16 changes: 7 additions & 9 deletions src/simplified/medicationRequestForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,31 @@ export class MedicationRequestForm implements ICardForm {

};

pageOne = (fieldElements: JSX.Element[]): JSX.Element[] => {
pageOne: ICardForm['pageOne'] = (props) => {
const placeHolderElem =
<Form.Group key='placeholder-formGroup' as={Col} >
</Form.Group>;
return (
[
<div>{
...this.cardFieldLayout.cardColumns.map((cr, i: number) => {
return (
<Row key={"row-" + i} className="mb-3">
{cr.map(field =>
[
placeHolderElem,
...fieldElements
...props.fieldElements
].find(elem =>
elem.key?.toString().startsWith(field + "-")))}
</Row>
)
}),
]
})
}</div>
);
}

pageTwo = (fieldElements: JSX.Element[]) => {
pageTwo: ICardForm['pageTwo'] = (props) => {
return (
[
<div key="page2">To be implemented</div>
]
<div key="page2">{props.conditions}</div>
);
}

Expand Down
9 changes: 7 additions & 2 deletions src/simplified/outerCardForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { faCaretLeft, faCaretRight } from '@fortawesome/pro-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { PlanDefinitionActionCondition } from 'fhir/r4';
import React from "react";
import State, { SageNodeInitializedFreezerNode } from '../state';
import { ICardForm } from './cardEditor';
Expand Down Expand Up @@ -27,6 +28,7 @@ export type CardFormProps = {
sageNode: SageNodeInitializedFreezerNode,
fieldHandlers: any[][],
resourceType: FriendlyResourceListEntry,
pdConditions: PlanDefinitionActionCondition[],
elementList: JSX.Element[]
innerCardForm: ICardForm,
}
Expand Down Expand Up @@ -96,11 +98,14 @@ export class OuterCardForm extends React.Component<CardFormProps, CardFormState>
resetForm = () => { this.setState({ step: 1 }) }

render() {
const PageOne = this.innerCardForm.pageOne; // https://reactjs.org/docs/jsx-in-depth.html#choosing-the-type-at-runtime
const PageTwo = this.innerCardForm.pageTwo;

return (
<div>
<div>{this.pageTitles.get(this.state.step)}</div>
<div>{this.state.step == 1 ? this.innerCardForm.pageOne(this.props.elementList) : null}</div>
{this.state.step == 2 ? this.innerCardForm.pageTwo([]) : null}
<div>{this.state.step == 1 ? <PageOne fieldElements={this.props.elementList} /> : null}</div>
{this.state.step == 2 ? <PageTwo conditions={this.props.pdConditions}/> : null}
{this.state.step == 3 ? this.innerCardForm.pageThree([]) : null}
<div><>
{this.state.step > 1 ? this.leftNavButton() : null}
Expand Down