mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-22 11:43:34 +03:00
Fix secondary links default value and types (#8532)
Fixes broken companies view
This commit is contained in:
parent
8c33e4cdae
commit
ac1197afe1
@ -93,7 +93,7 @@ const fieldLinksMock = {
|
|||||||
type: FieldMetadataType.LINKS,
|
type: FieldMetadataType.LINKS,
|
||||||
isNullable: false,
|
isNullable: false,
|
||||||
defaultValue: [
|
defaultValue: [
|
||||||
{ primaryLinkLabel: '', primaryLinkUrl: '', secondaryLinks: {} },
|
{ primaryLinkLabel: '', primaryLinkUrl: '', secondaryLinks: [] },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ export class LinksMetadata {
|
|||||||
primaryLinkUrl: string;
|
primaryLinkUrl: string;
|
||||||
|
|
||||||
@Field(() => [LinkMetadata], { nullable: true })
|
@Field(() => [LinkMetadata], { nullable: true })
|
||||||
secondaryLinks: object | null;
|
secondaryLinks: LinkMetadata[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ObjectType('TimelineCalendarEvent')
|
@ObjectType('TimelineCalendarEvent')
|
||||||
|
@ -27,8 +27,13 @@ export const linksCompositeType: CompositeType = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type LinkMetadata = {
|
||||||
|
label: string;
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type LinksMetadata = {
|
export type LinksMetadata = {
|
||||||
primaryLinkLabel: string;
|
primaryLinkLabel: string;
|
||||||
primaryLinkUrl: string;
|
primaryLinkUrl: string;
|
||||||
secondaryLinks: object | null;
|
secondaryLinks: LinkMetadata[] | null;
|
||||||
};
|
};
|
||||||
|
@ -31,7 +31,7 @@ export class FieldMetadataDefaultValueString {
|
|||||||
|
|
||||||
export class FieldMetadataDefaultValueRawJson {
|
export class FieldMetadataDefaultValueRawJson {
|
||||||
@ValidateIf((_object, value) => value !== null)
|
@ValidateIf((_object, value) => value !== null)
|
||||||
@IsObject()
|
@IsObject() // TODO: Should this also allow arrays?
|
||||||
value: object | null;
|
value: object | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,6 +137,14 @@ export class FieldMetadataDefaultValueAddress {
|
|||||||
addressLng: number | null;
|
addressLng: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LinkMetadata {
|
||||||
|
@IsString()
|
||||||
|
label: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
export class FieldMetadataDefaultValueLinks {
|
export class FieldMetadataDefaultValueLinks {
|
||||||
@ValidateIf((_object, value) => value !== null)
|
@ValidateIf((_object, value) => value !== null)
|
||||||
@IsQuotedString()
|
@IsQuotedString()
|
||||||
@ -147,8 +155,8 @@ export class FieldMetadataDefaultValueLinks {
|
|||||||
primaryLinkUrl: string | null;
|
primaryLinkUrl: string | null;
|
||||||
|
|
||||||
@ValidateIf((_object, value) => value !== null)
|
@ValidateIf((_object, value) => value !== null)
|
||||||
@IsObject()
|
@IsArray()
|
||||||
secondaryLinks: object | null;
|
secondaryLinks: LinkMetadata[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FieldMetadataDefaultActor {
|
export class FieldMetadataDefaultActor {
|
||||||
|
@ -38,7 +38,7 @@ export function generateDefaultValue(
|
|||||||
return {
|
return {
|
||||||
primaryLinkLabel: "''",
|
primaryLinkLabel: "''",
|
||||||
primaryLinkUrl: "''",
|
primaryLinkUrl: "''",
|
||||||
secondaryLinks: [],
|
secondaryLinks: "'[]'",
|
||||||
};
|
};
|
||||||
case FieldMetadataType.PHONES:
|
case FieldMetadataType.PHONES:
|
||||||
return {
|
return {
|
||||||
|
@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
|
|||||||
|
|
||||||
import axios, { AxiosInstance } from 'axios';
|
import axios, { AxiosInstance } from 'axios';
|
||||||
import uniqBy from 'lodash.uniqby';
|
import uniqBy from 'lodash.uniqby';
|
||||||
import { EntityManager, ILike } from 'typeorm';
|
import { DeepPartial, EntityManager, ILike } from 'typeorm';
|
||||||
|
|
||||||
import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
|
import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
|
||||||
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
import { WorkspaceRepository } from 'src/engine/twenty-orm/repository/workspace.repository';
|
||||||
@ -90,11 +90,7 @@ export class CreateCompanyService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Create new companies
|
// Create new companies
|
||||||
const createdCompanies = await companyRepository.save(
|
const createdCompanies = await companyRepository.save(newCompaniesData);
|
||||||
newCompaniesData,
|
|
||||||
undefined,
|
|
||||||
transactionManager,
|
|
||||||
);
|
|
||||||
const createdCompanyIdsMap = this.createCompanyMap(createdCompanies);
|
const createdCompanyIdsMap = this.createCompanyMap(createdCompanies);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -157,10 +153,10 @@ export class CreateCompanyService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private createCompanyMap(companies: CompanyWorkspaceEntity[]) {
|
private createCompanyMap(companies: DeepPartial<CompanyWorkspaceEntity>[]) {
|
||||||
return companies.reduce(
|
return companies.reduce(
|
||||||
(acc, company) => {
|
(acc, company) => {
|
||||||
if (!company.domainName) {
|
if (!company.domainName?.primaryLinkUrl || !company.id) {
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
const key = extractDomainFromLink(company.domainName.primaryLinkUrl);
|
const key = extractDomainFromLink(company.domainName.primaryLinkUrl);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
import { EntityManager } from 'typeorm';
|
import { DeepPartial, EntityManager } from 'typeorm';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
|
|
||||||
import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
|
import { FieldActorSource } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type';
|
||||||
|
Loading…
Reference in New Issue
Block a user