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

Enable a modal to edit bookmark categories #1799

Merged
merged 3 commits into from
Nov 27, 2024
Merged

Enable a modal to edit bookmark categories #1799

merged 3 commits into from
Nov 27, 2024

Conversation

quimmrc
Copy link
Contributor

@quimmrc quimmrc commented Nov 27, 2024

Issue(s)
#1577

Description
addition of a basic modal to rename bookmark categories

Deployment steps:

  1. new edit bookmark category modal
  2. new method to validate data in BookmarkCategoryForm
  3. new view funcion edit_bookmark_category
  4. in modals.js - changes to handelGenericModalsWithForms, including new parameter dataReloadOnSuccess

@quimmrc quimmrc changed the title Issue1577 Enable a modal to edit bookmark categories Nov 27, 2024
@quimmrc quimmrc merged commit a656ac8 into master Nov 27, 2024
1 check passed
@quimmrc quimmrc deleted the issue1577 branch November 27, 2024 16:39

if BookmarkCategory.objects.filter(user=self.instance.user, name=name).exists():
raise forms.ValidationError("This name already exists for a bookmark category")
Copy link
Member

Choose a reason for hiding this comment

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

This error message could be improved. Maybe "You have already created a bookmark category with that name"


if request.method == "POST":
edit_form = BookmarkCategoryForm(request.POST, instance=category)
print(edit_form.is_bound)
Copy link
Member

Choose a reason for hiding this comment

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

😲

category.save()
return JsonResponse({"success":True})
if not edit_form.is_valid():
print(edit_form.errors.as_json())
Copy link
Member

Choose a reason for hiding this comment

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

😲 😲
I guess this whole if clause can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess you're referring to the second if block that just prints the form errors? I probably forgot to erase that since I think it was for debugging purposes. The first if statement I am quite sure it is required in order to update the category name in the database.

Copy link
Member

Choose a reason for hiding this comment

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

yes, the one for printing only

@@ -195,7 +198,7 @@ const handleGenericModal = (fetchContentUrl, onLoadedCallback, onClosedCallback,
};


const handleGenericModalWithForm = (fetchContentUrl, onLoadedCallback, onClosedCallback, onFormSubmissionSucceeded, onFormSubmissionError, doRequestAsync, showLoadingToast, modalActivationParam) => {
const handleGenericModalWithForm = (fetchContentUrl, onLoadedCallback, onClosedCallback, onFormSubmissionSucceeded, onFormSubmissionError, doRequestAsync, showLoadingToast, modalActivationParam, dataReloadOnSuccess) => {
Copy link
Member

Choose a reason for hiding this comment

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

dataReloadOnSuccess should probably be called triggerPageReloadOnSuccess for making it fully self-explainable

handleGenericModal(modalUrl, undefined, undefined, true, true, modalActivationParam);
}

const handleDefaultModalWithForm = (modalUrl, modalActivationParam) => {
handleGenericModalWithForm(modalUrl, undefined, undefined, (req) => {showToast('Form submitted succesfully!')}, undefined, true, true, modalActivationParam, true);
Copy link
Member

Choose a reason for hiding this comment

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

You are enabling the reload on success by default, and also not providing a way to disable it unless handleGenericModalWithForm is used directly instead of an automatic binding. You should probably add a parameter to handleDefaultModalWithForm (e.g. reloadOnSuccess) which defaults to false, and then in the bind function, see if the element has a specific dataset property to decide if reloadOnSuccess should be true or false (e.g. data-reload-on-success)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure that I fully understood your suggestion because to my understanding you do not need to check anything in the bind function if the parameter is sent properly in handeDefaultModalWithForm. By now my proposal would be to:

  1. set triggerPageReloadSucces to false in handleGenericModalWithForm
  2. add "element" as a parameter in handeDefaultModalWithForm
  3. send element.reloadOnSuccess to handleGenericModalWithForm or false as a default value if it is not specified.
  4. define a data-reload-on-success="true" parameter in the html definition of the toggle

There are other implemented changes you proposed in another branch (as in messageOnSuccess). Anyway, the result seems to work fine and would allow not to reload the page by default (only when specified in the element). Did I understand it correctly?

image

Copy link
Member

Choose a reason for hiding this comment

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

Ok, it might be a good idea to simply pass element (also when binding), you can do it like that

ffont added a commit that referenced this pull request Dec 10, 2024
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