merged and added the layout

This commit is contained in:
2025-09-06 18:19:02 +05:30
parent 71484cba18
commit c8e9633050
5 changed files with 281 additions and 76 deletions

View File

@@ -31,7 +31,7 @@ interface SimulationManagerStore {
simulationRecords: ProjectSimulation[];
setSimulationRecords: (simulateData: ProjectSimulation[]) => void;
addSimulationRecord: (projectId: string | undefined, versionId: string, productId: string, record: SimulationUsageRecord) => void;
addSimulationRecords: (projectId: string | undefined, versionId: string, productId: string, records: SimulationUsageRecord[]) => void;
resetProductRecords: (projectId: string, versionId: string, productId: string) => void;
getProjectById: (projectId: string | undefined) => ProjectSimulation | undefined;
getVersionById: (projectId: string | undefined, versionId: string) => VersionSimulation | undefined;
@@ -85,6 +85,52 @@ export const useSimulationManager = create<SimulationManagerStore>((set, get) =>
}
}
return { simulationRecords: projects };
}),
addSimulationRecords: (projectId, versionId, productId, records) =>
set((state) => {
const projects = state.simulationRecords.map((project) => {
if (project.projectId !== projectId) return project;
return {
...project,
versions: project.versions.map((version) => {
if (version.versionId !== versionId) return version;
return {
...version,
products: version.products.map((product) => (product.productId === productId ? { ...product, simulateData: [...product.simulateData, ...records] } : product)),
};
}),
};
});
// same creation logic for new project/version/product
if (!state.simulationRecords.find((p) => p.projectId === projectId)) {
projects.push({
projectId,
versions: [
{
versionId,
products: [{ productId, simulateData: [...records] }],
},
],
});
} else {
const project = projects.find((p) => p.projectId === projectId)!;
if (!project.versions.find((v) => v.versionId === versionId)) {
project.versions.push({
versionId,
products: [{ productId, simulateData: [...records] }],
});
} else {
const version = project.versions.find((v) => v.versionId === versionId)!;
if (!version.products.find((p) => p.productId === productId)) {
version.products.push({ productId, simulateData: [...records] });
}
}
}
return { simulationRecords: projects };
}),