evidence-dev / evidence

Business intelligence as code: build fast, interactive data visualizations in pure SQL and markdown
https://evidence.dev
MIT License
3.44k stars 167 forks source link

Persistent query show/hide states #260

Closed archiewood closed 2 years ago

archiewood commented 2 years ago

As a user in dev mode, it's frustrating that query results collapse every time the page reloads.

Desired behaviour:

Rough approach

Questions

Next

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
evidence-docs ✅ Ready (Inspect) Visit Preview May 12, 2022 at 6:18PM (UTC)
hughess commented 2 years ago

This is great @archiewood. This approach makes sense to me. The one thing I'm going to check is if it would make sense to move into a centralized store as you mentioned.

In our preprocessor, we have access to all the queries before the page is loaded, so we may be able to create all the local storage variables from there and update them in the individual query viewers.

Good point on what we could do next - I think this approach could include:

hughess commented 2 years ago

@ud3sh, is there any reason we should avoid using local storage as a solution for persistent settings like these?

ud3sh commented 2 years ago

@ud3sh, is there any reason we should avoid using local storage as a solution for persistent settings like these?

The main thing I can think of is it won't be persisted if they chose to choose a different device or browser. Not sure if that's an issue in this case.

archiewood commented 2 years ago

Yeah @ud3sh I think that's probably desirable behaviour.

If you had two people working on / looking at a project they might want to have different stuff collapsed / expanded

ud3sh commented 2 years ago

Yeah @ud3sh I think that's probably desirable behaviour.

If you had two people working on / looking at a project they might want to have different stuff collapsed / expanded

yeah, that makes sense. What I meant more was if Archie looks at the deployed site on his laptop vs his iPad things would look different. Probably not a big issue in practice.

hughess commented 2 years ago

That makes sense.

@archiewood I think your approach here is a good way to manage that toggle. If we need to centralize the logic later we can think about it, but having the logic for the show/hide toggle in the component it's modifying seems like the right fit.

I'd say you're good to go to add this to the query text show/hide as well!

archiewood commented 2 years ago

Updated to include persistent show/hide for:

Question about the master switch: Do we want this to change the state of all queries throughout the project, or just the page the user is on?

Currently this will change throughout the project. Not sure what is best?

mcrascal commented 2 years ago

I like it persisted across pages. "I'm showing my work to someone non-technical, I hide queries, I'm not hitting that button over and over." And vice versa.

hughess commented 2 years ago

I like across pages as well. Should it also do that when the project is deployed?

For the "master" switch, as a user I think I'd want the same behaviour in a deployed site - whereas for the sql query text and results table being open/closed, I think I'd be okay with the page refreshing and the query viewers all being closed again.

archiewood commented 2 years ago

@hughess When you say -"you'd be okay with", do you mean you'd want?

Currently I believe this will not happen. All the queries would remain as they were last on the device.

I can alter the behaviour in deployed (I assume by using the 'dev' flag to determine which mode the site is in)

archiewood commented 2 years ago

@hughess When you say -"you'd be okay with", do you mean you'd want?

Currently I believe this will not happen. All the queries would remain as the last time they were viewed on the device.

I can alter the behaviour in deployed (I assume by using the 'dev' flag to determine which mode the site is in)

mcrascal commented 2 years ago

I think persisting "open" or "closed" between pages makes sense in both dev and prod. Whichever way you go on persistence between pages, I think it'd be preferable for that behaviour to be the same in dev and prod.

hughess commented 2 years ago

I think the way it works now will be great. I don't have a strong opinion about whether the settings should persist in a deployed project, but we can always change the deployed behaviour in the future if we need to.

archiewood commented 2 years ago

Cool - will merge.

archiewood commented 2 years ago

ah so it maybe it should be:

export const showQueries = writable(browser && (localStorage.getItem('showQueries')==='true' || dev ));

since I think dev is 'true'?

want to revert the PR and I'll change this?

I can then add changesets

hughess commented 2 years ago

I'm not sure what the exact logic should be for the localStorage check part of that line, but I think with the most recent proposed line, you could have a situation where:

What situation does the "||" cover?

archiewood commented 2 years ago

Okay I've tested this locally:

export const showQueries = writable(dev && browser && (localStorage.getItem('showQueries')!='false'));

I think this gives the desired behaviour:

CleanShot 2022-05-13 at 10 34 25

hughess commented 2 years ago

That's perfect! 🎉