From 60f3fb41a2ae318bcf33f7e37bf9462bd7b1cbda Mon Sep 17 00:00:00 2001 From: Leonardo <leomilho@gmail.com> Date: Tue, 9 Jul 2024 19:06:56 +0200 Subject: [PATCH] feat(schema): adding schema stats to eventBus --- libs/shared/lib/data-access/api/eventBus.tsx | 2 ++ .../shared/lib/data-access/broker/wsSchema.ts | 22 ++++++++++++++++++- libs/shared/lib/schema/model/FromBackend.ts | 12 ++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/libs/shared/lib/data-access/api/eventBus.tsx b/libs/shared/lib/data-access/api/eventBus.tsx index 838c1bb93..3eb73142c 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 81944b7f8..09a81f21a 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 78d5e6384..74611465c 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'; -- GitLab