-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #623 from liam-hq/browser_back_and_forward_for_hid…
…den_nodes ✨ Add support for hidden nodes in URL state management
- Loading branch information
Showing
6 changed files
with
70 additions
and
51 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,6 @@ | ||
--- | ||
"@liam-hq/erd-core": patch | ||
"@liam-hq/cli": patch | ||
--- | ||
|
||
✨ Add support for hidden nodes in URL state management |
41 changes: 5 additions & 36 deletions
41
frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/useInitialAutoLayout.ts
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
33 changes: 20 additions & 13 deletions
33
frontend/packages/erd-core/src/components/ERDRenderer/ERDContent/usePopStateListener.ts
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './compressionString' | ||
export * from './urlParams' |
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,33 @@ | ||
import type { QueryParam } from '@/schemas/queryParam' | ||
import { type ShowMode, showModeSchema } from '@/schemas/showMode' | ||
import { decompressFromEncodedURIComponent } from '@/utils' | ||
import * as v from 'valibot' | ||
|
||
const getQueryParam = (param: QueryParam): string | undefined => { | ||
const urlParams = new URLSearchParams(window.location.search) | ||
const value = urlParams.get(param) | ||
return value || undefined | ||
} | ||
|
||
export const getActiveTableNameFromUrl = (): string | undefined => { | ||
return getQueryParam('active') | ||
} | ||
|
||
export const getHiddenNodeIdsFromUrl = async (): Promise<string[]> => { | ||
const compressed = getQueryParam('hidden') | ||
const decompressed = compressed | ||
? await decompressFromEncodedURIComponent(compressed).catch(() => undefined) | ||
: undefined | ||
|
||
return decompressed ? decompressed.split(',') : [] | ||
} | ||
|
||
export const getShowModeFromUrl = (): ShowMode => { | ||
const showMode = getQueryParam('showMode') | ||
const result = v.safeParse(showModeSchema, showMode) | ||
if (result.success && result.output) { | ||
return result.output | ||
} | ||
|
||
return 'TABLE_NAME' | ||
} |