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 cancel button #40

Merged
merged 11 commits into from Jan 23, 2019
Merged

Fix cancel button #40

merged 11 commits into from Jan 23, 2019

Conversation

imobachgs
Copy link
Contributor

This PR fixes the behaviour of the Cancel button. However, we might need to rebase this branch
once that #39 is merged.

@coveralls
Copy link

coveralls commented Jan 22, 2019

Coverage Status

Coverage increased (+0.1%) to 94.749% when pulling c455652 on fix-cancel-button into 7c679c4 on salt-forms-support-ng.

@imobachgs imobachgs changed the base branch from hash-collections to salt-forms-support-ng January 23, 2019 10:07
@imobachgs imobachgs changed the title WIP: fix cancel button Fix cancel button Jan 23, 2019
@form_data_instances.pop unless @form_data_instances.size <= 1
end

# Clears the last backup if it exists
Copy link
Contributor

@teclator teclator Jan 23, 2019

Choose a reason for hiding this comment

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

It removes the previous backup if I get correctly, isn't it?


# Clears the last backup if it exists
def remove_backup
@form_data_instances.delete_at(-2) if @form_data_instances.size > 1
Copy link
Member

Choose a reason for hiding this comment

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

delete_at(-2) ? This looks very strange. Before this PR, FormControllerState is just a stack of triplets, very simple. Now I don't understand it anymore.

What are the invariants of its state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

form_data_instances keep a set of "snapshots" of the form state. Everytime you open a nested form, the current form values are saved in the stack. So if you decide to cancel the form, we just rollback to the previous version (removing the top of the stack).

Thinking about it, it might be easier to understand if we track the current value in a different instance variable (like @form_data) and keep the backups in a separate one (@form_data_backups).

# This class is responsible for reading the form data from its definition and a data pillar.
#
# The format used in the pillar is slightly different from the internal representation of this
# module, so this class takes care of the conversion. However, the initial intentation is to not
Copy link
Member

Choose a reason for hiding this comment

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

Huh, do we really have a representation of the data that is different from the pillar contents?
If so, this comment should explain the difference.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, like, we use FormData which has a #to_h method for the pillar, is that it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I will. Basically, keeping our own organization (especially when it comes to collections) makes the implementation easier. For instance, the collection widget does not need to know anything about the pillars format (hash and array based collections). Additionally, I felt that the pillar organization was leaking to our UI (and I think that's wrong).

@imobachgs imobachgs merged commit 224d061 into salt-forms-support-ng Jan 23, 2019
@imobachgs imobachgs mentioned this pull request Jan 25, 2019
9 tasks
@imobachgs imobachgs deleted the fix-cancel-button branch January 29, 2019 12:43
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.

None yet

4 participants