mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2026-08-08 02:02:33 +00:00
Add distributed settings and workspace import/export (M5)
This commit is contained in:
@@ -69,6 +69,14 @@ export interface DatasetState {
|
||||
|
||||
/** Low-level: add a fully-formed dataset and select it. */
|
||||
add: (dataset: Dataset) => void;
|
||||
/**
|
||||
* Append imported datasets (spec §08 → datasets imported before snippets). Each
|
||||
* is given a fresh monotonic numeric id so a batch never collides on the
|
||||
* `Date.now()` default (the `add` TODO) nor with existing ids — safe because
|
||||
* datasets are referenced by **name**, not id (docs/architecture/07 §1). Names
|
||||
* are assumed already de-duped by the import service. Selection is unchanged.
|
||||
*/
|
||||
addDatasets: (incoming: Dataset[]) => void;
|
||||
/** Low-level: merge a patch into a dataset, advancing `modified`. */
|
||||
update: (id: number, patch: Partial<Dataset>, now?: Date) => void;
|
||||
/** Low-level: remove a dataset; clears the selection if it was selected. */
|
||||
@@ -237,6 +245,15 @@ export const useDatasetStore = create<DatasetState>((set, get) => ({
|
||||
// before wiring import.
|
||||
add: (dataset) => set((s) => ({ datasets: [dataset, ...s.datasets], selectedId: dataset.id })),
|
||||
|
||||
addDatasets: (incoming) => {
|
||||
if (incoming.length === 0) return;
|
||||
set((s) => {
|
||||
let nextId = s.datasets.reduce((max, d) => Math.max(max, d.id), 0) + 1;
|
||||
const withIds = incoming.map((d) => ({ ...d, id: nextId++ }));
|
||||
return { datasets: [...withIds, ...s.datasets] };
|
||||
});
|
||||
},
|
||||
|
||||
update: (id, patch, now) => {
|
||||
const modified = patch.modified ?? (now ?? new Date()).toISOString();
|
||||
set((s) => ({
|
||||
|
||||
Reference in New Issue
Block a user