Skip to content

Commit

Permalink
Add shortcut metadata to data models & CommandMenu (twentyhq#7977)
Browse files Browse the repository at this point in the history
Resolves twentyhq#7503

---------

Co-authored-by: Félix Malfait <[email protected]>
  • Loading branch information
florianliebig and FelixMalfait authored Oct 25, 2024
1 parent 7edfa61 commit bf2ba25
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/twenty-front/src/generated-metadata/gql.ts

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions packages/twenty-front/src/generated-metadata/graphql.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ export const GotoHotkeysEffectsProvider = () => {
),
});

return nonSystemActiveObjectMetadataItems.map((objectMetadataItem) => (
<GoToHotkeyItemEffect
key={`go-to-hokey-item-${objectMetadataItem.id}`}
hotkey={objectMetadataItem.namePlural[0]}
pathToNavigateTo={`/objects/${objectMetadataItem.namePlural}`}
/>
));
return nonSystemActiveObjectMetadataItems.map((objectMetadataItem) => {
if (!objectMetadataItem.shortcut) {
return null;
}

return (
<GoToHotkeyItemEffect
key={`go-to-hokey-item-${objectMetadataItem.id}`}
hotkey={objectMetadataItem.shortcut}
pathToNavigateTo={`/objects/${objectMetadataItem.namePlural}`}
/>
);
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ describe('useCommandMenu', () => {
labelSingular: 'Task',
labelPlural: 'Tasks',
shouldSyncLabelAndName: true,
shortcut: 'T',
description: 'A task',
icon: 'IconCheckbox',
isCustom: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export const useCommandMenu = () => {
to: `/objects/${item.namePlural}`,
label: `Go to ${item.labelPlural}`,
type: CommandType.Navigate,
firstHotKey: 'G',
secondHotKey: item.labelPlural[0],
firstHotKey: item.shortcut ? 'G' : undefined,
secondHotKey: item.shortcut,
Icon: ALL_ICONS[
(item?.icon as keyof typeof ALL_ICONS) ?? 'IconArrowUpRight'
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const FIND_MANY_OBJECT_METADATA_ITEMS = gql`
updatedAt
labelIdentifierFieldMetadataId
imageIdentifierFieldMetadataId
shortcut
shouldSyncLabelAndName
indexMetadatas(paging: { first: 100 }) {
edges {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const query = gql`
updatedAt
labelIdentifierFieldMetadataId
imageIdentifierFieldMetadataId
shortcut
shouldSyncLabelAndName
fields(paging: { first: 1000 }, filter: $fieldFilter) {
edges {
node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export const objectMetadataItemSchema = z.object({
namePlural: camelCaseStringSchema,
nameSingular: camelCaseStringSchema,
updatedAt: z.string().datetime(),
shortcut: z.string().nullable().optional(),
shouldSyncLabelAndName: z.boolean(),
}) satisfies z.ZodType<ObjectMetadataItem>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddObjectShortcut1729676165199 implements MigrationInterface {
name = 'AddObjectShortcut1729676165199';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "metadata"."objectMetadata" ADD "shortcut" character varying`,
);
await queryRunner.query(
`CREATE UNIQUE INDEX "IDX_objectMetadata_shortcut_upper_workspace" ON "metadata"."objectMetadata" (UPPER("shortcut"), "workspaceId")`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DROP INDEX "metadata"."IDX_objectMetadata_shortcut_upper_workspace"`,
);

await queryRunner.query(
`ALTER TABLE "metadata"."objectMetadata" DROP COLUMN "shortcut"`,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export class CreateObjectInput {
@Field({ nullable: true })
icon?: string;

@IsString()
@IsOptional()
@Field({ nullable: true })
shortcut?: string;

@HideField()
dataSourceId: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ export class ObjectMetadataDTO {
@Field({ nullable: true })
icon: string;

@Field({ nullable: true })
shortcut: string;

@FilterableField()
isCustom: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export class UpdateObjectPayload {
@Field({ nullable: true })
icon?: string;

@IsString()
@IsOptional()
@Field({ nullable: true })
shortcut?: string;

@IsBoolean()
@IsOptional()
@Field({ nullable: true })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export class ObjectMetadataEntity implements ObjectMetadataInterface {
@Column({ default: true })
isAuditLogged: boolean;

@Column({ nullable: true })
shortcut: string;

@Column({ nullable: true, type: 'uuid' })
labelIdentifierFieldMetadataId?: string | null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface WorkspaceEntityOptions {
labelPlural: string;
description?: string;
icon?: string;
shortcut?: string;
labelIdentifierStandardId?: string;
imageIdentifierStandardId?: string;
}
Expand Down Expand Up @@ -44,6 +45,7 @@ export function WorkspaceEntity(
options.labelIdentifierStandardId ?? BASE_OBJECT_STANDARD_FIELD_IDS.id,
imageIdentifierStandardId: options.imageIdentifierStandardId ?? null,
icon: options.icon,
shortcut: options.shortcut,
isAuditLogged,
isSystem,
gate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export interface WorkspaceEntityMetadataArgs {
*/
readonly icon?: string;

/**
* Entity shortcut.
*/
readonly shortcut?: string;

/**
* Is audit logged.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const SEARCH_FIELDS_FOR_COMPANY: FieldTypeAndNameMetadata[] = [
labelPlural: 'Companies',
description: 'A company',
icon: 'IconBuildingSkyscraper',
shortcut: 'C',
labelIdentifierStandardId: COMPANY_STANDARD_FIELD_IDS.name,
})
export class CompanyWorkspaceEntity extends BaseWorkspaceEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const SEARCH_FIELDS_FOR_NOTES: FieldTypeAndNameMetadata[] = [
labelPlural: 'Notes',
description: 'A note',
icon: 'IconNotes',
shortcut: 'N',
labelIdentifierStandardId: NOTE_STANDARD_FIELD_IDS.title,
})
export class NoteWorkspaceEntity extends BaseWorkspaceEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const SEARCH_FIELDS_FOR_OPPORTUNITY: FieldTypeAndNameMetadata[] = [
labelPlural: 'Opportunities',
description: 'An opportunity',
icon: 'IconTargetArrow',
shortcut: 'O',
labelIdentifierStandardId: OPPORTUNITY_STANDARD_FIELD_IDS.name,
})
@WorkspaceIsNotAuditLogged()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const SEARCH_FIELDS_FOR_PERSON: FieldTypeAndNameMetadata[] = [
labelPlural: 'People',
description: 'A person',
icon: 'IconUser',
shortcut: 'P',
labelIdentifierStandardId: PERSON_STANDARD_FIELD_IDS.name,
imageIdentifierStandardId: PERSON_STANDARD_FIELD_IDS.avatarUrl,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/sta
labelPlural: 'Tasks',
description: 'A task',
icon: 'IconCheckbox',
shortcut: 'T',
labelIdentifierStandardId: TASK_STANDARD_FIELD_IDS.title,
})
export class TaskWorkspaceEntity extends BaseWorkspaceEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const WorkflowStatusOptions = [
labelPlural: 'Workflows',
description: 'A workflow',
icon: 'IconSettingsAutomation',
shortcut: 'W',
labelIdentifierStandardId: WORKFLOW_STANDARD_FIELD_IDS.name,
})
@WorkspaceGate({
Expand Down

0 comments on commit bf2ba25

Please sign in to comment.