5.7 KiB
5.7 KiB
Presets
To allow the user to save the current configuration of a machine, they can create a preset in the presets page. Presets are presited in electron's local storage.
Presets are all handled by the PresetsPage. To use the PresetsPage for a single machine, one must implement the following.
Create a zod schema for the data, the presets contain.
const mock1PresetDataSchema = z
.object({
frequency1: z.number(),
frequency2: z.number(),
frequency3: z.number(),
})
.partial();
type Mock1 = typeof mock1PresetDataSchema;
Here, intensionally, Mock1 is the schema type itself. It can be used as a type argument everything that uses presets.
Next, create a map containing all schema versions currently supported (the new schema, to be precise).
const schemas = new Map([[1, mock1PresetDataSchema]]);
New, the schema will be used to parse version 1. To create new versions, see migrations below.
One also needs to define a table, how the preset data should be shown to the user.
const previewEntries: PresetPreviewEntries<Mock1> = [
{
name: "Frequency 1",
unit: "mHz",
renderValue: (data: PresetData<Mock1>) => data?.frequency1?.toFixed(3),
},
{
name: "Frequency 2",
unit: "mHz",
renderValue: (data: PresetData<Mock1>) => data?.frequency2?.toFixed(3