Skip to content

Commit 2feb02d

Browse files
committed
Add SWM render stability tests and typechecked setup
1 parent cdae75e commit 2feb02d

51 files changed

Lines changed: 1299 additions & 1095 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.3.14/schema.json",
3+
"files": {
4+
"includes": [
5+
"src/**/*.{ts,tsx,js,jsx}",
6+
"tests/**/*.{ts,tsx,js,jsx}"
7+
]
8+
},
9+
"formatter": {
10+
"enabled": true,
11+
"indentStyle": "space",
12+
"indentWidth": 2,
13+
"lineWidth": 100,
14+
"lineEnding": "lf"
15+
},
16+
"linter": {
17+
"enabled": true,
18+
"rules": {
19+
"recommended": true
20+
}
21+
},
22+
"javascript": {
23+
"formatter": {
24+
"quoteStyle": "double"
25+
}
26+
}
27+
}

aidbox-forms/aidbox-forms-builder-custom-renderer/beda-renderer/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66
"dev": "vite",
77
"build": "vite build",
88
"preview": "vite preview",
9-
"test": "playwright test"
9+
"test": "playwright test",
10+
"lint": "biome lint .",
11+
"format": "biome format .",
12+
"typecheck": "tsc -p tsconfig.json --noEmit"
1013
},
1114
"dependencies": {
12-
"aidbox-swm": "file:../swm",
1315
"@beda.software/fhir-questionnaire": "github:beda-software/fhir-questionnaire",
1416
"lodash": "^4.17.23",
1517
"property-expr": "^2.0.6",
1618
"react": "^18.3.1",
1719
"react-dom": "^18.3.1",
1820
"sdc-qrf": "1.0.0-beta.13",
19-
"toposort": "^2.0.2",
21+
"sdc-smart-web-messaging-react": "1.0.3",
2022
"tiny-case": "^1.0.3",
23+
"toposort": "^2.0.2",
2124
"tslib": "^2.7.0"
2225
},
2326
"devDependencies": {
27+
"@biomejs/biome": "^2.3.14",
2428
"@playwright/test": "^1.58.1",
2529
"@types/fhir": "^0.0.41",
2630
"@types/react": "^18.3.27",

aidbox-forms/aidbox-forms-builder-custom-renderer/beda-renderer/pnpm-lock.yaml

Lines changed: 105 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

aidbox-forms/aidbox-forms-builder-custom-renderer/beda-renderer/src/shims/aidbox-service.ts renamed to aidbox-forms/aidbox-forms-builder-custom-renderer/beda-renderer/src/aidbox-service.ts

File renamed without changes.
Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
import React from "react";
2-
import { useSmartMessaging } from "aidbox-swm";
3-
import { ErrorView } from "./ui/error-view";
4-
import { BedaForm } from "./renderer/beda-form";
2+
import {
3+
SmartMessagingPhase,
4+
useSmartMessaging,
5+
} from "sdc-smart-web-messaging-react";
6+
import { ErrorView } from "./error-view";
7+
import { BedaForm } from "./beda-form";
8+
9+
declare global {
10+
interface Window {
11+
__rendererMetrics?: {
12+
renders: number;
13+
};
14+
}
15+
}
516

617
export const App = () => {
18+
const renderCountRef = React.useRef(0);
19+
if (import.meta.env.DEV) {
20+
renderCountRef.current += 1;
21+
window.__rendererMetrics = { renders: renderCountRef.current };
22+
}
23+
const [errorMessage, setErrorMessage] = React.useState<string | null>(null);
724
const {
825
questionnaire,
926
questionnaireResponse,
1027
context,
11-
error,
12-
renderKey,
13-
sendResponseChanged,
28+
phase,
29+
onQuestionnaireResponseChange,
1430
} = useSmartMessaging({
1531
application: {
1632
name: "Beda",
@@ -20,10 +36,18 @@ export const App = () => {
2036
extraction: false,
2137
focusChangeNotifications: false,
2238
},
39+
onError: (error) => {
40+
const suffix = error.messageType ? ` (${error.messageType})` : "";
41+
setErrorMessage(`${error.message}${suffix}`);
42+
},
2343
});
2444

25-
if (error) {
26-
return <ErrorView message={error} />;
45+
if (phase === SmartMessagingPhase.Disabled) {
46+
return <ErrorView message="Missing SDC SWM parameters." />;
47+
}
48+
49+
if (errorMessage) {
50+
return <ErrorView message={errorMessage} />;
2751
}
2852

2953
if (!questionnaire) {
@@ -32,11 +56,10 @@ export const App = () => {
3256

3357
return (
3458
<BedaForm
35-
key={renderKey}
3659
questionnaire={questionnaire}
3760
questionnaireResponse={questionnaireResponse}
3861
context={context}
39-
onResponseChange={sendResponseChanged}
62+
onResponseChange={onQuestionnaireResponseChange}
4063
/>
4164
);
4265
};

aidbox-forms/aidbox-forms-builder-custom-renderer/beda-renderer/src/renderer/beda-form.tsx renamed to aidbox-forms/aidbox-forms-builder-custom-renderer/beda-renderer/src/beda-form.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
useQuestionnaireResponseFormContext,
1616
} from "sdc-qrf";
1717
import type { AnswerValue, FormItems, QuestionItemProps } from "sdc-qrf";
18-
import type { QuestionnaireContext } from "sdc-swm-protocol/src";
18+
import type { QuestionnaireContext } from "sdc-smart-web-messaging-react";
1919

2020
type BedaFormProps = {
2121
questionnaire: fhir4.Questionnaire;
@@ -72,7 +72,7 @@ function buildLaunchContextParameters(
7272
if (item.contentResource) {
7373
return {
7474
name: item.name,
75-
resource: item.contentResource as fhir4b.Resource,
75+
resource: item.contentResource as fhir4b.FhirResource,
7676
};
7777
}
7878
if (item.contentReference) {
@@ -103,7 +103,7 @@ function GroupItem({ questionItem, children, addItem }: GroupItemProps) {
103103
);
104104
}
105105

106-
function useAnswerValue(
106+
function getAnswerValue(
107107
questionItem: QuestionItemProps["questionItem"],
108108
parentPath: string[],
109109
formValues: FormItems
@@ -123,7 +123,7 @@ function QuestionField({ questionItem, context, parentPath }: QuestionItemProps)
123123
void context;
124124
if (!questionItem.linkId) return null;
125125

126-
const answerValue = useAnswerValue(questionItem, parentPath, formValues);
126+
const answerValue = getAnswerValue(questionItem, parentPath, formValues);
127127
const fieldPath = [...parentPath, questionItem.linkId];
128128
const isReadOnly = Boolean(questionItem.readOnly);
129129

@@ -272,18 +272,21 @@ function QuestionField({ questionItem, context, parentPath }: QuestionItemProps)
272272
</label>
273273
);
274274
}
275-
case "string":
276-
case "text":
277275
default: {
278276
const value = answerValue?.string ?? "";
279277
const isMultiline = questionItem.type === "text";
278+
const inputId = `field-${questionItem.linkId}`;
280279
return (
281-
<label style={{ display: "block", marginBottom: "12px" }}>
282-
<div style={{ fontWeight: 600, marginBottom: "4px" }}>
280+
<div style={{ display: "block", marginBottom: "12px" }}>
281+
<label
282+
htmlFor={inputId}
283+
style={{ display: "block", fontWeight: 600, marginBottom: "4px" }}
284+
>
283285
{questionItem.text}
284-
</div>
286+
</label>
285287
{isMultiline ? (
286288
<textarea
289+
id={inputId}
287290
value={value}
288291
disabled={isReadOnly}
289292
onChange={(event) =>
@@ -294,6 +297,7 @@ function QuestionField({ questionItem, context, parentPath }: QuestionItemProps)
294297
/>
295298
) : (
296299
<input
300+
id={inputId}
297301
type="text"
298302
value={value}
299303
disabled={isReadOnly}
@@ -304,7 +308,7 @@ function QuestionField({ questionItem, context, parentPath }: QuestionItemProps)
304308
}
305309
/>
306310
)}
307-
</label>
311+
</div>
308312
);
309313
}
310314
}

aidbox-forms/aidbox-forms-builder-custom-renderer/smart-forms-renderer/src/ui/error-view.tsx renamed to aidbox-forms/aidbox-forms-builder-custom-renderer/beda-renderer/src/error-view.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import React from "react";
2-
31
type ErrorViewProps = {
42
message: string;
53
};

0 commit comments

Comments
 (0)