Skip to content

Commit 5f740a7

Browse files
authored
(fix) : resolve failing workspace launcher (#160)
1 parent f4ea6f3 commit 5f740a7

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

projects/ngx-formentry/src/components/workspace-launcher/workspace-launcher.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ export class WorkspaceLauncherComponent {
99
@Input() public buttonLabel: string;
1010
@Input() public buttonType: string;
1111
@Input() public workspaceName: string;
12+
@Input() public additionalProps: Record<string, unknown>;
1213

1314
public handleClick() {
1415
// We check that this is defined in question.factory.ts `toWorkspaceLauncher`
15-
window['_openmrs_esm_patient_common_lib'].launchPatientWorkspace(
16-
this.workspaceName
16+
window['_openmrs_esm_framework'].launchWorkspace(
17+
this.workspaceName,
18+
this.additionalProps ?? {}
1719
);
1820
}
1921
}

projects/ngx-formentry/src/form-entry/form-factory/question.factory.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class QuestionFactory {
3939
dataSources: any = {};
4040
historicalHelperService: HistoricalHelperService = new HistoricalHelperService();
4141
quetionIndex = 0;
42-
checkedForEsmPatientCommonLib = false;
42+
checkedForEsmFramework = false;
4343
constructor() {}
4444

4545
createQuestionModel(formSchema: any, form?: Form): QuestionBase {
@@ -822,18 +822,17 @@ export class QuestionFactory {
822822
}
823823

824824
toWorkspaceLauncher(schemaQuestion: any): WorkspaceLauncherQuestion {
825-
if (!this.checkedForEsmPatientCommonLib) {
826-
this.checkedForEsmPatientCommonLib = true;
827-
if (!window['_openmrs_esm_patient_common_lib']) {
825+
if (!this.checkedForEsmFramework) {
826+
this.checkedForEsmFramework = true;
827+
if (!window['_openmrs_esm_framework']) {
828828
console.error(
829-
"@openmrs/esm-patient-common-lib is not accessible. The 'workspace-launcher' question type can only be used in the context of the O3 patient chart, where the workspace is."
829+
"@openmrs/esm-framework is not accessible. The 'workspace-launcher' question type can only be used in the context of the O3 patient chart, where the workspace is."
830830
);
831831
} else if (
832-
typeof window['_openmrs_esm_patient_common_lib']
833-
.launchPatientWorkspace !== 'function'
832+
typeof window['_openmrs_esm_framework'].launchWorkspace !== 'function'
834833
) {
835834
console.error(
836-
'@openmrs/esm-patient-common-lib is accessible, but the `launchPatientWorkspace` function is missing. It is likely that the version of @openmrs/esm-patient-common-lib that is being used is not compatible with this version of ngx-formentry.'
835+
'@openmrs/esm-framework is accessible, but the `launchWorkspace` function is missing. It is likely that the version of @openmrs/esm-framework that is being used is not compatible with this version of ngx-formentry.'
837836
);
838837
}
839838
}
@@ -843,7 +842,8 @@ export class QuestionFactory {
843842
label: schemaQuestion.label,
844843
buttonLabel: schemaQuestion.questionOptions.buttonLabel,
845844
buttonType: schemaQuestion.questionOptions.buttonType,
846-
workspaceName: schemaQuestion.questionOptions.workspaceName
845+
workspaceName: schemaQuestion.questionOptions.workspaceName,
846+
additionalProps: schemaQuestion.questionOptions?.additionalProps ?? {}
847847
});
848848
question.questionIndex = this.quetionIndex;
849849
question.extras = schemaQuestion;

projects/ngx-formentry/src/form-entry/form-renderer/form-renderer.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@
361361
[workspaceName]="
362362
node.question.extras.questionOptions.workspaceName
363363
"
364+
[additionalProps]="
365+
node.question.extras.questionOptions.additionalProps
366+
"
364367
></ofe-workspace-launcher>
365368
</div>
366369

projects/ngx-formentry/src/form-entry/question-models/interfaces/workspace-launcher-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export interface WorkspaceLauncherOptions extends BaseOptions {
44
buttonLabel: string;
55
buttonType: string;
66
workspaceName: string;
7+
additionalProps: Record<string, unknown>;
78
}

projects/ngx-formentry/src/form-entry/question-models/workspace-launcher.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class WorkspaceLauncherQuestion extends QuestionBase {
66
buttonLabel: string;
77
buttonType: string;
88
workspaceName: string;
9+
additionalProps: Record<string, unknown>;
910

1011
constructor(options: WorkspaceLauncherOptions) {
1112
super(options);
@@ -14,6 +15,7 @@ export class WorkspaceLauncherQuestion extends QuestionBase {
1415
this.buttonLabel = options.buttonLabel || '';
1516
this.buttonType = options.buttonType || 'primary';
1617
this.workspaceName = options.workspaceName || 'order-basket';
18+
this.additionalProps = options.additionalProps || {};
1719
this.controlType = AfeControlType.AfeFormControl;
1820
}
1921
}

0 commit comments

Comments
 (0)