Merge remote-tracking branch 'origin/dev-simulation/human' into main-demo
This commit is contained in:
@@ -14,17 +14,17 @@ type ProductsStore = {
|
||||
// Event-level actions
|
||||
addEvent: (productUuid: string, event: EventsSchema) => void;
|
||||
removeEvent: (productUuid: string, modelUuid: string) => void;
|
||||
deleteEvent: (modelUuid: string) => void;
|
||||
deleteEvent: (modelUuid: string) => EventsSchema[];
|
||||
updateEvent: (productUuid: string, modelUuid: string, updates: Partial<EventsSchema>) => EventsSchema | undefined;
|
||||
|
||||
// Point-level actions
|
||||
addPoint: (productUuid: string, modelUuid: string, point: ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema) => void;
|
||||
addPoint: (productUuid: string, modelUuid: string, point: ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema | HumanPointSchema) => void;
|
||||
removePoint: (productUuid: string, modelUuid: string, pointUuid: string) => void;
|
||||
updatePoint: (
|
||||
productUuid: string,
|
||||
modelUuid: string,
|
||||
pointUuid: string,
|
||||
updates: Partial<ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema>
|
||||
updates: Partial<ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema | HumanPointSchema>
|
||||
) => EventsSchema | undefined;
|
||||
|
||||
// Action-level actions
|
||||
@@ -65,9 +65,9 @@ type ProductsStore = {
|
||||
getEventByActionUuid: (productUuid: string, actionUuid: string) => EventsSchema | undefined;
|
||||
getEventByTriggerUuid: (productUuid: string, triggerUuid: string) => EventsSchema | undefined;
|
||||
getEventByPointUuid: (productUuid: string, pointUuid: string) => EventsSchema | undefined;
|
||||
getPointByUuid: (productUuid: string, modelUuid: string, pointUuid: string) => ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema | undefined;
|
||||
getActionByUuid: (productUuid: string, actionUuid: string) => (ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']) | undefined;
|
||||
getActionByPointUuid: (productUuid: string, pointUuid: string) => (ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']) | undefined;
|
||||
getPointByUuid: (productUuid: string, modelUuid: string, pointUuid: string) => ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema | HumanPointSchema | undefined;
|
||||
getActionByUuid: (productUuid: string, actionUuid: string) => (ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action'] | HumanPointSchema['action']) | undefined;
|
||||
getActionByPointUuid: (productUuid: string, pointUuid: string) => (ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action'] | HumanPointSchema['action']) | undefined;
|
||||
getModelUuidByPointUuid: (productUuid: string, actionUuid: string) => (string) | undefined;
|
||||
getModelUuidByActionUuid: (productUuid: string, actionUuid: string) => (string) | undefined;
|
||||
getPointUuidByActionUuid: (productUuid: string, actionUuid: string) => (string) | undefined;
|
||||
@@ -145,11 +145,93 @@ export const createProductStore = () => {
|
||||
},
|
||||
|
||||
deleteEvent: (modelUuid) => {
|
||||
let updatedEvents: EventsSchema[] = [];
|
||||
set((state) => {
|
||||
const actionsToDelete = new Set<string>();
|
||||
|
||||
for (const product of state.products) {
|
||||
product.eventDatas = product.eventDatas.filter(e => 'modelUuid' in e && e.modelUuid !== modelUuid);
|
||||
const eventIndex = product.eventDatas.findIndex(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
if (eventIndex !== -1) {
|
||||
const event = product.eventDatas[eventIndex];
|
||||
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
if (point.action) {
|
||||
actionsToDelete.add(point.action.actionUuid);
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && point.action) {
|
||||
actionsToDelete.add(point.action.actionUuid);
|
||||
} else if ('actions' in point) {
|
||||
for (const action of point.actions) {
|
||||
actionsToDelete.add(action.actionUuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
product.eventDatas.splice(eventIndex, 1);
|
||||
}
|
||||
}
|
||||
|
||||
for (const product of state.products) {
|
||||
for (const event of product.eventDatas) {
|
||||
let eventModified = false;
|
||||
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
if (point.action?.triggers) {
|
||||
const originalLength = point.action.triggers.length;
|
||||
point.action.triggers = point.action.triggers.filter(trigger => {
|
||||
return !(
|
||||
(trigger.triggeredAsset?.triggeredModel?.modelUuid === modelUuid) ||
|
||||
(actionsToDelete.has(trigger.triggeredAsset?.triggeredAction?.actionUuid || ''))
|
||||
);
|
||||
});
|
||||
if (point.action.triggers.length !== originalLength) {
|
||||
eventModified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && point.action?.triggers) {
|
||||
const originalLength = point.action.triggers.length;
|
||||
point.action.triggers = point.action.triggers.filter((trigger: TriggerSchema) => {
|
||||
return !(
|
||||
(trigger.triggeredAsset?.triggeredModel?.modelUuid === modelUuid) ||
|
||||
(actionsToDelete.has(trigger.triggeredAsset?.triggeredAction?.actionUuid || ''))
|
||||
);
|
||||
});
|
||||
if (point.action.triggers.length !== originalLength) {
|
||||
eventModified = true;
|
||||
}
|
||||
} else if ('actions' in point) {
|
||||
for (const action of point.actions) {
|
||||
if (action.triggers) {
|
||||
const originalLength = action.triggers.length;
|
||||
action.triggers = action.triggers.filter((trigger: TriggerSchema) => {
|
||||
return !(
|
||||
(trigger.triggeredAsset?.triggeredModel?.modelUuid === modelUuid) ||
|
||||
(actionsToDelete.has(trigger.triggeredAsset?.triggeredAction?.actionUuid || ''))
|
||||
);
|
||||
});
|
||||
if (action.triggers.length !== originalLength) {
|
||||
eventModified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eventModified) {
|
||||
updatedEvents.push(JSON.parse(JSON.stringify(event)));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return updatedEvents;
|
||||
},
|
||||
|
||||
updateEvent: (productUuid, modelUuid, updates) => {
|
||||
|
||||
Reference in New Issue
Block a user