Skip to content

Commit

Permalink
(feat) O3-2006 Adds ability to launch workspace from form
Browse files Browse the repository at this point in the history
  • Loading branch information
pirupius committed Apr 15, 2024
1 parent 0abc705 commit 66cf176
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 3 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@
"peerDependencies": {
"@carbon/react": "1.x",
"@openmrs/esm-framework": "5.x",
"@openmrs/esm-patient-common-lib": "7.x",
"react": "18.x",
"react-i18next": "11.x",
"rxjs": "6.x"
},
"devDependencies": {
"@carbon/react": "^1.37.0",
"@openmrs/esm-framework": "next",
"@openmrs/esm-patient-common-lib": "next",
"@swc/cli": "^0.1.62",
"@swc/core": "^1.3.38",
"@swc/jest": "^0.2.24",
Expand Down
5 changes: 5 additions & 0 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ export interface OHRIFormField {
questionInfo?: string;
constrainMaxWidth?: boolean;
}

export interface previousValue {
field: string;
value: string | number | Date | boolean | previousValue[];
}

export interface OHRIFormFieldProps {
question: OHRIFormField;
onChange: (
Expand All @@ -137,6 +139,7 @@ export interface OHRIFormFieldProps {
useField?: (fieldId: string) => [FieldInputProps<any>, FieldMetaProps<any>, FieldHelperProps<any>];
previousValue?: previousValue;
}

export interface OHRIFormSection {
hide?: HideProps;
label: string;
Expand Down Expand Up @@ -182,6 +185,8 @@ export interface OHRIFormQuestionOptions {
allowMultiple?: boolean;
datasource?: { name: string; config?: Record<string, any> };
isSearchable?: boolean;
workspaceName?: string;
buttonLabel?: string;
}

export type SessionMode = 'edit' | 'enter' | 'view' | 'embedded-view';
Expand Down
15 changes: 15 additions & 0 deletions src/components/inputs/workspace-launcher/workspace-launcher.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@use '@carbon/colors';

.label {
font-weight: 600;
color: colors.$black-100;
}

.errorLabel label {
color: colors.$red-60;
font-weight: 600;
}

.workspaceButton {
margin: 1rem 0;
}
37 changes: 37 additions & 0 deletions src/components/inputs/workspace-launcher/workspace-launcher.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { OHRIFormFieldProps } from '../../../api/types';
import styles from './workspace-launcher.scss';
import { Button } from '@carbon/react';
import { useLaunchWorkspaceRequiringVisit } from '@openmrs/esm-patient-common-lib/src/useLaunchWorkspaceRequiringVisit';
import { showSnackbar } from '@openmrs/esm-framework';

const WorkspaceLauncher: React.FC<OHRIFormFieldProps> = ({ question, handler, onChange }) => {
const { t } = useTranslation();

const launchWorkspace = useLaunchWorkspaceRequiringVisit(question.questionOptions?.workspaceName);

const handleLaunchWorkspace = () => {
if (!launchWorkspace) {
showSnackbar({
title: t('invalidWorkspaceName', 'Invalid worksapce name.'),
subtitle: t('invalidWorkspaceNameSubtitle', 'Please provide a valid workspace name.'),
kind: 'error',
isLowContrast: true,
});
}
};

return (
<div>
<div className={styles.label}>{question.label}</div>
<div className={styles.workspaceButton}>
<Button onClick={handleLaunchWorkspace}>
{question.questionOptions?.workspaceName ?? t('launchWorkspace')}
</Button>
</div>
</div>
);
};

export default WorkspaceLauncher;
1 change: 0 additions & 1 deletion src/declarations.d.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
declare module '@carbon/react';
declare module '*.css';
declare module '*.scss';
declare type SideNavProps = {};
6 changes: 6 additions & 0 deletions src/registry/inbuilt-components/inbuiltControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import File from '../../components/inputs/file/file.component';
import { RegistryItem } from '../registry';
import { controlTemplates } from './control-templates';
import { templateToComponentMap } from './template-component-map';
import WorkspaceLauncher from '../../components/inputs/workspace-launcher/workspace-launcher';

/**
* @internal
Expand Down Expand Up @@ -112,6 +113,11 @@ export const inbuiltControls: Array<RegistryItem<React.ComponentType<OHRIFormFie
component: File,
type: 'file',
},
{
name: 'WorkspaceLauncher',
component: WorkspaceLauncher,
type: 'workspace-launcher',
},
...controlTemplates.map((template) => ({
name: `${template.name}Control`,
component: templateToComponentMap.find((component) => component.name === template.name).baseControlComponent,
Expand Down
92 changes: 90 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,41 @@ __metadata:
languageName: node
linkType: hard

"@carbon/react@npm:^1.12.0":
version: 1.55.0
resolution: "@carbon/react@npm:1.55.0"
dependencies:
"@babel/runtime": "npm:^7.18.3"
"@carbon/feature-flags": "npm:^0.19.0"
"@carbon/icons-react": "npm:^11.39.0"
"@carbon/layout": "npm:^11.21.0"
"@carbon/styles": "npm:^1.55.0"
"@floating-ui/react": "npm:^0.26.0"
"@ibm/telemetry-js": "npm:^1.2.1"
classnames: "npm:2.5.1"
copy-to-clipboard: "npm:^3.3.1"
downshift: "npm:8.5.0"
flatpickr: "npm:4.6.13"
invariant: "npm:^2.2.3"
lodash.debounce: "npm:^4.0.8"
lodash.findlast: "npm:^4.5.0"
lodash.isequal: "npm:^4.5.0"
lodash.omit: "npm:^4.5.0"
lodash.throttle: "npm:^4.1.1"
prop-types: "npm:^15.7.2"
react-is: "npm:^18.2.0"
tabbable: "npm:^6.2.0"
use-resize-observer: "npm:^6.0.0"
wicg-inert: "npm:^3.1.1"
window-or-global: "npm:^1.0.1"
peerDependencies:
react: ^16.8.6 || ^17.0.1 || ^18.2.0
react-dom: ^16.8.6 || ^17.0.1 || ^18.2.0
sass: ^1.33.0
checksum: 10/bc8437213c39a63d117c3adda633300d6fc5c8834e0e32dee7426a83fd9e9047331b76c1179f237b9cc911e063da045f9d2067c1474671d0e89c4e9f8f4c5417
languageName: node
linkType: hard

"@carbon/react@npm:^1.37.0":
version: 1.54.0
resolution: "@carbon/react@npm:1.54.0"
Expand Down Expand Up @@ -1578,6 +1613,28 @@ __metadata:
languageName: node
linkType: hard

"@carbon/styles@npm:^1.55.0":
version: 1.55.0
resolution: "@carbon/styles@npm:1.55.0"
dependencies:
"@carbon/colors": "npm:^11.21.0"
"@carbon/feature-flags": "npm:^0.19.0"
"@carbon/grid": "npm:^11.22.0"
"@carbon/layout": "npm:^11.21.0"
"@carbon/motion": "npm:^11.17.0"
"@carbon/themes": "npm:^11.34.0"
"@carbon/type": "npm:^11.26.0"
"@ibm/plex": "npm:6.0.0-next.6"
"@ibm/telemetry-js": "npm:^1.2.1"
peerDependencies:
sass: ^1.33.0
peerDependenciesMeta:
sass:
optional: true
checksum: 10/20bdabab64b75fc384064beef36038b3e188548191a320bc6ba1150bfb8d00ef85d09c19982527ea8fdd5fd4f975a3dc93ac3245139c7bf40d4d65e34e04b091
languageName: node
linkType: hard

"@carbon/telemetry@npm:0.1.0":
version: 0.1.0
resolution: "@carbon/telemetry@npm:0.1.0"
Expand Down Expand Up @@ -1688,7 +1745,7 @@ __metadata:
languageName: node
linkType: hard

"@floating-ui/react-dom@npm:^2.0.2":
"@floating-ui/react-dom@npm:^2.0.0, @floating-ui/react-dom@npm:^2.0.2":
version: 2.0.8
resolution: "@floating-ui/react-dom@npm:2.0.8"
dependencies:
Expand All @@ -1714,6 +1771,20 @@ __metadata:
languageName: node
linkType: hard

"@floating-ui/react@npm:^0.26.0":
version: 0.26.12
resolution: "@floating-ui/react@npm:0.26.12"
dependencies:
"@floating-ui/react-dom": "npm:^2.0.0"
"@floating-ui/utils": "npm:^0.2.0"
tabbable: "npm:^6.0.0"
peerDependencies:
react: ">=16.8.0"
react-dom: ">=16.8.0"
checksum: 10/da77f6b99ed0c8d5169f0ed287304615bef7c66b7a0011e4425e843016f6450a928bc27310a861fb14f8a1e58ef11fbdd92550583440f11af5d1a905968453a6
languageName: node
linkType: hard

"@floating-ui/utils@npm:^0.1.1":
version: 0.1.6
resolution: "@floating-ui/utils@npm:0.1.6"
Expand Down Expand Up @@ -3124,6 +3195,21 @@ __metadata:
languageName: node
linkType: hard

"@openmrs/esm-patient-common-lib@npm:next":
version: 7.1.1-pre.4335
resolution: "@openmrs/esm-patient-common-lib@npm:7.1.1-pre.4335"
dependencies:
"@carbon/react": "npm:^1.12.0"
lodash-es: "npm:^4.17.21"
uuid: "npm:^8.3.2"
peerDependencies:
"@openmrs/esm-framework": 5.x
react: 18.x
single-spa: 6.x
checksum: 10/82ef4384c7a704eb93c7a4cbb4f7ab05ba3bde17e5e988ca6078e633d3913971b5da98274ec558d3d92bbd5a49c5e9529c84877edc8944bba8050e7129c82ab3
languageName: node
linkType: hard

"@openmrs/esm-react-utils@npm:5.5.1-pre.1685":
version: 5.5.1-pre.1685
resolution: "@openmrs/esm-react-utils@npm:5.5.1-pre.1685"
Expand Down Expand Up @@ -3328,6 +3414,7 @@ __metadata:
dependencies:
"@carbon/react": "npm:^1.37.0"
"@openmrs/esm-framework": "npm:next"
"@openmrs/esm-patient-common-lib": "npm:next"
"@swc/cli": "npm:^0.1.62"
"@swc/core": "npm:^1.3.38"
"@swc/jest": "npm:^0.2.24"
Expand Down Expand Up @@ -3385,6 +3472,7 @@ __metadata:
peerDependencies:
"@carbon/react": 1.x
"@openmrs/esm-framework": 5.x
"@openmrs/esm-patient-common-lib": 7.x
react: 18.x
react-i18next: 11.x
rxjs: 6.x
Expand Down Expand Up @@ -16434,7 +16522,7 @@ __metadata:
languageName: node
linkType: hard

"tabbable@npm:^6.0.1, tabbable@npm:^6.2.0":
"tabbable@npm:^6.0.0, tabbable@npm:^6.0.1, tabbable@npm:^6.2.0":
version: 6.2.0
resolution: "tabbable@npm:6.2.0"
checksum: 10/980fa73476026e99dcacfc0d6e000d41d42c8e670faf4682496d30c625495e412c4369694f2a15cf1e5252d22de3c396f2b62edbe8d60b5dadc40d09e3f2dde3
Expand Down

0 comments on commit 66cf176

Please sign in to comment.