From 27e90b472695b722a0669ea761dddd0f0181c128 Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Fri, 12 Jul 2024 02:01:17 +0200 Subject: [PATCH 1/3] [Fix #507] Fixed FTA table head style --- .../table/FaultTreeAndSystemOverviewTable.tsx | 4 ++-- src/components/table/FaultTreeTableHead.tsx | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/components/table/FaultTreeAndSystemOverviewTable.tsx b/src/components/table/FaultTreeAndSystemOverviewTable.tsx index 19646963..3e355eec 100644 --- a/src/components/table/FaultTreeAndSystemOverviewTable.tsx +++ b/src/components/table/FaultTreeAndSystemOverviewTable.tsx @@ -68,7 +68,7 @@ const FaultTreeAndSystemOverviewTable: FC = ({ }; const applyFilters = () => { - setAppliedFilters(filterValues); // Apply the filters + setAppliedFilters(filterValues); handleFilterChange(filterValues.label, filterValues.snsLabel); handleFilterClose(); }; @@ -83,7 +83,7 @@ const FaultTreeAndSystemOverviewTable: FC = ({ sortConfig={sortConfig || initialSortConfig} onSortChange={handleSortChange} onFilterClick={handleFilterClick} - filterValues={appliedFilters} // Pass applied filters + filterValues={appliedFilters} /> )} {systems && } diff --git a/src/components/table/FaultTreeTableHead.tsx b/src/components/table/FaultTreeTableHead.tsx index 59fdfe89..77f49e01 100644 --- a/src/components/table/FaultTreeTableHead.tsx +++ b/src/components/table/FaultTreeTableHead.tsx @@ -1,6 +1,7 @@ import React, { FC } from "react"; import { TableCell, TableRow, Box, TableSortLabel } from "@mui/material"; import FilterListIcon from "@mui/icons-material/FilterList"; +import useStyles from "./FaultTreeOverviewTable.styles"; interface FaultTreeTableHeadProps { sortConfig: { key: string; direction: "asc" | "desc" }; @@ -10,9 +11,11 @@ interface FaultTreeTableHeadProps { } const FaultTreeTableHead: FC = ({ sortConfig, onSortChange, onFilterClick, filterValues }) => { + const { classes } = useStyles(); + return ( - + onFilterClick(e, "label")} style={{ cursor: "pointer", marginRight: "8px" }}> FHA Label @@ -25,10 +28,10 @@ const FaultTreeTableHead: FC = ({ sortConfig, onSortCha /> - Aircraft Type - + Aircraft Type + - onFilterClick(e, "snsLabel")} style={{ cursor: "pointer", marginRight: "8px" }}> + onFilterClick(e, "snsLabel")} style={{ cursor: "pointer" }}> SNS Label {filterValues.snsLabel && } @@ -39,11 +42,11 @@ const FaultTreeTableHead: FC = ({ sortConfig, onSortCha /> - Calculated Failure Rate - FHA Based Failure Rate - Required Failure Rate - Last Modified - + Calculated Failure Rate + FHA Based Failure Rate + Required Failure Rate + Last Modified + Created = ({ sortConfig, onSortCha /> - Last Editor + Last Editor ); }; From cf934109836bba67157ee2d18c1fbf988837da74 Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Fri, 12 Jul 2024 03:23:25 +0200 Subject: [PATCH 2/3] [Fix #510] Fixed inconsistent behavior of event creation --- .../dialog/faultEvent/FaultEventCreation.tsx | 57 ++++++++++++------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/src/components/dialog/faultEvent/FaultEventCreation.tsx b/src/components/dialog/faultEvent/FaultEventCreation.tsx index 187fb544..645e0617 100644 --- a/src/components/dialog/faultEvent/FaultEventCreation.tsx +++ b/src/components/dialog/faultEvent/FaultEventCreation.tsx @@ -1,5 +1,4 @@ import * as React from "react"; - import { FormControl, InputLabel, MenuItem, Select, TextField, Typography } from "@mui/material"; import useStyles from "@components/dialog/faultEvent/FaultEventCreation.styles"; import { Controller } from "react-hook-form"; @@ -19,7 +18,6 @@ interface Props { isEditMode?: boolean; } -// TODO: remove ts-ignores and migrate to higher version of react-hook-form const FaultEventCreation = ({ useFormMethods, isRootEvent, @@ -41,35 +39,55 @@ const FaultEventCreation = ({ } = useFormMethods; const faultEvents = useReusableFaultEvents(); - const [newEvent, setNewEvent] = useState(null); + const [newEvent, setNewEvent] = useState(null); const [selectedEvent, setSelectedEvent] = useState(null); const [showCreateEvent, setShowCreateEvent] = useState(false); + const [isCreatedEvent, setIsCreatedEvent] = useState(false); const existingEventSelected = Boolean(selectedEvent); const lastGateTypeRef = useRef(selectedEvent?.gateType); const eventTypeWatch = watch("eventType"); const gateTypeWatch = watch("gateType"); useEffect(() => { - if (selectedEvent) { - setValue("name", selectedEvent.name); - setValue("existingEvent", selectedEvent.iri ? selectedEvent : null); - } else { - reset(); - } - }, [selectedEvent]); + const updateValues = () => { + if (selectedEvent) { + setValue("name", selectedEvent.name); + setValue("existingEvent", selectedEvent.iri ? selectedEvent : null); + + if (existingEventSelected) { + setValue("eventType", selectedEvent.eventType); + } + + if (isRootEvent || isCreatedEvent) { + setValue("eventType", EventType.INTERMEDIATE); + setValue("gateType", GateType.OR); + } + } else { + reset(); + } + }; + + updateValues(); + }, [isRootEvent, selectedEvent, setValue, existingEventSelected, isCreatedEvent]); const [filteredOptions, setFilteredOptions] = useState([{}]); const updatedFHAEventTypes = updateEventsType(faultEvents, "fha-fault-event", EventType.EXTERNAL); - const handleFilterOptions = (inputValue) => { + const handleFilterOptions = (inputValue: string) => { const filtered = faultEvents.filter((option) => option.name.toLowerCase().includes(inputValue.toLowerCase())); setNewEvent(inputValue); setFilteredOptions(filtered); }; const handleOnCreateEventClick = (e: MouseEvent) => { - setSelectedEvent({ name: newEvent }); + setSelectedEvent({ name: newEvent } as FaultEvent); setShowCreateEvent(true); + setIsCreatedEvent(true); + }; + + const handleEventSelect = (data: any) => { + setSelectedEvent(data); + setIsCreatedEvent(false); }; function renderEventSelect() { @@ -85,7 +103,7 @@ const FaultEventCreation = ({ control={control} name="event" options={isRootEvent ? faultEvents : updatedFHAEventTypes} - onChangeCallback={(data: any) => setSelectedEvent(data)} + onChangeCallback={handleEventSelect} onInputChangeCallback={handleFilterOptions} onCreateEventClick={handleOnCreateEventClick} getOptionKey={(option) => option.iri} @@ -97,8 +115,8 @@ const FaultEventCreation = ({ disabled={disabled} /> - {!selectedEvent && !isRootEvent && ( - + {selectedEvent && ( + {t("newFtaModal.type")} { @@ -113,7 +131,7 @@ const FaultEventCreation = ({ return ( @@ -156,7 +154,7 @@ const FaultEventCreation = ({ function renderEventForm() { return ( <> - {selectedEvent && eventTypeWatch === EventType.INTERMEDIATE && ( + {eventTypeWatch === EventType.INTERMEDIATE && (
{t("newFtaModal.gateType")}