Skip to content

chore(explore): Save Resizable width to localStorage#12593

Merged
ktmud merged 4 commits into
apache:masterfrom
nikolagigic:issue-12428
Jan 25, 2021
Merged

chore(explore): Save Resizable width to localStorage#12593
ktmud merged 4 commits into
apache:masterfrom
nikolagigic:issue-12428

Conversation

@nikolagigic

@nikolagigic nikolagigic commented Jan 19, 2021

Copy link
Copy Markdown
Contributor

SUMMARY

Save Resizable component defaultSize value to localStorage.
closes #12428

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

issue-12428

TEST PLAN

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

@codecov-io

codecov-io commented Jan 19, 2021

Copy link
Copy Markdown

Codecov Report

Merging #12593 (4b8177b) into master (80deb4e) will decrease coverage by 0.12%.
The diff coverage is 41.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12593      +/-   ##
==========================================
- Coverage   66.77%   66.64%   -0.13%     
==========================================
  Files        1021     1021              
  Lines       49967    49979      +12     
  Branches     4890     5022     +132     
==========================================
- Hits        33364    33311      -53     
- Misses      16478    16543      +65     
  Partials      125      125              
Flag Coverage Δ
cypress 50.90% <41.66%> (+0.46%) ⬆️
javascript 60.87% <0.00%> (-0.04%) ⬇️
python 63.70% <ø> (-0.29%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...nd/src/explore/components/ExploreViewContainer.jsx 77.24% <41.66%> (-2.76%) ⬇️
superset/sql_validators/postgres.py 50.00% <0.00%> (-50.00%) ⬇️
superset/databases/commands/create.py 83.67% <0.00%> (-8.17%) ⬇️
superset/databases/commands/update.py 85.71% <0.00%> (-8.17%) ⬇️
superset/db_engine_specs/sqlite.py 90.62% <0.00%> (-6.25%) ⬇️
superset/databases/commands/test_connection.py 84.78% <0.00%> (-4.35%) ⬇️
superset/utils/celery.py 96.42% <0.00%> (-3.58%) ⬇️
superset/models/core.py 85.86% <0.00%> (-2.99%) ⬇️
superset/views/core.py 72.82% <0.00%> (-2.48%) ⬇️
superset/db_engine_specs/mysql.py 89.79% <0.00%> (-2.05%) ⬇️
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 80deb4e...4b8177b. Read the comment docs.

@nikolagigic nikolagigic changed the title Save Resizable width to localStorage chore(explore): Save Resizable width to localStorage Jan 19, 2021
@nikolagigic nikolagigic reopened this Jan 19, 2021
@adam-stasiak

Copy link
Copy Markdown
Contributor

Does this PR affect only Dataset side edition?
I observed that it is saved only this one and very useful would be having width stored also for the middle part of view.
image

@nikolagigic

Copy link
Copy Markdown
Contributor Author

@adam-stasiak I believe this specific ticket was to address only these resizable components: #12411 (comment)

@adam-stasiak

adam-stasiak commented Jan 19, 2021

Copy link
Copy Markdown
Contributor

I see. @junlincc Do you think we should create Issue for having the middle part of view also kept in memory?

@nikolagigic One thing is weird that the value in local storage can be lower than 0. You can reproduce this by draging tab far left (to the right side also but then we have very high number). Maybe it should me limited to real values?
image

@junlincc

Copy link
Copy Markdown
Member

I see. @junlincc Do you think we should create Issue for having the middle part of view also kept in memory?

absolutely, that's the plan. Let's create a separate issue. @pkdotson is working on something related @adam-stasiak
Thank you both for testing and the PR!

@nikolagigic

nikolagigic commented Jan 19, 2021

Copy link
Copy Markdown
Contributor Author

@adam-stasiak I will address this. thanks for noting it

@adam-stasiak

Copy link
Copy Markdown
Contributor

I created issue for this: #12599

@junlincc

Copy link
Copy Markdown
Member

@nikolagigic @adam-stasiak can we take a look at the failing tests? would like to include this PR in v1.0.1

@nikolagigic nikolagigic reopened this Jan 19, 2021
@nikolagigic

Copy link
Copy Markdown
Contributor Author

@junlincc changes have nothing to do with this failing test. Reopened the PR

function onResize(evt) {
const { x } = evt;
if (x > 0) {
localStorage.setItem('explore_sidebar_widths', x);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You might want to check that localStorage is available or catch eventual errors. It might be disabled and will throw an exception in that case.

}

const exploreSidebarWidth =
localStorage.getItem('explore_sidebar_widths') || 320;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as my other comment

<Resizable
defaultSize={{ width: 300 }}
onResize={onResize}
defaultSize={{ width: exploreSidebarWidth }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the dataset pane and the controls pane should have separate widths. You might want to create a pair of small getter/setter functions to handle saving and reading both widths in one key safely.

enum StorageKey  {
   sidebarWidth = "explore_sidebar_widths"
}

function getSidebarWidths() {
  try {
     return localStorage.getItem(StorageKey.siderbarWidth).split(":");
  } catch {}
  return [300, 320]
}

function setSidebarWidths(widths: number[]) {
  try {
    localStorage.setItem(StorageKey.siderbarWidth, widths.join(":"));
  } catch {}
}

@rusackas rusackas Jan 20, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I noticed SQL Lab is using localstorage without a try/catch safety net. This PR makes me wonder if we should make an abstracted helper method, kind of like the "logging" method from @superset-ui/core. These methods, maybe setStoredValue and getStoredValue, could try local storage, then try setting a cookie, and take an optional callback for the catch block. I don't think we need to get that crazy with this PR, but wonder if folks think it's an idea worth ticketing separately.

@ktmud ktmud Jan 20, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I always do that in my other projects. Here's an example file with typing for storage keys & values:

import { User } from 'graphql/job.graphql';

/**
 * Local storage manager
 */
export function safeJsonParse(jsonString: string | null) {
  if (jsonString === null) return null;
  try {
    return JSON.parse(jsonString);
  } catch {
    return null;
  }
}

export type StorageKey = 'persistedStates' | 'hasWelcomed';

export type StorageValues = {
  persistedStates: Record<string, any> | null;
  hasWelcomed: boolean;
};

export const defaultStorageValues = {
  userIdMap: null,
  persistedStates: null,
  hasWelcomed: false,
};

export function entries() {
  Object.values(Storage).forEach(key => {
    return [key, getItem(key)];
  });
}

export function getItem<K extends StorageKey>(key: K): StorageValues[K] | null {
  return safeJsonParse(localStorage.getItem(key)) ?? defaultStorageValues[key];
}

export function setItem(key: StorageKey, value: string | number | object) {
  return localStorage.setItem(key, JSON.stringify(value));
}

@rusackas

Copy link
Copy Markdown
Member

As to @ktmud's point, I agree the two panes should be sizeable independently, and have their values stored independently. You could save them together as he proposes here, or with two getter/setters. Whatever seems cleaner.

The bigger issue to me with the current state of the PR is what's seen in the description GIF. If you make the data source panel wide, the controls panel does not scale (this is fine). However, when you refresh, the controls panel is big, too.

Resizing the controls panel (at the line to the right of it) yeilds unpredictable results as well. It seems like whether the controls panel is small, medium or large, if you widen the controls panel, and then refresh, both columns become full width.

column-resize-issue.mp4

@ktmud

ktmud commented Jan 20, 2021

Copy link
Copy Markdown
Member

Also note folding the dataset pane should be persistent as well. You can probably save a width: -previousWidth when users click on the fold icon.

@pull-request-size pull-request-size Bot added size/M and removed size/S labels Jan 21, 2021
@nikolagigic

Copy link
Copy Markdown
Contributor Author

@ktmud @rusackas can you have a look again pleae? This should do

@junlincc

Copy link
Copy Markdown
Member

@ktmud @zhaoyongjie guys, can you take a look at the changes? if they look ok, can we merge? thank you both~

@ktmud ktmud left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

Thought of persisting the folding state, too, but then realized there is not easy access to change/edit dataset once it's folded.

@ktmud

ktmud commented Jan 23, 2021

Copy link
Copy Markdown
Member

@nikolagigic can you solve the merge conflicts?

@junlincc

Copy link
Copy Markdown
Member

@ktmud hey we resolved the conflicts, mind taking another look? Thanks!

@ktmud ktmud left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@ktmud
ktmud merged commit bcbd8f9 into apache:master Jan 25, 2021
@geido geido added explore:design Related to the Explore UI/UX and removed viz:explore:ux labels Feb 9, 2022
@mistercrunch mistercrunch added 🍒 1.0.1 Cherry-picked to 1.0.1 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.0 First shipped in 1.2.0 labels Mar 12, 2024
qfcwell pushed a commit to qfcwell/superset that referenced this pull request May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels explore:design Related to the Explore UI/UX size/M v1.0.1 🍒 1.0.1 Cherry-picked to 1.0.1 🚢 1.2.0 First shipped in 1.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Explore]set width persistent in data and control panel

8 participants