-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[IndexTable]: optimizes and add more stuff to use-index-resource-state
#11657
base: main
Are you sure you want to change the base?
Conversation
use-index-resource-state
); | ||
} | ||
|
||
function MockClearComponent<T extends {[key: string]: unknown}>({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was unnecessary since we can do everything from the "main" component
const [unselectedResources, setUnselectedResources] = useState< | ||
ReadonlySet<string> | ||
>(new Set()); | ||
const [dirty, setDirty] = useState(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This state is needed for Test drive
.
We need to know if the user made some changes on the table and we display some text based on this condition
const [allResourcesSelected, setAllResourcesSelected] = useState( | ||
initAllResourcesSelected, | ||
); | ||
const [unselectedResources, setUnselectedResources] = useState< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This state is needed for Test drive
.
We need to know all the "stores" that were unselected. In our UX, we pre-check every store and if they become unselected we must update them on the backend.
useEffect(() => { | ||
if (!isEqual(prevPreCheckedResourcesRef.current, preCheckedResources)) { | ||
const filteredResources = dirty | ||
? preCheckedResources.filter( | ||
(resource) => !unselectedResources.has(resource), | ||
) | ||
: preCheckedResources; | ||
|
||
setSelectedResources(new Set(filteredResources)); | ||
prevPreCheckedResourcesRef.current = preCheckedResources; | ||
} | ||
}, [dirty, preCheckedResources, unselectedResources]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sure that preCheckedResources
are synced on pagination.
The current behavior does not re-hydrates on pagination since the state is never updated.
useEffect(() => { | ||
return () => { | ||
setDirty(false); | ||
}; | ||
}, []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure the state is cleaned when the component unmounts
? [...newSelectedResources, selection as string] | ||
: newSelectedResources.filter((id) => id !== selection), | ||
); | ||
if (typeof selection !== 'string') break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It felt odd to use selection as String
when the Types allowed for more.
/snapit |
🫰✨ Thanks @lbenie! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/polaris-icons@0.0.0-snapshot-20240227192044 yarn add @shopify/polaris@0.0.0-snapshot-20240227192044 |
91df46b
to
e082aef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes are looking good to me! Would love to get a Spin URL to test this snapshot with in the PR description before approving
Yes I spun an environment last night but kids prevented me from working haha, will get something up in a few! |
Here's the Product Index Here's Test drive For test drive you need to click on manage so show the modal and see the Index Table. One thing I've noticed is we are still bound to pass a bulk/promoted actions in order to show the |
Also just want to confirm, taking a look at the two URLs there, I can discern no difference from the behaviour that we currently have in production – is that what we expect? |
Yes that was the goal, API is retro-compatible meaning that it shouldn't break any IndexTable using this hook. Also it adds some perf/stuff to the API (dirty/unselected) so it's "opt-in" from a consumer perspective. On a side note, I began investigating last night about this design. Here's my plan to achieve this
Thoughts on ^ I think as a follow-up on web for test drive, I can check if |
/snapit |
🫰✨ Thanks @lbenie! Your snapshot has been published to npm. Test the snapshot by updating your yarn add @shopify/polaris@0.0.0-snapshot-20240228183806 |
839f0a7
to
3e69e73
Compare
3e69e73
to
12e0ddb
Compare
/snapit |
🫰✨ Thanks @lbenie! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/polaris-migrator@0.0.0-snapshot-20240318204532 yarn add @shopify/polaris@0.0.0-snapshot-20240318204532 yarn add @shopify/stylelint-polaris@0.0.0-snapshot-20240318204532 |
2968e00
to
82f1811
Compare
Spin:
What to expect, no changes and regressions on products. For test drive, if you select/unselect it should send a different payload to the API with the proper resources. Here's the diff with web: https://github.com/Shopify/web/compare/main...polaris-index-state Can I get this merged for tomorrow? |
/snapit |
🫰✨ Thanks @lbenie! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/polaris-migrator@0.0.0-snapshot-20240321175357 yarn add @shopify/polaris@0.0.0-snapshot-20240321175357 yarn add @shopify/stylelint-polaris@0.0.0-snapshot-20240321175357 |
/snapit |
🫰✨ Thanks @lbenie! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/polaris-migrator@0.0.0-snapshot-20240321181526 yarn add @shopify/polaris@0.0.0-snapshot-20240321181526 yarn add @shopify/stylelint-polaris@0.0.0-snapshot-20240321181526 |
/snapit |
🫰✨ Thanks @lbenie! Your snapshots have been published to npm. Test the snapshots by updating your yarn add @shopify/polaris-migrator@0.0.0-snapshot-20240325145122 yarn add @shopify/polaris@0.0.0-snapshot-20240325145122 yarn add @shopify/stylelint-polaris@0.0.0-snapshot-20240325145122 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @lbenie 👋🏽 Changes overall look good, but I noticed while tophatting that when SelectionType is Range (e.g., with subheaders, with nested rows) the "All" deselection breaks. 👀
thanks @chloerice I'll investigate |
7fe360a
to
b029416
Compare
Localization quality issues found The following issues may affect the quality of localized translations if they are not addressed:
Please look out for other instances of this issue in your PR and fix them as well if possible. Questions about these messages? Hop in the #help-localization Slack channel. |
WHY are these changes introduced?
Closes: https://github.com/Shopify/admin-comms/issues/1261
WHAT is this pull request doing?
This PR introduces
2
new states for theuse-index-resource-state
hook.Dirty
-- A boolean that reflects the dirty state of the IndexTableUnselectedResources
-- A string array of IDs. This array adds/removes IDs that were previously selected. It's initially set to an empty array.Also, there were some performance improvements by using a
Set
instead of anArray
. In a lot of cases we are concerned with the lookup access and using aSet
gives us a O(1) access time compared to O(N) on the array since we were using operations likefilter
.The hook's API returned object still exposes an array and not a
Set
.How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
🎩 checklist
README.md
with documentation changes