-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dashboard): Use derived state in DataTable (#11487)
**What** - Uses derived state in DataTable, to prevent the state in the URL and component from going out of sync. - Introduces a way for RouteModals to restore URL params on close. Resolves CMRC-936
- Loading branch information
1 parent
51b0af1
commit c28ae57
Showing
7 changed files
with
103 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@medusajs/dashboard": patch | ||
--- | ||
|
||
fix(dashboard): Use derrived state in DataTable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/admin/dashboard/src/components/modals/hooks/use-state-aware-to.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useMemo } from "react" | ||
import { Path, useLocation } from "react-router-dom" | ||
|
||
/** | ||
* Checks if the current location has a restore_params property. | ||
* If it does, it will return a new path with the params added to it. | ||
* Otherwise, it will return the previous path. | ||
* | ||
* This is useful if the modal needs to return to the original path, with | ||
* the params that were present when the modal was opened. | ||
*/ | ||
export const useStateAwareTo = (prev: string | Partial<Path>) => { | ||
const location = useLocation() | ||
|
||
const to = useMemo(() => { | ||
const params = location.state?.restore_params | ||
|
||
if (!params) { | ||
return prev | ||
} | ||
|
||
return `${prev}?${params.toString()}` | ||
}, [location.state, prev]) | ||
|
||
return to | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/admin/dashboard/src/components/modals/route-modal-provider/route-provider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters