Skip to content

Commit

Permalink
feat: update links field
Browse files Browse the repository at this point in the history
Closes #5113
  • Loading branch information
thaisguigon committed Apr 29, 2024
1 parent ca8caf7 commit c498bc1
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 41 deletions.
19 changes: 18 additions & 1 deletion packages/twenty-front/src/generated-metadata/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export type CreateRelationInput = {
export type CreateRemoteServerInput = {
foreignDataWrapperOptions: Scalars['JSON']['input'];
foreignDataWrapperType: Scalars['String']['input'];
userMappingOptions?: InputMaybe<Scalars['JSON']['input']>;
userMappingOptions?: InputMaybe<UserMappingOptionsInput>;
};

export type CursorPaging = {
Expand Down Expand Up @@ -380,6 +380,7 @@ export type Mutation = {
updateBillingSubscription: UpdateBillingEntity;
updateOneField: Field;
updateOneObject: Object;
updateOneRemoteServer: RemoteServer;
updatePasswordViaResetToken: InvalidatePassword;
updateWorkspace: Workspace;
uploadFile: Scalars['String']['output'];
Expand Down Expand Up @@ -527,6 +528,11 @@ export type MutationUpdateOneObjectArgs = {
};


export type MutationUpdateOneRemoteServerArgs = {
input: UpdateRemoteServerInput;
};


export type MutationUpdatePasswordViaResetTokenArgs = {
newPassword: Scalars['String']['input'];
passwordResetToken: Scalars['String']['input'];
Expand Down Expand Up @@ -995,6 +1001,12 @@ export type UpdateOneObjectInput = {
update: UpdateObjectInput;
};

export type UpdateRemoteServerInput = {
foreignDataWrapperOptions?: InputMaybe<Scalars['JSON']['input']>;
id: Scalars['String']['input'];
userMappingOptions?: InputMaybe<UserMappingOptionsInput>;
};

export type UpdateWorkspaceInput = {
allowImpersonation?: InputMaybe<Scalars['Boolean']['input']>;
displayName?: InputMaybe<Scalars['String']['input']>;
Expand Down Expand Up @@ -1039,6 +1051,11 @@ export type UserExists = {
exists: Scalars['Boolean']['output'];
};

export type UserMappingOptionsInput = {
password?: InputMaybe<Scalars['String']['input']>;
username?: InputMaybe<Scalars['String']['input']>;
};

export type UserWorkspace = {
__typename?: 'UserWorkspace';
createdAt: Scalars['DateTime']['output'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { isUndefined } from '@sniptt/guards';

import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { mapObjectMetadataToGraphQLQuery } from '@/object-metadata/utils/mapObjectMetadataToGraphQLQuery';
import { FieldMetadataType } from '~/generated-metadata/graphql';
import {
FieldMetadataType,
RelationMetadataType,
} from '~/generated-metadata/graphql';

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

Expand All @@ -25,29 +28,29 @@ export const mapFieldMetadataToGraphQLQuery = ({
}): any => {
const fieldType = field.type;

const fieldIsSimpleValue = (
[
'UUID',
'TEXT',
'PHONE',
'DATE_TIME',
'DATE',
'EMAIL',
'NUMBER',
'BOOLEAN',
'RATING',
'SELECT',
'MULTI_SELECT',
'POSITION',
'RAW_JSON',
] as FieldMetadataType[]
).includes(fieldType);
const fieldIsSimpleValue = [
FieldMetadataType.Uuid,
FieldMetadataType.Text,
FieldMetadataType.Phone,
FieldMetadataType.DateTime,
FieldMetadataType.Date,
FieldMetadataType.Email,
FieldMetadataType.Number,
FieldMetadataType.Boolean,
FieldMetadataType.Rating,
FieldMetadataType.Select,
FieldMetadataType.MultiSelect,
FieldMetadataType.Position,
FieldMetadataType.RawJson,
].includes(fieldType);

if (fieldIsSimpleValue) {
return field.name;
} else if (
fieldType === 'RELATION' &&
field.toRelationMetadata?.relationType === 'ONE_TO_MANY' &&
}

if (
fieldType === FieldMetadataType.Relation &&
field.toRelationMetadata?.relationType === RelationMetadataType.OneToMany &&
depth > 0
) {
const relationMetadataItem = objectMetadataItems.find(
Expand All @@ -69,9 +72,12 @@ ${mapObjectMetadataToGraphQLQuery({
computeReferences: computeReferences,
isRootLevel: false,
})}`;
} else if (
fieldType === 'RELATION' &&
field.fromRelationMetadata?.relationType === 'ONE_TO_MANY' &&
}

if (
fieldType === FieldMetadataType.Relation &&
field.fromRelationMetadata?.relationType ===
RelationMetadataType.OneToMany &&
depth > 0
) {
const relationMetadataItem = objectMetadataItems.find(
Expand All @@ -97,26 +103,43 @@ ${mapObjectMetadataToGraphQLQuery({
})}
}
}`;
} else if (fieldType === 'LINK') {
}

if (fieldType === FieldMetadataType.Link) {
return `${field.name}
{
label
url
}`;
} else if (fieldType === 'CURRENCY') {
}

if (fieldType === FieldMetadataType.Links) {
return `${field.name}
{
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}`;
}

if (fieldType === FieldMetadataType.Currency) {
return `${field.name}
{
amountMicros
currencyCode
}
`;
} else if (fieldType === 'FULL_NAME') {
}

if (fieldType === FieldMetadataType.FullName) {
return `${field.name}
{
firstName
lastName
}`;
} else if (fieldType === 'ADDRESS') {
}

if (fieldType === FieldMetadataType.Address) {
return `${field.name}
{
addressStreet1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const LinksFieldInput = ({
persistLinksField({
primaryLinkUrl: url,
primaryLinkLabel: '',
secondaryLinks: [],
}),
);
};
Expand All @@ -36,6 +37,7 @@ export const LinksFieldInput = ({
persistLinksField({
primaryLinkUrl: url,
primaryLinkLabel: '',
secondaryLinks: [],
}),
);
};
Expand All @@ -45,6 +47,7 @@ export const LinksFieldInput = ({
persistLinksField({
primaryLinkUrl: url,
primaryLinkLabel: '',
secondaryLinks: [],
}),
);
};
Expand All @@ -54,6 +57,7 @@ export const LinksFieldInput = ({
persistLinksField({
primaryLinkUrl: url,
primaryLinkLabel: '',
secondaryLinks: [],
}),
);
};
Expand All @@ -63,6 +67,7 @@ export const LinksFieldInput = ({
persistLinksField({
primaryLinkUrl: url,
primaryLinkLabel: '',
secondaryLinks: [],
}),
);
};
Expand All @@ -71,6 +76,7 @@ export const LinksFieldInput = ({
setDraftValue({
primaryLinkUrl: url,
primaryLinkLabel: '',
secondaryLinks: [],
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type FieldLinkDraftValue = { url: string; label: string };
export type FieldLinksDraftValue = {
primaryLinkLabel: string;
primaryLinkUrl: string;
secondaryLinks?: string | null;
secondaryLinks?: { label: string; url: string }[] | null;
};
export type FieldCurrencyDraftValue = {
currencyCode: CurrencyCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export type FieldLinkValue = { url: string; label: string };
export type FieldLinksValue = {
primaryLinkLabel: string;
primaryLinkUrl: string;
secondaryLinks?: string | null;
secondaryLinks?: { label: string; url: string }[] | null;
};
export type FieldCurrencyValue = {
currencyCode: CurrencyCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { FieldLinksValue } from '../FieldMetadata';
export const linksSchema = z.object({
primaryLinkLabel: z.string(),
primaryLinkUrl: absoluteUrlSchema,
secondaryLinks: z.string().optional().nullable(),
secondaryLinks: z
.array(z.object({ label: z.string(), url: absoluteUrlSchema }))
.nullable(),
}) satisfies z.ZodType<FieldLinksValue>;

export const isFieldLinksValue = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export const SettingsObjectNewFieldStep2 = () => {
FieldMetadataType.Email,
FieldMetadataType.FullName,
FieldMetadataType.Link,
FieldMetadataType.Links,
// FieldMetadataType.Links,
FieldMetadataType.Numeric,
FieldMetadataType.Phone,
FieldMetadataType.Probability,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metada
import { compositeTypeDefintions } from 'src/engine/metadata-modules/field-metadata/composite-types';
import { computeCompositeColumnName } from 'src/engine/metadata-modules/field-metadata/utils/compute-column-name.util';
import { isCompositeFieldMetadataType } from 'src/engine/metadata-modules/field-metadata/utils/is-composite-field-metadata-type.util';
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';

@Injectable()
export class ArgsAliasFactory {
Expand Down Expand Up @@ -45,6 +46,11 @@ export class ArgsAliasFactory {
for (const [key, value] of Object.entries(args)) {
const fieldMetadata = fieldMetadataMap.get(key);

if (fieldMetadata?.type === FieldMetadataType.RAW_JSON) {
newArgs[key] = JSON.stringify(value);
continue;
}

// If it's a composite type, we need to transform args to properly map column name
if (
fieldMetadata &&
Expand Down Expand Up @@ -76,7 +82,11 @@ export class ArgsAliasFactory {
compositeProperty,
);

newArgs[columnName] = subValue;
if (compositeType.type === FieldMetadataType.RAW_JSON) {
newArgs[columnName] = JSON.stringify(subValue);
} else {
newArgs[columnName] = subValue;
}
}
}
} else if (fieldMetadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ export const linksCompositeType: CompositeType = {
export type LinksMetadata = {
primaryLinkLabel: string;
primaryLinkUrl: string;
secondaryLinks: JSON | null;
secondaryLinks: object | null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {
IsArray,
IsBoolean,
IsDate,
IsJSON,
IsNotEmpty,
IsNumber,
IsNumberString,
IsObject,
IsString,
Matches,
ValidateIf,
Expand All @@ -28,9 +28,9 @@ export class FieldMetadataDefaultValueString {
}

export class FieldMetadataDefaultValueRawJson {
@ValidateIf((object, value) => value !== null)
@IsJSON()
value: JSON | null;
@ValidateIf((_object, value) => value !== null)
@IsObject()
value: object | null;
}

export class FieldMetadataDefaultValueNumber {
Expand Down Expand Up @@ -149,6 +149,6 @@ export class FieldMetadataDefaultValueLinks {
primaryLinkUrl: string | null;

@ValidateIf((_object, value) => value !== null)
@IsJSON()
secondaryLinks: JSON | null;
@IsObject()
secondaryLinks: object | null;
}

0 comments on commit c498bc1

Please sign in to comment.