Skip to content

Commit

Permalink
Fix/record group index and seed (#9605)
Browse files Browse the repository at this point in the history
- [x] [Disable group by on default view Options
menu](https://discord.com/channels/1130383047699738754/1328421803399446568)
- [x] Add default seed for view group
  • Loading branch information
magrinj authored Jan 15, 2025
1 parent 1a5b3ef commit eaa6842
Show file tree
Hide file tree
Showing 12 changed files with 393 additions and 143 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Key } from 'ts-key-enum';
import {
AppTooltip,
IconFileExport,
IconFileImport,
IconLayout,
Expand Down Expand Up @@ -55,6 +56,10 @@ export const ObjectOptionsDropdownMenuContent = () => {
recordGroupFieldMetadataComponentState,
);

const isGroupByEnabled =
(isDefined(currentView?.viewGroups) && currentView.viewGroups.length > 0) ||
currentView?.key !== 'INDEX';

useScopedHotkeys(
[Key.Escape],
() => {
Expand Down Expand Up @@ -115,20 +120,34 @@ export const ObjectOptionsDropdownMenuContent = () => {
contextualText={`${visibleBoardFields.length} shown`}
hasSubMenu
/>
{viewType === ViewType.Kanban ||
(currentView?.key !== 'INDEX' && (
<MenuItem
onClick={() =>
isDefined(recordGroupFieldMetadata)
? onContentChange('recordGroups')
: onContentChange('recordGroupFields')
}
LeftIcon={IconLayoutList}
text="Group by"
contextualText={recordGroupFieldMetadata?.label}
hasSubMenu
/>
))}

<div id="group-by-menu-item">
<MenuItem
onClick={() =>
isDefined(recordGroupFieldMetadata)
? onContentChange('recordGroups')
: onContentChange('recordGroupFields')
}
LeftIcon={IconLayoutList}
text="Group by"
contextualText={
!isGroupByEnabled
? 'Not available on Default View'
: recordGroupFieldMetadata?.label
}
hasSubMenu
disabled={!isGroupByEnabled}
/>
</div>
{!isGroupByEnabled && (
<AppTooltip
anchorSelect={`#group-by-menu-item`}
content="Not available on Default View"
noArrow
place="bottom"
width="100%"
/>
)}
</DropdownMenuItemsContainer>
<DropdownMenuSeparator />
<DropdownMenuItemsContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ import { SURVEY_RESULTS_METADATA_SEEDS } from 'src/engine/seeder/metadata-seeds/
import { SeederService } from 'src/engine/seeder/seeder.service';
import { shouldSeedWorkspaceFavorite } from 'src/engine/utils/should-seed-workspace-favorite';
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
import { createWorkspaceViews } from 'src/engine/workspace-manager/standard-objects-prefill-data/create-workspace-views';
import { seedViewWithDemoData } from 'src/engine/workspace-manager/standard-objects-prefill-data/seed-view-with-demo-data';
import { opportunitiesTableByStageView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/opportunity-table-by-stage.view';
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
import { WorkspaceSyncMetadataService } from 'src/engine/workspace-manager/workspace-sync-metadata/workspace-sync-metadata.service';

Expand Down Expand Up @@ -230,6 +232,14 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
isWorkflowEnabled,
);

const devViewDefinitionsWithId = await createWorkspaceViews(
entityManager,
dataSourceMetadata.schema,
[opportunitiesTableByStageView(objectMetadataStandardIdToIdMap)],
);

viewDefinitionsWithId.push(...devViewDefinitionsWithId);

await seedWorkspaceFavorites(
viewDefinitionsWithId
.filter(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { EntityManager } from 'typeorm';
import { v4 } from 'uuid';

import { ViewDefinition } from 'src/engine/workspace-manager/standard-objects-prefill-data/types/view-definition.interface';

export const createWorkspaceViews = async (
entityManager: EntityManager,
schemaName: string,
viewDefinitions: ViewDefinition[],
) => {
const viewDefinitionsWithId = viewDefinitions.map((viewDefinition) => ({
...viewDefinition,
id: v4(),
}));

await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.view`, [
'id',
'name',
'objectMetadataId',
'type',
'key',
'position',
'icon',
'kanbanFieldMetadataId',
])
.values(
viewDefinitionsWithId.map(
({
id,
name,
objectMetadataId,
type,
key,
position,
icon,
kanbanFieldMetadataId,
}) => ({
id,
name,
objectMetadataId,
type,
key,
position,
icon,
kanbanFieldMetadataId,
}),
),
)
.returning('*')
.execute();

for (const viewDefinition of viewDefinitionsWithId) {
if (viewDefinition.fields && viewDefinition.fields.length > 0) {
await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.viewField`, [
'fieldMetadataId',
'position',
'isVisible',
'size',
'viewId',
])
.values(
viewDefinition.fields.map((field) => ({
fieldMetadataId: field.fieldMetadataId,
position: field.position,
isVisible: field.isVisible,
size: field.size,
viewId: viewDefinition.id,
})),
)
.execute();
}

if (viewDefinition.filters && viewDefinition.filters.length > 0) {
await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.viewFilter`, [
'fieldMetadataId',
'displayValue',
'operand',
'value',
'viewId',
])
.values(
viewDefinition.filters.map((filter: any) => ({
fieldMetadataId: filter.fieldMetadataId,
displayValue: filter.displayValue,
operand: filter.operand,
value: filter.value,
viewId: viewDefinition.id,
})),
)
.execute();
}

if (
'groups' in viewDefinition &&
viewDefinition.groups &&
viewDefinition.groups.length > 0
) {
await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.viewGroup`, [
'fieldMetadataId',
'isVisible',
'fieldValue',
'position',
'viewId',
])
.values(
viewDefinition.groups.map((group: any) => ({
fieldMetadataId: group.fieldMetadataId,
isVisible: group.isVisible,
fieldValue: group.fieldValue,
position: group.position,
viewId: viewDefinition.id,
})),
)
.execute();
}
}

return viewDefinitionsWithId;
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { EntityManager } from 'typeorm';
import { v4 } from 'uuid';

import { ObjectMetadataStandardIdToIdMap } from 'src/engine/metadata-modules/object-metadata/interfaces/object-metadata-standard-id-to-id-map';

import { createWorkspaceViews } from 'src/engine/workspace-manager/standard-objects-prefill-data/create-workspace-views';
import { seedCompaniesAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/companies-all.view';
import { notesAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/notes-all.view';
import { opportunitiesAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/opportunities-all.view';
Expand Down Expand Up @@ -37,124 +37,5 @@ export const seedViewWithDemoData = async (
: []),
];

const viewDefinitionsWithId = viewDefinitions.map((viewDefinition) => ({
...viewDefinition,
id: v4(),
}));

await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.view`, [
'id',
'name',
'objectMetadataId',
'type',
'key',
'position',
'icon',
'kanbanFieldMetadataId',
])
.values(
viewDefinitionsWithId.map(
({
id,
name,
objectMetadataId,
type,
key,
position,
icon,
kanbanFieldMetadataId,
}) => ({
id,
name,
objectMetadataId,
type,
key,
position,
icon,
kanbanFieldMetadataId,
}),
),
)
.returning('*')
.execute();

for (const viewDefinition of viewDefinitionsWithId) {
if (viewDefinition.fields && viewDefinition.fields.length > 0) {
await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.viewField`, [
'fieldMetadataId',
'position',
'isVisible',
'size',
'viewId',
])
.values(
viewDefinition.fields.map((field) => ({
fieldMetadataId: field.fieldMetadataId,
position: field.position,
isVisible: field.isVisible,
size: field.size,
viewId: viewDefinition.id,
})),
)
.execute();
}

if (viewDefinition.filters && viewDefinition.filters.length > 0) {
await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.viewFilter`, [
'fieldMetadataId',
'displayValue',
'operand',
'value',
'viewId',
])
.values(
viewDefinition.filters.map((filter: any) => ({
fieldMetadataId: filter.fieldMetadataId,
displayValue: filter.displayValue,
operand: filter.operand,
value: filter.value,
viewId: viewDefinition.id,
})),
)
.execute();
}

if (
'groups' in viewDefinition &&
viewDefinition.groups &&
viewDefinition.groups.length > 0
) {
await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.viewGroup`, [
'fieldMetadataId',
'isVisible',
'fieldValue',
'position',
'viewId',
])
.values(
viewDefinition.groups.map((group: any) => ({
fieldMetadataId: group.fieldMetadataId,
isVisible: group.isVisible,
fieldValue: group.fieldValue,
position: group.position,
viewId: viewDefinition.id,
})),
)
.execute();
}
}

return viewDefinitionsWithId;
return createWorkspaceViews(entityManager, schemaName, viewDefinitions);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export interface ViewDefinition {
id?: string;
name: string;
objectMetadataId: string;
type: string;
key: string | null;
position: number;
icon?: string;
kanbanFieldMetadataId?: string;
fields?: {
fieldMetadataId: string;
position: number;
isVisible: boolean;
size: number;
}[];
filters?: {
fieldMetadataId: string;
displayValue: string;
operand: string;
value: string;
}[];
groups?: {
fieldMetadataId: string;
isVisible: boolean;
fieldValue: string;
position: number;
}[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const opportunitiesByStageView = (
objectMetadataStandardIdToIdMap[STANDARD_OBJECT_IDS.opportunity].id,
type: 'kanban',
key: null,
position: 1,
position: 2,
icon: 'IconLayoutKanban',
kanbanFieldMetadataId:
objectMetadataStandardIdToIdMap[STANDARD_OBJECT_IDS.opportunity].fields[
Expand Down
Loading

0 comments on commit eaa6842

Please sign in to comment.