Skip to content

Commit

Permalink
refector
Browse files Browse the repository at this point in the history
Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid committed Nov 14, 2023
1 parent 4b3fb03 commit b440204
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
16 changes: 1 addition & 15 deletions client/src/pages/schema/Schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
import { usePaginationHook } from '@/hooks';
import icons from '@/components/icons/Icons';
import { FieldHttp, IndexHttp } from '@/http';
import { formatFieldType } from '@/utils';
import { FieldView } from './Types';
import IndexTypeElement from './IndexTypeElement';

Expand Down Expand Up @@ -102,21 +103,6 @@ const Schema: FC<{
return fields;
};

const formatFieldType = (field: FieldView) => {
const { _fieldType, element_type, _maxLength, _maxCapacity, _dimension } =
field;

const elementType =
element_type !== 'None'
? `<${element_type}${_maxLength ? `(${_maxLength})` : ''}>`
: '';
const maxCapacity = _maxCapacity ? `[${_maxCapacity}]` : '';
const dimension = _dimension ? `(${_dimension})` : '';
const maxLength = _fieldType === 'VarChar' ? `(${_maxLength})` : '';

return `${_fieldType}${elementType}${maxCapacity}${dimension}${maxLength}`;
};

const fetchFields = useCallback(
async (collectionName: string) => {
const KeyIcon = icons.key;
Expand Down
21 changes: 21 additions & 0 deletions client/src/utils/Format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DataTypeEnum,
} from '@/consts';
import { CreateFieldType, Field } from '@/pages/collections/Types';
import { FieldView } from '@/pages/schema/Types';

/**
* transform large capacity to capacity in b.
Expand Down Expand Up @@ -225,3 +226,23 @@ export const formatUtcToMilvus = (bigNumber: number) => {
const milvusTimeStamp = BigInt(bigNumber) << BigInt(18);
return milvusTimeStamp.toString();
};

/**
* Format field
* @param bigNumber
* @returns
*/
export const formatFieldType = (field: FieldView) => {
const { _fieldType, element_type, _maxLength, _maxCapacity, _dimension } =
field;

const elementType =
element_type !== 'None'
? `<${element_type}${_maxLength ? `(${_maxLength})` : ''}>`
: '';
const maxCapacity = _maxCapacity ? `[${_maxCapacity}]` : '';
const dimension = _dimension ? `(${_dimension})` : '';
const maxLength = _fieldType === 'VarChar' ? `(${_maxLength})` : '';

return `${_fieldType}${elementType}${maxCapacity}${dimension}${maxLength}`;
};

0 comments on commit b440204

Please sign in to comment.