Skip to content

Commit

Permalink
refactor: merge FieldType and FieldMetadataType
Browse files Browse the repository at this point in the history
  • Loading branch information
thaisguigon committed Mar 25, 2024
1 parent 9e70f5b commit dac5253
Show file tree
Hide file tree
Showing 27 changed files with 72 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
import { ApolloClient, useMutation } from '@apollo/client';
import { getOperationName } from '@apollo/client/utilities';

import { FieldType } from '@/object-record/record-field/types/FieldType';
import {
CreateFieldInput,
CreateOneFieldMetadataItemMutation,
CreateOneFieldMetadataItemMutationVariables,
FieldMetadataType,
} from '~/generated-metadata/graphql';

import { CREATE_ONE_FIELD_METADATA_ITEM } from '../graphql/mutations';
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';

import { useApolloMetadataClient } from './useApolloMetadataClient';

type CreateOneFieldMetadataItemArgs = Omit<
CreateOneFieldMetadataItemMutationVariables['input']['field'],
'type'
> & {
type: FieldType;
};

export const useCreateOneFieldMetadataItem = () => {
const apolloMetadataClient = useApolloMetadataClient();

Expand All @@ -30,16 +22,11 @@ export const useCreateOneFieldMetadataItem = () => {
client: apolloMetadataClient ?? ({} as ApolloClient<any>),
});

const createOneFieldMetadataItem = async (
input: CreateOneFieldMetadataItemArgs,
) => {
const createOneFieldMetadataItem = async (input: CreateFieldInput) => {
return await mutate({
variables: {
input: {
field: {
...input,
type: input.type as FieldMetadataType, // Todo improve typing once we have aligned backend and frontend
},
field: input,
},
},
awaitRefetchQueries: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { v4 } from 'uuid';

import { FieldType } from '@/object-record/record-field/types/FieldType';
import { Field } from '~/generated/graphql';
import { FieldMetadataType } from '~/generated-metadata/graphql';

Expand Down Expand Up @@ -29,7 +28,7 @@ export const useFieldMetadataItem = () => {
...formatFieldMetadataItemInput(input),
defaultValue: input.defaultValue,
objectMetadataId: input.objectMetadataId,
type: input.type as FieldType,
type: input.type,
});

const editMetadataField = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { parseFieldRelationType } from '@/object-metadata/utils/parseFieldRelati

import { FieldMetadataItem } from '../types/FieldMetadataItem';

import { parseFieldType } from './parseFieldType';

export type FieldMetadataItemAsFieldDefinitionProps = {
field: FieldMetadataItem;
objectMetadataItem: ObjectMetadataItem;
Expand All @@ -31,7 +29,7 @@ export const formatFieldMetadataItemAsFieldDefinition = ({
label: field.label,
showLabel,
labelWidth,
type: parseFieldType(field.type),
type: field.type,
metadata: {
fieldName: field.name,
placeHolder: field.label,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isUndefined } from '@sniptt/guards';

import { FieldType } from '@/object-record/record-field/types/FieldType';
import { FieldMetadataType } from '~/generated-metadata/graphql';

import { FieldMetadataItem } from '../types/FieldMetadataItem';

Expand All @@ -13,18 +13,20 @@ export const shouldFieldBeQueried = ({
depth?: number;
eagerLoadedRelations?: Record<string, boolean>;
}): any => {
const fieldType = field.type as FieldType;

if (!isUndefined(depth) && depth < 0) {
return false;
}

if (!isUndefined(depth) && depth < 1 && fieldType === 'RELATION') {
if (
!isUndefined(depth) &&
depth < 1 &&
field.type === FieldMetadataType.Relation
) {
return false;
}

if (
fieldType === 'RELATION' &&
field.type === FieldMetadataType.Relation &&
!isUndefined(eagerLoadedRelations) &&
(isUndefined(eagerLoadedRelations[field.name]) ||
!eagerLoadedRelations[field.name])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
FieldSelectMetadata,
FieldTextMetadata,
} from '@/object-record/record-field/types/FieldMetadata';
import { FieldMetadataType } from '~/generated-metadata/graphql';
import {
mockedCompaniesMetadata,
mockedCustomMetadata,
Expand Down Expand Up @@ -34,7 +35,7 @@ export const textfieldDefinition: FieldDefinition<FieldTextMetadata> = {
fieldMetadataId,
label: 'User Name',
iconName: 'User',
type: 'TEXT',
type: FieldMetadataType.Text,
metadata: { placeHolder: 'John Doe', fieldName: 'userName' },
};

Expand All @@ -52,7 +53,7 @@ export const selectFieldDefinition: FieldDefinition<FieldSelectMetadata> = {
fieldMetadataId,
label: 'Account Owner',
iconName: 'iconName',
type: 'SELECT',
type: FieldMetadataType.Select,
metadata: {
fieldName: 'accountOwner',
options: [{ label: 'Elon Musk', color: 'blue', value: 'userId' }],
Expand All @@ -63,7 +64,7 @@ export const fullNameFieldDefinition: FieldDefinition<FieldFullNameMetadata> = {
fieldMetadataId,
label: 'Display Name',
iconName: 'profile',
type: 'FULL_NAME',
type: FieldMetadataType.FullName,
metadata: {
fieldName: 'displayName',
placeHolder: 'Mr Miagi',
Expand All @@ -74,7 +75,7 @@ export const linkFieldDefinition: FieldDefinition<FieldLinkMetadata> = {
fieldMetadataId,
label: 'LinkedIn URL',
iconName: 'url',
type: 'LINK',
type: FieldMetadataType.Link,
metadata: {
fieldName: 'linkedInURL',
placeHolder: 'https://linkedin.com/user',
Expand All @@ -93,7 +94,7 @@ export const ratingfieldDefinition: FieldDefinition<FieldRatingMetadata> = {
fieldMetadataId,
label: 'Rating',
iconName: 'iconName',
type: 'RATING',
type: FieldMetadataType.Rating,
metadata: {
fieldName: 'rating',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useSetRecoilState } from 'recoil';
import { FieldContext } from '@/object-record/record-field/contexts/FieldContext';
import { ChipFieldDisplay } from '@/object-record/record-field/meta-types/display/components/ChipFieldDisplay';
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
import { FieldMetadataType } from '~/generated/graphql';
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';
import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator';

Expand Down Expand Up @@ -37,7 +38,7 @@ const meta: Meta = {
fieldDefinition: {
fieldMetadataId: 'full name',
label: 'Henry Cavill',
type: 'FULL_NAME',
type: FieldMetadataType.FullName,
iconName: 'IconCalendarEvent',
metadata: {
fieldName: 'full name',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect } from 'react';
import { Meta, StoryObj } from '@storybook/react';

import { FieldMetadataType } from '~/generated/graphql';
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';

import { FieldContext } from '../../../../contexts/FieldContext';
Expand Down Expand Up @@ -30,7 +31,7 @@ const meta: Meta = {
fieldDefinition: {
fieldMetadataId: 'date',
label: 'Date',
type: 'DATE_TIME',
type: FieldMetadataType.DateTime,
iconName: 'IconCalendarEvent',
metadata: {
fieldName: 'Date',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Meta, StoryObj } from '@storybook/react';

import { FieldContext } from '@/object-record/record-field/contexts/FieldContext';
import { useEmailField } from '@/object-record/record-field/meta-types/hooks/useEmailField';
import { FieldMetadataType } from '~/generated/graphql';
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';
import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator';

Expand Down Expand Up @@ -30,7 +31,7 @@ const meta: Meta = {
fieldDefinition: {
fieldMetadataId: 'email',
label: 'Email',
type: 'EMAIL',
type: FieldMetadataType.Email,
iconName: 'IconLink',
metadata: {
fieldName: 'Email',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect } from 'react';
import { Meta, StoryObj } from '@storybook/react';

import { FieldMetadataType } from '~/generated/graphql';
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';

import { FieldContext } from '../../../../contexts/FieldContext';
Expand Down Expand Up @@ -28,7 +29,7 @@ const meta: Meta = {
fieldDefinition: {
fieldMetadataId: 'number',
label: 'Number',
type: 'NUMBER',
type: FieldMetadataType.Number,
iconName: 'Icon123',
metadata: {
fieldName: 'Number',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Meta, StoryObj } from '@storybook/react';

import { FieldContext } from '@/object-record/record-field/contexts/FieldContext';
import { usePhoneField } from '@/object-record/record-field/meta-types/hooks/usePhoneField';
import { FieldMetadataType } from '~/generated/graphql';
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';
import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator';

Expand Down Expand Up @@ -30,7 +31,7 @@ const meta: Meta = {
fieldDefinition: {
fieldMetadataId: 'phone',
label: 'Phone',
type: 'TEXT',
type: FieldMetadataType.Text,
iconName: 'IconPhone',
metadata: {
fieldName: 'phone',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect } from 'react';
import { Meta, StoryObj } from '@storybook/react';

import { FieldMetadataType } from '~/generated/graphql';
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator';

import { FieldContext } from '../../../../contexts/FieldContext';
Expand Down Expand Up @@ -28,7 +29,7 @@ const meta: Meta = {
fieldDefinition: {
fieldMetadataId: 'text',
label: 'Text',
type: 'TEXT',
type: FieldMetadataType.Text,
iconName: 'IconLink',
metadata: {
fieldName: 'Text',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expect, fn, userEvent, within } from '@storybook/test';
import { useSetRecoilState } from 'recoil';

import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
import { FieldMetadataType } from '~/generated/graphql';

import { FieldContextProvider } from '../../../__stories__/FieldContextProvider';
import {
Expand Down Expand Up @@ -43,7 +44,7 @@ const BooleanFieldInputWithContext = ({
fieldMetadataId: 'boolean',
label: 'Boolean',
iconName: 'Icon123',
type: 'BOOLEAN',
type: FieldMetadataType.Boolean,
metadata: {
fieldName: 'Boolean',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Meta, StoryObj } from '@storybook/react';
import { expect, fn, userEvent, within } from '@storybook/test';

import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
import { FieldMetadataType } from '~/generated/graphql';

import { FieldContextProvider } from '../../../__stories__/FieldContextProvider';
import { useDateTimeField } from '../../../hooks/useDateTimeField';
Expand Down Expand Up @@ -44,7 +45,7 @@ const DateFieldInputWithContext = ({
fieldDefinition={{
fieldMetadataId: 'date',
label: 'Date',
type: 'DATE_TIME',
type: FieldMetadataType.DateTime,
iconName: 'IconCalendarEvent',
metadata: {
fieldName: 'Date',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Decorator, Meta, StoryObj } from '@storybook/react';
import { expect, fn, userEvent, waitFor, within } from '@storybook/test';

import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
import { FieldMetadataType } from '~/generated/graphql';

import { FieldContextProvider } from '../../../__stories__/FieldContextProvider';
import { useEmailField } from '../../../hooks/useEmailField';
Expand Down Expand Up @@ -44,7 +45,7 @@ const EmailFieldInputWithContext = ({
fieldDefinition={{
fieldMetadataId: 'email',
label: 'Email',
type: 'EMAIL',
type: FieldMetadataType.Email,
iconName: 'IconLink',
metadata: {
fieldName: 'email',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Decorator, Meta, StoryObj } from '@storybook/react';
import { expect, fn, userEvent, waitFor, within } from '@storybook/test';

import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
import { FieldMetadataType } from '~/generated/graphql';

import { FieldContextProvider } from '../../../__stories__/FieldContextProvider';
import { useNumberField } from '../../../hooks/useNumberField';
Expand Down Expand Up @@ -45,7 +46,7 @@ const NumberFieldInputWithContext = ({
fieldMetadataId: 'number',
label: 'Number',
iconName: 'Icon123',
type: 'NUMBER',
type: FieldMetadataType.Number,
metadata: {
fieldName: 'number',
placeHolder: 'Enter number',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Decorator, Meta, StoryObj } from '@storybook/react';
import { expect, fn, userEvent, waitFor, within } from '@storybook/test';

import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
import { FieldMetadataType } from '~/generated/graphql';

import { FieldContextProvider } from '../../../__stories__/FieldContextProvider';
import { usePhoneField } from '../../../hooks/usePhoneField';
Expand Down Expand Up @@ -44,7 +45,7 @@ const PhoneFieldInputWithContext = ({
fieldDefinition={{
fieldMetadataId: 'phone',
label: 'Phone',
type: 'TEXT',
type: FieldMetadataType.Text,
iconName: 'IconPhone',
metadata: {
fieldName: 'phone',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMembe
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
import { FieldMetadataType } from '~/generated/graphql';
import { ComponentWithRecoilScopeDecorator } from '~/testing/decorators/ComponentWithRecoilScopeDecorator';
import { ObjectMetadataItemsDecorator } from '~/testing/decorators/ObjectMetadataItemsDecorator';
import { SnackBarDecorator } from '~/testing/decorators/SnackBarDecorator';
Expand Down Expand Up @@ -65,7 +66,7 @@ const RelationFieldInputWithContext = ({
fieldDefinition={{
fieldMetadataId: 'relation',
label: 'Relation',
type: 'RELATION',
type: FieldMetadataType.Relation,
iconName: 'IconLink',
metadata: {
fieldName: 'Relation',
Expand Down
Loading

0 comments on commit dac5253

Please sign in to comment.