Skip to content

Commit a38a8c0

Browse files
committed
Add overview sidebar
1 parent b03e50d commit a38a8c0

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

specifyweb/frontend/js_src/lib/components/SetupTool/index.tsx

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ const stepOrder: RA<keyof SetupProgress> = [
3434
'specifyUser',
3535
];
3636

37-
// function findInitialStep(progress: SetupProgress): number {
38-
// return stepOrder.findIndex((key) => !progress[key]);
39-
// }
40-
4137
function findNextStep(currentStep: number, formData: ResourceFormData, direction: number = 1): number {
4238
// Find the next *accessible* form.
4339
// Handles conditional pages, like the global geography tree.
@@ -351,19 +347,22 @@ export function SetupTool({
351347
</>
352348
) :
353349
<>
354-
<div className="flex w-full justify-center gap-8">
355-
<div>
350+
<div className="flex flex-col md:flex-row w-full justify-center gap-8">
351+
<div className="w-[18rem] h-full overflow-auto">
356352
<Container.Center className="p-3 shadow-md max-w-lg h-full">
357353
<H3 className="text-xl font-semibold mb-4">
358354
{setupToolText.overview()}
359355
</H3>
360-
<pre className="text-xs whitespace-pre-wrap break-all">
361-
{JSON.stringify(formData, null, 2)}
362-
</pre>
356+
<div className="overflow-auto">
357+
<SetupOverview
358+
formData={formData}
359+
currentStep={currentStep}
360+
/>
361+
</div>
363362
</Container.Center>
364363
</div>
365-
<div>
366-
<Container.Center className="p-3 shadow-md max-w-lg">
364+
<div className="w-[32rem]">
365+
<Container.Center className="p-3 shadow-md">
367366
<Form
368367
className="flex-1 overflow-auto gap-2"
369368
forwardRef={formRef}
@@ -400,6 +399,56 @@ export function SetupTool({
400399
);
401400
}
402401

402+
function SetupOverview({
403+
formData,
404+
currentStep
405+
}: {
406+
readonly formData: ResourceFormData,
407+
readonly currentStep: number
408+
}): JSX.Element {
409+
// Display all previously filled out forms.
410+
return (
411+
<div className="space-y-4 max-h-[70vh] overflow-auto ">
412+
<table className="w-full text-sm border-collapse table-fixed">
413+
<colgroup>
414+
<col style={{ width: '60%' }} />
415+
<col style={{ width: '40%' }} />
416+
</colgroup>
417+
<tbody>
418+
{resources.map((resource, step) => {
419+
// Display only the forms that have been visited.
420+
if (Object.keys(formData[resource.resourceName]).length > 0 || step <= currentStep) {
421+
return (<React.Fragment key={resource.resourceName}>
422+
<tr key={`${resource.resourceName}`}>
423+
<td className="font-bold py-1 pr-2" colSpan={2}>{resource.label}</td>
424+
</tr>
425+
{resource.fields.map((field) => {
426+
let value = formData[resource.resourceName]?.[field.name]?.toString() ?? '-'
427+
if (field.type === 'object') {
428+
value = '●'
429+
} else if (field.type === 'password') {
430+
value = (formData[resource.resourceName]?.[field.name]) ? '***' : '-'
431+
} else if (field.type === 'select' && Array.isArray(field.options)) {
432+
const match = field.options.find((option) => String(option.value) === value);
433+
value = match ? (match.label ?? match.value) : value;
434+
}
435+
return (
436+
<tr key={`${resource.resourceName}-${field.name}`}>
437+
<td className="font-medium py-1 pr-2">{field.label}</td>
438+
<td className="py-1">{value}</td>
439+
</tr>
440+
);
441+
})}
442+
</React.Fragment>)
443+
}
444+
return undefined;
445+
})}
446+
</tbody>
447+
</table>
448+
</div>
449+
)
450+
}
451+
403452
// Turn 'table.field' keys to nested objects to send to the backend
404453
function flattenToNested(data: Record<string, any>): Record<string, any> {
405454
const result: Record<string, any> = {};

specifyweb/frontend/js_src/lib/components/SetupTool/setupResources.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export const resources: RA<ResourceConfig> = [
117117
required: false,
118118
},
119119
{
120-
name: 'phone',
120+
name: 'phone1',
121121
label: 'Phone',
122122
description: 'A contact phone number.',
123123
required: false,

0 commit comments

Comments
 (0)