diff --git a/libs/shared/lib/data-access/api/eventBus.tsx b/libs/shared/lib/data-access/api/eventBus.tsx index 838c1bb9367a7891924f443ab78e2bb429ed7cfd..3eb73142c20e3b6ca033bebf94ecc3a50b10677f 100644 --- a/libs/shared/lib/data-access/api/eventBus.tsx +++ b/libs/shared/lib/data-access/api/eventBus.tsx @@ -13,6 +13,7 @@ import { wsSchemaRequest, wsSchemaSubscription, useQuerybuilderAttributesShown, + wsSchemaStatsRequest, } from '@graphpolaris/shared/lib/data-access'; import { Broker, wsQuerySubscription, wsQueryTranslationSubscription } from '@graphpolaris/shared/lib/data-access/broker'; import { addInfo } from '@graphpolaris/shared/lib/data-access/store/configSlice'; @@ -207,6 +208,7 @@ export const EventBus = (props: { onRunQuery: Function; onAuthorized: Function } // New active database if (session.currentSaveState && session.currentSaveState !== nilUUID) { wsSchemaRequest(session.currentSaveState); + wsSchemaStatsRequest(session.currentSaveState); wsSelectState(session.currentSaveState); loadSaveState(session.currentSaveState, session.saveStates); } diff --git a/libs/shared/lib/data-access/broker/wsSchema.ts b/libs/shared/lib/data-access/broker/wsSchema.ts index 81944b7f857476021649e69dc9bdb8d07b21c0b5..09a81f21a1fc0dd2c3b44a7d1d66ef733f5bf287 100644 --- a/libs/shared/lib/data-access/broker/wsSchema.ts +++ b/libs/shared/lib/data-access/broker/wsSchema.ts @@ -1,6 +1,6 @@ // All database related API calls -import { SchemaFromBackend } from '../../schema'; +import { SchemaFromBackend, SchemaStatsFromBackend } from '../../schema'; import { Broker } from './broker'; export function wsSchemaRequest(saveStateID: string) { @@ -13,6 +13,7 @@ export function wsSchemaRequest(saveStateID: string) { }, }); } + type SchemaResponse = (data: SchemaFromBackend) => void; export function wsSchemaSubscription(callback: SchemaResponse) { const id = Broker.instance().subscribe(callback, 'schema_result'); @@ -20,3 +21,22 @@ export function wsSchemaSubscription(callback: SchemaResponse) { Broker.instance().unSubscribe('schema_result', id); }; } + +export function wsSchemaStatsRequest(saveStateID: string) { + Broker.instance().sendMessage({ + key: 'schema', + subKey: 'getSchemaStats', + body: { + cached: false, + saveStateID: saveStateID, + }, + }); +} + +type SchemaStatsResponse = (data: SchemaStatsFromBackend) => void; +export function wsSchemaStatsSubscription(callback: SchemaStatsResponse) { + const id = Broker.instance().subscribe(callback, 'schema_stats_result'); + return () => { + Broker.instance().unSubscribe('schema_stats_result', id); + }; +} diff --git a/libs/shared/lib/schema/model/FromBackend.ts b/libs/shared/lib/schema/model/FromBackend.ts index 78d5e638456fb2091c8de7e1f2ca17bb378c00c2..74611465c9a7f994687b08a42fb60d40343fdf50 100644 --- a/libs/shared/lib/schema/model/FromBackend.ts +++ b/libs/shared/lib/schema/model/FromBackend.ts @@ -6,6 +6,18 @@ export type SchemaFromBackend = { nodes: SchemaNode[]; }; +export type SchemaStatsFromBackend = { + edgeStats: { + type: string; + count: number; + }[]; + nodeStats: { + key: string; + labels: string[]; + count: number; + }[]; +}; + export type SchemaAttributeTypes = 'string' | 'float' | 'int' | 'bool' | 'date' | 'time' | 'datetime' | 'duration'; export type DimensionType = 'categorical' | 'numerical' | 'temporal' | 'spatial';