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

Reactive form preview #8663

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nklmantey
Copy link

Description

This PR fixes issues with field previews not updating immediately when settings are changed in the Data Model Editor. The changes affect number field types, ensuring that the preview updates in real-time as settings are modified.

Fixed Issues

  • Number field preview not updating when changing decimals or number type (e.g., percentage)

Recording
https://www.loom.com/share/14a30f67266d4a08a694c759ae06b0f3?sid=c0de35ef-9982-438b-b822-94ed106f6891

Copy link

github-actions bot commented Nov 21, 2024

Welcome!

Hello there, congrats on your first PR! We're excited to have you contributing to this project.
By submitting your Pull Request, you acknowledge that you agree with the terms of our Contributor License Agreement.

Generated by 🚫 dangerJS against bf6d366

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

Implemented real-time preview updates for number fields in the Data Model Editor, focusing on immediate UI feedback when modifying field settings.

  • Fixed percentage display in NumberFieldDisplay.tsx by removing incorrect *100 multiplication
  • Added settings watch functionality in SettingsDataModelFieldNumberSettingsFormCard.tsx for live preview updates
  • Modified getFieldPreviewValue.ts to handle number fields with a default preview value of 2000
  • Extended fieldMetadataItem type to include settings property for better type safety
  • Simplified field preview logic by removing redundant utility functions while maintaining core functionality

3 file(s) reviewed, 6 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 14 to 15
const value = type === 'percentage'
? `${formatNumber(numericValue, decimals)}%`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Percentage values should be multiplied by 100 before display. The old code correctly did Number(fieldValue) * 100, but this was removed. This will cause percentages to display incorrectly (e.g. 0.5 will show as '0.5%' instead of '50%').


if (!fieldValue) return <NumberDisplay value={null} />;

const numericValue = Number(fieldValue);
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 handling invalid number conversion (NaN) cases here

fieldMetadataItem={fieldMetadataItem}
fieldMetadataItem={{
...fieldMetadataItem,
settings: settings || fieldMetadataItem.settings,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: The fallback to fieldMetadataItem.settings could be undefined if both settings are undefined, potentially causing runtime issues

fieldMetadataItem: Pick<
FieldMetadataItem,
'type' | 'defaultValue' | 'settings'
>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: 'settings' property is picked but never used in the function

isDefined(fieldTypeConfig.exampleValue)
) {
return fieldTypeConfig.exampleValue;
const fieldTypeConfig = getSettingsFieldTypeConfig(fieldMetadataItem.type as SettingsFieldType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Type assertion to SettingsFieldType may be unsafe if fieldMetadataItem.type is not a valid SettingsFieldType

const fieldTypeConfig = getSettingsFieldTypeConfig(fieldMetadataItem.type as SettingsFieldType);

if (fieldMetadataItem.type === FieldMetadataType.Number) {
return fieldTypeConfig.exampleValue || 2000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Magic number 2000 should be defined as a constant with meaningful name

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.

1 participant