Types.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import { Dispatch, ReactElement, SetStateAction } from 'react';
  2. import type { NavInfo } from '@/router/Types';
  3. import type {
  4. IndexCreateParam,
  5. IndexManageParam,
  6. } from '@/pages/databases/collections/schema/Types';
  7. import type {
  8. CollectionObject,
  9. CollectionFullObject,
  10. DatabaseObject,
  11. AuthReq,
  12. AuthObject,
  13. ResStatus
  14. } from '@server/types';
  15. export type RootContextType = {
  16. openSnackBar: OpenSnackBarType;
  17. dialog: DialogType;
  18. dialog2: DialogType;
  19. setDialog: (params: DialogType) => void;
  20. setDialog2: (params: DialogType) => void;
  21. handleCloseDialog: () => void;
  22. handleCloseDialog2: () => void;
  23. versionInfo: { attu: string; sdk: string };
  24. drawer: DrawerType;
  25. setDrawer: (params: DrawerType) => void;
  26. };
  27. // this is for any custom dialog
  28. export type DialogType = {
  29. open: boolean;
  30. type: 'notice' | 'custom';
  31. params: {
  32. title?: string;
  33. component?: React.ReactNode;
  34. confirm?: () => Promise<any>;
  35. cancel?: () => Promise<any>;
  36. confirmLabel?: string;
  37. cancelLabel?: string;
  38. confirmClass?: string;
  39. /**
  40. * Usually we control open status in root context,
  41. * if we need a hoc component depend on setDialog in context,
  42. * we may need control open status by ourself
  43. **/
  44. handleClose?: () => void;
  45. // used for dialog position
  46. containerClass?: string;
  47. };
  48. };
  49. export type SnackBarType = {
  50. open: boolean;
  51. message: string | ReactElement;
  52. type?: 'error' | 'info' | 'success' | 'warning';
  53. autoHideDuration?: number | null;
  54. horizontal: 'center' | 'left' | 'right';
  55. vertical: 'bottom' | 'top';
  56. };
  57. export type OpenSnackBarType = (
  58. message: string | ReactElement,
  59. type?: 'error' | 'info' | 'success' | 'warning',
  60. autoHideDuration?: number | null,
  61. position?: {
  62. horizontal: 'center' | 'left' | 'right';
  63. vertical: 'bottom' | 'top';
  64. }
  65. ) => void;
  66. export type AuthContextType = {
  67. authReq: AuthReq;
  68. setAuthReq: Dispatch<SetStateAction<AuthReq>>;
  69. clientId: string;
  70. isManaged: boolean;
  71. isServerless: boolean;
  72. isDedicated: boolean;
  73. isAuth: boolean;
  74. logout: (pass?: boolean) => void;
  75. login: (params: AuthReq) => Promise<AuthObject>;
  76. };
  77. export type SystemContextType = {
  78. data?: any;
  79. };
  80. export type PrometheusContextType = {
  81. withPrometheus: boolean;
  82. setWithPrometheus: Dispatch<SetStateAction<boolean>>;
  83. isPrometheusReady: boolean;
  84. prometheusAddress: string;
  85. prometheusInstance: string;
  86. prometheusNamespace: string;
  87. setPrometheusAddress: Dispatch<SetStateAction<string>>;
  88. setPrometheusInstance: Dispatch<SetStateAction<string>>;
  89. setPrometheusNamespace: Dispatch<SetStateAction<string>>;
  90. };
  91. export type NavContextType = {
  92. navInfo: NavInfo;
  93. setNavInfo: (param: NavInfo) => void;
  94. };
  95. export type DataContextType = {
  96. loading: boolean;
  97. loadingDatabases: boolean;
  98. collections: CollectionObject[];
  99. setCollections: Dispatch<SetStateAction<CollectionObject[]>>;
  100. database: string;
  101. setDatabase: Dispatch<SetStateAction<string>>;
  102. databases: DatabaseObject[];
  103. setDatabaseList: Dispatch<SetStateAction<DatabaseObject[]>>;
  104. // APIs
  105. // databases
  106. fetchDatabases: () => Promise<DatabaseObject[]>;
  107. createDatabase: (params: { db_name: string }) => Promise<void>;
  108. dropDatabase: (params: { db_name: string }) => Promise<void>;
  109. // collections
  110. fetchCollections: () => Promise<void>;
  111. fetchCollection: (name: string) => Promise<CollectionFullObject>;
  112. createCollection: (data: any) => Promise<CollectionFullObject>;
  113. loadCollection: (name: string, param?: any) => Promise<void>;
  114. releaseCollection: (name: string) => Promise<void>;
  115. renameCollection: (
  116. name: string,
  117. newName: string
  118. ) => Promise<CollectionFullObject>;
  119. duplicateCollection: (
  120. name: string,
  121. newName: string
  122. ) => Promise<CollectionFullObject>;
  123. dropCollection: (name: string) => Promise<ResStatus>;
  124. createIndex: (param: IndexCreateParam) => Promise<CollectionFullObject>;
  125. dropIndex: (params: IndexManageParam) => Promise<CollectionFullObject>;
  126. createAlias: (
  127. collectionName: string,
  128. alias: string
  129. ) => Promise<CollectionFullObject>;
  130. dropAlias: (
  131. collectionName: string,
  132. alias: string
  133. ) => Promise<CollectionFullObject>;
  134. setCollectionProperty: (
  135. collectionName: string,
  136. key: string,
  137. value: any
  138. ) => Promise<CollectionFullObject>;
  139. // UI preferences
  140. ui: {
  141. tree: {
  142. width: number;
  143. };
  144. };
  145. setUIPref: (pref: DataContextType['ui']) => void;
  146. };
  147. export interface DrawerAction {
  148. label: string;
  149. onClick: () => void;
  150. }
  151. export interface DrawerType {
  152. open: boolean;
  153. title: string;
  154. content: React.ReactNode;
  155. hasActionBar: boolean;
  156. actions?: DrawerAction[];
  157. }