Skip to content

Commit 63d9479

Browse files
committed
Merge branch '1.6.02' of https://github.com/msupply-foundation/open-msupply into 1.6.02
2 parents 98a479f + 4d150e1 commit 63d9479

40 files changed

+487
-337
lines changed

client/packages/common/src/hooks/useEditModal/useEditModal.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@ export const useEditModal = <T>(): EditModalState<T> => {
2020
const [entity, setEntity] = useState<T | null>(null);
2121
const [mode, setMode] = useState<ModalMode | null>(null);
2222

23-
const onOpen = useCallback((entity: T | null = null) => {
24-
setEntity(entity);
25-
setMode(entity ? ModalMode.Update : ModalMode.Create);
26-
modalControl.toggleOn();
27-
}, []);
23+
const onOpen = useCallback(
24+
(entity: T | null = null) => {
25+
setEntity(entity);
26+
setMode(entity ? ModalMode.Update : ModalMode.Create);
27+
modalControl.toggleOn();
28+
},
29+
[modalControl]
30+
);
2831

2932
const onClose = useCallback(() => {
3033
setMode(null);
3134
setEntity(null);
3235
modalControl.toggleOff();
33-
}, []);
36+
}, [modalControl]);
3437

3538
return {
3639
onOpen,

client/packages/common/src/types/schema.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4792,6 +4792,7 @@ export type StocktakeLineConnector = {
47924792

47934793
export type StocktakeLineFilterInput = {
47944794
id?: InputMaybe<EqualFilterStringInput>;
4795+
itemCodeOrName?: InputMaybe<StringFilterInput>;
47954796
locationId?: InputMaybe<EqualFilterStringInput>;
47964797
stocktakeId?: InputMaybe<EqualFilterStringInput>;
47974798
};
@@ -4822,7 +4823,7 @@ export enum StocktakeLineSortFieldInput {
48224823
ExpiryDate = 'expiryDate',
48234824
ItemCode = 'itemCode',
48244825
ItemName = 'itemName',
4825-
LocationName = 'locationName',
4826+
LocationCode = 'locationCode',
48264827
PackSize = 'packSize'
48274828
}
48284829

client/packages/common/src/ui/components/navigation/Tabs/DetailTabs.tsx

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FC, ReactNode, useState, useEffect } from 'react';
1+
import React, { FC, ReactNode, useState, useEffect, useCallback } from 'react';
22
import TabContext from '@mui/lab/TabContext';
33
import { Box } from '@mui/material';
44
import {
@@ -25,24 +25,36 @@ interface DetailTabsProps {
2525
tabs: TabDefinition[];
2626
requiresConfirmation?: (tab: string) => boolean;
2727
}
28+
29+
const handleResize = debounce(
30+
() => window.dispatchEvent(new Event('resize')),
31+
100
32+
);
33+
2834
export const DetailTabs: FC<DetailTabsProps> = ({
2935
tabs,
3036
requiresConfirmation = () => false,
3137
}) => {
38+
const isValidTab = useCallback(
39+
(tab?: string): tab is string =>
40+
!!tab && tabs.some(({ value }) => value === tab),
41+
[tabs]
42+
);
43+
3244
const { urlQuery, updateQuery } = useUrlQuery();
33-
const [currentTab, setCurrentTab] = useState<string>(tabs[0]?.value ?? '');
3445
const t = useTranslation();
46+
const currentUrlTab = urlQuery['tab'] as string | undefined;
47+
const currentTab = isValidTab(currentUrlTab)
48+
? currentUrlTab
49+
: tabs[0]?.value ?? '';
3550

3651
// Inelegant hack to force the "Underline" indicator for the currently active
3752
// tab to re-render in the correct position when one of the side "drawers" is
3853
// expanded. See issue #777 for more detail.
3954
const { isOpen: detailPanelOpen } = useDetailPanelStore();
4055
const { isOpen: drawerOpen } = useDrawer();
4156
const { showConfirmation } = useConfirmOnLeaving(false);
42-
const handleResize = debounce(
43-
() => window.dispatchEvent(new Event('resize')),
44-
100
45-
);
57+
4658
useEffect(() => {
4759
handleResize();
4860
}, [detailPanelOpen, drawerOpen]);
@@ -73,14 +85,9 @@ export const DetailTabs: FC<DetailTabsProps> = ({
7385
}
7486
};
7587

76-
const isValidTab = (tab?: string): tab is string =>
77-
!!tab && tabs.some(({ value }) => value === tab);
78-
7988
useEffect(() => {
8089
const tab = urlQuery['tab'] as string | undefined;
8190
if (isValidTab(tab)) {
82-
setCurrentTab(tab);
83-
8491
// store the query params for the current tab
8592
setTabQueryParams(value => {
8693
return {
@@ -89,7 +96,7 @@ export const DetailTabs: FC<DetailTabsProps> = ({
8996
};
9097
});
9198
}
92-
}, [urlQuery]);
99+
}, [isValidTab, urlQuery]);
93100

94101
return (
95102
<TabContext value={currentTab}>

client/packages/inventory/src/Stocktake/DetailView/AppBarButtons.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
useReport,
1919
} from '@openmsupply-client/system';
2020
import { JsonData } from '@openmsupply-client/programs';
21+
import { isStocktakeDisabled } from '../../utils';
2122

2223
interface AppBarButtonProps {
2324
onAddItem: (newState: boolean) => void;
@@ -26,11 +27,11 @@ interface AppBarButtonProps {
2627
export const AppBarButtonsComponent: FC<AppBarButtonProps> = ({
2728
onAddItem,
2829
}) => {
29-
const isDisabled = useStocktake.utils.isDisabled();
3030
const { OpenButton } = useDetailPanel();
3131
const t = useTranslation('common');
32-
const { data } = useStocktake.document.get();
3332
const { print, isPrinting } = useReport.utils.print();
33+
const { data } = useStocktake.document.get();
34+
const isDisabled = !data || isStocktakeDisabled(data);
3435

3536
const {
3637
queryParams: { sortBy },

client/packages/inventory/src/Stocktake/DetailView/ContentArea/ContentArea.tsx

+17-7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import {
33
DataTable,
44
useTranslation,
55
Box,
6-
useIsGrouped,
76
MiniTable,
87
createQueryParamsStore,
98
NothingHere,
109
useRowStyle,
1110
placeholderRowStyle,
11+
useUrlQueryParams,
12+
BasicSpinner,
1213
} from '@openmsupply-client/common';
1314
import { useStocktakeColumns, useExpansionColumns } from './columns';
1415
import { StocktakeLineFragment, useStocktake } from '../../api';
@@ -37,10 +38,10 @@ const Expando = ({
3738
};
3839

3940
interface ContentAreaProps {
41+
onAddItem: () => void;
4042
onRowClick:
4143
| null
4244
| ((item: StocktakeSummaryItem | StocktakeLineFragment) => void);
43-
onAddItem: () => void;
4445
}
4546

4647
const isUncounted = (line: StocktakeLineFragment): boolean =>
@@ -89,15 +90,22 @@ export const ContentArea: FC<ContentAreaProps> = ({
8990
onRowClick,
9091
}) => {
9192
const t = useTranslation('inventory');
92-
const { isGrouped } = useIsGrouped('stocktake');
93-
const { rows, onChangeSortBy, sortBy } = useStocktake.line.rows(isGrouped);
93+
const {
94+
updateSortQuery: onChangeSortBy,
95+
updatePaginationQuery,
96+
queryParams: { page, first, offset, sortBy },
97+
} = useUrlQueryParams({ initialSort: { key: 'itemName', dir: 'asc' } });
98+
const { isDisabled, isLoading, rows, totalLineCount } =
99+
useStocktake.line.rows();
94100
const columns = useStocktakeColumns({ onChangeSortBy, sortBy });
95-
const isDisabled = useStocktake.utils.isDisabled();
101+
const pagination = { page, first, offset };
96102

97103
useHighlightUncountedRows(rows);
98104

99-
return (
100-
<Box flexDirection="column" flex={1}>
105+
return isLoading ? (
106+
<BasicSpinner />
107+
) : (
108+
<Box flexDirection="column" flex={1} display="flex">
101109
<DataTable<StocktakeSummaryItem | StocktakeLineFragment>
102110
onRowClick={onRowClick}
103111
ExpandContent={Expando}
@@ -113,6 +121,8 @@ export const ContentArea: FC<ContentAreaProps> = ({
113121
/>
114122
}
115123
enableColumnSelection
124+
pagination={{ ...pagination, total: totalLineCount }}
125+
onChangePage={updatePaginationQuery}
116126
/>
117127
</Box>
118128
);

client/packages/inventory/src/Stocktake/DetailView/ContentArea/columns.ts

+16-77
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export const useStocktakeColumns = ({
9999
accessor: ({ rowData }) => {
100100
return rowData.item?.unitName ?? '';
101101
},
102+
sortable: false,
102103
},
103104
],
104105
[
@@ -119,41 +120,26 @@ export const useStocktakeColumns = ({
119120
[
120121
'expiryDate',
121122
{
122-
getSortValue: row =>
123-
getColumnPropertyAsString(row, [
124-
{ path: ['lines', 'expiryDate'] },
125-
{ path: ['expiryDate'], default: '' },
126-
]),
127123
accessor: ({ rowData }) =>
128124
getColumnProperty(rowData, [
129125
{ path: ['lines', 'expiryDate'] },
130126
{ path: ['expiryDate'] },
131127
]),
132128
},
133129
],
134-
[
135-
'location',
136-
{
137-
getSortValue: row =>
138-
getColumnPropertyAsString(row, [
139-
{ path: ['lines', 'location', 'code'] },
140-
{ path: ['location', 'code'], default: '' },
141-
]),
142-
accessor: ({ rowData }) =>
143-
getColumnProperty(rowData, [
144-
{ path: ['lines', 'location', 'code'] },
145-
{ path: ['location', 'code'] },
146-
]),
147-
},
148-
],
130+
{
131+
key: 'locationCode',
132+
label: 'label.location',
133+
width: 90,
134+
accessor: ({ rowData }) =>
135+
getColumnProperty(rowData, [
136+
{ path: ['lines', 'location', 'code'] },
137+
{ path: ['location', 'code'] },
138+
]),
139+
},
149140
[
150141
'packSize',
151142
{
152-
getSortValue: row =>
153-
getColumnPropertyAsString(row, [
154-
{ path: ['lines', 'packSize'] },
155-
{ path: ['packSize'], default: '' },
156-
]),
157143
accessor: ({ rowData }) =>
158144
getColumnProperty(rowData, [
159145
{ path: ['lines', 'packSize'] },
@@ -171,19 +157,7 @@ export const useStocktakeColumns = ({
171157
getLinesFromRow(row).some(
172158
r => getError(r)?.__typename === 'SnapshotCountCurrentCountMismatch'
173159
),
174-
getSortValue: row => {
175-
if ('lines' in row) {
176-
const { lines } = row;
177-
return (
178-
lines.reduce(
179-
(total, line) => total + line.snapshotNumberOfPacks,
180-
0
181-
) ?? 0
182-
).toString();
183-
} else {
184-
return row.snapshotNumberOfPacks ?? '';
185-
}
186-
},
160+
sortable: false,
187161
accessor: ({ rowData }) => {
188162
if ('lines' in rowData) {
189163
const { lines } = rowData;
@@ -208,19 +182,7 @@ export const useStocktakeColumns = ({
208182
getLinesFromRow(row).some(
209183
r => getError(r)?.__typename === 'SnapshotCountCurrentCountMismatch'
210184
),
211-
getSortValue: row => {
212-
if ('lines' in row) {
213-
const { lines } = row;
214-
return (
215-
lines.reduce(
216-
(total, line) => total + (line.countedNumberOfPacks ?? 0),
217-
0
218-
) ?? 0
219-
).toString();
220-
} else {
221-
return row.countedNumberOfPacks ?? '';
222-
}
223-
},
185+
sortable: false,
224186
accessor: ({ rowData }) => {
225187
if ('lines' in rowData) {
226188
const { lines } = rowData;
@@ -239,25 +201,7 @@ export const useStocktakeColumns = ({
239201
key: 'difference',
240202
label: 'label.difference',
241203
align: ColumnAlign.Right,
242-
getSortValue: row => {
243-
if ('lines' in row) {
244-
const { lines } = row;
245-
const total =
246-
lines.reduce(
247-
(total, line) =>
248-
total +
249-
(line.snapshotNumberOfPacks -
250-
(line.countedNumberOfPacks ?? line.snapshotNumberOfPacks)),
251-
0
252-
) ?? 0;
253-
return (total < 0 ? Math.abs(total) : -total).toString();
254-
} else {
255-
return (
256-
row.snapshotNumberOfPacks -
257-
(row.countedNumberOfPacks ?? row.snapshotNumberOfPacks) ?? ''
258-
);
259-
}
260-
},
204+
sortable: false,
261205
accessor: ({ rowData }) => {
262206
if ('lines' in rowData) {
263207
const { lines } = rowData;
@@ -282,17 +226,12 @@ export const useStocktakeColumns = ({
282226
key: 'inventoryAdjustmentReason',
283227
label: 'label.reason',
284228
accessor: ({ rowData }) => getStocktakeReasons(rowData, t),
285-
getSortValue: rowData => getStocktakeReasons(rowData, t),
229+
sortable: false,
286230
},
287231
{
288232
key: 'comment',
289233
label: 'label.stocktake-comment',
290-
291-
getSortValue: row =>
292-
getColumnPropertyAsString(row, [
293-
{ path: ['lines', 'comment'] },
294-
{ path: ['comment'], default: '' },
295-
]),
234+
sortable: false,
296235
accessor: ({ rowData }) =>
297236
getColumnProperty(rowData, [
298237
{ path: ['lines', 'comment'] },

0 commit comments

Comments
 (0)