Skip to content

Commit

Permalink
Merge pull request #412 from kbss-cvut/fix/minor-fault-event-update-bugs
Browse files Browse the repository at this point in the history
Fix/minor fault event update bugs
  • Loading branch information
blcham authored Jun 13, 2024
2 parents 41f3537 + 1305c9e commit 4d2a3c2
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components/dialog/component/ComponentPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const ComponentPicker = ({ selectedComponent, onComponentSelected }: Props) => {
name={"component"}
fullWidth
options={components}
getOptionKey={(option) => option.iri}
getOptionLabel={(option) => option.name}
onChangeCallback={(value: Component) => onComponentSelected(value)}
renderInput={(params) => <TextField {...params} label="Select Component" variant="outlined" />}
Expand Down
1 change: 1 addition & 0 deletions src/components/dialog/faultEvent/FaultEventCreation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const FaultEventCreation = ({ useFormMethods, isRootEvent, eventValue, isEditedE
onChangeCallback={(data: any) => setSelectedEvent(data)}
onInputChangeCallback={handleFilterOptions}
onCreateEventClick={handleOnCreateEventClick}
getOptionKey={(option) => option.iri}
getOptionLabel={(option) => option.name}
renderInput={(params) => (
<TextField {...params} label={t("newFtaModal.eventPlaceholder")} variant="outlined" {...register("name")} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { SnackbarType, useSnackbar } from "@hooks/useSnackbar";
import useStyles from "@components/editor/faultTree/menu/faultEvent/FaultEventShapeToolPane.styles";
import { ReusableFaultEventsProvider } from "@hooks/useReusableFaultEvents";
import { useCurrentFaultTree } from "@hooks/useCurrentFaultTree";
import { asArray } from "@utils/utils";

interface Props {
data?: FaultEvent;
Expand All @@ -33,13 +34,15 @@ const FaultEventShapeToolPane = ({ data, onEventUpdated, refreshTree }: Props) =
let defaultValues;

if (data) {
const safeSupertype = asArray(data.supertypes).map((t) => ({ name: t.name, iri: t.iri, types: t.types }))?.[0];
defaultValues = {
eventType: data.eventType,
name: data.name,
description: data.description,
probability: data.probability ? data.probability : 0.01,
gateType: data.gateType ? data.gateType : null,
sequenceProbability: data.sequenceProbability,
existingEvent: safeSupertype,
};

useFormMethods = useForm({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const ComponentSidebarMenu = ({ component, onComponentUpdated, systemComponents
name="linkedComponent"
options={allowedComponents}
onChangeCallback={handleLinkedComponentChange}
getOptionKey={(option) => option.iri}
getOptionLabel={(option) => option.name}
renderInput={(params) => <TextField {...params} label="Linked Component" variant="outlined" />}
defaultValue={null}
Expand Down
3 changes: 3 additions & 0 deletions src/components/materialui/ControlledAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useTranslation } from "react-i18next";
interface Props {
name: string;
options: any[];
getOptionKey: (any) => string;
getOptionLabel: (any) => string;
renderInput;
control;
Expand Down Expand Up @@ -46,6 +47,7 @@ const ControlledAutocomplete = ({
options = [],
name,
renderInput,
getOptionKey,
getOptionLabel,
control,
onChangeCallback,
Expand Down Expand Up @@ -88,6 +90,7 @@ const ControlledAutocomplete = ({
<Autocomplete
fullWidth
options={_options}
getOptionKey={getOptionKey}
getOptionLabel={getOptionLabel}
renderOption={renderOption}
renderInput={renderInput}
Expand Down
2 changes: 1 addition & 1 deletion src/services/faultEventService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const findAll = async (): Promise<FaultEvent[]> => {

export const update = async (faultEvent: FaultEvent): Promise<void> => {
try {
const updateRequest = Object.assign({}, faultEvent, { "@context": EVENT_CONTEXT });
const updateRequest = simplifyReferencesOfReferences(Object.assign({}, faultEvent, { "@context": EVENT_CONTEXT }));

await axiosClient.put("/faultEvents", updateRequest, {
headers: authHeaders(),
Expand Down

0 comments on commit 4d2a3c2

Please sign in to comment.