refactor: Optimize AisleProperties component with useMemo for performance improvements
This commit is contained in:
parent
9875239d54
commit
2f5b20e2d5
|
@ -1,4 +1,4 @@
|
||||||
import React, { useState } from "react";
|
import React, { useMemo, useState } from "react";
|
||||||
import InputWithDropDown from "../../../ui/inputs/InputWithDropDown";
|
import InputWithDropDown from "../../../ui/inputs/InputWithDropDown";
|
||||||
import { ArrowIcon } from "../../../icons/ExportCommonIcons";
|
import { ArrowIcon } from "../../../icons/ExportCommonIcons";
|
||||||
|
|
||||||
|
@ -90,6 +90,26 @@ const AisleProperties: React.FC = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const dashLengthValue = useMemo(() => {
|
||||||
|
return dashLength.toString();
|
||||||
|
}, [aisleType, dashLength]);
|
||||||
|
|
||||||
|
const dotRadiusValue = useMemo(() => {
|
||||||
|
return dotRadius.toString();
|
||||||
|
}, [aisleType, dotRadius]);
|
||||||
|
|
||||||
|
const gapLengthValue = useMemo(() => {
|
||||||
|
return gapLength.toString();
|
||||||
|
}, [aisleType, gapLength]);
|
||||||
|
|
||||||
|
const aisleWidthValue = useMemo(() => {
|
||||||
|
return aisleWidth.toString();
|
||||||
|
}, [aisleType, aisleWidth]);
|
||||||
|
|
||||||
|
const aisleLengthValue = useMemo(() => {
|
||||||
|
return aisleLength.toString();
|
||||||
|
}, [aisleType, aisleLength]);
|
||||||
|
|
||||||
const renderAdvancedProperties = () => {
|
const renderAdvancedProperties = () => {
|
||||||
switch (aisleType) {
|
switch (aisleType) {
|
||||||
case 'dashed-aisle':
|
case 'dashed-aisle':
|
||||||
|
@ -99,7 +119,7 @@ const AisleProperties: React.FC = () => {
|
||||||
<>
|
<>
|
||||||
<InputWithDropDown
|
<InputWithDropDown
|
||||||
label="Dash Length"
|
label="Dash Length"
|
||||||
value={`${dashLength}`}
|
value={`${dashLengthValue}`}
|
||||||
min={0.1}
|
min={0.1}
|
||||||
step={0.1}
|
step={0.1}
|
||||||
max={2}
|
max={2}
|
||||||
|
@ -107,7 +127,7 @@ const AisleProperties: React.FC = () => {
|
||||||
/>
|
/>
|
||||||
<InputWithDropDown
|
<InputWithDropDown
|
||||||
label="Gap Length"
|
label="Gap Length"
|
||||||
value={`${gapLength}`}
|
value={`${gapLengthValue}`}
|
||||||
min={0.1}
|
min={0.1}
|
||||||
step={0.1}
|
step={0.1}
|
||||||
max={2}
|
max={2}
|
||||||
|
@ -124,7 +144,7 @@ const AisleProperties: React.FC = () => {
|
||||||
<>
|
<>
|
||||||
<InputWithDropDown
|
<InputWithDropDown
|
||||||
label="Dot Radius"
|
label="Dot Radius"
|
||||||
value={`${dotRadius}`}
|
value={`${dotRadiusValue}`}
|
||||||
min={0.1}
|
min={0.1}
|
||||||
step={0.1}
|
step={0.1}
|
||||||
max={2}
|
max={2}
|
||||||
|
@ -132,7 +152,7 @@ const AisleProperties: React.FC = () => {
|
||||||
/>
|
/>
|
||||||
<InputWithDropDown
|
<InputWithDropDown
|
||||||
label="Gap Length"
|
label="Gap Length"
|
||||||
value={`${gapLength}`}
|
value={`${gapLengthValue}`}
|
||||||
min={0.1}
|
min={0.1}
|
||||||
step={0.1}
|
step={0.1}
|
||||||
max={2}
|
max={2}
|
||||||
|
@ -148,7 +168,7 @@ const AisleProperties: React.FC = () => {
|
||||||
<>
|
<>
|
||||||
<InputWithDropDown
|
<InputWithDropDown
|
||||||
label="Arrow Length"
|
label="Arrow Length"
|
||||||
value={`${aisleLength}`}
|
value={`${aisleLengthValue}`}
|
||||||
min={0.1}
|
min={0.1}
|
||||||
step={0.1}
|
step={0.1}
|
||||||
max={2}
|
max={2}
|
||||||
|
@ -156,7 +176,7 @@ const AisleProperties: React.FC = () => {
|
||||||
/>
|
/>
|
||||||
<InputWithDropDown
|
<InputWithDropDown
|
||||||
label="Gap Length"
|
label="Gap Length"
|
||||||
value={`${gapLength}`}
|
value={`${gapLengthValue}`}
|
||||||
min={0.1}
|
min={0.1}
|
||||||
step={0.1}
|
step={0.1}
|
||||||
max={2}
|
max={2}
|
||||||
|
@ -179,7 +199,7 @@ const AisleProperties: React.FC = () => {
|
||||||
{aisleType !== 'dotted-aisle' &&
|
{aisleType !== 'dotted-aisle' &&
|
||||||
<InputWithDropDown
|
<InputWithDropDown
|
||||||
label="Aisle Width"
|
label="Aisle Width"
|
||||||
value={`${aisleWidth}`}
|
value={`${aisleWidthValue}`}
|
||||||
min={0.1}
|
min={0.1}
|
||||||
step={0.1}
|
step={0.1}
|
||||||
max={2}
|
max={2}
|
||||||
|
|
|
@ -184,7 +184,7 @@ const ZoneGroup: React.FC = () => {
|
||||||
const target: [number, number, number] | null = calculateCenter(
|
const target: [number, number, number] | null = calculateCenter(
|
||||||
zone.points
|
zone.points
|
||||||
);
|
);
|
||||||
if (!target) return;
|
if (!target || zone.points.length < 4) return;
|
||||||
const position = [target[0], 10, target[2]];
|
const position = [target[0], 10, target[2]];
|
||||||
|
|
||||||
const input = {
|
const input = {
|
||||||
|
@ -238,7 +238,7 @@ const ZoneGroup: React.FC = () => {
|
||||||
const target: [number, number, number] | null = calculateCenter(
|
const target: [number, number, number] | null = calculateCenter(
|
||||||
zone.points
|
zone.points
|
||||||
);
|
);
|
||||||
if (!target) return;
|
if (!target || zone.points.length < 4) return;
|
||||||
const position = [target[0], 10, target[2]];
|
const position = [target[0], 10, target[2]];
|
||||||
|
|
||||||
const input = {
|
const input = {
|
||||||
|
@ -553,7 +553,7 @@ const ZoneGroup: React.FC = () => {
|
||||||
const midpoint = new THREE.Vector3(
|
const midpoint = new THREE.Vector3(
|
||||||
(point1.x + point2.x) / 2,
|
(point1.x + point2.x) / 2,
|
||||||
CONSTANTS.zoneConfig.height / 2 +
|
CONSTANTS.zoneConfig.height / 2 +
|
||||||
(zone.layer - 1) * CONSTANTS.zoneConfig.height,
|
(zone.layer - 1) * CONSTANTS.zoneConfig.height,
|
||||||
(point1.z + point2.z) / 2
|
(point1.z + point2.z) / 2
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -583,12 +583,13 @@ const ZoneGroup: React.FC = () => {
|
||||||
|
|
||||||
// Ensure the polygon is closed
|
// Ensure the polygon is closed
|
||||||
if (
|
if (
|
||||||
coords2D.length >= 3 &&
|
coords2D.length >= 4 &&
|
||||||
(coords2D[0][0] !== coords2D[coords2D.length - 1][0] ||
|
(coords2D[0][0] !== coords2D[coords2D.length - 1][0] ||
|
||||||
coords2D[0][1] !== coords2D[coords2D.length - 1][1])
|
coords2D[0][1] !== coords2D[coords2D.length - 1][1])
|
||||||
) {
|
) {
|
||||||
coords2D.push(coords2D[0]);
|
coords2D.push(coords2D[0]);
|
||||||
}
|
}
|
||||||
|
if (coords2D.length < 4) return null;
|
||||||
|
|
||||||
const polygon = turf.polygon([coords2D]);
|
const polygon = turf.polygon([coords2D]);
|
||||||
const center2D = turf.center(polygon).geometry.coordinates;
|
const center2D = turf.center(polygon).geometry.coordinates;
|
||||||
|
@ -648,12 +649,13 @@ const ZoneGroup: React.FC = () => {
|
||||||
const coords2D = points3D.map((p: any) => [p[0], p[2]]);
|
const coords2D = points3D.map((p: any) => [p[0], p[2]]);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
coords2D.length < 3 ||
|
coords2D.length < 4 ||
|
||||||
coords2D[0][0] !== coords2D[coords2D.length - 1][0] ||
|
coords2D[0][0] !== coords2D[coords2D.length - 1][0] ||
|
||||||
coords2D[0][1] !== coords2D[coords2D.length - 1][1]
|
coords2D[0][1] !== coords2D[coords2D.length - 1][1]
|
||||||
) {
|
) {
|
||||||
coords2D.push(coords2D[0]);
|
coords2D.push(coords2D[0]);
|
||||||
}
|
}
|
||||||
|
if (coords2D.length < 4) return null;
|
||||||
|
|
||||||
const polygon = turf.polygon([coords2D]);
|
const polygon = turf.polygon([coords2D]);
|
||||||
const center2D = turf.center(polygon).geometry.coordinates;
|
const center2D = turf.center(polygon).geometry.coordinates;
|
||||||
|
|
Loading…
Reference in New Issue