-
Notifications
You must be signed in to change notification settings - Fork 16
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
roxy-dao
wants to merge
11
commits into
5675.3-batch-create-IS-from-IO
Choose a base branch
from
5675.4-frontend
base: 5675.3-batch-create-IS-from-IO
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+471
β40
Open
5675.4 frontend #6390
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
82e241c
Make add button in IS split buttons
roxy-dao 8a0c261
Add selection option for Dialog buttons
roxy-dao e74de03
Hook to get internal order lines
roxy-dao b3a19b7
Columns for internal order lines
roxy-dao 1c0525a
Add from IO button
roxy-dao 0deb163
Hook to insert lines from Internal Order
roxy-dao f28892e
Button to add lines from Internal Order
roxy-dao b89164b
Have option pop up on arrow selection
roxy-dao 90e6c1a
Add shadow to split buttons
roxy-dao 3f19cbb
Open menu from bottom
roxy-dao 2592d7b
Remove
roxy-dao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
}} | ||
> | ||
<ButtonWithIcon | ||
color={color} | ||
disabled={isDisabled || selectedOption.isDisabled} | ||
|
@@ -89,6 +97,7 @@ export const SplitButton = <T,>({ | |
borderRadius: 0, | ||
borderStartEndRadius: '24px', | ||
borderEndEndRadius: '24px', | ||
borderLeft: theme => `1px solid ${theme.palette.divider}`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 />} | ||
|
101 changes: 101 additions & 0 deletions
101
client/packages/invoices/src/InboundShipment/DetailView/AddButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; |
111 changes: 111 additions & 0 deletions
111
client/packages/invoices/src/InboundShipment/DetailView/AddFromInternalOrder.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); |
33 changes: 11 additions & 22 deletions
33
client/packages/invoices/src/InboundShipment/DetailView/AddFromMasterListButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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