@openmrs/esm-patient-common-lib 7.1.1-pre.4449 → 7.1.1-pre.4459
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +1 -2
- package/src/types/index.ts +0 -1
- package/src/use-allowed-file-extensions.ts +25 -0
- package/src/workspaces.ts +55 -0
- package/src/declarations.d.ts +0 -3
- package/src/siderail-nav-button/index.ts +0 -1
- package/src/siderail-nav-button/siderail-nav-button.component.tsx +0 -89
- package/src/siderail-nav-button/siderail-nav-button.scss +0 -112
- package/src/siderail-nav-button/siderail-nav-button.test.tsx +0 -266
- package/src/types/workspace.ts +0 -57
- package/src/useLaunchWorkspaceRequiringVisit.ts +0 -26
- package/src/workspaces/index.ts +0 -2
- package/src/workspaces/useWorkspaces.tsx +0 -38
- package/src/workspaces/workspaces.test.ts +0 -414
- package/src/workspaces/workspaces.ts +0 -448
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -16,8 +16,7 @@ export * from './patient-summary/patient-summary-extension-order';
|
|
|
16
16
|
export * from './programs/usePatientProgramEnrollment';
|
|
17
17
|
export * from './time-helper';
|
|
18
18
|
export * from './types';
|
|
19
|
-
export * from './useLaunchWorkspaceRequiringVisit';
|
|
20
19
|
export * from './useSystemVisitSetting';
|
|
21
20
|
export * from './workspaces';
|
|
22
|
-
export * from './siderail-nav-button';
|
|
23
21
|
export * from './form-entry-interop';
|
|
22
|
+
export * from './use-allowed-file-extensions';
|
package/src/types/index.ts
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import useSWRImmutable from 'swr/immutable';
|
|
2
|
+
import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
|
|
3
|
+
|
|
4
|
+
export interface GlobalProperty {
|
|
5
|
+
property: string;
|
|
6
|
+
uuid: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function useAllowedFileExtensions() {
|
|
11
|
+
const allowedFileExtensionsGlobalProperty = 'attachments.allowedFileExtensions';
|
|
12
|
+
const customRepresentation = 'custom:(value)';
|
|
13
|
+
const url = `${restBaseUrl}/systemsetting?&v=${customRepresentation}&q=${allowedFileExtensionsGlobalProperty}`;
|
|
14
|
+
|
|
15
|
+
const { data, error, isLoading } = useSWRImmutable<{ data: { results: Array<GlobalProperty> } }>(url, openmrsFetch);
|
|
16
|
+
|
|
17
|
+
const allowedFileExtensions =
|
|
18
|
+
data?.data?.results?.length > 0 ? data?.data?.results[0].value?.toLowerCase().split(',') || undefined : undefined;
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
allowedFileExtensions,
|
|
22
|
+
error,
|
|
23
|
+
isLoading,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type DefaultWorkspaceProps, launchWorkspace, navigateAndLaunchWorkspace, usePatient } from '@openmrs/esm-framework';
|
|
2
|
+
import { getPatientUuidFromUrl } from './get-patient-uuid-from-url';
|
|
3
|
+
import { useSystemVisitSetting } from './useSystemVisitSetting';
|
|
4
|
+
import { useVisitOrOfflineVisit } from './offline/visit';
|
|
5
|
+
import { useCallback } from 'react';
|
|
6
|
+
import { launchStartVisitPrompt } from './launchStartVisitPrompt';
|
|
7
|
+
|
|
8
|
+
export interface DefaultPatientWorkspaceProps extends DefaultWorkspaceProps {
|
|
9
|
+
patientUuid: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function launchPatientWorkspace(workspaceName: string, additionalProps?: object) {
|
|
13
|
+
const patientUuid = getPatientUuidFromUrl();
|
|
14
|
+
launchWorkspace(workspaceName, {
|
|
15
|
+
patientUuid: patientUuid,
|
|
16
|
+
...additionalProps,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function launchPatientChartWithWorkspaceOpen({
|
|
21
|
+
patientUuid,
|
|
22
|
+
workspaceName,
|
|
23
|
+
dashboardName,
|
|
24
|
+
additionalProps,
|
|
25
|
+
}: {
|
|
26
|
+
patientUuid: string;
|
|
27
|
+
workspaceName: string;
|
|
28
|
+
dashboardName?: string;
|
|
29
|
+
additionalProps?: object;
|
|
30
|
+
}) {
|
|
31
|
+
navigateAndLaunchWorkspace({
|
|
32
|
+
targetUrl: '${openmrsSpaBase}/patient/' + `${patientUuid}/chart` + (dashboardName ? `/${dashboardName}` : ''),
|
|
33
|
+
workspaceName: workspaceName,
|
|
34
|
+
contextKey: `patient/${patientUuid}`,
|
|
35
|
+
additionalProps,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function useLaunchWorkspaceRequiringVisit<T extends object>(workspaceName: string) {
|
|
40
|
+
const { patientUuid } = usePatient();
|
|
41
|
+
const { systemVisitEnabled } = useSystemVisitSetting();
|
|
42
|
+
const { currentVisit } = useVisitOrOfflineVisit(patientUuid);
|
|
43
|
+
|
|
44
|
+
const launchPatientWorkspaceCb = useCallback(
|
|
45
|
+
(additionalProps?: T) => {
|
|
46
|
+
if (!systemVisitEnabled || currentVisit) {
|
|
47
|
+
launchPatientWorkspace(workspaceName, additionalProps);
|
|
48
|
+
} else {
|
|
49
|
+
launchStartVisitPrompt();
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
[currentVisit, systemVisitEnabled, workspaceName],
|
|
53
|
+
);
|
|
54
|
+
return launchPatientWorkspaceCb;
|
|
55
|
+
}
|
package/src/declarations.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './siderail-nav-button.component';
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import classNames from 'classnames';
|
|
3
|
-
import { Button, IconButton } from '@carbon/react';
|
|
4
|
-
import { useLayoutType } from '@openmrs/esm-framework';
|
|
5
|
-
import { useWorkspaces } from '../workspaces';
|
|
6
|
-
import styles from './siderail-nav-button.scss';
|
|
7
|
-
|
|
8
|
-
interface TagsProps {
|
|
9
|
-
getIcon: (props: object) => JSX.Element;
|
|
10
|
-
formOpenInTheBackground: boolean;
|
|
11
|
-
tagContent?: string | React.ReactNode;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function Tags({ getIcon, formOpenInTheBackground, tagContent }: TagsProps) {
|
|
15
|
-
return (
|
|
16
|
-
<>
|
|
17
|
-
{getIcon({ size: 16 })}
|
|
18
|
-
|
|
19
|
-
{formOpenInTheBackground ? (
|
|
20
|
-
<span className={styles.interruptedTag}>!</span>
|
|
21
|
-
) : (
|
|
22
|
-
<span className={styles.countTag}>{tagContent}</span>
|
|
23
|
-
)}
|
|
24
|
-
</>
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface SiderailNavButtonProps {
|
|
29
|
-
name: string;
|
|
30
|
-
getIcon: (props: object) => JSX.Element;
|
|
31
|
-
label: string;
|
|
32
|
-
iconDescription: string;
|
|
33
|
-
handler: () => void;
|
|
34
|
-
type: string;
|
|
35
|
-
tagContent?: string | React.ReactNode;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const SiderailNavButton: React.FC<SiderailNavButtonProps> = ({
|
|
39
|
-
name,
|
|
40
|
-
getIcon,
|
|
41
|
-
label,
|
|
42
|
-
iconDescription,
|
|
43
|
-
handler,
|
|
44
|
-
type,
|
|
45
|
-
tagContent,
|
|
46
|
-
}) => {
|
|
47
|
-
const layout = useLayoutType();
|
|
48
|
-
const { workspaces, workspaceWindowState } = useWorkspaces();
|
|
49
|
-
const workspaceIndex = workspaces?.findIndex(({ type: workspaceType }) => workspaceType === type) ?? -1;
|
|
50
|
-
const isWorkspaceActive = workspaceWindowState !== 'hidden' && workspaceIndex === 0;
|
|
51
|
-
const formOpenInTheBackground = workspaceIndex > 0 || (workspaceIndex === 0 && workspaceWindowState === 'hidden');
|
|
52
|
-
|
|
53
|
-
if (layout === 'tablet' || layout === 'phone') {
|
|
54
|
-
return (
|
|
55
|
-
<Button
|
|
56
|
-
className={classNames(styles.container, { [styles.active]: isWorkspaceActive })}
|
|
57
|
-
iconDescription={iconDescription}
|
|
58
|
-
kind="ghost"
|
|
59
|
-
onClick={handler}
|
|
60
|
-
role="button"
|
|
61
|
-
tabIndex={0}
|
|
62
|
-
>
|
|
63
|
-
<span className={styles.elementContainer}>
|
|
64
|
-
<Tags formOpenInTheBackground={formOpenInTheBackground} getIcon={getIcon} tagContent={tagContent} />
|
|
65
|
-
</span>
|
|
66
|
-
<span>{label}</span>
|
|
67
|
-
</Button>
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<IconButton
|
|
73
|
-
align="left"
|
|
74
|
-
aria-label={iconDescription}
|
|
75
|
-
className={classNames(styles.container, {
|
|
76
|
-
[styles.active]: isWorkspaceActive,
|
|
77
|
-
})}
|
|
78
|
-
enterDelayMs={300}
|
|
79
|
-
kind="ghost"
|
|
80
|
-
label={label}
|
|
81
|
-
onClick={handler}
|
|
82
|
-
size="md"
|
|
83
|
-
>
|
|
84
|
-
<div className={styles.elementContainer}>
|
|
85
|
-
<Tags formOpenInTheBackground={formOpenInTheBackground} getIcon={getIcon} tagContent={tagContent} />
|
|
86
|
-
</div>
|
|
87
|
-
</IconButton>
|
|
88
|
-
);
|
|
89
|
-
};
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
@use '@carbon/styles/scss/spacing';
|
|
2
|
-
@use '@carbon/styles/scss/type';
|
|
3
|
-
@import '@openmrs/esm-styleguide/src/vars';
|
|
4
|
-
|
|
5
|
-
.container {
|
|
6
|
-
margin-top: spacing.$spacing-02;
|
|
7
|
-
margin-bottom: spacing.$spacing-02;
|
|
8
|
-
border-radius: 50%;
|
|
9
|
-
color: $ui-05;
|
|
10
|
-
max-width: none;
|
|
11
|
-
|
|
12
|
-
&:hover {
|
|
13
|
-
background-color: $color-gray-30;
|
|
14
|
-
color: $text-02;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
&:focus {
|
|
18
|
-
border-color: $interactive-01;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
& > span {
|
|
22
|
-
margin-top: spacing.$spacing-02;
|
|
23
|
-
@include type.type-style("body-compact-01");
|
|
24
|
-
color: $text-02;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
& svg {
|
|
28
|
-
transform: scale(1.25);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.elementContainer {
|
|
33
|
-
display: flex;
|
|
34
|
-
align-items: center;
|
|
35
|
-
position: relative;
|
|
36
|
-
flex-direction: column;
|
|
37
|
-
|
|
38
|
-
.countTag {
|
|
39
|
-
position: absolute;
|
|
40
|
-
font-size: 10px;
|
|
41
|
-
text-align: center;
|
|
42
|
-
color: $ui-01;
|
|
43
|
-
background-color: $danger;
|
|
44
|
-
padding: 0 4px;
|
|
45
|
-
border-radius: 50%;
|
|
46
|
-
top: -14px;
|
|
47
|
-
right: -12px;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
.interruptedTag {
|
|
51
|
-
@extend .countTag;
|
|
52
|
-
font-size: 10px;
|
|
53
|
-
padding: 0 5px;
|
|
54
|
-
width: 14px;
|
|
55
|
-
height: 14px;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/* Desktop */
|
|
60
|
-
:global(.omrs-breakpoint-gt-tablet) {
|
|
61
|
-
.active {
|
|
62
|
-
border: spacing.$spacing-01 solid;
|
|
63
|
-
@include brand-03(border-color);
|
|
64
|
-
border-radius: 50%;
|
|
65
|
-
background-color: $ui-02;
|
|
66
|
-
|
|
67
|
-
&:focus {
|
|
68
|
-
border-color: var(--brand-03) !important;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
.container {
|
|
73
|
-
& svg {
|
|
74
|
-
transform: scale(1.25);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/* Tablet */
|
|
80
|
-
:global(.omrs-breakpoint-lt-desktop) {
|
|
81
|
-
|
|
82
|
-
.container {
|
|
83
|
-
margin-bottom: 0;
|
|
84
|
-
margin-top: 0;
|
|
85
|
-
border-radius: unset;
|
|
86
|
-
color: $ui-05;
|
|
87
|
-
max-width: none;
|
|
88
|
-
|
|
89
|
-
display: flex;
|
|
90
|
-
flex-direction: column;
|
|
91
|
-
align-items: center;
|
|
92
|
-
width: 100%;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
.active {
|
|
96
|
-
background-color: $color-blue-10;
|
|
97
|
-
color: $interactive-01;
|
|
98
|
-
|
|
99
|
-
&:hover {
|
|
100
|
-
color: $interactive-01;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
& > span {
|
|
104
|
-
color: $interactive-01;
|
|
105
|
-
@include type.type-style("heading-compact-01");
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
svg {
|
|
109
|
-
fill: $interactive-01;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { screen, render, cleanup } from '@testing-library/react';
|
|
3
|
-
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import { useLayoutType } from '@openmrs/esm-framework';
|
|
5
|
-
import { SiderailNavButton } from './siderail-nav-button.component';
|
|
6
|
-
import { Pen } from '@carbon/react/icons';
|
|
7
|
-
import { useWorkspaces } from '../workspaces';
|
|
8
|
-
|
|
9
|
-
const mockedUseLayoutType = useLayoutType as jest.Mock;
|
|
10
|
-
|
|
11
|
-
jest.mock('@carbon/react/icons', () => ({
|
|
12
|
-
...(jest.requireActual('@carbon/react/icons') as jest.Mock),
|
|
13
|
-
Pen: jest.fn(({ size }) => <div data-testid="pen-icon">size: {size}</div>),
|
|
14
|
-
}));
|
|
15
|
-
|
|
16
|
-
jest.mock('@openmrs/esm-framework', () => {
|
|
17
|
-
const originalModule = jest.requireActual('@openmrs/esm-framework');
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
...originalModule,
|
|
21
|
-
useLayoutType: jest.fn(),
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
jest.mock('../workspaces', () => {
|
|
26
|
-
const originalModule = jest.requireActual('../workspaces');
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
...originalModule,
|
|
30
|
-
useWorkspaces: jest.fn(),
|
|
31
|
-
};
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe('SiderailNavButton', () => {
|
|
35
|
-
beforeEach(cleanup);
|
|
36
|
-
|
|
37
|
-
it('should display tablet view', async () => {
|
|
38
|
-
const user = userEvent.setup();
|
|
39
|
-
|
|
40
|
-
(useWorkspaces as jest.Mock).mockReturnValue({
|
|
41
|
-
workspaces: [{ type: 'order' }],
|
|
42
|
-
workspaceWindowState: 'normal',
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
mockedUseLayoutType.mockReturnValue('tablet');
|
|
46
|
-
|
|
47
|
-
const handler = jest.fn();
|
|
48
|
-
|
|
49
|
-
render(
|
|
50
|
-
<SiderailNavButton
|
|
51
|
-
name={'visit-note-nav-button'}
|
|
52
|
-
getIcon={(props) => <Pen {...props} />}
|
|
53
|
-
label={'Visit note'}
|
|
54
|
-
iconDescription={'Note'}
|
|
55
|
-
handler={handler}
|
|
56
|
-
type={'visit-note'}
|
|
57
|
-
/>,
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
expect(screen.getByTestId('pen-icon')).toBeInTheDocument();
|
|
61
|
-
expect(screen.getByTestId('pen-icon').innerHTML).toBe('size: 16');
|
|
62
|
-
|
|
63
|
-
const button = screen.getByRole('button', { name: /Visit note/i });
|
|
64
|
-
expect(button).toBeInTheDocument();
|
|
65
|
-
await user.click(button);
|
|
66
|
-
expect(handler).toBeCalled();
|
|
67
|
-
|
|
68
|
-
expect(button).not.toHaveClass('active');
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should have not active className if workspace is not active', async () => {
|
|
72
|
-
(useWorkspaces as jest.Mock).mockReturnValue({
|
|
73
|
-
workspaces: [{ type: 'order' }, { type: 'visit-note' }],
|
|
74
|
-
workspaceWindowState: 'normal',
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
mockedUseLayoutType.mockReturnValue('tablet');
|
|
78
|
-
|
|
79
|
-
const handler = jest.fn();
|
|
80
|
-
|
|
81
|
-
render(
|
|
82
|
-
<SiderailNavButton
|
|
83
|
-
name={'visit-note-nav-button'}
|
|
84
|
-
getIcon={(props) => <Pen {...props} />}
|
|
85
|
-
label={'Visit note'}
|
|
86
|
-
iconDescription={'Note'}
|
|
87
|
-
handler={handler}
|
|
88
|
-
type={'visit-note'}
|
|
89
|
-
/>,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const button = screen.getByRole('button', { name: /Visit note/i });
|
|
93
|
-
expect(button).toBeInTheDocument();
|
|
94
|
-
|
|
95
|
-
expect(button).not.toHaveClass('active');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('should have active className if workspace is active', async () => {
|
|
99
|
-
(useWorkspaces as jest.Mock).mockReturnValue({
|
|
100
|
-
workspaces: [{ type: 'visit-note' }, { type: 'order' }],
|
|
101
|
-
workspaceWindowState: 'normal',
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
mockedUseLayoutType.mockReturnValue('tablet');
|
|
105
|
-
|
|
106
|
-
const handler = jest.fn();
|
|
107
|
-
|
|
108
|
-
render(
|
|
109
|
-
<SiderailNavButton
|
|
110
|
-
name={'visit-note-nav-button'}
|
|
111
|
-
getIcon={(props) => <Pen {...props} />}
|
|
112
|
-
label={'Visit note'}
|
|
113
|
-
iconDescription={'Note'}
|
|
114
|
-
handler={handler}
|
|
115
|
-
type={'visit-note'}
|
|
116
|
-
/>,
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
const button = screen.getByRole('button', { name: /Visit note/i });
|
|
120
|
-
expect(button).toBeInTheDocument();
|
|
121
|
-
|
|
122
|
-
expect(button).toHaveClass('active');
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('should not display active className if workspace is active but workspace window is hidden', async () => {
|
|
126
|
-
(useWorkspaces as jest.Mock).mockReturnValue({
|
|
127
|
-
workspaces: [{ type: 'visit-note' }, { type: 'order' }],
|
|
128
|
-
workspaceWindowState: 'hidden',
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
mockedUseLayoutType.mockReturnValue('tablet');
|
|
132
|
-
|
|
133
|
-
const handler = jest.fn();
|
|
134
|
-
|
|
135
|
-
render(
|
|
136
|
-
<SiderailNavButton
|
|
137
|
-
name={'visit-note-nav-button'}
|
|
138
|
-
getIcon={(props) => <Pen {...props} />}
|
|
139
|
-
label={'Visit note'}
|
|
140
|
-
iconDescription={'Note'}
|
|
141
|
-
handler={handler}
|
|
142
|
-
type={'visit-note'}
|
|
143
|
-
/>,
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
const button = screen.getByRole('button');
|
|
147
|
-
expect(button).toBeInTheDocument();
|
|
148
|
-
|
|
149
|
-
expect(button).not.toHaveClass('active');
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('should display desktop view', async () => {
|
|
153
|
-
const user = userEvent.setup();
|
|
154
|
-
|
|
155
|
-
(useWorkspaces as jest.Mock).mockReturnValue({
|
|
156
|
-
workspaces: [{ type: 'order' }],
|
|
157
|
-
workspaceWindowState: 'normal',
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
mockedUseLayoutType.mockReturnValue('small-desktop');
|
|
161
|
-
|
|
162
|
-
const handler = jest.fn();
|
|
163
|
-
|
|
164
|
-
render(
|
|
165
|
-
<SiderailNavButton
|
|
166
|
-
name={'visit-note-nav-button'}
|
|
167
|
-
getIcon={(props) => <Pen {...props} />}
|
|
168
|
-
label={'Visit note'}
|
|
169
|
-
iconDescription={'Note'}
|
|
170
|
-
handler={handler}
|
|
171
|
-
type={'visit-note'}
|
|
172
|
-
/>,
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
expect(screen.getByTestId('pen-icon')).toBeInTheDocument();
|
|
176
|
-
expect(screen.getByTestId('pen-icon').innerHTML).toBe('size: 16');
|
|
177
|
-
|
|
178
|
-
const button = screen.getByRole('button');
|
|
179
|
-
expect(button).toBeInTheDocument();
|
|
180
|
-
await user.click(button);
|
|
181
|
-
expect(handler).toBeCalled();
|
|
182
|
-
|
|
183
|
-
expect(button).not.toHaveClass('active');
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('should display have active className if workspace is not active', async () => {
|
|
187
|
-
(useWorkspaces as jest.Mock).mockReturnValue({
|
|
188
|
-
workspaces: [{ type: 'order' }, { type: 'visit-note' }],
|
|
189
|
-
workspaceWindowState: 'normal',
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
mockedUseLayoutType.mockReturnValue('small-desktop');
|
|
193
|
-
|
|
194
|
-
const handler = jest.fn();
|
|
195
|
-
|
|
196
|
-
render(
|
|
197
|
-
<SiderailNavButton
|
|
198
|
-
name={'visit-note-nav-button'}
|
|
199
|
-
getIcon={(props) => <Pen {...props} />}
|
|
200
|
-
label={'Visit note'}
|
|
201
|
-
iconDescription={'Note'}
|
|
202
|
-
handler={handler}
|
|
203
|
-
type={'visit-note'}
|
|
204
|
-
/>,
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
const button = screen.getByRole('button');
|
|
208
|
-
expect(button).toBeInTheDocument();
|
|
209
|
-
|
|
210
|
-
expect(button).not.toHaveClass('active');
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it('should display active className if workspace is active and workspace window is normal', async () => {
|
|
214
|
-
(useWorkspaces as jest.Mock).mockReturnValue({
|
|
215
|
-
workspaces: [{ type: 'visit-note' }, { type: 'order' }],
|
|
216
|
-
workspaceWindowState: 'normal',
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
mockedUseLayoutType.mockReturnValue('small-desktop');
|
|
220
|
-
|
|
221
|
-
const handler = jest.fn();
|
|
222
|
-
|
|
223
|
-
render(
|
|
224
|
-
<SiderailNavButton
|
|
225
|
-
name={'visit-note-nav-button'}
|
|
226
|
-
getIcon={(props) => <Pen {...props} />}
|
|
227
|
-
label={'Visit note'}
|
|
228
|
-
iconDescription={'Note'}
|
|
229
|
-
handler={handler}
|
|
230
|
-
type={'visit-note'}
|
|
231
|
-
/>,
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
const button = screen.getByRole('button');
|
|
235
|
-
expect(button).toBeInTheDocument();
|
|
236
|
-
|
|
237
|
-
expect(button).toHaveClass('active');
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it('should not display active className if workspace is active but workspace window is hidden', async () => {
|
|
241
|
-
(useWorkspaces as jest.Mock).mockReturnValue({
|
|
242
|
-
workspaces: [{ type: 'visit-note' }, { type: 'order' }],
|
|
243
|
-
workspaceWindowState: 'hidden',
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
mockedUseLayoutType.mockReturnValue('small-desktop');
|
|
247
|
-
|
|
248
|
-
const handler = jest.fn();
|
|
249
|
-
|
|
250
|
-
render(
|
|
251
|
-
<SiderailNavButton
|
|
252
|
-
name={'visit-note-nav-button'}
|
|
253
|
-
getIcon={(props) => <Pen {...props} />}
|
|
254
|
-
label={'Visit note'}
|
|
255
|
-
iconDescription={'Note'}
|
|
256
|
-
handler={handler}
|
|
257
|
-
type={'visit-note'}
|
|
258
|
-
/>,
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
const button = screen.getByRole('button');
|
|
262
|
-
expect(button).toBeInTheDocument();
|
|
263
|
-
|
|
264
|
-
expect(button).not.toHaveClass('active');
|
|
265
|
-
});
|
|
266
|
-
});
|
package/src/types/workspace.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/* The possible states a workspace window can be opened in. */
|
|
2
|
-
export type WorkspaceWindowState = 'maximized' | 'hidden' | 'normal';
|
|
3
|
-
|
|
4
|
-
export interface CloseWorkspaceOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Whether to close the workspace ignoring all the changes present in the workspace.
|
|
7
|
-
*
|
|
8
|
-
* If ignoreChanges is true, the user will not be prompted to save changes before closing
|
|
9
|
-
* even if the `testFcn` passed to `promptBeforeClosing` returns `true`.
|
|
10
|
-
*/
|
|
11
|
-
ignoreChanges?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* If you want to take an action after the workspace is closed, you can pass your function as
|
|
14
|
-
* `onWorkspaceClose`. This function will be called only after the workspace is closed, given
|
|
15
|
-
* that the user might be shown a prompt.
|
|
16
|
-
* @returns void
|
|
17
|
-
*/
|
|
18
|
-
onWorkspaceClose?: () => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** The default parameters received by all workspaces */
|
|
22
|
-
export interface DefaultWorkspaceProps {
|
|
23
|
-
/**
|
|
24
|
-
* Call this function to close the workspace. This function will prompt the user
|
|
25
|
-
* if there are any unsaved changes to workspace.
|
|
26
|
-
*
|
|
27
|
-
* You can pass `onWorkspaceClose` function to be called when the workspace is finally
|
|
28
|
-
* closed, given the user forcefully closes the workspace.
|
|
29
|
-
*/
|
|
30
|
-
closeWorkspace(closeWorkspaceOptions?: CloseWorkspaceOptions): void;
|
|
31
|
-
/**
|
|
32
|
-
* Call this with a no-args function that returns true if the user should be prompted before
|
|
33
|
-
* this workspace is closed; e.g. if there is unsaved data.
|
|
34
|
-
*/
|
|
35
|
-
promptBeforeClosing(testFcn: () => boolean): void;
|
|
36
|
-
/**
|
|
37
|
-
* Call this function to close the workspace after the form is saved. This function
|
|
38
|
-
* will directly close the workspace without any prompt
|
|
39
|
-
*/
|
|
40
|
-
closeWorkspaceWithSavedChanges(closeWorkspaceOptions?: CloseWorkspaceOptions): void;
|
|
41
|
-
patientUuid: string;
|
|
42
|
-
handlePostResponse?(): void;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface WorkspaceWindowSize {
|
|
46
|
-
size: WorkspaceWindowState;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface WorkspaceWindowSizeProviderProps {
|
|
50
|
-
children?: React.ReactNode;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface WorkspaceWindowSizeContext {
|
|
54
|
-
windowSize: WorkspaceWindowSize;
|
|
55
|
-
updateWindowSize?(value: WorkspaceWindowState): any;
|
|
56
|
-
active: boolean;
|
|
57
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import { usePatient } from '@openmrs/esm-framework';
|
|
3
|
-
import {
|
|
4
|
-
launchPatientWorkspace,
|
|
5
|
-
launchStartVisitPrompt,
|
|
6
|
-
useVisitOrOfflineVisit,
|
|
7
|
-
} from '@openmrs/esm-patient-common-lib';
|
|
8
|
-
import { useSystemVisitSetting } from './useSystemVisitSetting';
|
|
9
|
-
|
|
10
|
-
export function useLaunchWorkspaceRequiringVisit<T extends object>(workspaceName: string) {
|
|
11
|
-
const { patientUuid } = usePatient();
|
|
12
|
-
const { systemVisitEnabled } = useSystemVisitSetting();
|
|
13
|
-
const { currentVisit } = useVisitOrOfflineVisit(patientUuid);
|
|
14
|
-
|
|
15
|
-
const launchWorkspace = useCallback(
|
|
16
|
-
(additionalProps?: T) => {
|
|
17
|
-
if (!systemVisitEnabled || currentVisit) {
|
|
18
|
-
launchPatientWorkspace(workspaceName, additionalProps);
|
|
19
|
-
} else {
|
|
20
|
-
launchStartVisitPrompt();
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
[currentVisit, systemVisitEnabled, workspaceName],
|
|
24
|
-
);
|
|
25
|
-
return launchWorkspace;
|
|
26
|
-
}
|
package/src/workspaces/index.ts
DELETED