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

feat: implemented delivery information in the frontend #362

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ private boolean validateResponsibility(ReportedDelivery delivery) {
return delivery.getIncoterm() != null && switch (delivery.getIncoterm().getResponsibility()) {
case CUSTOMER ->
delivery.getMaterial().isProductFlag() &&
ownPartnerEntity.getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getDestinationBpns())) &&
delivery.getPartner().getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getOriginBpns()));
ownPartnerEntity.getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getOriginBpns())) &&
delivery.getPartner().getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getDestinationBpns()));
case SUPPLIER ->
delivery.getMaterial().isMaterialFlag() &&
delivery.getPartner().getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getDestinationBpns())) &&
ownPartnerEntity.getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getOriginBpns()));
delivery.getPartner().getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getOriginBpns())) &&
ownPartnerEntity.getSites().stream().anyMatch(site -> site.getBpns().equals(delivery.getDestinationBpns()));
case PARTIAL ->
(
delivery.getMaterial().isMaterialFlag() &&
Expand Down
2 changes: 1 addition & 1 deletion charts/puris/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies:
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 2.2.0
version: 2.3.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
10 changes: 9 additions & 1 deletion charts/puris/templates/frontend-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
{{- toYaml .Values.frontend.podSecurityContext | nindent 8 }}
containers:
- name: {{ include "frontend.fullname" . }}
securityContext:

Check warning on line 53 in charts/puris/templates/frontend-deployment.yaml

View workflow job for this annotation

GitHub Actions / Analyze

[MEDIUM] Container Running With Low UID

Check if containers are running with low UID, which might cause conflicts with the host's user table.
{{- toYaml .Values.frontend.securityContext | nindent 12 }}
image: "{{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.frontend.image.pullPolicy }}
Expand Down Expand Up @@ -80,7 +80,15 @@
- name: ENDPOINT_UPDATE_REPORTED_PRODUCT_STOCKS
value: "{{ .Values.frontend.puris.endpointUpdateReportedProductStocks }}"
- name: ENDPOINT_PARTNER_OWNSITES
value: "{{ .Values.frontend.puris.endpointPartnerOwnSites }}"
value: "{{ .Values.frontend.puris.endpointPartnerOwnSites }}"
- name: ENDPOINT_DEMAND
value: "{{ .Values.frontend.puris.endpointDemand }}"
- name: ENDPOINT_PRODUCTION
value: "{{ .Values.frontend.puris.endpointProduction }}"
- name: ENDPOINT_PRODUCTION_RANGE
value: "{{ .Values.frontend.puris.endpointProductionRange }}"
- name: ENDPOINT_DELIVERY
value: "{{ .Values.frontend.puris.endpointDelivery }}"
- name: BACKEND_API_KEY
value: "{{ .Values.backend.puris.api.key}}"
- name: IDP_DISABLE
Expand Down
8 changes: 8 additions & 0 deletions charts/puris/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ frontend:
endpointUpdateReportedProductStocks: stockView/update-reported-product-stocks?ownMaterialNumber=
# -- The endpoint for the partners BPNS
endpointPartnerOwnSites: partners/ownSites
# -- The endpoint for the demand submodel
endpointDemand: demand
# -- The endpoint for the production submodel
endpointProduction: production
# -- The endpoint for the production range of the production submodel
endpointProductionRange: production/range
# -- The endpoint for the delivery submodel
endpointDelivery: delivery
Copy link
Contributor

Choose a reason for hiding this comment

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

Please run helm-docs to update the readme of the chart

keycloak:
# -- Disable the Keycloak integration.
disabled: true
Expand Down
1 change: 1 addition & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ VITE_ENDPOINT_PARTNER_OWNSITES=partners/ownSites
VITE_ENDPOINT_DEMAND=demand
VITE_ENDPOINT_PRODUCTION=production
VITE_ENDPOINT_PRODUCTION_RANGE=production/range
VITE_ENDPOINT_DELIVERY=delivery
tom-rm-meyer-ISST marked this conversation as resolved.
Show resolved Hide resolved

VITE_IDP_DISABLE=true
VITE_IDP_URL=http://localhost:10081/
Expand Down
1 change: 1 addition & 0 deletions frontend/.env.dockerbuild
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ VITE_ENDPOINT_PARTNER_OWNSITES=\$ENDPOINT_PARTNER_OWNSITES
VITE_ENDPOINT_DEMAND=\$ENDPOINT_DEMAND
VITE_ENDPOINT_PRODUCTION=\$ENDPOINT_PRODUCTION
VITE_ENDPOINT_PRODUCTION_RANGE=\$ENDPOINT_PRODUCTION_RANGE
VITE_ENDPOINT_DELIVERY=\$ENDPOINT_DELIVERY

VITE_IDP_DISABLE=\$IDP_DISABLE
VITE_IDP_URL=\$IDP_URL
Expand Down
80 changes: 51 additions & 29 deletions frontend/src/features/dashboard/components/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,22 @@ import { PlannedProductionModal } from './PlannedProductionModal';
import { useProduction } from '../hooks/useProduction';
import { useReportedProduction } from '../hooks/useReportedProduction';

import { refreshPartnerStocks } from '@services/stocks-service';
import { requestReportedStocks } from '@services/stocks-service';
import { useDelivery } from '../hooks/useDelivery';
import { requestReportedDeliveries } from '@services/delivery-service';
import { requestReportedProductions } from '@services/productions-service';
import { requestReportedDemands } from '@services/demands-service';
import { ModalMode } from '@models/types/data/modal-mode';

const NUMBER_OF_DAYS = 28;

type DashboardState = {
selectedMaterial: MaterialDescriptor | null;
selectedSite: Site | null;
selectedPartnerSites: Site[] | null;
deliveryDialogOptions: { open: boolean; mode: 'create' | 'edit' };
demandDialogOptions: { open: boolean; mode: 'create' | 'edit' };
productionDialogOptions: { open: boolean; mode: 'create' | 'edit' };
deliveryDialogOptions: { open: boolean; mode: ModalMode, direction: 'incoming' | 'outgoing', site: Site | null };
demandDialogOptions: { open: boolean; mode: ModalMode };
productionDialogOptions: { open: boolean; mode: ModalMode };
delivery: Delivery | null;
demand: Partial<Demand> | null;
production: Partial<Production> | null;
Expand All @@ -71,7 +76,7 @@ const initialState: DashboardState = {
selectedMaterial: null,
selectedSite: null,
selectedPartnerSites: null,
deliveryDialogOptions: { open: false, mode: 'create' },
deliveryDialogOptions: { open: false, mode: 'edit', direction: 'incoming', site: null },
demandDialogOptions: { open: false, mode: 'edit' },
productionDialogOptions: { open: false, mode: 'edit' },
delivery: null,
Expand All @@ -83,7 +88,7 @@ const initialState: DashboardState = {
export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
const [state, dispatch] = useReducer(reducer, initialState);
const { stocks } = useStocks(type === 'customer' ? 'material' : 'product');
const { partnerStocks, refreshPartnerStocks: refresh } = usePartnerStocks(
const { partnerStocks } = usePartnerStocks(
type === 'customer' ? 'material' : 'product',
state.selectedMaterial?.ownMaterialNumber ?? null
);
Expand All @@ -94,25 +99,37 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
state.selectedSite?.bpns ?? null
);
const { reportedProductions } = useReportedProduction(state.selectedMaterial?.ownMaterialNumber ?? null);
const { deliveries, refreshDelivery } = useDelivery(
state.selectedMaterial?.ownMaterialNumber ?? null,
state.selectedSite?.bpns ?? null
);

const handleRefresh = () => {
dispatch({ type: 'isRefreshing', payload: true });
refreshPartnerStocks( type === 'customer' ? 'material' : 'product', state.selectedMaterial?.ownMaterialNumber ?? null )
.then(refresh)
.finally(() => dispatch({ type: 'isRefreshing', payload: false }));
Promise.all([
requestReportedStocks(type === 'customer' ? 'material' : 'product', state.selectedMaterial?.ownMaterialNumber ?? null),
requestReportedDeliveries(state.selectedMaterial?.ownMaterialNumber ?? null),
type === 'customer'
? requestReportedProductions(state.selectedMaterial?.ownMaterialNumber ?? null)
: requestReportedDemands(state.selectedMaterial?.ownMaterialNumber ?? null)
]).finally(() => dispatch({ type: 'isRefreshing', payload: false }));
};
const openDeliveryDialog = (d: Partial<Delivery>) => {
const openDeliveryDialog = useCallback(
(d: Partial<Delivery>, mode: ModalMode, direction: 'incoming' | 'outgoing' = 'outgoing', site: Site | null) => {
d.ownMaterialNumber = state.selectedMaterial?.ownMaterialNumber ?? '';
dispatch({ type: 'delivery', payload: d });
dispatch({ type: 'deliveryDialogOptions', payload: { open: true, mode: 'edit' } });
};
const openDemandDialog = (d: Partial<Demand>, mode: 'create' | 'edit') => {
dispatch({ type: 'deliveryDialogOptions', payload: { open: true, mode, direction, site } });
},
[state.selectedMaterial?.ownMaterialNumber]
);
const openDemandDialog = (d: Partial<Demand>, mode: ModalMode) => {
d.measurementUnit ??= 'unit:piece';
d.demandCategoryCode ??= DEMAND_CATEGORY[0]?.key;
d.ownMaterialNumber = state.selectedMaterial?.ownMaterialNumber ?? '';
dispatch({ type: 'demand', payload: d });
dispatch({ type: 'demandDialogOptions', payload: { open: true, mode } });
};
const openProductionDialog = (p: Partial<Production>, mode: 'create' | 'edit') => {
const openProductionDialog = (p: Partial<Production>, mode: ModalMode) => {
p.material ??= {
materialFlag: true,
productFlag: false,
Expand Down Expand Up @@ -154,18 +171,20 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
numberOfDays={NUMBER_OF_DAYS}
stocks={stocks ?? []}
site={state.selectedSite}
onDeliveryClick={openDeliveryDialog}
onDeliveryClick={(delivery, mode) => openDeliveryDialog(delivery, mode, 'outgoing', state.selectedSite)}
onProductionClick={openProductionDialog}
productions={productions ?? []}
deliveries={deliveries ?? []}
/>
) : (
<DemandTable
numberOfDays={NUMBER_OF_DAYS}
stocks={stocks}
site={state.selectedSite}
onDeliveryClick={openDeliveryDialog}
onDeliveryClick={(delivery, mode) => openDeliveryDialog(delivery, mode, 'incoming', state.selectedSite)}
onDemandClick={openDemandDialog}
demands={demands}
deliveries={deliveries ?? []}
/>
)
) : (
Expand Down Expand Up @@ -209,9 +228,10 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
numberOfDays={NUMBER_OF_DAYS}
stocks={partnerStocks}
site={ps}
onDeliveryClick={openDeliveryDialog}
onDeliveryClick={(delivery, mode) => openDeliveryDialog(delivery, mode, 'incoming', ps)}
onDemandClick={openDemandDialog}
demands={reportedDemands?.filter((d) => d.demandLocationBpns === ps.bpns) ?? []}
deliveries={deliveries ?? []}
readOnly
/>
) : (
Expand All @@ -220,9 +240,10 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
numberOfDays={NUMBER_OF_DAYS}
stocks={partnerStocks ?? []}
site={ps}
onDeliveryClick={openDeliveryDialog}
onDeliveryClick={(delivery, mode) => openDeliveryDialog(delivery, mode, 'outgoing', ps)}
onProductionClick={openProductionDialog}
productions={reportedProductions?.filter((p) => p.productionSiteBpns === ps.bpns) ?? []}
deliveries={deliveries ?? []}
readOnly
/>
)
Expand All @@ -236,27 +257,28 @@ export const Dashboard = ({ type }: { type: 'customer' | 'supplier' }) => {
</Stack>
)}
</Stack>
<DeliveryInformationModal
open={state.deliveryDialogOptions.open}
onClose={() =>
dispatch({ type: 'deliveryDialogOptions', payload: { open: false, mode: state.deliveryDialogOptions.mode } })
}
delivery={state.delivery}
/>
<DemandCategoryModal
open={state.demandDialogOptions.open}
mode={state.demandDialogOptions.mode}
{...state.demandDialogOptions}
onClose={() => dispatch({ type: 'demandDialogOptions', payload: { open: false, mode: state.demandDialogOptions.mode } })}
onSave={refreshDemand}
demand={state.demand}
demands={demands ?? []}
demands={(state.demandDialogOptions.mode === 'view' ? reportedDemands : demands) ?? []}
/>
<PlannedProductionModal
{...state.productionDialogOptions}
onClose={() => dispatch({ type: 'productionDialogOptions', payload: { open: false, mode: state.productionDialogOptions.mode } })}
onSave={refreshProduction}
production={state.production}
productions={state.productionDialogOptions.mode === 'edit' ? productions ?? [] : []}
productions={(state.productionDialogOptions.mode === 'view' ? reportedProductions : productions) ?? []}
/>
<DeliveryInformationModal
{...state.deliveryDialogOptions}
onClose={() =>
dispatch({ type: 'deliveryDialogOptions', payload: { ...state.deliveryDialogOptions, open: false, } })
}
onSave={refreshDelivery}
delivery={state.delivery}
deliveries={deliveries ?? []}
/>
</>
);
Expand Down
Loading
Loading