Types.ts 4.2 KB

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