Skip to content

Commit

Permalink
change: requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneSchroederLJ committed Feb 19, 2024
1 parent 2dfa735 commit 0dd0e3c
Show file tree
Hide file tree
Showing 43 changed files with 357 additions and 486 deletions.
5 changes: 2 additions & 3 deletions frontend/src/components/RouteGuard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
Copyright (c) 2022-2024 Volkswagen AG
Copyright (c) 2022-2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST)
Copyright (c) 2022-2024 Contributors to the Eclipse Foundation
Copyright (c) 2024 Volkswagen AG
Copyright (c) 2024 Contributors to the Eclipse Foundation
See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright (c) 2024 Volkswagen AG
Copyright (c) 2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST)
Copyright (c) 2024 Contributors to the Eclipse Foundation
See the NOTICE file(s) distributed with this work for additional
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/layout/SideBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright (c) 2024 Volkswagen AG
Copyright (c) 2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST)
Copyright (c) 2024 Contributors to the Eclipse Foundation
Copyright (c) 2023-24 Volkswagen AG
Copyright (c) 2023-24 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST)
Copyright (c) 2023-24 Contributors to the Eclipse Foundation
See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.
Expand Down
1 change: 0 additions & 1 deletion frontend/src/contexts/authContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright (c) 2024 Volkswagen AG
Copyright (c) 2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST)
Copyright (c) 2024 Contributors to the Eclipse Foundation
See the NOTICE file(s) distributed with this work for additional
Expand Down
45 changes: 0 additions & 45 deletions frontend/src/features/stock-view/components/MaterialStockView.tsx

This file was deleted.

36 changes: 14 additions & 22 deletions frontend/src/features/stock-view/components/PartnerStockTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright (c) 2024 Volkswagen AG
Copyright (c) 2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST)
Copyright (c) 2024 Contributors to the Eclipse Foundation
See the NOTICE file(s) distributed with this work for additional
Expand All @@ -20,27 +19,27 @@ SPDX-License-Identifier: Apache-2.0
*/

import { LoadingButton, Table } from '@catena-x/portal-shared-components';
import { MaterialStock, ProductStock } from '@models/types/data/stock';
import { usePartnerStocks } from '../hooks/usePartnerStocks';
import { Stock, StockType } from '@models/types/data/stock';
import { getUnitOfMeasurement } from '@util/helpers';
import { refreshPartnerStocks } from '@services/stocks-service';
import { useState } from 'react';

type PartnerStockTableProps = {
type: 'material' | 'product';
materialNumber?: string | null;
type PartnerStockTableProps<T extends StockType> = {
type: T;
materialName?: string | null;
partnerStocks: Stock[];
isRefreshing: boolean;
onRefresh: () => void;
};

const partnerStockTableColumns = [
{
field: 'partner',
valueGetter: (data: { row: MaterialStock | ProductStock }) => data.row.partner?.name,
valueGetter: (data: { row: Stock }) => data.row.partner?.name,
headerName: 'Partner',
flex: 5,
},
{
field: 'quantity',
valueGetter: (data: { row: MaterialStock | ProductStock }) =>
valueGetter: (data: { row: Stock }) =>
data.row.quantity + ' ' + getUnitOfMeasurement(data.row.measurementUnit),
headerName: 'Quantity',
flex: 3,
Expand All @@ -57,7 +56,7 @@ const partnerStockTableColumns = [
},
{
field: 'customerOrder',
renderCell: (params: { row: MaterialStock | ProductStock }) => (
renderCell: (params: { row: Stock }) => (
<div className="flex flex-col">
<span>{params.row.customerOrderNumber}</span>
<span>{params.row.customerOrderPositionNumber}</span>
Expand All @@ -73,24 +72,17 @@ const partnerStockTableColumns = [
},
{
field: 'lastUpdatedOn',
valueGetter: (data: { row: MaterialStock }) => new Date(data.row.lastUpdatedOn)?.toLocaleString(),
valueGetter: (data: { row: Stock }) => new Date(data.row.lastUpdatedOn)?.toLocaleString(),
headerName: 'Last Updated On',
flex: 3,
},
];

export const PartnerStockTable = ({ materialNumber, type }: PartnerStockTableProps) => {
const { partnerStocks } = usePartnerStocks(type, materialNumber);
const [refreshing, setRefreshing] = useState(false);

const handleStockRefresh = () => {
setRefreshing(true);
refreshPartnerStocks(type, materialNumber ?? null).then(()=>setRefreshing(false));
};
export const PartnerStockTable = <T extends StockType>({ type, materialName, partnerStocks, onRefresh, isRefreshing }: PartnerStockTableProps<T>) => {
return (
<div className="relative">
<Table
title={`Your ${type === 'material' ? 'Customers' : 'Suppliers'}' Stocks ${materialNumber ? `for Material ${materialNumber}` : ''}`}
title={`Your ${type === 'material' ? 'Customers' : 'Suppliers'}' Stocks ${materialName ? `for ${materialName}` : ''}`}
noRowsMsg={
type === 'material'
? 'Select a Material to show your suppliers stocks'
Expand All @@ -101,7 +93,7 @@ export const PartnerStockTable = ({ materialNumber, type }: PartnerStockTablePro
getRowId={(row) => row.uuid}
hideFooter={true}
></Table>
<LoadingButton label='Refresh Stocks' loadIndicator='refreshing...' loading={refreshing} className="absolute top-8 end-8" variant="contained" onButtonClick={() => handleStockRefresh()} />
<LoadingButton label='Refresh Stocks' loadIndicator='refreshing...' loading={isRefreshing} className="absolute top-8 end-8" variant="contained" onButtonClick={() => onRefresh()} />
</div>
);
};
45 changes: 0 additions & 45 deletions frontend/src/features/stock-view/components/ProductStockView.tsx

This file was deleted.

92 changes: 92 additions & 0 deletions frontend/src/features/stock-view/components/StockDetailsView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
Copyright (c) 2024 Volkswagen AG
Copyright (c) 2024 Contributors to the Eclipse Foundation
See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.
This program and the accompanying materials are made available under the
terms of the Apache License, Version 2.0 which is available at
https://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
SPDX-License-Identifier: Apache-2.0
*/

import { useState } from 'react';

import { Stock, StockType } from '@models/types/data/stock';
import { postStocks, putStocks, refreshPartnerStocks } from '@services/stocks-service';

import { useMaterials } from '../hooks/useMaterials';
import { StockUpdateForm } from './StockUpdateForm';
import { PartnerStockTable } from './PartnerStockTable';
import { StockTable } from './StockTable';
import { useStocks } from '../hooks/useStocks';
import { usePartnerStocks } from '../hooks/usePartnerStocks';

type StockDetailsViewProps<T extends StockType> = {
type: T;
};

export const StockDetailsView = <T extends StockType>({ type }: StockDetailsViewProps<T>) => {
const { materials } = useMaterials(type);
const { stocks, refreshStocks } = useStocks(type);
const [selectedMaterial, setSelectedMaterial] = useState<Stock | null>(null);
const { partnerStocks, refreshPartnerStocks: refresh } = usePartnerStocks(
type,
type === 'product' ? selectedMaterial?.material?.materialNumberSupplier : selectedMaterial?.material?.materialNumberCustomer
);
const [saving, setSaving] = useState<boolean>(false);
const [refreshing, setRefreshing] = useState(false);

const handleStockRefresh = () => {
setRefreshing(true);
refreshPartnerStocks(
type,
(type == 'product' ? selectedMaterial?.material?.materialNumberSupplier : selectedMaterial?.material?.materialNumberCustomer) ??
null
).then(() => {
refresh();
setRefreshing(false);
});
};

const saveStock = (stock: Stock) => {
if (saving) return;
stock.uuid ??=
stocks?.find(
(s) =>
s.stockLocationBpna === stock.stockLocationBpna &&
s.stockLocationBpns === stock.stockLocationBpns &&
(s.material.materialNumberCustomer === stock.material.materialNumberCustomer ||
s.material.materialNumberSupplier === stock.material.materialNumberSupplier) &&
s.partner?.uuid === stock.partner?.uuid
)?.uuid ?? null;
(stock.uuid == null ? postStocks(type, stock) : putStocks(type, stock)).then(() => {
setSaving(false);
refreshStocks();
});
};

return (
<div className="flex flex-col gap-10 pb-5">
<div className="mx-auto">
<StockUpdateForm items={materials} type={type} selectedItem={selectedMaterial} onSubmit={saveStock} isSaving={saving} />
</div>
<StockTable type={type} onSelection={setSelectedMaterial} stocks={stocks ?? []} />
<PartnerStockTable
type={type}
materialName={selectedMaterial?.material?.name}
partnerStocks={partnerStocks ?? []}
onRefresh={handleStockRefresh}
isRefreshing={refreshing}
/>
</div>
);
};
25 changes: 12 additions & 13 deletions frontend/src/features/stock-view/components/StockTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Copyright (c) 2024 Volkswagen AG
Copyright (c) 2024 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST)
Copyright (c) 2024 Contributors to the Eclipse Foundation
See the NOTICE file(s) distributed with this work for additional
Expand All @@ -20,20 +19,21 @@ SPDX-License-Identifier: Apache-2.0
*/

import { Table } from '@catena-x/portal-shared-components';
import { MaterialStock, ProductStock } from '@models/types/data/stock';
import { Stock, StockType } from '@models/types/data/stock';
import { capitalize } from '@mui/material';
import { getUnitOfMeasurement } from '@util/helpers';
import { useStocks } from '../hooks/useStocks';

type StockTableProps<T extends ProductStock | MaterialStock> = {
type: 'material' | 'product';
onSelection: (stock: T) => void;
type StockTableProps = {
type: StockType;
stocks: Stock[];
onSelection: (stock: Stock) => void;
};

const createStockTableColumns = (type: 'material' | 'product') => [
const createStockTableColumns = (type: StockType) => [
{
field: 'materialNumber',
headerName: type === 'material' ? 'Material' : 'Product',
renderCell: (params: { row: MaterialStock }) => (
headerName: capitalize(type),
renderCell: (params: { row: Stock }) => (
<div className="flex flex-col">
<span>{params.row.material?.name}</span>
<span>({type === 'material' ? params.row.material?.materialNumberCustomer : params.row.material?.materialNumberSupplier})</span>
Expand All @@ -43,13 +43,13 @@ const createStockTableColumns = (type: 'material' | 'product') => [
},
{
field: 'quantity',
valueGetter: (data: { row: MaterialStock }) => data.row.quantity + ' ' + getUnitOfMeasurement(data.row.measurementUnit),
valueGetter: (data: { row: Stock }) => data.row.quantity + ' ' + getUnitOfMeasurement(data.row.measurementUnit),
headerName: 'Quantity',
flex: 2,
},
{
field: 'partner',
renderCell: (params: { row: MaterialStock }) => (
renderCell: (params: { row: Stock }) => (
<div className="flex flex-col">
<span>{params.row.partner?.name}</span>
<span>({params.row.partner?.bpnl})</span>
Expand Down Expand Up @@ -89,8 +89,7 @@ const createStockTableColumns = (type: 'material' | 'product') => [
flex: 3,
},
];
export const StockTable = <T extends ProductStock | MaterialStock>({ onSelection, type }: StockTableProps<T>) => {
const { stocks } = useStocks(type);
export const StockTable = ({ onSelection, type, stocks }: StockTableProps) => {
return (
<Table
title="Your Stocks"
Expand Down
Loading

0 comments on commit 0dd0e3c

Please sign in to comment.