Files
worldwideview/src/core/state/dataSlice.ts
T
SilvertakanaandCopilot Autofix powered by AI 16c82c9184 refactor(lint): address React 19 hook purity and immutability violations (#136)
* chore(merge): resolve conflicts, fix mockWs error, and apply refactor standards

* Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

* fix(ci): Stabilize github actions and resolve test failures

- fix(tests): update WsClient mock to use standard function for Vitest constructor compatibility

- fix(db): correct PrismaClient import path to use generated output directory

- fix(e2e): add predev database boot step to playwright CI workflow

- chore: sync pnpm-lock.yaml after merge conflict resolution

* refactor(plugins): decouple GeoJSON plugin and implement data bus lifecycle

- feat(sdk): [Minor] Added dynamicPluginCreate, dynamicPluginRemove, and pluginUnregistered to DataBusEvents.

- feat(core): [Minor] Implemented unregisterPlugin in PluginManager.ts for automated IndexedDB caching cleanup and polling teardown.

- feat(core): [Minor] Added removeLayer to layersSlice.ts to support safe removal of plugin states.

- refactor(plugins): [Patch] Refactored useGeoJsonImport.ts and ImportedLayerList.tsx to decouple from direct manager imports, utilizing DataBus for lifecycle events.

- refactor(core): [Patch] Added pluginUnregistered listener to DataBusSubscriber.tsx to handle state and cache cleanup synchronously via event.

* fix(types): resolve PluginManager type errors

* refactor(core): decouple PluginManager and fix rendering invariants

- refactor(core): Replace Zustand mutations in PluginManager with DataBus events (Patch)
- refactor(sdk): Add layerLoadingChanged, pluginError, pluginUnregistered to DataBusEvents (Patch)
- refactor(ui): Subscribe to new DataBus events in DataBusSubscriber (Patch)
- fix(plugins): Remove size from BaseAviationPlugin to fix model rendering clipping (Patch)
- fix(plugins): Migrate BaseIncidentPlugin from size to iconScale to fix billboard clipping (Patch)

* chore: resolve lockfile conflict

---------

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2026-05-16 13:03:05 +12:00

48 lines
2.0 KiB
TypeScript

/**
* @file dataSlice.ts
* @description State slice managing the core geospatial entities retrieved from all active plugins.
*/
import type { StateCreator } from "zustand";
import type { GeoEntity } from "@/core/plugins/PluginTypes";
import type { AppStore } from "./store";
// ─── Data Slice ──────────────────────────────────────────────
/**
* Zustand state slice for storing and retrieving geospatial entity data.
*/
export interface DataSlice {
/** Map of plugin IDs to their currently loaded arrays of GeoEntities. */
entitiesByPlugin: Record<string, GeoEntity[]>;
/** Updates the entity list for a specific plugin and refreshes selection if needed. */
setEntities: (pluginId: string, entities: GeoEntity[]) => void;
/** Removes all entities associated with a specific plugin from memory. */
clearEntities: (pluginId: string) => void;
/** Retrieves a flattened array of all visible entities from all active plugins. */
getAllEntities: () => GeoEntity[];
}
export const createDataSlice: StateCreator<AppStore, [], [], DataSlice> = (set, get) => ({
entitiesByPlugin: {},
setEntities: (pluginId, entities) => set((state) => {
const updates: Partial<AppStore> = {
entitiesByPlugin: { ...state.entitiesByPlugin, [pluginId]: entities },
};
// Keep selectedEntity fresh when new polling data arrives
if (state.selectedEntity?.pluginId === pluginId) {
const fresh = entities.find((e) => e.id === state.selectedEntity!.id);
if (fresh) updates.selectedEntity = fresh;
}
return updates;
}),
clearEntities: (pluginId) => set((state) => {
const copy = { ...state.entitiesByPlugin };
delete copy[pluginId];
return { entitiesByPlugin: copy };
}),
getAllEntities: () => {
const state = get();
return Object.values(state.entitiesByPlugin).flat();
},
});