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

chore: Refactor localstorage into typesafe version #17832

Merged
merged 1 commit into from Dec 20, 2021

Conversation

etr2460
Copy link
Member

@etr2460 etr2460 commented Dec 20, 2021

SUMMARY

Refactors localstorage usage into a typesafe version, and unifies the key constants into an enum so that we can ensure they aren't reused by accident

Precursor to #17708

TESTING INSTRUCTIONS

CI, new unit tests for my changes, test various features in testenv

  • Confirm that welcome page open sections persist on page reload
  • Confirm that explore view sidebar width persists on page reload

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

to: @ktmud @rusackas @graceguo-supercat @pkdotson

@apache apache deleted a comment from github-actions bot Dec 20, 2021
@apache apache deleted a comment from github-actions bot Dec 20, 2021
@apache apache deleted a comment from github-actions bot Dec 20, 2021
@apache apache deleted a comment from github-actions bot Dec 20, 2021
@etr2460
Copy link
Member Author

etr2460 commented Dec 20, 2021

/testenv up

@github-actions
Copy link
Contributor

@etr2460 Ephemeral environment spinning up at http://54.201.109.147:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@codecov
Copy link

codecov bot commented Dec 20, 2021

Codecov Report

Merging #17832 (ce48f9a) into master (0a33fcf) will decrease coverage by 0.01%.
The diff coverage is 56.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17832      +/-   ##
==========================================
- Coverage   67.17%   67.16%   -0.02%     
==========================================
  Files        1609     1608       -1     
  Lines       64797    64798       +1     
  Branches     6855     6851       -4     
==========================================
- Hits        43530    43520      -10     
- Misses      19411    19419       +8     
- Partials     1856     1859       +3     
Flag Coverage Δ
javascript 53.87% <56.36%> (-0.04%) ⬇️

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

Impacted Files Coverage Δ
...ugin-chart-pivot-table/src/plugin/controlPanel.tsx 12.50% <ø> (ø)
...rontend/src/dashboard/containers/DashboardPage.tsx 26.88% <0.00%> (ø)
...ntend/src/explore/components/ExploreChartPanel.jsx 14.66% <0.00%> (-1.13%) ⬇️
...nd/src/explore/components/ExploreViewContainer.jsx 2.32% <0.00%> (+0.01%) ⬆️
superset-frontend/src/explore/constants.ts 92.00% <ø> (+1.61%) ⬆️
...perset-frontend/src/views/CRUD/chart/ChartList.tsx 62.14% <25.00%> (ø)
...rontend/src/views/CRUD/dashboard/DashboardList.tsx 63.35% <50.00%> (ø)
...perset-frontend/src/views/CRUD/welcome/Welcome.tsx 76.06% <57.14%> (-2.75%) ⬇️
...-frontend/src/views/CRUD/welcome/ActivityTable.tsx 54.66% <60.00%> (-9.81%) ⬇️
...set-frontend/src/views/CRUD/welcome/ChartTable.tsx 69.86% <60.00%> (-0.41%) ⬇️
... and 6 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 0a33fcf...ce48f9a. Read the comment docs.

Copy link
Member

@ktmud ktmud left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning things up! This definitely looks cleaner. Just have one little non-blocking suggestion for your consideration.

@@ -164,7 +164,8 @@ function ChartList(props: ChartListProps) {
const [preparingExport, setPreparingExport] = useState<boolean>(false);

const { userId } = props.user;
const userKey = getFromLocalStorage(userId?.toString(), null);
// TODO: Fix usage of localStorage keying on the user id
const userKey = dangerouslyGetItemDoNotUse(userId?.toString(), null);
Copy link
Member

Choose a reason for hiding this comment

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

I think userKey may actually be userProfile or userSettings. We can also do type coercing to avoid calling the private dangerous functions:

const userProfile = getItem(String(userId || '') as "FIXME_user_profile_by_user_id", null);

type LocalStorageValues {
  // it's a bad practice to use the raw user id as storage keys
  // we should at least prefix them.
  FIXME_user_profile_by_user_id: {
    thumbnails: boolean;
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

i'll update the variable name. personally i prefer using the dangerous function here though, since it seems a bit easier to parse than the type assertion (that's clearly not true)

@etr2460 etr2460 force-pushed the erik-ritter--localstorage-refactor branch from 4caa3b7 to ce48f9a Compare December 20, 2021 21:13
@etr2460 etr2460 merged commit 6edc183 into apache:master Dec 20, 2021
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

shcoderAlex pushed a commit to casual-precision/superset that referenced this pull request Feb 7, 2022
bwang221 pushed a commit to casual-precision/superset that referenced this pull request Feb 10, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.0 labels Mar 13, 2024
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 size/L 🚢 1.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants