Skip to content

Commit d4b0564

Browse files
Merge branch 'develop' into bugfix/DEVSU-2194-retain-report-text-formatting
2 parents 8c4fc47 + 450ad37 commit d4b0564

File tree

33 files changed

+213
-233
lines changed

33 files changed

+213
-233
lines changed

app/components/IPRWYSIWYGEditor/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
Box,
1515
} from '@mui/material';
1616
import './index.scss';
17+
import Underline from '@tiptap/extension-underline';
1718
import {
1819
useEditor, EditorContent, Editor,
1920
} from '@tiptap/react';
@@ -25,6 +26,7 @@ import {
2526

2627
const extensions = [
2728
StarterKit,
29+
Underline,
2830
];
2931

3032
const MenuBarButton = forwardRef<HTMLButtonElement, ToggleButtonProps>(
@@ -61,7 +63,7 @@ const MenuBar = ({
6163
<FormatItalic />
6264
</MenuBarButton>
6365
<MenuBarButton
64-
onClick={() => editor.chain().focus().toggleCode().run()}
66+
onClick={() => editor.chain().focus().toggleUnderline().run()}
6567
value="underline"
6668
selected={editor.isActive('underline')}
6769
>

app/components/SignatureCard/SignatureCard.stories.tsx

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
import React from 'react';
1+
import React, { useMemo } from 'react';
22
import { action } from '@storybook/addon-actions';
33
import { Story } from '@storybook/react/types-6-0';
44

5-
import UserContext from '@/context/UserContext';
5+
import ReportContext from '@/context/ReportContext';
66
import SignatureCard, { SignatureCardProps } from '.';
77

88
export default {
99
title: 'components/SignatureCard',
1010
component: SignatureCard,
1111
};
1212

13-
const Template = (args) => (
14-
<UserContext.Provider value={{ canEdit: true }}>
15-
<SignatureCard {...args} />
16-
</UserContext.Provider>
17-
);
13+
const Template = (args) => {
14+
const value = useMemo(() => ({
15+
canEdit: true,
16+
report: null,
17+
setReport: () => { },
18+
}), []);
19+
20+
return (
21+
<ReportContext.Provider value={value}>
22+
<SignatureCard {...args} />
23+
</ReportContext.Provider>
24+
);
25+
};
1826

1927
export const Unsigned: Story<SignatureCardProps> = Template.bind({});
2028

app/components/SignatureCard/__tests__/SignatureCard.test.tsx

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
import React from 'react';
22
import { render, screen, fireEvent } from '@testing-library/react';
33

4-
import UserContext from '@/context/UserContext';
5-
import SignatureCard from '..';
4+
import ReportContext from '@/context/ReportContext';
5+
import SignatureCard, { SignatureType } from '..';
66
import { mockNullData, mockNullObjectData, mockObjectData } from './mockData';
77

88
describe('SignatureCard', () => {
99
test('Author and sign button are visible', async () => {
1010
render(
11-
<UserContext.Provider value={{ canEdit: true, setCanEdit: () => {} }}>
11+
<ReportContext.Provider value={{ canEdit: true, report: null, setReport: () => {} }}>
1212
<SignatureCard
1313
title="Author"
1414
type="author"
1515
signatures={null}
1616
onClick={() => {}}
1717
/>
18-
</UserContext.Provider>,
18+
</ReportContext.Provider>,
1919
);
2020
expect(await screen.findByText('Author')).toBeInTheDocument();
2121
expect(await screen.findByRole('button', { name: 'Sign' })).toBeInTheDocument();
2222
});
2323

2424
test('Sign button is not visible without edit permissions', async () => {
2525
render(
26-
<UserContext.Provider value={{ canEdit: false, setCanEdit: () => {} }}>
26+
<ReportContext.Provider value={{ canEdit: false, report: null, setReport: () => {} }}>
2727
<SignatureCard
2828
title="Author"
2929
type="author"
3030
signatures={null}
3131
onClick={() => {}}
3232
/>
33-
</UserContext.Provider>,
33+
</ReportContext.Provider>,
3434
);
3535
expect(screen.queryByRole('button', { name: 'Sign' })).not.toBeInTheDocument();
3636
});
3737

3838
test('Sign button calls onClick', async () => {
3939
const handleClick = jest.fn();
4040
render(
41-
<UserContext.Provider value={{ canEdit: true, setCanEdit: () => {} }}>
41+
<ReportContext.Provider value={{ canEdit: true, report: null, setReport: () => {} }}>
4242
<SignatureCard
4343
title="Author"
4444
type="author"
4545
signatures={null}
4646
onClick={handleClick}
4747
/>
48-
</UserContext.Provider>,
48+
</ReportContext.Provider>,
4949
);
5050
fireEvent.click(await screen.findByRole('button', { name: 'Sign' }));
5151

@@ -54,44 +54,44 @@ describe('SignatureCard', () => {
5454

5555
test('Sign button is visible when reviewerSignature is null', async () => {
5656
render(
57-
<UserContext.Provider value={{ canEdit: true, setCanEdit: () => {} }}>
57+
<ReportContext.Provider value={{ canEdit: true, report: null, setReport: () => {} }}>
5858
<SignatureCard
5959
title="Reviewer"
6060
type="reviewer"
61-
signatures={mockNullData}
61+
signatures={mockNullData as SignatureType}
6262
onClick={() => {}}
6363
/>
64-
</UserContext.Provider>,
64+
</ReportContext.Provider>,
6565
);
6666

6767
expect(await screen.findByRole('button', { name: 'Sign' })).toBeInTheDocument();
6868
});
6969

7070
test('Sign button is visible when reviewerSignature has null data', async () => {
7171
render(
72-
<UserContext.Provider value={{ canEdit: true, setCanEdit: () => {} }}>
72+
<ReportContext.Provider value={{ canEdit: true, report: null, setReport: () => {} }}>
7373
<SignatureCard
7474
title="Reviewer"
7575
type="reviewer"
76-
signatures={mockNullObjectData}
76+
signatures={mockNullObjectData as SignatureType}
7777
onClick={() => {}}
7878
/>
79-
</UserContext.Provider>,
79+
</ReportContext.Provider>,
8080
);
8181

8282
expect(await screen.findByRole('button', { name: 'Sign' })).toBeInTheDocument();
8383
});
8484

8585
test('Reviewer name & remove signature button are visible', async () => {
8686
render(
87-
<UserContext.Provider value={{ canEdit: true, setCanEdit: () => {} }}>
87+
<ReportContext.Provider value={{ canEdit: true, report: null, setReport: () => {} }}>
8888
<SignatureCard
8989
title="Reviewer"
9090
type="reviewer"
91-
signatures={mockObjectData}
91+
signatures={mockObjectData as SignatureType}
9292
onClick={() => {}}
9393
/>
94-
</UserContext.Provider>,
94+
</ReportContext.Provider>,
9595
);
9696

9797
expect(screen.queryByRole('button', { name: 'Sign' })).not.toBeInTheDocument();
@@ -100,15 +100,15 @@ describe('SignatureCard', () => {
100100

101101
test('No buttons are visible in print view', async () => {
102102
render(
103-
<UserContext.Provider value={{ canEdit: true, setCanEdit: () => {} }}>
103+
<ReportContext.Provider value={{ canEdit: true, report: null, setReport: () => {} }}>
104104
<SignatureCard
105105
title="Reviewer"
106106
type="reviewer"
107-
signatures={mockObjectData}
107+
signatures={mockObjectData as SignatureType}
108108
onClick={() => {}}
109109
isPrint
110110
/>
111-
</UserContext.Provider>,
111+
</ReportContext.Provider>,
112112
);
113113

114114
expect(screen.queryByRole('button')).not.toBeInTheDocument();

app/components/SignatureCard/index.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import GestureIcon from '@mui/icons-material/Gesture';
1111
import RemoveCircleIcon from '@mui/icons-material/RemoveCircle';
1212

1313
import { UserType } from '@/common';
14-
import { useUser } from '@/context/UserContext';
14+
import useReport from '@/hooks/useReport';
1515
import { formatDate } from '@/utils/date';
1616
import { SignatureType, SignatureUserType } from './types';
1717

@@ -36,7 +36,7 @@ const SignatureCard = ({
3636
type,
3737
isPrint = false,
3838
}: SignatureCardProps): JSX.Element => {
39-
const { canEdit } = useUser();
39+
const { canEdit } = useReport();
4040
const [userSignature, setUserSignature] = useState<UserType>();
4141

4242
useEffect(() => {

app/context/ReportContext/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import {
44
} from './types';
55

66
const ReportContext = React.createContext<ReportContextType>({
7+
canEdit: false,
78
report: null,
89
setReport: () => {},
910
});
1011

1112
export default ReportContext;
1213

1314
export type {
15+
ReportContextType,
1416
ReportType,
1517
PatientInformationType,
1618
SampleInfoType,

app/context/ReportContext/types.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React from 'react';
55
type PatientInformationType = {
66
age: string | null;
77
biopsySite: string | null;
8-
caseType: 'Pediatric' | 'Adult';
8+
caseType: 'Pediatric' | 'Adult' | null;
99
constitutionalProtocol: string | null;
1010
constitutionalSample: string | null;
1111
diagnosis: string | null;
@@ -59,6 +59,8 @@ type ReportType = {
5959
} & RecordDefaults;
6060

6161
type ReportContextType = {
62+
/** Is current report editable by user */
63+
canEdit: boolean;
6264
/** Current report that's being viewed */
6365
report: ReportType | null,
6466
/** Set new current report */

app/context/ResourceContext/index.tsx

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import React, {
2-
createContext, ReactChild, useState, useEffect, useMemo, useContext,
2+
createContext, ReactChild, useState, useEffect, useMemo,
33
} from 'react';
44
import { checkAccess, ALL_ROLES } from '@/utils/checkAccess';
55
import useSecurity from '@/hooks/useSecurity';
66
import ResourceContextType from './types';
7-
import ReportContext from '../ReportContext';
87

98
const GERMLINE_ACCESS = ['admin', 'analyst', 'bioinformatician', 'projects', 'manager'];
109
const GERMLINE_BLOCK = ALL_ROLES;
@@ -14,8 +13,7 @@ const ADMIN_ACCESS = ['admin'];
1413
const ADMIN_BLOCK = ALL_ROLES;
1514

1615
const useResources = (): ResourceContextType => {
17-
const { userDetails: { groups, ident: userIdent } } = useSecurity();
18-
const { report } = useContext(ReportContext);
16+
const { userDetails: { groups } } = useSecurity();
1917

2018
const [germlineAccess, setGermlineAccess] = useState(false);
2119
const [reportsAccess, setReportsAccess] = useState(false);
@@ -45,19 +43,6 @@ const useResources = (): ResourceContextType => {
4543
}
4644
}, [groups]);
4745

48-
/**
49-
* Check report specific permissions if user isn't admin
50-
*/
51-
useEffect(() => {
52-
if (!adminAccess) {
53-
if (report && report.users.some(({ ident: i }) => i === userIdent)) {
54-
setReportEditAccess(true);
55-
} else {
56-
setReportEditAccess(false);
57-
}
58-
}
59-
}, [report, userIdent, adminAccess]);
60-
6146
return {
6247
germlineAccess,
6348
reportsAccess,

app/context/UserContext/index.tsx

-58
This file was deleted.

app/context/UserContext/interfaces.ts

-7
This file was deleted.

app/hooks/useReport.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { useContext } from 'react';
2+
3+
import ReportContext, { ReportContextType } from '@/context/ReportContext';
4+
5+
const useReport = (): ReportContextType => useContext(ReportContext);
6+
7+
export default useReport;

app/utils/checkAccess.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const checkAccess = (
2626
allowList: string[],
2727
blockList: string[] = ALL_ROLES,
2828
): boolean => {
29+
if (groups.length < 1) { return false; }
2930
const groupNames = groups.map((group) => group.name.toLowerCase());
3031
const isAllowed = allowList.includes('*') || allowList.some((group) => groupNames.includes(group.toLowerCase()));
3132
const isBlocked = blockList.some((group) => groupNames.includes(group.toLowerCase()));

0 commit comments

Comments
 (0)