-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: record group issues #8854
fix: record group issues #8854
Changes from all commits
8259ded
7ff1876
73100fb
7a8fa12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,11 +73,24 @@ export const useHandleRecordGroupField = ({ | |
}) satisfies ViewGroup, | ||
); | ||
|
||
const viewGroupsToDelete = view.viewGroups.filter( | ||
(group) => group.fieldMetadataId !== fieldMetadataItem.id, | ||
); | ||
|
||
if (viewGroupsToCreate.length > 0) { | ||
await createViewGroupRecords(viewGroupsToCreate, view); | ||
} | ||
|
||
if (viewGroupsToDelete.length > 0) { | ||
await deleteViewGroupRecords(viewGroupsToDelete); | ||
} | ||
Comment on lines
80
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: the order of operations here could cause a brief visual flicker - consider deleting old groups before creating new ones |
||
}, | ||
[createViewGroupRecords, currentViewIdCallbackState, getViewFromCache], | ||
[ | ||
createViewGroupRecords, | ||
deleteViewGroupRecords, | ||
currentViewIdCallbackState, | ||
getViewFromCache, | ||
], | ||
); | ||
|
||
const resetRecordGroupField = useRecoilCallback( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ export type View = { | |
viewFilters: ViewFilter[]; | ||
viewFilterGroups?: ViewFilterGroup[]; | ||
viewSorts: ViewSort[]; | ||
/** | ||
* @deprecated Use `viewGroups.fieldMetadataId` instead. | ||
*/ | ||
kanbanFieldMetadataId: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider making kanbanFieldMetadataId optional since it's deprecated |
||
position: number; | ||
icon: string; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { In } from 'typeorm'; | ||
import { EntityManager, In } from 'typeorm'; | ||
|
||
import { | ||
FieldMetadataComplexOption, | ||
|
@@ -27,6 +27,7 @@ export class FieldMetadataRelatedRecordsService { | |
public async updateRelatedViewGroups( | ||
oldFieldMetadata: FieldMetadataEntity, | ||
newFieldMetadata: FieldMetadataEntity, | ||
transactionManager?: EntityManager, | ||
) { | ||
if ( | ||
!isSelectFieldMetadataType(newFieldMetadata.type) || | ||
|
@@ -49,6 +50,10 @@ export class FieldMetadataRelatedRecordsService { | |
); | ||
|
||
for (const view of views) { | ||
if (view.viewGroups.length === 0) { | ||
continue; | ||
} | ||
|
||
const maxPosition = view.viewGroups.reduce( | ||
(max, viewGroup) => Math.max(max, viewGroup.position), | ||
0, | ||
|
@@ -64,7 +69,7 @@ export class FieldMetadataRelatedRecordsService { | |
}), | ||
); | ||
|
||
await viewGroupRepository.insert(viewGroupsToCreate); | ||
await viewGroupRepository.insert(viewGroupsToCreate, transactionManager); | ||
|
||
for (const { old: oldOption, new: newOption } of updated) { | ||
const viewGroup = view.viewGroups.find( | ||
|
@@ -82,15 +87,19 @@ export class FieldMetadataRelatedRecordsService { | |
{ | ||
fieldValue: newOption.value, | ||
}, | ||
transactionManager, | ||
); | ||
} | ||
|
||
const valuesToDelete = deleted.map((option) => option.value); | ||
|
||
await viewGroupRepository.delete({ | ||
fieldMetadataId: newFieldMetadata.id, | ||
fieldValue: In(valuesToDelete), | ||
}); | ||
await viewGroupRepository.delete( | ||
{ | ||
fieldMetadataId: newFieldMetadata.id, | ||
fieldValue: In(valuesToDelete), | ||
}, | ||
transactionManager, | ||
); | ||
Comment on lines
94
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: check if valuesToDelete is empty before performing delete operation to avoid unnecessary database calls |
||
} | ||
} | ||
|
||
|
@@ -143,7 +152,9 @@ export class FieldMetadataRelatedRecordsService { | |
|
||
return await viewRepository.find({ | ||
where: { | ||
kanbanFieldMetadataId: fieldMetadata.id, | ||
viewGroups: { | ||
fieldMetadataId: fieldMetadata.id, | ||
}, | ||
}, | ||
relations: ['viewGroups'], | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,9 @@ export class ViewWorkspaceEntity extends BaseWorkspaceEntity { | |
label: 'kanbanfieldMetadataId', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: label should be 'Kanban Field Metadata Id' to match standard casing |
||
description: 'View Kanban column field', | ||
}) | ||
/** | ||
* @deprecated Use `viewGroups.fieldMetadataId` instead | ||
*/ | ||
kanbanFieldMetadataId: string; | ||
|
||
@WorkspaceField({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: this filter removes all groups from other fields, which means switching back to a previous field will lose any customizations made to those groups