import { Dispatch, ReactElement, SetStateAction } from 'react'; import { CollectionObject, CollectionFullObject, DatabaseObject, AuthReq, } from '@server/types'; import { NavInfo } from '@/router/Types'; import { IndexCreateParam, IndexManageParam, } from '@/pages/databases/collections/schema/Types'; import { AuthObject } from '@server/types'; export type RootContextType = { openSnackBar: OpenSnackBarType; dialog: DialogType; dialog2: DialogType; setDialog: (params: DialogType) => void; setDialog2: (params: DialogType) => void; handleCloseDialog: () => void; handleCloseDialog2: () => void; versionInfo: { attu: string; sdk: string }; }; // this is for any custom dialog export type DialogType = { open: boolean; type: 'notice' | 'custom'; params: { title?: string; component?: React.ReactNode; confirm?: () => Promise; cancel?: () => Promise; confirmLabel?: string; cancelLabel?: string; confirmClass?: string; /** * Usually we control open status in root context, * if we need a hoc component depend on setDialog in context, * we may need control open status by ourself **/ handleClose?: () => void; // used for dialog position containerClass?: string; }; }; export type SnackBarType = { open: boolean; message: string | ReactElement; type?: 'error' | 'info' | 'success' | 'warning'; autoHideDuration?: number | null; horizontal: 'center' | 'left' | 'right'; vertical: 'bottom' | 'top'; }; export type OpenSnackBarType = ( message: string | ReactElement, type?: 'error' | 'info' | 'success' | 'warning', autoHideDuration?: number | null, position?: { horizontal: 'center' | 'left' | 'right'; vertical: 'bottom' | 'top'; } ) => void; export type AuthContextType = { authReq: AuthReq; setAuthReq: Dispatch>; clientId: string; isManaged: boolean; isAuth: boolean; logout: (pass?: boolean) => void; login: (params: AuthReq) => Promise; }; export type SystemContextType = { data?: any; }; export type PrometheusContextType = { withPrometheus: boolean; setWithPrometheus: Dispatch>; isPrometheusReady: boolean; prometheusAddress: string; prometheusInstance: string; prometheusNamespace: string; setPrometheusAddress: Dispatch>; setPrometheusInstance: Dispatch>; setPrometheusNamespace: Dispatch>; }; export type NavContextType = { navInfo: NavInfo; setNavInfo: (param: NavInfo) => void; }; export type DataContextType = { loading: boolean; loadingDatabases: boolean; collections: CollectionObject[]; setCollections: Dispatch>; database: string; setDatabase: Dispatch>; databases: DatabaseObject[]; setDatabaseList: Dispatch>; // APIs // databases fetchDatabases: () => Promise; createDatabase: (params: { db_name: string }) => Promise; dropDatabase: (params: { db_name: string }) => Promise; // collections fetchCollections: () => Promise; fetchCollection: (name: string) => Promise; createCollection: (data: any) => Promise; loadCollection: (name: string, param?: any) => Promise; releaseCollection: (name: string) => Promise; renameCollection: ( name: string, newName: string ) => Promise; duplicateCollection: ( name: string, newName: string ) => Promise; dropCollection: (name: string) => Promise; createIndex: (param: IndexCreateParam) => Promise; dropIndex: (params: IndexManageParam) => Promise; createAlias: ( collectionName: string, alias: string ) => Promise; dropAlias: ( collectionName: string, alias: string ) => Promise; setCollectionProperty: ( collectionName: string, key: string, value: any ) => Promise; // UI preferences ui: { tree: { width: number; }; }; setUIPref: (pref: DataContextType['ui']) => void; };