Skip to content

Commit

Permalink
Add isInactive to FieldMetadata decorator (#6623)
Browse files Browse the repository at this point in the history
This PR was created by [GitStart](https://gitstart.com/) to address the
requirements from this ticket:
[TWNTY-4145](https://clients.gitstart.com/twenty/5449/tickets/TWNTY-4145).
This ticket was imported from:
[TWNTY-4145](#4145)

 --- 
### Description
This PR introduces the @isInActive() decorator to the standard field
metadata. \
- This gives the ability to allow workspaces to be able to be created
with standard fields as inactive *Helps prevent polluting existing
workspaces
- A new standard field can be added to* eg company-workspace-entity.ts
and the @WorkspaceIsInActive() decorator can be added to create it in
deactivated mode
sync-metadata command: `yarn command:prod workspace:sync-metadata -f`

### Refs
#4145 

### Demo

<https://www.loom.com/share/10c13e2614d749809cfe2d2d847e963e?sid=017bbfcf-53c6-4205-8ffc-8a09c416220a>\

<https://www.loom.com/share/6ab86bd36f344c999cb8dacdb82c7bb0?sid=13ac78a2-de44-4772-bb54-7b57975e7360>\

Fixes: #4145

---------

Co-authored-by: gitstart-twenty <[email protected]>
Co-authored-by: Charles Bochet <[email protected]>
  • Loading branch information
3 people authored Aug 22, 2024
1 parent 1eeeae8 commit 7ca091f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface WorkspaceFieldOptions<
defaultValue?: FieldMetadataDefaultValue<T>;
options?: FieldMetadataOptions<T>;
settings?: FieldMetadataSettings<T>;
isActive?: boolean;
}

export function WorkspaceField<T extends FieldMetadataType>(
Expand Down Expand Up @@ -75,6 +76,7 @@ export function WorkspaceField<T extends FieldMetadataType>(
isSystem,
gate,
isDeprecated,
isActive: options.isActive,
});
};
}
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 active field.
*/
readonly isActive?: 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 active field.
*/
readonly isActive?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export class StandardFieldFactory {
isNullable: workspaceFieldMetadataArgs.isNullable,
isCustom: workspaceFieldMetadataArgs.isDeprecated ? true : false,
isSystem: workspaceFieldMetadataArgs.isSystem ?? false,
isActive: workspaceFieldMetadataArgs.isActive ?? true,
},
];
}
Expand Down Expand Up @@ -222,6 +223,7 @@ export class StandardFieldFactory {
isCustom: false,
isSystem: true,
isNullable: workspaceRelationMetadataArgs.isNullable,
isActive: workspaceRelationMetadataArgs.isActive ?? true,
});
}

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

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

0 comments on commit 7ca091f

Please sign in to comment.