refactor: Improve code readability and structure in EventProperties, DelayAction, SwapAction, and PreviewSelectionWithUpload components
This commit is contained in:
parent
328b045a7c
commit
5b6badaa52
|
@ -1,5 +1,8 @@
|
||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { useSelectedEventData, useSelectedProduct } from "../../../../../store/simulation/useSimulationStore";
|
import {
|
||||||
|
useSelectedEventData,
|
||||||
|
useSelectedProduct,
|
||||||
|
} from "../../../../../store/simulation/useSimulationStore";
|
||||||
import { useProductStore } from "../../../../../store/simulation/useProductStore";
|
import { useProductStore } from "../../../../../store/simulation/useProductStore";
|
||||||
import ConveyorMechanics from "./mechanics/conveyorMechanics";
|
import ConveyorMechanics from "./mechanics/conveyorMechanics";
|
||||||
import VehicleMechanics from "./mechanics/vehicleMechanics";
|
import VehicleMechanics from "./mechanics/vehicleMechanics";
|
||||||
|
@ -8,55 +11,69 @@ import MachineMechanics from "./mechanics/machineMechanics";
|
||||||
import StorageMechanics from "./mechanics/storageMechanics";
|
import StorageMechanics from "./mechanics/storageMechanics";
|
||||||
|
|
||||||
const EventProperties: React.FC = () => {
|
const EventProperties: React.FC = () => {
|
||||||
const { selectedEventData } = useSelectedEventData();
|
const { selectedEventData } = useSelectedEventData();
|
||||||
const { getEventByModelUuid } = useProductStore();
|
const { getEventByModelUuid } = useProductStore();
|
||||||
const { selectedProduct } = useSelectedProduct();
|
const { selectedProduct } = useSelectedProduct();
|
||||||
const [currentEventData, setCurrentEventData] = useState<EventsSchema | null>(null);
|
const [currentEventData, setCurrentEventData] = useState<EventsSchema | null>(
|
||||||
const [assetType, setAssetType] = useState<string | null>(null);
|
null
|
||||||
|
);
|
||||||
|
const [assetType, setAssetType] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const event = getCurrentEventData();
|
const event = getCurrentEventData();
|
||||||
setCurrentEventData(event);
|
setCurrentEventData(event);
|
||||||
|
|
||||||
const type = determineAssetType(event);
|
const type = determineAssetType(event);
|
||||||
setAssetType(type);
|
setAssetType(type);
|
||||||
|
}, [selectedEventData, selectedProduct]);
|
||||||
}, [selectedEventData, selectedProduct]);
|
|
||||||
|
|
||||||
const getCurrentEventData = () => {
|
|
||||||
if (!selectedEventData?.data || !selectedProduct) return null;
|
|
||||||
return getEventByModelUuid(selectedProduct.productId, selectedEventData.data.modelUuid) || null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const determineAssetType = (event: EventsSchema | null) => {
|
|
||||||
if (!event) return null;
|
|
||||||
|
|
||||||
switch (event.type) {
|
|
||||||
case 'transfer': return 'conveyor';
|
|
||||||
case 'vehicle': return 'vehicle';
|
|
||||||
case 'roboticArm': return 'roboticArm';
|
|
||||||
case 'machine': return 'machine';
|
|
||||||
case 'storageUnit': return 'storageUnit';
|
|
||||||
default: return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
const getCurrentEventData = () => {
|
||||||
|
if (!selectedEventData?.data || !selectedProduct) return null;
|
||||||
return (
|
return (
|
||||||
<div className="event-proprties-wrapper">
|
getEventByModelUuid(
|
||||||
{currentEventData &&
|
selectedProduct.productId,
|
||||||
<>
|
selectedEventData.data.modelUuid
|
||||||
<div className="header">
|
) ?? null
|
||||||
<div className="header-value">{selectedEventData?.data.modelName}</div>
|
|
||||||
</div>
|
|
||||||
{assetType === 'conveyor' && <ConveyorMechanics />}
|
|
||||||
{assetType === 'vehicle' && <VehicleMechanics />}
|
|
||||||
{assetType === 'roboticArm' && <RoboticArmMechanics />}
|
|
||||||
{assetType === 'machine' && <MachineMechanics />}
|
|
||||||
{assetType === 'storageUnit' && <StorageMechanics />}
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const determineAssetType = (event: EventsSchema | null) => {
|
||||||
|
if (!event) return null;
|
||||||
|
|
||||||
|
switch (event.type) {
|
||||||
|
case "transfer":
|
||||||
|
return "conveyor";
|
||||||
|
case "vehicle":
|
||||||
|
return "vehicle";
|
||||||
|
case "roboticArm":
|
||||||
|
return "roboticArm";
|
||||||
|
case "machine":
|
||||||
|
return "machine";
|
||||||
|
case "storageUnit":
|
||||||
|
return "storageUnit";
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="event-proprties-wrapper">
|
||||||
|
{currentEventData && (
|
||||||
|
<>
|
||||||
|
<div className="header">
|
||||||
|
<div className="header-value">
|
||||||
|
{selectedEventData?.data.modelName}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{assetType === "conveyor" && <ConveyorMechanics />}
|
||||||
|
{assetType === "vehicle" && <VehicleMechanics />}
|
||||||
|
{assetType === "roboticArm" && <RoboticArmMechanics />}
|
||||||
|
{assetType === "machine" && <MachineMechanics />}
|
||||||
|
{assetType === "storageUnit" && <StorageMechanics />}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default EventProperties;
|
export default EventProperties;
|
||||||
|
|
|
@ -2,29 +2,33 @@ import React from "react";
|
||||||
import InputWithDropDown from "../../../../../ui/inputs/InputWithDropDown";
|
import InputWithDropDown from "../../../../../ui/inputs/InputWithDropDown";
|
||||||
|
|
||||||
interface DelayActionProps {
|
interface DelayActionProps {
|
||||||
value: string;
|
value: string;
|
||||||
defaultValue: string;
|
defaultValue: string;
|
||||||
min: number;
|
min: number;
|
||||||
max: number;
|
max: number;
|
||||||
onChange: (value: string) => void;
|
onChange: (value: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DelayAction: React.FC<DelayActionProps> = ({ value, defaultValue, min, max, onChange }) => {
|
const DelayAction: React.FC<DelayActionProps> = ({
|
||||||
return (
|
value,
|
||||||
<>
|
defaultValue,
|
||||||
<InputWithDropDown
|
min,
|
||||||
label="Delay"
|
max,
|
||||||
value={value}
|
onChange,
|
||||||
min={min}
|
}) => {
|
||||||
step={0.1}
|
return (
|
||||||
defaultValue={defaultValue}
|
<InputWithDropDown
|
||||||
max={max}
|
label="Delay"
|
||||||
activeOption="s"
|
value={value}
|
||||||
onClick={() => { }}
|
min={min}
|
||||||
onChange={onChange}
|
step={0.1}
|
||||||
/>
|
defaultValue={defaultValue}
|
||||||
</>
|
max={max}
|
||||||
);
|
activeOption="s"
|
||||||
|
onClick={() => {}}
|
||||||
|
onChange={onChange}
|
||||||
|
/>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DelayAction;
|
export default DelayAction;
|
||||||
|
|
|
@ -1,27 +1,25 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import PreviewSelectionWithUpload from "../../../../../ui/inputs/PreviewSelectionWithUpload";
|
import PreviewSelectionWithUpload from "../../../../../ui/inputs/PreviewSelectionWithUpload";
|
||||||
import LabledDropdown from "../../../../../ui/inputs/LabledDropdown";
|
|
||||||
|
|
||||||
interface SwapActionProps {
|
interface SwapActionProps {
|
||||||
onSelect: (option: string) => void;
|
onSelect: (option: string) => void;
|
||||||
defaultOption: string;
|
defaultOption: string;
|
||||||
options: string[];
|
options: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const SwapAction: React.FC<SwapActionProps> = ({ onSelect, defaultOption, options }) => {
|
const SwapAction: React.FC<SwapActionProps> = ({
|
||||||
|
onSelect,
|
||||||
return (
|
defaultOption,
|
||||||
<>
|
options,
|
||||||
{/* <PreviewSelectionWithUpload /> */}
|
}) => {
|
||||||
|
return (
|
||||||
<LabledDropdown
|
<PreviewSelectionWithUpload
|
||||||
label="Presets"
|
label="Presets"
|
||||||
defaultOption={defaultOption}
|
defaultOption={defaultOption}
|
||||||
options={options}
|
options={options}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
/>
|
/>
|
||||||
</>
|
);
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SwapAction;
|
export default SwapAction;
|
||||||
|
|
|
@ -1,41 +1,72 @@
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import LabledDropdown from "./LabledDropdown";
|
|
||||||
import { ArrowIcon } from "../../icons/ExportCommonIcons";
|
import { ArrowIcon } from "../../icons/ExportCommonIcons";
|
||||||
|
import LabledDropdown from "./LabledDropdown";
|
||||||
|
|
||||||
const PreviewSelectionWithUpload: React.FC = () => {
|
interface PreviewSelectionWithUploadProps {
|
||||||
const [showPreview, setSetshowPreview] = useState(false);
|
preview?: boolean;
|
||||||
|
upload?: boolean;
|
||||||
|
label?: string;
|
||||||
|
onSelect: (option: string) => void;
|
||||||
|
defaultOption: string;
|
||||||
|
options: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const PreviewSelectionWithUpload: React.FC<PreviewSelectionWithUploadProps> = ({
|
||||||
|
preview = false,
|
||||||
|
upload = false,
|
||||||
|
onSelect,
|
||||||
|
label,
|
||||||
|
defaultOption,
|
||||||
|
options,
|
||||||
|
}) => {
|
||||||
|
const [showPreview, setShowPreview] = useState(false);
|
||||||
return (
|
return (
|
||||||
<div className="preview-selection-with-upload-wrapper">
|
<div className="preview-selection-with-upload-wrapper">
|
||||||
<div
|
{preview && (
|
||||||
className="input-header-container"
|
<>
|
||||||
onClick={() => setSetshowPreview(!showPreview)}
|
<button
|
||||||
>
|
className="input-header-container"
|
||||||
<div className="input-header">Preview</div>
|
onClick={() => setShowPreview(!showPreview)}
|
||||||
<div
|
>
|
||||||
className="arrow-container"
|
<div className="input-header">Preview</div>
|
||||||
style={{ rotate: showPreview ? "0deg" : "90deg" }}
|
<div
|
||||||
>
|
className="arrow-container"
|
||||||
<ArrowIcon />
|
style={{ rotate: showPreview ? "0deg" : "90deg" }}
|
||||||
</div>
|
>
|
||||||
</div>
|
<ArrowIcon />
|
||||||
{showPreview && (
|
</div>
|
||||||
<div className="canvas-wrapper">
|
</button>
|
||||||
<div className="canvas-container"></div>
|
{showPreview && (
|
||||||
|
<div className="canvas-wrapper">
|
||||||
|
<div className="canvas-container"></div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{upload && (
|
||||||
|
<div className="asset-selection-container">
|
||||||
|
<div className="upload-custom-asset-button">
|
||||||
|
<div className="title">Upload Product</div>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
accept=".glb, .gltf"
|
||||||
|
id="simulation-product-upload"
|
||||||
|
/>
|
||||||
|
<label
|
||||||
|
className="upload-button"
|
||||||
|
htmlFor="simulation-product-upload"
|
||||||
|
>
|
||||||
|
Upload here
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="asset-selection-container">
|
<LabledDropdown
|
||||||
<div className="upload-custom-asset-button">
|
label={label}
|
||||||
<div className="title">Upload Product</div>
|
defaultOption={defaultOption}
|
||||||
<input
|
options={options}
|
||||||
type="file"
|
onSelect={onSelect}
|
||||||
accept=".glb, .gltf"
|
/>
|
||||||
id="simulation-product-upload"
|
|
||||||
/>
|
|
||||||
<label className="upload-button" htmlFor="simulation-product-upload">
|
|
||||||
Upload here
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue