Simulations life cycle improvements #191

Merged
bustikiller merged 6 commits from mark-expired-simulations into main 2025-01-26 13:07:58 +00:00
5 changed files with 82 additions and 39 deletions

View File

@ -2,15 +2,41 @@
'use client';
import { AbstractApi } from '@/app/api/abstract-api';
import { TableSimulation, TableSimulationSerializer } from '@/app/lib/tableSimulation';
import Arrangement from '@/app/ui/arrangements/arrangement';
import React, { useState } from 'react';
import ArrangementsTable from '@/app/ui/arrangements/arrangements-table';
import { classNames } from '@/app/ui/components/button';
import { Toast } from 'primereact/toast';
import React, { useRef, useState } from 'react';
export default function Page() {
const toast = useRef<Toast>(null);
const show = () => {
toast.current?.show({
severity: 'success',
summary: 'Simulation created',
detail: 'Table distributions will be calculated shortly, please come back in some minutes'
});
};
const [currentArrangement, setCurrentArrangement] = useState<string | null>(null);
function createSimulation() {
const api = new AbstractApi<TableSimulation>();
const serializer = new TableSimulationSerializer();
api.create(serializer, new TableSimulation(), show);
}
return (
<>
<div className="flex flex-col w-full items-center justify-between">
<Toast ref={toast} />
<button onClick={createSimulation} className={classNames('primary')}>Add new</button>
</div>
<ArrangementsTable onArrangementSelected={setCurrentArrangement} />
{currentArrangement && <Arrangement key={currentArrangement} id={currentArrangement} />}
</>

View File

@ -12,6 +12,7 @@ export function loadTableSimulations(onLoad?: (tableSimulations: TableArrangemen
id: record.id,
name: record.name,
discomfort: record.discomfort,
valid: record.valid,
});
}));
}, (error) => {

View File

@ -12,7 +12,8 @@ export type TableArrangement = {
number: number;
name: string;
guests?: Guest[];
discomfort?: number
discomfort?: number;
valid?: boolean;
}
export type User = {

View File

@ -19,12 +19,12 @@ export type Table = {
}
export class TableSimulation implements Entity {
id: string;
id?: string;
tables: Table[];
constructor(id: string, tables: Table[]) {
constructor(id?: string, tables?: Table[]) {
this.id = id;
this.tables = tables;
this.tables = tables || [];
}
}

View File

@ -7,8 +7,11 @@ import { TableArrangement } from '@/app/lib/definitions';
import { classNames } from "../components/button";
import TableOfContents from "../components/table-of-contents";
import { loadTableSimulations } from "@/app/api/tableSimulations";
import { ArchiveBoxXMarkIcon, CheckBadgeIcon } from "@heroicons/react/24/outline";
import { Tooltip } from "primereact/tooltip";
import clsx from "clsx";
export default function ArrangementsTable ({onArrangementSelected}: {onArrangementSelected: (arrangementId: string) => void}) {
export default function ArrangementsTable({ onArrangementSelected }: { onArrangementSelected: (arrangementId: string) => void }) {
const [arrangements, setArrangements] = useState<Array<TableArrangement>>([]);
const [arrangementsLoaded, setArrangementsLoaded] = useState(false);
@ -25,14 +28,17 @@ export default function ArrangementsTable ({onArrangementSelected}: {onArrangeme
!arrangementsLoaded && refreshSimulations();
return(
return (
<TableOfContents
headers={['Name', 'Discomfort', 'Actions']}
headers={['Name', 'Discomfort', 'Actions', 'Status']}
caption='Simulations'
elements={arrangements}
rowRender={(arrangement) => (
<tr key={arrangement.id} className="bg-white border-b odd:bg-white odd:dark:bg-gray-900 even:bg-gray-50 even:dark:bg-gray-800">
<th scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
<tr key={arrangement.id} className={clsx("border-b", {
"bg-white odd:bg-white even:bg-gray-50": arrangement.valid,
"bg-red-50 odd:bg-red-50 even:bg-red-100": !arrangement.valid
})}>
<th scope="row" className="px-6 py-4 font-medium text-gray-900 whitespace-nowrap">
{arrangement.name}
</th>
<td className="px-6 py-4">
@ -41,6 +47,15 @@ export default function ArrangementsTable ({onArrangementSelected}: {onArrangeme
<td>
<button data-arrangement-id={arrangement.id} onClick={arrangementClicked} className={classNames('primary')}>Load</button>
</td>
<td>
<Tooltip target=".tooltip-status" />
{
arrangement.valid ?
<CheckBadgeIcon className='size-6 tooltip-status' data-pr-position="right" data-pr-tooltip="Simulation is valid" /> :
<ArchiveBoxXMarkIcon className='size-6 tooltip-status' data-pr-position="right" data-pr-tooltip="Simulation is expired due to attendance or affinity changes" />
}
</td>
</tr>
)}
/>