Skip to content

Commit

Permalink
Add isInactive to FieldMetadata decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
gitstart-twenty committed Aug 14, 2024
1 parent 0f75e14 commit 0450cca
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ export function WorkspaceField<T extends FieldMetadataType>(
propertyKey.toString(),
) ?? false;

const isInactive =
TypedReflect.getMetadata(
'workspace:is-inactive-field-metadata-args',
object,
propertyKey.toString(),
) ?? false;

const defaultValue = (options.defaultValue ??
generateDefaultValue(
options.type,
Expand All @@ -75,6 +82,7 @@ export function WorkspaceField<T extends FieldMetadataType>(
isSystem,
gate,
isDeprecated,
isInactive,
});
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { TypedReflect } from 'src/utils/typed-reflect';

export function isInactive(): PropertyDecorator {
return (object, propertyKey) => {
TypedReflect.defineMetadata(
'workspace:is-inactive-field-metadata-args',
true,
object,
propertyKey.toString(),
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ export interface WorkspaceFieldMetadataArgs {
* Is deprecated field.
*/
readonly isDeprecated?: boolean;

/**
* Is inactive field.
*/
readonly isInactive?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ export interface WorkspaceRelationMetadataArgs {
* Field gate.
*/
readonly gate?: Gate;

/**
* Is inactive field.
*/
readonly isInactive?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export class StandardFieldFactory {
isNullable: workspaceFieldMetadataArgs.isNullable,
isCustom: workspaceFieldMetadataArgs.isDeprecated ? true : false,
isSystem: workspaceFieldMetadataArgs.isSystem ?? false,
isActive: !workspaceFieldMetadataArgs.isInactive,
},
];
}
Expand Down Expand Up @@ -214,6 +215,7 @@ export class StandardFieldFactory {
isCustom: false,
isSystem: true,
isNullable: workspaceRelationMetadataArgs.isNullable,
isActive: !workspaceRelationMetadataArgs.isInactive,
});
}

Expand All @@ -231,6 +233,7 @@ export class StandardFieldFactory {
workspaceEntityMetadataArgs?.isSystem ||
workspaceRelationMetadataArgs.isSystem,
isNullable: true,
isActive: !workspaceRelationMetadataArgs.isInactive,
});

return fieldMetadataCollection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type PartialFieldMetadata = Omit<
isSystem?: boolean;
workspaceId: string;
objectMetadataId?: string;
isActive?: boolean;
};

export type PartialComputedFieldMetadata = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import {
In,
ObjectLiteral,
} from 'typeorm';
import { v4 as uuidV4 } from 'uuid';
import { DeepPartial } from 'typeorm/common/DeepPartial';
import { v4 as uuidV4 } from 'uuid';

import { PartialFieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-field-metadata.interface';
import { PartialIndexMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-index-metadata.interface';

import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { FieldMetadataComplexOption } from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
import {
FieldMetadataEntity,
FieldMetadataType,
} from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import { IndexMetadataEntity } from 'src/engine/metadata-modules/index-metadata/index-metadata.entity';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { RelationMetadataEntity } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
import { FieldMetadataComplexOption } from 'src/engine/metadata-modules/field-metadata/dtos/options.input';
import { WorkspaceSyncStorage } from 'src/engine/workspace-manager/workspace-sync-metadata/storage/workspace-sync.storage';
import { FieldMetadataUpdate } from 'src/engine/workspace-manager/workspace-migration-builder/factories/workspace-migration-field.factory';
import { ObjectMetadataUpdate } from 'src/engine/workspace-manager/workspace-migration-builder/factories/workspace-migration-object.factory';
import { IndexMetadataEntity } from 'src/engine/metadata-modules/index-metadata/index-metadata.entity';
import { WorkspaceSyncStorage } from 'src/engine/workspace-manager/workspace-sync-metadata/storage/workspace-sync.storage';

@Injectable()
export class WorkspaceMetadataUpdaterService {
Expand Down Expand Up @@ -104,7 +104,6 @@ export class WorkspaceMetadataUpdaterService {
),
}
: {}),
isActive: true,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class CreateCompanyService {
transactionManager?: EntityManager,
): Promise<number> {
const lastCompanyPosition = await companyRepository.maximum(
'position',
'position' as never,
undefined,
transactionManager,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class CreateContactService {
transactionManager?: EntityManager,
): Promise<number> {
const lastPersonPosition = await personRepository.maximum(
'position',
'position' as never,
undefined,
transactionManager,
);
Expand Down
1 change: 1 addition & 0 deletions packages/twenty-server/src/utils/typed-reflect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface ReflectMetadataTypeMap {
['workspace:is-audit-logged-metadata-args']: false;
['workspace:is-primary-field-metadata-args']: true;
['workspace:is-deprecated-field-metadata-args']: true;
['workspace:is-inactive-field-metadata-args']: true;
}

export class TypedReflect {
Expand Down

0 comments on commit 0450cca

Please sign in to comment.