Launching Workspaces
Use launchWorkspace2 from @openmrs/esm-framework to open a workspace.
import { launchWorkspace2 } from '@openmrs/esm-framework';
const MyComponent = ({ patientUuid }) => {
const openGastrodynamics = () => {
void launchWorkspace2('gastrodynamics-form-workspace', {
patientUuid,
});
};
return <button onClick={openGastrodynamics}>Open gastrodynamics</button>;
};The full signature is:
launchWorkspace2<WorkspaceProps, WindowProps, GroupProps>(
workspaceName,
workspaceProps,
windowProps,
groupProps,
);workspacePropsare passed to the workspace component asworkspaceProps.windowPropsare shared by workspaces in the same window.groupPropsare shared by all windows and workspaces in the same group.nullor omitted props are considered compatible with existing props.
launchWorkspace2 returns a Promise<boolean>. It resolves to true when the workspace is launched or restored, and false when the user cancels a required close confirmation.
Patient Workspaces That Require Visits
For patient workspaces that require an active visit, use useLaunchWorkspaceRequiringVisit from @openmrs/esm-patient-common-lib.
import React from 'react';
import { Button } from '@carbon/react';
import { useTranslation } from 'react-i18next';
import { useLaunchWorkspaceRequiringVisit } from '@openmrs/esm-patient-common-lib';
const OrderBasketActionButton = ({ patientUuid }) => {
const { t } = useTranslation();
const launchOrderBasket = useLaunchWorkspaceRequiringVisit(patientUuid, 'order-basket');
return <Button onClick={() => launchOrderBasket()}>{t('launchOrderBasket', 'Launch order basket')}</Button>;
};
export default OrderBasketActionButton;If visits are enabled and the patient has no active visit, O3 prompts the user to start or select a visit before launching the workspace.
Behavior
launchWorkspace2 follows the workspace v2 group and window model:
- If the target group is not open, O3 opens the group, opens the target window, and renders the requested workspace.
- If another group is open, or if the existing group props are incompatible, O3 checks the affected workspaces for unsaved changes, prompts when needed, and then closes the current group and its windows.
- If the target window is already open with compatible window props, launching an already-open workspace with compatible workspace props restores that window.
- If the target window or workspace has incompatible props, O3 checks for unsaved changes before closing the window and opening a fresh instance.
launchWorkspace2does not create child workspaces. From inside a workspace, use thelaunchChildWorkspaceprop supplied byWorkspace2DefinitionProps.
Workspace titles are set by the <Workspace2 title="..."> wrapper. The v1 workspaceTitle launch option is not used by workspace v2.
Last updated on