Skip to content

Commit

Permalink
fix: corrected the handling of views for supplier and customer
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneSchroederLJ committed Mar 20, 2024
1 parent 7a3980f commit ecd6c72
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
9 changes: 5 additions & 4 deletions frontend/src/features/dashboard/components/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ProductionTable } from './ProductionTable';
import { Stack, Typography, capitalize } from '@mui/material';
import { Delivery } from '@models/types/data/delivery';
import { DeliveryInformationModal } from './DeliveryInformationModal';
import { getPartnerType } from '../util/helpers';

const NUMBER_OF_DAYS = 42;

Expand Down Expand Up @@ -65,7 +66,7 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
Our Stock Information {selectedMaterial && selectedSite && <>for {selectedMaterial.description}</>}
</Typography>
{selectedSite ? (
type === 'customer' ? (
type === 'supplier' ? (
<ProductionTable
numberOfDays={NUMBER_OF_DAYS}
stocks={stocks}
Expand All @@ -86,11 +87,11 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
{selectedSite && (
<>
<Typography variant="h5" component="h2">
{`${capitalize(type)} Stocks ${selectedMaterial ? `for ${selectedMaterial?.description}` : ''}`}
{`${capitalize(getPartnerType(type))} Stocks ${selectedMaterial ? `for ${selectedMaterial?.description}` : ''}`}
</Typography>
{selectedPartnerSites ? (
selectedPartnerSites.map((ps) =>
type === 'customer' ? (
type === 'supplier' ? (
<DemandTable
numberOfDays={NUMBER_OF_DAYS}
stocks={partnerStocks}
Expand All @@ -107,7 +108,7 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
)
)
) : (
<Typography variant="body1">{`Select a ${type} site to show their stock information`}</Typography>
<Typography variant="body1">{`Select a ${getPartnerType(type)} site to show their stock information`}</Typography>
)}
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useSites } from '@features/stock-view/hooks/useSites';
import { MaterialDescriptor } from '@models/types/data/material-descriptor';
import { Site } from '@models/types/edc/site';
import { Autocomplete, Grid, capitalize } from '@mui/material';
import { getPartnerType } from '../util/helpers';

type DashboardFiltersProps = {
type: 'customer' | 'supplier';
Expand Down Expand Up @@ -73,14 +74,18 @@ export const DashboardFilters = ({
</Grid>
<Grid item md={12} paddingTop='0 !important'>
<Autocomplete
id="customer-site"
id="partner-site"
value={partnerSites ?? []}
options={partners?.reduce((acc: Site[], p) => [...acc, ...p.sites], []) ?? []}
disabled={!site}
getOptionLabel={(option) => `${option.name} (${option.bpns})`}
isOptionEqualToValue={(option, value) => option.bpns === value.bpns}
renderInput={(params) => (
<Input {...params} label={`${capitalize(type)} Sites*`} placeholder="Select a Customer site" />
<Input
{...params}
label={`${capitalize(getPartnerType(type))} Sites*`}
placeholder={`Select a ${capitalize(getPartnerType(type))} site`}
/>
)}
onChange={(_, newValue) => onPartnerSitesChange(newValue?.length > 0 ? newValue : null)}
multiple={true}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/features/dashboard/components/DemandTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SPDX-License-Identifier: Apache-2.0
import { TableWithRowHeader } from '@components/TableWithRowHeader';
import { Stock } from '@models/types/data/stock';
import { Site } from '@models/types/edc/site';
import { createDateColumnHeaders } from '../util/table-helpers';
import { createDateColumnHeaders } from '../util/helpers';
import { Box, Typography } from '@mui/material';
import { Delivery } from '@models/types/data/delivery';

Expand All @@ -47,7 +47,7 @@ const createDemandRows = (numberOfDays: number, stocks: Stock[], site: Site) =>
...Object.keys(Array.from({ length: numberOfDays })).reduce(
(acc, _, index) => ({
...acc,
[index]: Math.max(itemStock[index as keyof typeof itemStock] / demands[index as keyof typeof demands], 0),
[index]: Math.max(itemStock[index as keyof typeof itemStock] / demands[index as keyof typeof demands], 0).toFixed(2),
}),
{}
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SPDX-License-Identifier: Apache-2.0
import { TableWithRowHeader } from '@components/TableWithRowHeader';
import { Stock } from '@models/types/data/stock';
import { Site } from '@models/types/edc/site';
import { createDateColumnHeaders } from '../util/table-helpers';
import { createDateColumnHeaders } from '../util/helpers';
import { Box, Typography } from '@mui/material';
import { Delivery } from '@models/types/data/delivery';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ export const createDateColumnHeaders = (numberOfDays: number) => {
};
});
};

export const getPartnerType = (type: 'customer' | 'supplier') => (type === 'customer' ? 'supplier' : 'customer');

0 comments on commit ecd6c72

Please sign in to comment.