refactor(rack-planner): lift port config modal state to root level to avoid rendering issues within transformed modules
This commit is contained in:
@@ -15,11 +15,9 @@ interface ModuleBlockProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function ModuleBlock({ module }: ModuleBlockProps) {
|
export function ModuleBlock({ module }: ModuleBlockProps) {
|
||||||
const { racks, updateModuleLocal } = useRackStore();
|
const { racks, updateModuleLocal, setActiveConfigPortId } = useRackStore();
|
||||||
const [hovered, setHovered] = useState(false);
|
const [hovered, setHovered] = useState(false);
|
||||||
const [editOpen, setEditOpen] = useState(false);
|
const [editOpen, setEditOpen] = useState(false);
|
||||||
const [portModalOpen, setPortModalOpen] = useState(false);
|
|
||||||
const [selectedPortId, setSelectedPortId] = useState<string | null>(null);
|
|
||||||
|
|
||||||
// Resize state
|
// Resize state
|
||||||
const [previewUSize, setPreviewUSize] = useState<number | null>(null);
|
const [previewUSize, setPreviewUSize] = useState<number | null>(null);
|
||||||
@@ -105,8 +103,7 @@ export function ModuleBlock({ module }: ModuleBlockProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openPort(portId: string) {
|
function openPort(portId: string) {
|
||||||
setSelectedPortId(portId);
|
setActiveConfigPortId(portId);
|
||||||
setPortModalOpen(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { cablingFromPortId, setCablingFromPortId, createConnection } = useRackStore();
|
const { cablingFromPortId, setCablingFromPortId, createConnection } = useRackStore();
|
||||||
@@ -236,17 +233,6 @@ export function ModuleBlock({ module }: ModuleBlockProps) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ModuleEditPanel module={module} open={editOpen} onClose={() => setEditOpen(false)} />
|
<ModuleEditPanel module={module} open={editOpen} onClose={() => setEditOpen(false)} />
|
||||||
|
|
||||||
{selectedPortId && (
|
|
||||||
<PortConfigModal
|
|
||||||
portId={selectedPortId}
|
|
||||||
open={portModalOpen}
|
|
||||||
onClose={() => {
|
|
||||||
setPortModalOpen(false);
|
|
||||||
setSelectedPortId(null);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import { RackColumn } from './RackColumn';
|
|||||||
import { DevicePalette } from './DevicePalette';
|
import { DevicePalette } from './DevicePalette';
|
||||||
import { ConnectionLayer } from './ConnectionLayer';
|
import { ConnectionLayer } from './ConnectionLayer';
|
||||||
import { AddModuleModal } from '../modals/AddModuleModal';
|
import { AddModuleModal } from '../modals/AddModuleModal';
|
||||||
|
import { PortConfigModal } from '../modals/PortConfigModal';
|
||||||
import { RackSkeleton } from '../ui/Skeleton';
|
import { RackSkeleton } from '../ui/Skeleton';
|
||||||
import type { ModuleType } from '../../types';
|
import type { ModuleType } from '../../types';
|
||||||
import { MODULE_TYPE_COLORS, MODULE_TYPE_LABELS } from '../../lib/constants';
|
import { MODULE_TYPE_COLORS, MODULE_TYPE_LABELS } from '../../lib/constants';
|
||||||
@@ -85,7 +86,7 @@ const POINTER_SENSOR_OPTIONS = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function RackPlanner() {
|
export function RackPlanner() {
|
||||||
const { racks, loading, fetchRacks, moveModule } = useRackStore();
|
const { racks, loading, fetchRacks, moveModule, activeConfigPortId, setActiveConfigPortId } = useRackStore();
|
||||||
const canvasRef = useRef<HTMLDivElement>(null);
|
const canvasRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
// Drag state
|
// Drag state
|
||||||
@@ -295,6 +296,14 @@ export function RackPlanner() {
|
|||||||
initialType={pendingDrop.type}
|
initialType={pendingDrop.type}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{activeConfigPortId && (
|
||||||
|
<PortConfigModal
|
||||||
|
open={!!activeConfigPortId}
|
||||||
|
portId={activeConfigPortId}
|
||||||
|
onClose={() => setActiveConfigPortId(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</DndContext>
|
</DndContext>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ interface RackState {
|
|||||||
setCablingFromPortId: (id: string | null) => void;
|
setCablingFromPortId: (id: string | null) => void;
|
||||||
createConnection: (fromPortId: string, toPortId: string) => Promise<void>;
|
createConnection: (fromPortId: string, toPortId: string) => Promise<void>;
|
||||||
deleteConnection: (id: string) => Promise<void>;
|
deleteConnection: (id: string) => Promise<void>;
|
||||||
|
// Port Config Global Modal
|
||||||
|
activeConfigPortId: string | null;
|
||||||
|
setActiveConfigPortId: (id: string | null) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useRackStore = create<RackState>((set, get) => ({
|
export const useRackStore = create<RackState>((set, get) => ({
|
||||||
@@ -128,4 +131,7 @@ export const useRackStore = create<RackState>((set, get) => ({
|
|||||||
const racks = await apiClient.racks.list();
|
const racks = await apiClient.racks.list();
|
||||||
set({ racks });
|
set({ racks });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
activeConfigPortId: null,
|
||||||
|
setActiveConfigPortId: (id) => set({ activeConfigPortId: id }),
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user