slush-marklogic-node icon indicating copy to clipboard operation
slush-marklogic-node copied to clipboard

Search state not preserved

Open grtjn opened this issue 9 years ago • 25 comments

Moving back and forth between search and create, does not preserve earlier selected facets, and such. Should be possible to preserve that in memory, until someone reloads the browser..

grtjn avatar Sep 03 '15 14:09 grtjn

That's supposed to happen via URL params; I'll investigate.

joemfb avatar Sep 03 '15 14:09 joemfb

I think we voted to replace url params with keeping state in memory, but looks like that got executed only partially..

grtjn avatar Sep 03 '15 18:09 grtjn

Is there a record of that decision somewhere? I feel like deep linking is pretty important.

joemfb avatar Sep 03 '15 18:09 joemfb

On second thought, could be something 'simpler', like an (ng-)href to /search without request params, or in the newer approach a state reference that won't recover the earlier request params, so reading them fails?

grtjn avatar Sep 03 '15 18:09 grtjn

No record, but it was discussed when we also talked about ml-remote-input..

grtjn avatar Sep 03 '15 18:09 grtjn

I feel strongly about deep linking too. Would rather that be on the url than in-memory.

paxtonhare avatar Sep 03 '15 18:09 paxtonhare

Can we get a test case or detailed description of the circumstances under which the search state is not preserved? The current search controller inherits from MLSearchController, which automatically handles URL params. Any cases where the search state is incorrectly lost are bugs in that prototype controller.

joemfb avatar Sep 03 '15 18:09 joemfb

Very simple to reproduce. Generate a vanilla app from the latest slush on github. Deploy and load sample-data. Go to search, and click a facet value. Then go to Create, and back to Search. Selected facet is lost..

grtjn avatar Sep 03 '15 18:09 grtjn

Then go to Create, and back to Search.

Go back how? By clicking a static link to /search? Hitting the back button?

joemfb avatar Sep 03 '15 18:09 joemfb

I rarely use the back button of the browser. I simply clicked 'Search' in the header. Not sure what kind of link that is. I thought a ui-ref..

grtjn avatar Sep 03 '15 18:09 grtjn

To be clear: I am not against displaying those request params. But it should not be necessary to use them to recover search results and filters that you had available in angular a minute ago. All those redundant calls to ML can really kill the performance of the app.

grtjn avatar Sep 03 '15 19:09 grtjn

I see what you're saying @grtjn . Basically execute a search and hit another tab (think mobile apps) and then you go hit search (which routes to /search) and now to have to search again. So basically you want to save the search state if you click away from search.

Honestly not sure if that's the general behavior of most web apps or not..

hunterwilliams avatar Sep 03 '15 19:09 hunterwilliams

It is actually very simple to do. Keep in mind this really is a single page app. Just stick the search context in a singleton (an angular factory for instance), and restore the context whenever the ctrl gets reloaded. Have been doing that in pretty much all my demos, and also demo-cat for instance..

grtjn avatar Sep 03 '15 19:09 grtjn

The question is, should that be the default behavior? I like resetting the context when I navigate to /search, and I think it's how most web apps behave.

joemfb avatar Sep 03 '15 20:09 joemfb

I think users will want to be able to choose. If opening a search result, one likely want to jump back quickly to view another. Coming back from another page could depend on user expectation. So maybe we need two buttons. In my demos i typically used the logo for an oldfashion reload with href="/", and Search link preserving state. I'm open for other suggestions.

I do think it to be easier to flush context than to recover it. Particularly if you have lost the info..

grtjn avatar Sep 03 '15 20:09 grtjn

You could make it that by default it takes you back to the last search. If you press search while on the search page (not viewing a result or anything) it just flushes all of the search params.

hunterwilliams avatar Sep 03 '15 20:09 hunterwilliams

Not sure that is as easy as it sounds, but does sound interesting.

@jenbreese What is your view on when search state should be preserved and when not, and how you think a user would expect to clear search?

grtjn avatar Sep 04 '15 13:09 grtjn

Can we get some more clarification on thoughts for this?

After some research, it seems that the implementation seems to use a service to keep the search when swapping between routes.

My current behavior thought is do as a I said previously. When on a different route and the user presses search (note if they don't actually reload or use a new tab) they will be taken to the previous search. Similar to if they had pressed the browser back button. However if they are on the search route and press search it will reset search.

My reference (also used if we never had persisted route params): http://stackoverflow.com/questions/12940974/maintain-model-of-scope-when-changing-between-views-in-angularjs

hunterwilliams avatar Sep 11 '15 06:09 hunterwilliams

I personally like using the Search button that way.

Just as a reminder, it is also important to not make unnecessary round-trips to MarkLogic. You could recover state by repeating the search from parameters, but that will make a demo app respond very sluggishly..

Regarding the ref: yes, $rootScope is one option, service/factory/provider another. I choose the latter in my demos, because it allows isolating the per-ctrl-models more nicely..

grtjn avatar Sep 11 '15 07:09 grtjn

Can I just move the search context onto service and that way it has the results and all? Also do we show any indication of when search occurred? Just in case you expected a new search and none happened or otherwise.

hunterwilliams avatar Sep 11 '15 11:09 hunterwilliams

Users always love some feedback. A tumbler while it is making a backend call would be nice, but we have been doing without that for pretty long already.

I'd be fine with putting the state/context in a service. I typically had a factory in the same file, for instance for a SearchModel to go with SearchCtrl. Not sure if you were thinking more in terms of a store kind of service. Whatever feels right to you.

Just make sure it won't bite with param setting/parsing from ml-search, we want to keep that to make deep linking easy..

grtjn avatar Sep 11 '15 11:09 grtjn

Is there a demo available now that exhibits the behavior you want?

joemfb avatar Sep 11 '15 14:09 joemfb

Demo-cat gets close I'd say..

grtjn avatar Sep 11 '15 14:09 grtjn

Should this still be a bug? I feel like we've now determined the desired functionality needs to be settled on.

hunterwilliams avatar Sep 21 '15 00:09 hunterwilliams

Hmm, was in doubt, but the current status is that if you go from search to detail, and back to search by clicking the Search on top, search state is not recovered. That only happens if you use the browser back button. I don't think we should depend on that.

Anyhow, the proposed PR was pushed back, so pushing this back as well. We have a solution if people ask. We can think more closely about the issue and possible solutions later..

grtjn avatar Sep 24 '15 19:09 grtjn