Merge pull request #127 from beatz174-bit/codex/fix-packaging-type-filter-functionality
Fix packaging filter availability logic
This commit is contained in:
@@ -577,6 +577,50 @@ describe('ActivePickListScreen product search', () => {
|
|||||||
expect(unitsRadio).toBeEnabled();
|
expect(unitsRadio).toBeEnabled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('resets the packaging filter when show picked is unchecked', async () => {
|
||||||
|
pickItemsMock.mockReturnValue([
|
||||||
|
{
|
||||||
|
id: 'item-1',
|
||||||
|
pick_list_id: 'list-1',
|
||||||
|
product_id: 'prod-1',
|
||||||
|
quantity: 1,
|
||||||
|
is_carton: true,
|
||||||
|
status: 'picked',
|
||||||
|
created_at: 0,
|
||||||
|
updated_at: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'item-2',
|
||||||
|
pick_list_id: 'list-1',
|
||||||
|
product_id: 'prod-2',
|
||||||
|
quantity: 1,
|
||||||
|
is_carton: false,
|
||||||
|
status: 'pending',
|
||||||
|
created_at: 0,
|
||||||
|
updated_at: 0,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const user = userEvent.setup();
|
||||||
|
|
||||||
|
render(
|
||||||
|
<MemoryRouter initialEntries={['/pick-lists/1']} future={{ v7_startTransition: true, v7_relativeSplatPath: true }}>
|
||||||
|
<Routes>
|
||||||
|
<Route path="/pick-lists/:id" element={<ActivePickListScreen />} />
|
||||||
|
</Routes>
|
||||||
|
</MemoryRouter>,
|
||||||
|
);
|
||||||
|
|
||||||
|
await user.click(screen.getByRole('radio', { name: /cartons/i }));
|
||||||
|
expect(screen.getByRole('radio', { name: /cartons/i })).toBeChecked();
|
||||||
|
|
||||||
|
await user.click(screen.getByLabelText(/show picked/i));
|
||||||
|
|
||||||
|
await waitFor(() => expect(screen.getByRole('radio', { name: /all/i })).toBeChecked());
|
||||||
|
expect(screen.getByRole('radio', { name: /cartons/i })).toBeDisabled();
|
||||||
|
expect(screen.getByRole('radio', { name: /units/i })).toBeDisabled();
|
||||||
|
});
|
||||||
|
|
||||||
it('resets the filter when the selected packaging type is unavailable', async () => {
|
it('resets the filter when the selected packaging type is unavailable', async () => {
|
||||||
const user = userEvent.setup();
|
const user = userEvent.setup();
|
||||||
|
|
||||||
@@ -771,6 +815,42 @@ describe('ActivePickListScreen product search', () => {
|
|||||||
expect(screen.getByRole('radio', { name: /units/i })).toBeDisabled();
|
expect(screen.getByRole('radio', { name: /units/i })).toBeDisabled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('disables packaging filters when every item is picked', () => {
|
||||||
|
pickItemsMock.mockReturnValue([
|
||||||
|
{
|
||||||
|
id: 'item-1',
|
||||||
|
pick_list_id: 'list-1',
|
||||||
|
product_id: 'prod-1',
|
||||||
|
quantity: 1,
|
||||||
|
is_carton: true,
|
||||||
|
status: 'picked',
|
||||||
|
created_at: 0,
|
||||||
|
updated_at: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'item-2',
|
||||||
|
pick_list_id: 'list-1',
|
||||||
|
product_id: 'prod-2',
|
||||||
|
quantity: 1,
|
||||||
|
is_carton: false,
|
||||||
|
status: 'picked',
|
||||||
|
created_at: 0,
|
||||||
|
updated_at: 0,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
render(
|
||||||
|
<MemoryRouter initialEntries={['/pick-lists/1']} future={{ v7_startTransition: true, v7_relativeSplatPath: true }}>
|
||||||
|
<Routes>
|
||||||
|
<Route path="/pick-lists/:id" element={<ActivePickListScreen />} />
|
||||||
|
</Routes>
|
||||||
|
</MemoryRouter>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.getByRole('radio', { name: /cartons/i })).toBeDisabled();
|
||||||
|
expect(screen.getByRole('radio', { name: /units/i })).toBeDisabled();
|
||||||
|
});
|
||||||
|
|
||||||
it('disables show picked toggle when all items are picked', async () => {
|
it('disables show picked toggle when all items are picked', async () => {
|
||||||
pickItemsMock.mockReturnValue([
|
pickItemsMock.mockReturnValue([
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,19 +50,22 @@ export const ActivePickListScreen = () => {
|
|||||||
[itemState, showPicked],
|
[itemState, showPicked],
|
||||||
);
|
);
|
||||||
|
|
||||||
const allItemsPicked = useMemo(
|
const hasPickedItemsInList = useMemo(
|
||||||
() => itemState.length > 0 && itemState.every((item) => item.status === 'picked'),
|
() => itemState.some((item) => item.status === 'picked'),
|
||||||
[itemState],
|
[itemState],
|
||||||
);
|
);
|
||||||
const hasUnpickedItems = useMemo(
|
const hasUnpickedItemsInList = useMemo(
|
||||||
() => itemsVisibleByStatus.some((item) => item.status !== 'picked'),
|
() => itemState.some((item) => item.status !== 'picked'),
|
||||||
[itemsVisibleByStatus],
|
[itemState],
|
||||||
);
|
);
|
||||||
const hasPickedItems = useMemo(
|
const allItemsPicked = useMemo(
|
||||||
() => itemsVisibleByStatus.some((item) => item.status === 'picked'),
|
() => itemState.length > 0 && !hasUnpickedItemsInList,
|
||||||
[itemsVisibleByStatus],
|
[hasUnpickedItemsInList, itemState.length],
|
||||||
|
);
|
||||||
|
const allItemsUnpicked = useMemo(
|
||||||
|
() => itemState.length > 0 && !hasPickedItemsInList,
|
||||||
|
[hasPickedItemsInList, itemState.length],
|
||||||
);
|
);
|
||||||
const hasMixedPickStatuses = hasPickedItems && hasUnpickedItems;
|
|
||||||
|
|
||||||
const productMap = useMemo(() => {
|
const productMap = useMemo(() => {
|
||||||
const map = new Map<string, Product>();
|
const map = new Map<string, Product>();
|
||||||
@@ -163,7 +166,7 @@ export const ActivePickListScreen = () => {
|
|||||||
);
|
);
|
||||||
const packagingTypeCount = Number(hasCartonItems) + Number(hasUnitItems);
|
const packagingTypeCount = Number(hasCartonItems) + Number(hasUnitItems);
|
||||||
const singlePackagingType = packagingTypeCount === 1;
|
const singlePackagingType = packagingTypeCount === 1;
|
||||||
const packagingFiltersDisabled = !hasMixedPickStatuses;
|
const packagingFiltersDisabled = !showPicked || allItemsPicked || allItemsUnpicked;
|
||||||
|
|
||||||
const productIdsInList = useMemo(
|
const productIdsInList = useMemo(
|
||||||
() => new Set(itemState.map((item) => item.product_id)),
|
() => new Set(itemState.map((item) => item.product_id)),
|
||||||
@@ -197,6 +200,12 @@ export const ActivePickListScreen = () => {
|
|||||||
}
|
}
|
||||||
}, [allItemsPicked, showPicked]);
|
}, [allItemsPicked, showPicked]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (packagingFiltersDisabled && itemFilter !== 'all') {
|
||||||
|
setItemFilter('all');
|
||||||
|
}
|
||||||
|
}, [itemFilter, packagingFiltersDisabled]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (packagingTypeCount <= 1) {
|
if (packagingTypeCount <= 1) {
|
||||||
if (itemFilter !== 'all') {
|
if (itemFilter !== 'all') {
|
||||||
|
|||||||
Reference in New Issue
Block a user