Skip to content
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

Merged
merged 6 commits into from
Nov 6, 2024

Conversation

magrinj
Copy link
Member

@magrinj magrinj commented Nov 5, 2024

No description provided.

@magrinj magrinj marked this pull request as ready for review November 5, 2024 16:16
Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 to useFindManyRecords 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 !');
Copy link
Contributor

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

Comment on lines 31 to 33
if (!objectMetadataId) {
return;
}
Copy link
Contributor

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

Comment on lines 35 to 45
return await apolloClient.query({
query: findManyRecordsQuery,
variables: {
filter: {
objectMetadataId: {
eq: objectMetadataId,
},
},
},
fetchPolicy: 'network-only',
});
Copy link
Contributor

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();
Copy link
Contributor

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();
Copy link
Contributor

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

Comment on lines 424 to 425
console.log('updatedFieldMetadata', updatedFieldMetadata);
if (
Copy link
Contributor

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

Comment on lines 429 to 434
console.log('updateRelatedViewGroups');
await this.fieldMetadataRelatedRecordsService.updateRelatedViewGroups(
existingFieldMetadata,
updatedFieldMetadata,
);
}
Copy link
Contributor

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);
Copy link
Contributor

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

Comment on lines 79 to 81
if (!viewGroup) {
throw new Error('View group not found');
}
Copy link
Contributor

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

Comment on lines 151 to 156
return await viewRepository.findOneOrFail({
where: {
kanbanFieldMetadataId: fieldMetadata.id,
},
relations: ['viewGroups'],
});
Copy link
Contributor

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({
Copy link
Member

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!

@charlesBochet charlesBochet merged commit ac7d740 into main Nov 6, 2024
17 of 18 checks passed
@charlesBochet charlesBochet deleted the fix/record-group branch November 6, 2024 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants