Skip to content

Forms : Add attachment fixes #425

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

Merged
merged 35 commits into from
May 16, 2024

Conversation

kaushikrw
Copy link
Collaborator

@kaushikrw kaushikrw commented May 13, 2024

Summary of changes

Issue

  • Fixes an issue where loaded attachments become not-loaded after a new attachment is added.
  • This was due to the fact that the FormAttachmentState list is rebuilt after calling fetchAttachments and hence any previous UI state is lost.
  • The fix is to re-use the FormAttachmentState objects after a call to fetchAttachments.
  • Also fixes a possible bug in Dialog where the state object can be empty.

@kaushikrw kaushikrw self-assigned this May 13, 2024
@kaushikrw kaushikrw changed the base branch from feature-branches/forms to kaushik/forms/view-attachments May 13, 2024 22:28
@kaushikrw kaushikrw marked this pull request as ready for review May 14, 2024 21:42
@kaushikrw kaushikrw requested a review from sorenoid May 14, 2024 21:42
Copy link
Collaborator

@sorenoid sorenoid left a comment

Choose a reason for hiding this comment

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

looks good, just one suggestion to simplify the mapping of FormAttachment to FormAttachmentState.

@@ -80,7 +82,7 @@ internal class AttachmentElementState(
/**
* The attachments associated with the form element.
*/
val attachments = SnapshotStateList<FormAttachmentState>()
var attachments by mutableStateOf(emptyMap<Int, FormAttachmentState>())
Copy link
Collaborator

Choose a reason for hiding this comment

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

FormAttachments are unique, persistent, and implement equals and hashCode. You can key on them, and if that doesn't work there is likely a bug somewhere.

Suggested change
var attachments by mutableStateOf(emptyMap<Int, FormAttachmentState>())
var attachments by mutableStateOf(emptyMap<FormAttachment, FormAttachmentState>())

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe this should work too, but it the adds a FormAttachment dependency to the AttachmentFormElement. This would mean previews cannot be generated with a list of attachments.

@Composable
AttachmentFormElement(
    ..
    attachments: Map<FormAttachment, FormAttachmentState>,
    ..
)

@kaushikrw kaushikrw requested a review from sorenoid May 15, 2024 16:42
Base automatically changed from kaushik/forms/view-attachments to feature-branches/forms May 16, 2024 18:12
@kaushikrw kaushikrw merged commit cb031b9 into feature-branches/forms May 16, 2024
@kaushikrw kaushikrw deleted the kaushik/forms/add-attachment-fixes branch May 16, 2024 21:02
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