Skip to content
This repository has been archived by the owner on Jul 17, 2022. It is now read-only.

Commit

Permalink
feat: filter groups in pallet selection based on receivingGroups
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed May 8, 2022
1 parent c27ee2b commit 5ec4f2d
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 101 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/frontend-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ jobs:
working-directory: frontend
run: npx playwright test tests/playwright/unauthenticated

- name: Run tests (admin workflows)
working-directory: frontend
run: npx playwright test tests/playwright/authenticated/admin

- name: Run tests (user onboarding)
working-directory: frontend
run: npx playwright test tests/playwright/authenticated/user/onboarding

- name: Run tests (admin workflows)
working-directory: frontend
run: npx playwright test tests/playwright/authenticated/admin

- name: Run tests (user offer creation)
working-directory: frontend
run: npx playwright test tests/playwright/authenticated/user/offer
Expand Down
4 changes: 2 additions & 2 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ You can also run the tests against the frontend development server. Export the e
You can then run the tests using

npx playwright test tests/playwright/unauthenticated
npx playwright test tests/playwright/authenticated/admin
npx playwright test tests/playwright/authenticated/user/onboarding
npx playwright test tests/playwright/authenticated/admin
npx playwright test tests/playwright/authenticated/user/offer

This works on your local machine, as well as using the Docker container.
Expand All @@ -36,8 +36,8 @@ For developing tests it is helpful to run the [Playwright Inspector](https://pla
Then launch the inspector **on your local machine** using

PWDEBUG=1 npx playwright test tests/playwright/unauthenticated
PWDEBUG=1 npx playwright test tests/playwright/authenticated/admin
PWDEBUG=1 npx playwright test tests/playwright/authenticated/user/onboarding
PWDEBUG=1 npx playwright test tests/playwright/authenticated/admin
PWDEBUG=1 npx playwright test tests/playwright/authenticated/user/offer

This cannot be done inside the Docker container, since it launches the Firefox browser.
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/offers/CreateOfferForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ const CreateOfferForm: FunctionComponent<PropsWithChildren<Props>> = (
<p className="">{formatShipmentName(targetShipment.shipment)}</p>
<p className="text-gray-500 text-sm">
{formatListOfHubs(targetShipment.shipment.sendingHubs)}{' '}
{formatListOfHubs(targetShipment.shipment.receivingHubs)}
{formatListOfHubs(targetShipment.shipment.receivingHubs)}{' '}
{formatListOfHubs(targetShipment.shipment.receivingGroups)}
</p>
</>
)}
Expand Down
41 changes: 14 additions & 27 deletions frontend/src/pages/offers/LineItemForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useForm } from 'react-hook-form'
import Button from '../../components/Button'
import InlineError from '../../components/forms/InlineError'
import PlaceholderField from '../../components/forms/PlaceholderField'
import SelectField, { SelectOption } from '../../components/forms/SelectField'
import SelectField from '../../components/forms/SelectField'
import TextField from '../../components/forms/TextField'
import Spinner from '../../components/Spinner'
import {
Expand All @@ -21,21 +21,16 @@ import {
} from '../../data/constants'
import {
DangerousGoods,
GroupType,
LineItemCategory,
LineItemContainerType,
LineItemUpdateInput,
OfferQuery,
PalletType,
useAllGroupsMinimalQuery,
ShipmentQuery,
useLineItemQuery,
useUpdateLineItemMutation,
} from '../../types/api-types'
import {
gramsToKilos,
groupToSelectOption,
kilosToGrams,
} from '../../utils/format'
import { gramsToKilos, kilosToGrams } from '../../utils/format'
import { setEmptyFieldsToUndefined } from '../../utils/setEmptyFieldsToUndefined'

interface Props {
Expand All @@ -54,13 +49,15 @@ interface Props {
*/
palletType: PalletType
offer: OfferQuery['offer']
shipment: ShipmentQuery['shipment']
}

const LineItemForm: FunctionComponent<PropsWithChildren<Props>> = ({
lineItemId,
onEditingComplete,
palletType,
offer,
shipment,
}) => {
const {
data,
Expand All @@ -70,25 +67,15 @@ const LineItemForm: FunctionComponent<PropsWithChildren<Props>> = ({
variables: { id: lineItemId },
})

const [receivingGroups, setReceivingGroups] = useState<SelectOption[]>([])
const { data: groups, loading: groupsAreLoading } = useAllGroupsMinimalQuery({
variables: { groupType: GroupType.Regular },
})

// Groups available for reception are all groups that are not the sending group
const availableReceivingGroups = useMemo(
// Groups available for reception are all receiving groups that are not the sending group
const receivingGroups = useMemo(
() =>
groups?.listGroups.filter(({ id }) => offer.sendingGroupId !== id) ?? [],
[groups, offer],
)

useEffect(
function organizeGroups() {
if (availableReceivingGroups.length) {
setReceivingGroups(availableReceivingGroups.map(groupToSelectOption))
}
},
[availableReceivingGroups],
(
shipment.receivingGroups.filter(
({ id }) => offer.sendingGroupId !== id,
) ?? []
).map(({ id, name }) => ({ label: name, value: id })),
[shipment, offer],
)

/**
Expand Down Expand Up @@ -275,7 +262,7 @@ const LineItemForm: FunctionComponent<PropsWithChildren<Props>> = ({
})
})

if (!groupsAreLoading && receivingGroups.length === 0) {
if (receivingGroups.length === 0) {
return (
<div>
<h2 className="text-lg mb-2">Unable to add items</h2>
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/pages/offers/PalletsEditor.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import { MockedProvider } from '@apollo/react-testing'
import { act, render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { createLineItem, createOffer } from '../../../tests/builders'
import createLineItem from '../../../tests/builders/createLineItem'
import createOffer from '../../../tests/builders/createOffer'
import createPallet from '../../../tests/builders/createPallet'
import { createShipment } from '../../../tests/builders/createShipment'
import {
AllGroupsMinimalDocument,
GroupType,
Expand All @@ -15,6 +17,7 @@ import {
import PalletsEditor from './PalletsEditor'

describe('PalletsEditor', () => {
const shipment = createShipment({ id: 1 })
const offer = createOffer({ id: 2, offerId: 2 })
const pallet = createPallet({
id: 2,
Expand Down Expand Up @@ -60,7 +63,11 @@ describe('PalletsEditor', () => {
it('shows form only for the line item which is being edited', async () => {
render(
<MockedProvider mocks={apolloQueryMocks}>
<PalletsEditor offer={offer} pallets={offer.pallets} />
<PalletsEditor
shipment={shipment}
offer={offer}
pallets={offer.pallets}
/>
</MockedProvider>,
)

Expand Down
4 changes: 4 additions & 0 deletions frontend/src/pages/offers/PalletsEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
PalletCreateInput,
PalletDocument,
PalletType,
ShipmentQuery,
useCreateLineItemMutation,
useCreatePalletMutation,
usePalletLazyQuery,
Expand All @@ -19,6 +20,7 @@ import ViewLineItem from './ViewLineItem'
import ViewPallet from './ViewPallet'
interface Props {
offer: OfferQuery['offer']
shipment: ShipmentQuery['shipment']
pallets?: OfferQuery['offer']['pallets']
}

Expand All @@ -28,6 +30,7 @@ interface Props {
*/
const PalletsEditor: FunctionComponent<PropsWithChildren<Props>> = ({
offer,
shipment,
pallets = [],
}) => {
// TODO move this to the URL
Expand Down Expand Up @@ -182,6 +185,7 @@ const PalletsEditor: FunctionComponent<PropsWithChildren<Props>> = ({
{lineItemToEditId === selectedLineItemId ? (
<LineItemForm
offer={offer}
shipment={shipment}
lineItemId={selectedLineItemId}
palletType={
selectedPalletData.data?.pallet.palletType ||
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/pages/offers/ViewOfferPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ const ViewOfferPage: FunctionComponent = () => {
</p>
<p className="text-gray-600 text-sm">
{formatListOfHubs(shipment.shipment.sendingHubs)}{' '}
{formatListOfHubs(shipment.shipment.receivingHubs)}
{formatListOfHubs(shipment.shipment.receivingHubs)}{' '}
{formatListOfHubs(shipment.shipment.receivingGroups)}
</p>
</>
)}
Expand All @@ -115,8 +116,12 @@ const ViewOfferPage: FunctionComponent = () => {
)}
</header>
<main className="flex-grow flex items-stretch">
{offer?.offer && (
<PalletsEditor offer={offer.offer} pallets={offer?.offer.pallets} />
{offer?.offer && shipment?.shipment && (
<PalletsEditor
shipment={shipment.shipment}
offer={offer.offer}
pallets={offer?.offer.pallets}
/>
)}
</main>
</div>
Expand Down
24 changes: 23 additions & 1 deletion frontend/src/pages/shipments/ShipmentDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const ShipmentDetails: FunctionComponent<PropsWithChildren<Props>> = ({
</div>
<div className="border border-gray-200 p-4 md:p-6 rounded flex-shrink-0 space-y-2">
<div className="uppercase text-xs text-gray-500 mb-2">To</div>
<div className="uppercase text-xs text-gray-500 mb-2">Via</div>
{shipmentData.receivingHubs.map((hub) => (
<div key={hub.id}>
<div className="text-lg md:text-xl text-gray-800">{hub.name}</div>
Expand All @@ -99,6 +99,28 @@ const ShipmentDetails: FunctionComponent<PropsWithChildren<Props>> = ({
</div>
))}
</div>
<div className="text-2xl text-gray-500 p-2 md:p-4 transform md:-rotate-90 text-center">
</div>
<div className="border border-gray-200 p-4 md:p-6 rounded flex-shrink-0 space-y-2">
<div className="uppercase text-xs text-gray-500 mb-2">To</div>
{shipmentData.receivingGroups.map((group) => (
<div key={group.id}>
<div className="text-lg md:text-xl text-gray-800">
{group.name}
</div>
<div className="text-gray-600">
{group.locality}
{group.country && (
<>
{', '}
{group.country.alias ?? group.country.shortName}
</>
)}
</div>
</div>
))}
</div>
</div>
</div>
)
Expand Down
Loading

0 comments on commit 5ec4f2d

Please sign in to comment.