-
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: when field metadata SELECT type is edited update view groups #8344
Conversation
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.
PR Summary
This PR adds functionality to update view groups when SELECT type field metadata is edited, ensuring synchronization between field changes and their associated views.
- Added
FieldMetadataRelatedRecordsService
in/packages/twenty-server/src/engine/metadata-modules/field-metadata/services/field-metadata-related-records.service.ts
to manage view group updates - Added
useObjectMetadataViews
hook in/packages/twenty-front/src/modules/views/hooks/useObjectMetadataViews.ts
to fetch view metadata with network-only policy - Added
refetch
function touseFindManyRecords
hook return value for manual query refreshes - Added view group update logic in
field-metadata.service.ts
to handle SELECT field modifications - Added type guard utility
isSelectFieldMetadataType
for type-safe SELECT field checks
8 file(s) reviewed, 10 comment(s)
Edit PR Review Bot Settings | Greptile
@@ -171,6 +171,8 @@ export const RecordIndexContainer = () => { | |||
return; | |||
} | |||
|
|||
console.log('CURRENT VIEW CHANGE !'); |
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.
style: Remove debug console.log before merging to production
if (!objectMetadataId) { | ||
return; | ||
} |
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: Early return should return null or empty array instead of undefined for consistent return types
return await apolloClient.query({ | ||
query: findManyRecordsQuery, | ||
variables: { | ||
filter: { | ||
objectMetadataId: { | ||
eq: objectMetadataId, | ||
}, | ||
}, | ||
}, | ||
fetchPolicy: 'network-only', | ||
}); |
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.
style: Consider adding error handling for failed queries
@@ -157,6 +162,8 @@ export const SettingsObjectFieldEdit = () => { | |||
}); | |||
} | |||
|
|||
fetchObjectMetadataViews(); | |||
|
|||
navigate(`/settings/objects/${objectSlug}`); | |||
|
|||
refetchRecords(); |
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: refetchRecords is called after navigation, which could lead to a race condition or unnecessary fetch if component unmounts
@@ -157,6 +162,8 @@ export const SettingsObjectFieldEdit = () => { | |||
}); | |||
} | |||
|
|||
fetchObjectMetadataViews(); |
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: fetchObjectMetadataViews result is not awaited, which could lead to stale data if navigation happens too quickly
console.log('updatedFieldMetadata', updatedFieldMetadata); | ||
if ( |
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.
style: Remove console.log statements before merging to production
console.log('updateRelatedViewGroups'); | ||
await this.fieldMetadataRelatedRecordsService.updateRelatedViewGroups( | ||
existingFieldMetadata, | ||
updatedFieldMetadata, | ||
); | ||
} |
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.
style: Consider wrapping updateRelatedViewGroups in try/catch to handle potential errors gracefully
return; | ||
} | ||
|
||
const view = await this.getFieldMetadataView(newFieldMetadata); |
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.
style: Consider wrapping all database operations in a transaction to ensure atomicity
if (!viewGroup) { | ||
throw new Error('View group not found'); | ||
} |
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.
style: Error should include more context like fieldMetadataId and fieldValue to help debugging
return await viewRepository.findOneOrFail({ | ||
where: { | ||
kanbanFieldMetadataId: fieldMetadata.id, | ||
}, | ||
relations: ['viewGroups'], | ||
}); |
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: Add error handling if view is not found for the given kanbanFieldMetadataId
@@ -311,7 +314,7 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit | |||
FieldMetadataEntity, | |||
); | |||
|
|||
const [existingFieldMetadata] = await fieldMetadataRepository.find({ | |||
const existingFieldMetadata = await fieldMetadataRepository.findOne({ |
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.
nope this is not equivalent :p typeORM makes two queries for a findOne and one for find!
No description provided.