Skip to content

Commit cc6e4e2

Browse files
authored
Merge pull request #4692 from msupply-foundation/3797-hotfix-internal-order-toolbar-layout
3797 move internal order toolbar content to side panel
2 parents 1def978 + 4d083e3 commit cc6e4e2

File tree

8 files changed

+159
-131
lines changed

8 files changed

+159
-131
lines changed

client/packages/common/src/hooks/useDetailPanel/useDetailPanel.tsx

+31-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect } from 'react';
22
import { create } from 'zustand';
33
import { useTranslation } from '@common/intl';
44
import { SidebarIcon, ButtonWithIcon } from '../../ui';
@@ -8,31 +8,43 @@ type DetailPanelController = {
88
hasUserSet: boolean;
99
isOpen: boolean;
1010
shouldPersist: boolean;
11+
enabled: boolean;
1112
open: () => void;
1213
close: () => void;
14+
setEnabled: (enabled: boolean) => void;
1315
};
1416

1517
export const useDetailPanelStore = create<DetailPanelController>(set => {
1618
const initialValue = LocalStorage.getItem('/detailpanel/open');
1719

1820
return {
21+
enabled: false,
1922
hasUserSet: initialValue !== null,
2023
isOpen: false,
2124
shouldPersist: true,
2225
open: () =>
23-
set(state => ({
24-
...state,
25-
isOpen: true,
26-
hasUserSet: true,
27-
shouldPersist: true,
28-
})),
26+
set(state =>
27+
state.enabled
28+
? {
29+
...state,
30+
isOpen: true,
31+
hasUserSet: true,
32+
shouldPersist: true,
33+
}
34+
: state
35+
),
2936
close: () =>
30-
set(state => ({
31-
...state,
32-
isOpen: false,
33-
hasUserSet: true,
34-
shouldPersist: true,
35-
})),
37+
set(state =>
38+
state.enabled
39+
? {
40+
...state,
41+
isOpen: false,
42+
hasUserSet: true,
43+
shouldPersist: true,
44+
}
45+
: state
46+
),
47+
setEnabled: (enabled: boolean) => set(state => ({ ...state, enabled })),
3648
};
3749
});
3850

@@ -43,7 +55,7 @@ interface DetailPanel {
4355
}
4456
export const useDetailPanel = (): DetailPanel => {
4557
const t = useTranslation();
46-
const { isOpen, open, close } = useDetailPanelStore();
58+
const { isOpen, open, close, setEnabled } = useDetailPanelStore();
4759
const OpenButton = isOpen ? null : (
4860
<ButtonWithIcon
4961
Icon={<SidebarIcon />}
@@ -52,6 +64,11 @@ export const useDetailPanel = (): DetailPanel => {
5264
/>
5365
);
5466

67+
useEffect(() => {
68+
setEnabled(true);
69+
return () => setEnabled(false);
70+
}, []);
71+
5572
return { OpenButton, open, close };
5673
};
5774

client/packages/common/src/intl/locales/en/app.json

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"cmdk.goto-stock": "Go to: Stock",
3333
"cmdk.goto-stocktakes": "Go to: Stocktakes",
3434
"cmdk.goto-suppliers": "Go to: Suppliers",
35+
"cmdk.more-info-close": "Close the more info panel",
36+
"cmdk.more-info-open": "Open the more info panel",
3537
"cmdk.placeholder": "Type a command or search",
3638
"customer-requisition": "Requisitions",
3739
"customers": "Customers",

client/packages/common/src/intl/locales/en/common.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
"heading.404": "Feeling lost?",
128128
"heading.actions": "Actions",
129129
"heading.add-item": "Add Item",
130-
"heading.additional-info": "Additional Info",
130+
"heading.additional-info": "Additional info",
131131
"heading.are-you-sure": "Are you sure?",
132132
"heading.barcode-scanners": "Barcode Scanners",
133133
"heading.comment": "Comment",

client/packages/common/src/intl/locales/en/replenishment.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
"heading.charges": "Charges",
3737
"heading.consumption-history": "Consumption History (monthly)",
3838
"heading.edit-tax-rate": "Edit tax rate percentage",
39+
"heading.order-info": "Order info",
40+
"heading.program-info": "Program info",
3941
"heading.related-documents": "Related documents",
4042
"heading.requested-to-suggested": "Request Suggested",
4143
"heading.return-items": "Return Items",
@@ -48,7 +50,7 @@
4850
"heading.total": "Total",
4951
"info.automatic-shipment": "This shipment was created automatically, as the result of an Outbound Shipment in another store.",
5052
"info.automatic-shipment-no-edit": "You are unable to edit details until the status is confirmed as Delivered.",
51-
"info.cannot-edit-program-requisition": "Cannot edit supplier, minimum MOS, maximum MOS or add items in a program requisition.",
53+
"info.cannot-edit-program-requisition": "Cannot edit supplier, reorder threshold MOS, target MOS or add items in a program requisition.",
5254
"info.manual-shipment": "This shipment was created manually. The delivery status will not be automatically updated.",
5355
"label.add-batch": "Add batch",
5456
"label.add-charges": "Add charges",

client/packages/host/src/CommandK.tsx

+21-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
StoreModeNodeType,
2020
useRegisterActions,
2121
useConfirmationModal,
22+
useDetailPanelStore,
2223
} from '@openmsupply-client/common';
2324
import { AppRoute } from '@openmsupply-client/config';
2425
import { Action } from 'kbar/lib/types';
@@ -97,12 +98,13 @@ const Actions = () => {
9798
message: t('messages.logout-confirm'),
9899
title: t('heading.logout-confirm'),
99100
});
101+
const { close, open } = useDetailPanelStore();
100102

101103
const actions = [
102104
{
103105
id: 'navigation-drawer:toggle',
104-
name: `${t('cmdk.drawer-toggle')} (m)`,
105-
shortcut: ['m'],
106+
name: `${t('cmdk.drawer-toggle')} (n)`,
107+
shortcut: ['n'],
106108
keywords: 'drawer, close',
107109
perform: () => drawer.toggle(),
108110
},
@@ -304,6 +306,23 @@ const Actions = () => {
304306
),
305307
});
306308

309+
actions.push(
310+
{
311+
id: 'action:more-open',
312+
name: `${t('cmdk.more-info-close')} (m+o)`,
313+
keywords: 'more open',
314+
shortcut: ['m', 'o'],
315+
perform: open,
316+
},
317+
{
318+
id: 'action:more-close',
319+
name: `${t('cmdk.more-info-close')} (m+c)`,
320+
keywords: 'more close',
321+
shortcut: ['m', 'c'],
322+
perform: close,
323+
}
324+
);
325+
307326
if (store?.preferences.vaccineModule ?? false) {
308327
actions.push({
309328
id: 'navigation:coldchain-monitoring',

client/packages/requisitions/src/RequestRequisition/DetailView/Toolbar/ToolbarActions.tsx client/packages/requisitions/src/RequestRequisition/DetailView/OrderInfoSection.tsx

+36-38
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
import React from 'react';
22
import {
3-
Switch,
43
Grid,
54
Autocomplete,
6-
InputWithLabelRow,
75
useTranslation,
86
useConfirmationModal,
7+
DetailPanelSection,
8+
PanelRow,
9+
PanelLabel,
10+
PanelField,
911
} from '@openmsupply-client/common';
10-
import { useRequest, useHideOverStocked } from '../../api';
12+
import { useRequest } from '../api';
13+
import { getApprovalStatusKey } from '../../utils';
1114

1215
const months = [1, 2, 3, 4, 5, 6];
1316

14-
export const ToolbarActions = () => {
15-
const { on, toggle } = useHideOverStocked();
17+
export const OrderInfoSection = () => {
1618
const t = useTranslation('replenishment');
1719
const isDisabled = useRequest.utils.isDisabled();
1820
const isProgram = useRequest.utils.isProgram();
19-
const { minMonthsOfStock, maxMonthsOfStock, update } =
20-
useRequest.document.fields(['minMonthsOfStock', 'maxMonthsOfStock']);
21+
const { minMonthsOfStock, maxMonthsOfStock, linkedRequisition, update } =
22+
useRequest.document.fields([
23+
'minMonthsOfStock',
24+
'maxMonthsOfStock',
25+
'programName',
26+
'linkedRequisition',
27+
]);
28+
const { usesRemoteAuthorisation } = useRequest.utils.isRemoteAuthorisation();
2129

2230
const getMinMOSConfirmation = useConfirmationModal({
2331
title: t('heading.are-you-sure'),
@@ -35,12 +43,19 @@ export const ToolbarActions = () => {
3543
});
3644

3745
return (
38-
<Grid container gap={1} direction="column">
39-
<Grid item>
40-
<InputWithLabelRow
41-
labelWidth="150px"
42-
label={t('label.min-months-of-stock')}
43-
Input={
46+
<DetailPanelSection title={t('heading.order-info')}>
47+
<Grid container gap={0.5} key="order-info">
48+
{usesRemoteAuthorisation && (
49+
<PanelRow>
50+
<PanelLabel>{t('label.auth-status')}</PanelLabel>
51+
<PanelField>
52+
{t(getApprovalStatusKey(linkedRequisition?.approvalStatus))}
53+
</PanelField>
54+
</PanelRow>
55+
)}
56+
<PanelRow>
57+
<PanelLabel>{t('label.min-months-of-stock')}</PanelLabel>
58+
<PanelField>
4459
<Autocomplete
4560
disabled={isDisabled || isProgram}
4661
clearIcon={null}
@@ -78,14 +93,11 @@ export const ToolbarActions = () => {
7893
}}
7994
getOptionDisabled={option => option.value > maxMonthsOfStock}
8095
/>
81-
}
82-
/>
83-
</Grid>
84-
<Grid item>
85-
<InputWithLabelRow
86-
labelWidth="150px"
87-
label={t('label.max-months-of-stock')}
88-
Input={
96+
</PanelField>
97+
</PanelRow>
98+
<PanelRow>
99+
<PanelLabel>{t('label.max-months-of-stock')}</PanelLabel>
100+
<PanelField>
89101
<Autocomplete
90102
disabled={isDisabled || isProgram}
91103
clearIcon={null}
@@ -107,23 +119,9 @@ export const ToolbarActions = () => {
107119
}
108120
getOptionDisabled={option => option.value < minMonthsOfStock}
109121
/>
110-
}
111-
/>
112-
</Grid>
113-
<Grid item>
114-
<InputWithLabelRow
115-
labelWidth="225px"
116-
label={t('label.hide-stock-over-minimum')}
117-
Input={
118-
<Switch
119-
onChange={toggle}
120-
checked={on}
121-
color="secondary"
122-
size="small"
123-
/>
124-
}
125-
/>
122+
</PanelField>
123+
</PanelRow>
126124
</Grid>
127-
</Grid>
125+
</DetailPanelSection>
128126
);
129127
};

client/packages/requisitions/src/RequestRequisition/DetailView/SidePanel.tsx

+33
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,37 @@ import {
2626
} from '@openmsupply-client/common';
2727
import { useRequest } from '../api';
2828
import { AppRoute } from '@openmsupply-client/config';
29+
import { OrderInfoSection } from './OrderInfoSection';
30+
31+
const ProgramInfoSection: FC = () => {
32+
const { orderType, programName, period } = useRequest.document.fields([
33+
'orderType',
34+
'programName',
35+
'period',
36+
]);
37+
const t = useTranslation('replenishment');
38+
39+
return programName ? (
40+
<DetailPanelSection title={t('heading.program-info')}>
41+
<Grid container gap={0.5} key="program-info">
42+
<PanelRow>
43+
<PanelLabel>{t('label.order-type')}</PanelLabel>
44+
<PanelField>{orderType ?? ''}</PanelField>
45+
</PanelRow>
46+
<PanelRow>
47+
<PanelLabel>{t('label.program')}</PanelLabel>
48+
<PanelField>{programName ?? ''}</PanelField>
49+
</PanelRow>
50+
<PanelRow>
51+
<PanelLabel>{t('label.period')}</PanelLabel>
52+
<PanelField>{period?.name ?? ''}</PanelField>
53+
</PanelRow>
54+
</Grid>
55+
</DetailPanelSection>
56+
) : (
57+
<></>
58+
);
59+
};
2960

3061
const AdditionalInfoSection: FC = () => {
3162
const isDisabled = useRequest.utils.isDisabled();
@@ -189,6 +220,8 @@ export const SidePanel: FC = () => {
189220
</>
190221
}
191222
>
223+
<OrderInfoSection />
224+
<ProgramInfoSection />
192225
<AdditionalInfoSection />
193226
<RelatedDocumentsSection />
194227
</DetailPanelPortal>

0 commit comments

Comments
 (0)