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(SavedSearch): Force user to validate criteria before saved search #18385

Draft
wants to merge 3 commits into
base: 10.0/bugfixes
Choose a base branch
from

Conversation

stonebuzz
Copy link
Contributor

@stonebuzz stonebuzz commented Nov 26, 2024

Checklist before requesting a review

Please delete options that are not relevant.

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

Description

  • It fixes !35211

Perhaps an alternative to #18376.

After further review, I believe the issue here is that the saved search system expects the user to execute a search based on their criteria at least once (to include them in the URL).

See GenericView.js L102

const bs_modal = new bootstrap.Modal(modal.get(0), {show: false});
modal.on('show.bs.modal', () => {
    const params = JSON.parse(modal.attr('data-params'));
    params['url'] = window.location.pathname + window.location.search;
    modal.find('.modal-body').load(CFG_GLPI.root_doc + '/ajax/savedsearch.php', params);
});

If the user does not execute a search at least once, the default search for the item type is used and saved in the database.

Since I don’t see how to extract the search

image

convert it into a URL as shown here

image

and then pass it to the modal (from GenericView.js L102)

I simply propose checking whether window.location.search is not empty or does not correspond to a search reset (reset=reset).

Screenshots (if appropriate):

@stonebuzz
Copy link
Contributor Author

Awaiting user feedback
!35211

});
bs_modal.show();

if (window.location.search.includes('reset=reset') || window.location.search.trim() === '') {
Copy link
Member

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 this condition will match all problematic cases.

A solution could be to rebuild the expected parameters based on the current criteria form values instead of relying on window.location.search. It is probably simple to do as this computation is probably already done on the JS side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the user does not check the criteria (press the search button before save), window.location.search is empty.

I can't see how to rebuild the expected parameters based on the current values in the criteria form.

Copy link
Contributor

@cconard96 cconard96 Dec 6, 2024

Choose a reason for hiding this comment

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

Building the query params for the search is already handled in the refreshResults function of Table.js.

However, this isn't intuitive UX. When you create a bookmark in a browser for example, it is for the page you are on, not the page you are typing in the address bar but haven't navigated to yet. In Firefox, they even hide the bookmark button when you are typing in the address bar.

Simply disabling the button to create a saved search when there are unsaved changes, and having a helpful tooltip on it, should be sufficient. Then when the results refresh, the button gets re-enabled.

@stonebuzz
Copy link
Contributor Author

image

@stonebuzz stonebuzz marked this pull request as draft December 13, 2024 16:09
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.

3 participants