Browse Source

refactor: mv g2g type defs

mizozobu 3 years ago
parent
commit
b1d23c874a

+ 1 - 37
packages/app/src/components/Admin/G2GDataTransfer.tsx

@@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next';
 import { useGenerateTransferKeyWithThrottle } from '~/client/services/g2g-transfer';
 import { toastError, toastSuccess } from '~/client/util/apiNotification';
 import { apiv3Get, apiv3Post } from '~/client/util/apiv3-client';
+import { G2G_PROGRESS_STATUS, type G2GProgress } from '~/interfaces/g2g-transfer';
 import { useAdminSocket } from '~/stores/socket-io';
 
 import CustomCopyToClipBoard from '../Common/CustomCopyToClipBoard';
@@ -16,43 +17,6 @@ const IGNORED_COLLECTION_NAMES = [
   'sessions', 'rlflx', 'activities', 'attachmentFiles.files', 'attachmentFiles.chunks',
 ];
 
-/**
- * Get the union type of all the values in an object, array or array-like type `T`
- * @see {@link https://github.com/piotrwitek/utility-types/blob/df2502ef504c4ba8bd9de81a45baef112b7921d0/src/mapped-types.ts#L589-L597}
- */
-type ValuesType<
-  T extends ReadonlyArray<any> | ArrayLike<any> | Record<any, any>
-> = T extends ReadonlyArray<any>
-  ? T[number]
-  : T extends ArrayLike<any>
-  ? T[number]
-  : T extends object
-  ? T[keyof T]
-  : never;
-
-/**
- * G2G transfer progress status master
- */
-const G2G_PROGRESS_STATUS = {
-  PENDING: 'PENDING',
-  IN_PROGRESS: 'IN_PROGRESS',
-  COMPLETED: 'COMPLETED',
-  ERROR: 'ERROR',
-} as const;
-
-/**
- * G2G transfer progress status
- */
-type G2GProgressStatus = ValuesType<typeof G2G_PROGRESS_STATUS>
-
-/**
- * G2G transfer progress
- */
-interface G2GProgress {
-  mongo: G2GProgressStatus;
-  attachments: G2GProgressStatus;
-}
-
 const G2GDataTransfer = (): JSX.Element => {
   const { data: socket } = useAdminSocket();
   const { t } = useTranslation();

+ 3 - 30
packages/app/src/components/Admin/G2GDataTransferStatusIcon.tsx

@@ -1,36 +1,9 @@
 import React, { type ComponentPropsWithoutRef } from 'react';
 
-/**
- * Get the union type of all the values in an object, array or array-like type `T`
- * @see {@link https://github.com/piotrwitek/utility-types/blob/df2502ef504c4ba8bd9de81a45baef112b7921d0/src/mapped-types.ts#L589-L597}
- */
-type ValuesType<
- T extends ReadonlyArray<any> | ArrayLike<any> | Record<any, any>
-> = T extends ReadonlyArray<any>
- ? T[number]
- : T extends ArrayLike<any>
- ? T[number]
- : T extends object
- ? T[keyof T]
- : never;
-
-/**
- * G2G transfer progress status master
- */
-const G2G_PROGRESS_STATUS = {
-  PENDING: 'PENDING',
-  IN_PROGRESS: 'IN_PROGRESS',
-  COMPLETED: 'COMPLETED',
-  ERROR: 'ERROR',
-} as const;
-
-/**
- * G2G transfer progress status
- */
-type G2GProgressStatus = ValuesType<typeof G2G_PROGRESS_STATUS>
+import { G2G_PROGRESS_STATUS, type G2GProgressStatus } from '~/interfaces/g2g-transfer';
 
 /**
- * Props for {@link G2GDataTransfer}
+ * Props for {@link G2GDataTransferStatusIcon}
  */
 interface Props extends ComponentPropsWithoutRef<'i'>{
   status: G2GProgressStatus;
@@ -39,7 +12,7 @@ interface Props extends ComponentPropsWithoutRef<'i'>{
 /**
  * Icon for G2G transfer status
  */
-const G2GDataTransferStatusIcon = ({ status, className, ...props }: Props): JSX.Element | null => {
+const G2GDataTransferStatusIcon = ({ status, className, ...props }: Props): JSX.Element => {
   if (status === G2G_PROGRESS_STATUS.IN_PROGRESS) {
     return (
       <i className={`fa fa-spinner fa-pulse fa-fw ${className}`} aria-label="in progress" {...props} />

+ 36 - 0
packages/app/src/interfaces/g2g-transfer.ts

@@ -0,0 +1,36 @@
+/**
+ * Get the union type of all the values in an object, array or array-like type `T`
+ * @see {@link https://github.com/piotrwitek/utility-types/blob/df2502ef504c4ba8bd9de81a45baef112b7921d0/src/mapped-types.ts#L589-L597}
+ */
+type ValuesType<
+ T extends ReadonlyArray<any> | ArrayLike<any> | Record<any, any>
+> = T extends ReadonlyArray<any>
+ ? T[number]
+ : T extends ArrayLike<any>
+ ? T[number]
+ : T extends object
+ ? T[keyof T]
+ : never;
+
+/**
+* G2G transfer progress status master
+*/
+export const G2G_PROGRESS_STATUS = {
+  PENDING: 'PENDING',
+  IN_PROGRESS: 'IN_PROGRESS',
+  COMPLETED: 'COMPLETED',
+  ERROR: 'ERROR',
+} as const;
+
+/**
+* G2G transfer progress status
+*/
+export type G2GProgressStatus = ValuesType<typeof G2G_PROGRESS_STATUS>
+
+/**
+* G2G transfer progress
+*/
+export interface G2GProgress {
+ mongo: G2GProgressStatus;
+ attachments: G2GProgressStatus;
+}

+ 1 - 10
packages/app/src/server/service/g2g-transfer.ts

@@ -7,6 +7,7 @@ import rawAxios from 'axios';
 import FormData from 'form-data';
 import { Types as MongooseTypes } from 'mongoose';
 
+import { G2G_PROGRESS_STATUS } from '~/interfaces/g2g-transfer';
 import TransferKeyModel from '~/server/models/transfer-key';
 import { createBatchStream } from '~/server/util/batch-stream';
 import axios from '~/utils/axios';
@@ -31,16 +32,6 @@ export const uploadConfigKeys = [
   'gcs:useOnlyEnvVarsForSomeOptions',
 ];
 
-/**
-* G2G transfer progress status master
-*/
-const G2G_PROGRESS_STATUS = {
-  PENDING: 'PENDING',
-  IN_PROGRESS: 'IN_PROGRESS',
-  COMPLETED: 'COMPLETED',
-  ERROR: 'ERROR',
-} as const;
-
 /**
  * Data used for comparing to/from GROWI information
  */