Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5675.4 frontend #6390

Open
wants to merge 11 commits into
base: 5675.3-batch-create-IS-from-IO
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/packages/common/src/intl/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"button.add-contact-trace": "Add Contact",
"button.add-encounter": "Add Encounter",
"button.add-form": "Add Form",
"button.add-from-internal-order": "Add from Internal Order",
"button.add-from-master-list": "Add from master list",
"button.add-item": "Add Item",
"button.add-new-indicator": "Add New Indicator",
Expand Down Expand Up @@ -93,6 +94,7 @@
"button.save-and-confirm-status": "Confirm {{status}}",
"button.save-log": "Save log",
"button.scan": "Scan",
"button.select": "Select",
"button.select-a-color": "Select a colour",
"button.send": "Send",
"button.show-all": "Show all",
Expand Down
17 changes: 16 additions & 1 deletion client/packages/common/src/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ export type BatchInboundShipmentInput = {
deleteInboundShipmentLines?: InputMaybe<Array<DeleteInboundShipmentLineInput>>;
deleteInboundShipmentServiceLines?: InputMaybe<Array<DeleteInboundShipmentServiceLineInput>>;
deleteInboundShipments?: InputMaybe<Array<DeleteInboundShipmentInput>>;
insertFromInternalOrderLines?: InputMaybe<Array<InsertInboundShipmentLineFromInternalOrderLineInput>>;
insertInboundShipmentLines?: InputMaybe<Array<InsertInboundShipmentLineInput>>;
insertInboundShipmentServiceLines?: InputMaybe<Array<InsertInboundShipmentServiceLineInput>>;
insertInboundShipments?: InputMaybe<Array<InsertInboundShipmentInput>>;
Expand All @@ -679,6 +680,7 @@ export type BatchInboundShipmentResponse = {
deleteInboundShipmentLines?: Maybe<Array<DeleteInboundShipmentLineResponseWithId>>;
deleteInboundShipmentServiceLines?: Maybe<Array<DeleteInboundShipmentServiceLineResponseWithId>>;
deleteInboundShipments?: Maybe<Array<DeleteInboundShipmentResponseWithId>>;
insertFromInternalOrderLines?: Maybe<Array<InsertInboundShipmentLineFromInternalOrderLineResponseWithId>>;
insertInboundShipmentLines?: Maybe<Array<InsertInboundShipmentLineResponseWithId>>;
insertInboundShipmentServiceLines?: Maybe<Array<InsertInboundShipmentServiceLineResponseWithId>>;
insertInboundShipments?: Maybe<Array<InsertInboundShipmentResponseWithId>>;
Expand Down Expand Up @@ -1097,7 +1099,7 @@ export type ConsumptionHistoryNode = {
};

export type ConsumptionOptionsInput = {
/** Defaults to 3 months */
/** Defaults to store preference amc_lookback_months */
amcLookbackMonths?: InputMaybe<Scalars['Int']['input']>;
/** Defaults to 12 */
numberOfDataPoints?: InputMaybe<Scalars['Int']['input']>;
Expand Down Expand Up @@ -2691,6 +2693,8 @@ export type InsertFormSchemaInput = {

export type InsertFormSchemaResponse = FormSchemaNode;

export type InsertFromInternalOrderResponse = InvoiceLineNode;

export type InsertInboundShipmentError = {
__typename: 'InsertInboundShipmentError';
error: InsertInboundShipmentErrorInterface;
Expand Down Expand Up @@ -2719,6 +2723,17 @@ export type InsertInboundShipmentLineErrorInterface = {
description: Scalars['String']['output'];
};

export type InsertInboundShipmentLineFromInternalOrderLineInput = {
invoiceId: Scalars['String']['input'];
requisitionLineId: Scalars['String']['input'];
};

export type InsertInboundShipmentLineFromInternalOrderLineResponseWithId = {
__typename: 'InsertInboundShipmentLineFromInternalOrderLineResponseWithId';
id: Scalars['String']['output'];
response: InsertFromInternalOrderResponse;
};

export type InsertInboundShipmentLineInput = {
batch?: InputMaybe<Scalars['String']['input']>;
costPricePerPack: Scalars['Float']['input'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ type DialogButtonVariant =
| 'copy'
| 'delete'
| 'export'
| 'close';
| 'close'
| 'select';

interface DialogButtonProps {
disabled?: boolean;
Expand Down Expand Up @@ -114,6 +115,12 @@ const getButtonProps = (
labelKey: 'button.previous',
variant: 'contained',
};
case 'select':
return {
icon: <CheckIcon />,
labelKey: 'button.select',
variant: 'contained',
};
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ export const SplitButton = <T,>({
return (
<>
<Tooltip title={label}>
<ButtonGroup color={color} variant="outlined" aria-label={ariaLabel}>
<ButtonGroup
color={color}
variant="outlined"
aria-label={ariaLabel}
sx={{
boxShadow: theme => theme.shadows[2],
borderRadius: 24,
}}
Comment on lines +62 to +65
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix for GEDSI bug, adding shadow back to the split buttons

>
<ButtonWithIcon
color={color}
disabled={isDisabled || selectedOption.isDisabled}
Expand Down Expand Up @@ -89,6 +97,7 @@ export const SplitButton = <T,>({
borderRadius: 0,
borderStartEndRadius: '24px',
borderEndEndRadius: '24px',
borderLeft: theme => `1px solid ${theme.palette.divider}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To show that both parts of the button can be clicked

}}
label=""
startIcon={<ChevronDownIcon />}
Expand Down
101 changes: 101 additions & 0 deletions client/packages/invoices/src/InboundShipment/DetailView/AddButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React, { useState } from 'react';
import { SplitButton, SplitButtonOption } from '@common/components';
import { useTranslation } from '@common/intl';
import { AddFromMasterListButton } from './AddFromMasterListButton';
import { useToggle } from '@common/hooks';
import { AddFromInternalOrder } from './AddFromInternalOrder';

interface AddButtonProps {
requisitionId: string;
invoiceId: string;
onAddItem: (newState: boolean) => void;
/** Disable the whole control */
disable: boolean;
disableAddFromMasterListButton: boolean;
disableAddFromInternalOrderButton: boolean;
}

export const AddButton = ({
requisitionId,
invoiceId,
onAddItem,
disable,
disableAddFromMasterListButton,
disableAddFromInternalOrderButton,
}: AddButtonProps) => {
const t = useTranslation();
const masterListModalController = useToggle();
const internalOrderModalController = useToggle();

const options: [
SplitButtonOption<string>,
SplitButtonOption<string>,
SplitButtonOption<string>,
] = [
{
value: 'add-item',
label: t('button.add-item'),
isDisabled: disable,
},
{
value: 'add-from-master-list',
label: t('button.add-from-master-list'),
isDisabled: disableAddFromMasterListButton || disable,
},
{
value: 'add-from-internal-order',
label: t('button.add-from-internal-order'),
isDisabled: disableAddFromInternalOrderButton || disable,
},
];
const [addItemOption] = options;
const [selectedOption, setSelectedOption] =
useState<SplitButtonOption<string>>(addItemOption);

const handleOptionSelection = (option: SplitButtonOption<string>) => {
switch (option.value) {
case 'add-item':
onAddItem(true);
break;
case 'add-from-master-list':
masterListModalController.toggleOn();
break;
case 'add-from-internal-order':
internalOrderModalController.toggleOn();
break;
}
};

const onSelectOption = (option: SplitButtonOption<string>) => {
setSelectedOption(option);
handleOptionSelection(option);
};

return (
<>
<SplitButton
color="primary"
options={options}
selectedOption={selectedOption}
onSelectOption={onSelectOption}
onClick={handleOptionSelection}
openFrom="bottom"
/>

{masterListModalController.isOn && (
<AddFromMasterListButton
isOn={masterListModalController.isOn}
toggleOff={masterListModalController.toggleOff}
/>
)}
{internalOrderModalController.isOn && (
<AddFromInternalOrder
isOpen={internalOrderModalController.isOn}
onClose={internalOrderModalController.toggleOff}
requisitionId={requisitionId}
invoiceId={invoiceId}
/>
)}
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import React from 'react';
import { useDialog, useWindowDimensions } from '@common/hooks';
import { useTranslation } from '@common/intl';
import { LinkedRequestLineFragment, useInbound } from '../api';
import {
ColumnAlign,
createTableStore,
DataTable,
DialogButton,
GenericColumnKey,
TableProvider,
useColumns,
useTableStore,
} from '@openmsupply-client/common';

interface AddFromInternalOrderProps {
isOpen: boolean;
onClose: () => void;
requisitionId?: string;
invoiceId?: string;
}

export const useInternalOrderLineColumns = (requisitionId: string) => {
const { data, isLoading } = useInbound.document.listInternalOrderLines(
requisitionId ?? ''
);
const sortedLines = data?.lines?.nodes?.sort(
(a, b) => b.requestedQuantity - a.requestedQuantity
);

const columns = useColumns<LinkedRequestLineFragment>([
[
GenericColumnKey.Selection,
{
width: 50,
align: ColumnAlign.Center,
},
],
[
'itemCode',
{
width: 100,
accessor: ({ rowData }) => rowData.item.code ?? '',
},
],
[
'itemName',
{
width: 200,
accessor: ({ rowData }) => rowData.item.name ?? '',
},
],
['requestedQuantity'],
]);

return { columns, sortedLines, isLoading };
};

const AddFromInternalOrderComponent = ({
isOpen,
onClose,
requisitionId,
invoiceId,
}: AddFromInternalOrderProps) => {
const t = useTranslation();
const { width, height } = useWindowDimensions();
const { Modal } = useDialog({ isOpen, onClose });
const { columns, sortedLines, isLoading } = useInternalOrderLineColumns(
requisitionId ?? ''
);
const { mutateAsync } = useInbound.lines.insertFromInternalOrder();
const selectedRows = useTableStore(state => {
return (
sortedLines?.filter(({ id }) => state.rowState[id]?.isSelected) ?? []
);
});

const onSelect = async () => {
const rowsToInsert = selectedRows.map(row => ({
invoiceId: invoiceId ?? '',
requisitionLineId: row.id,
}));

await mutateAsync(rowsToInsert);
onClose();
};

return (
<Modal
title={t('header.link-internal-order')}
width={width * 0.5}
height={height * 0.8}
okButton={<DialogButton variant="select" onClick={onSelect} />}
cancelButton={<DialogButton variant="cancel" onClick={onClose} />}
>
<DataTable
id="link-internal-order-to-inbound"
columns={columns}
data={sortedLines}
isLoading={isLoading}
dense
/>
</Modal>
);
};

export const AddFromInternalOrder = (props: AddFromInternalOrderProps) => (
<TableProvider createStore={createTableStore}>
<AddFromInternalOrderComponent {...props} />
</TableProvider>
);
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
import React from 'react';
import {
ButtonWithIcon,
useTranslation,
useToggle,
PlusCircleIcon,
InvoiceNodeStatus,
useAuthContext,
} from '@openmsupply-client/common';
import { useAuthContext } from '@openmsupply-client/common';
import { MasterListSearchModal } from '@openmsupply-client/system';
import { useInbound } from '../api';

export const AddFromMasterListButtonComponent = () => {
const t = useTranslation();
export const AddFromMasterListButtonComponent = ({
isOn,
toggleOff,
}: {
isOn: boolean;
toggleOff: () => void;
}) => {
const { addFromMasterList } = useInbound.utils.addFromMasterList();
const { storeId } = useAuthContext();
const { status } = useInbound.document.fields(['status']);
const isDisabled = status !== InvoiceNodeStatus.New;
const modalController = useToggle();
const filterByStore = { existsForStoreId: { equalTo: storeId } };

return (
<>
<MasterListSearchModal
open={modalController.isOn}
onClose={modalController.toggleOff}
open={isOn}
onClose={toggleOff}
onChange={masterList => {
modalController.toggleOff();
toggleOff();
addFromMasterList(masterList);
}}
filterBy={filterByStore}
/>
<ButtonWithIcon
disabled={isDisabled}
Icon={<PlusCircleIcon />}
label={t('button.add-from-master-list')}
onClick={modalController.toggleOn}
/>
</>
);
};
Expand Down
Loading
Loading