From 8c4b5aff409496952989d17b357223761a39c844 Mon Sep 17 00:00:00 2001 From: Evert Pot Date: Thu, 16 Dec 2021 19:18:40 -0500 Subject: [PATCH] Add a flag allowing users to see 'all links' --- README.md | 7 +++++++ src/components/links-table.tsx | 4 +++- src/index.ts | 1 + src/types.ts | 12 ++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b83517..adf62a6 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,13 @@ settings: * `hiddenRels` - List of relationship types that will be hidden from the user by default. This can be used for links that are simply not interesting for a human to see. (default: `['self', 'curies']`. +* `fullBody` - If turned on, full JSON bodies are always rendered. This can also + be turned on during runtime by adding a `?_browser-fullbody` query parameter. +* `allLinks` - By default the Browser will hide links from the 'Links' table + that will be rendered as 'navigation buttons', forms (templated links), or are + considered special (the 'self' link). While this might be a nicer interface + for an average user browsing the hypermedia graph, as a developer you might + just want to see all the links. Example: diff --git a/src/components/links-table.tsx b/src/components/links-table.tsx index 78a33cb..5cd4f2c 100644 --- a/src/components/links-table.tsx +++ b/src/components/links-table.tsx @@ -10,7 +10,9 @@ export function LinksTable(props: PageProps) { for (const link of props.resourceState.links.getAll()) { - if (props.options.hiddenRels.includes(link.rel) || link.rel in props.options.navigationLinks || (link as any).rendered) { + if (!props.options.allLinks && + (props.options.hiddenRels.includes(link.rel) || link.rel in props.options.navigationLinks || (link as any).rendered)) + { continue; } diff --git a/src/index.ts b/src/index.ts index 6e49ee9..b12ec97 100644 --- a/src/index.ts +++ b/src/index.ts @@ -213,6 +213,7 @@ function normalizeOptions(options?: Partial): Options { assetBaseUrl: '/_hal-browser/assets/', serveAssets: true, fullBody: false, + allLinks: false, }; const tmpNavLinks = Object.assign( diff --git a/src/types.ts b/src/types.ts index 8f84d45..0073866 100644 --- a/src/types.ts +++ b/src/types.ts @@ -59,6 +59,18 @@ export type Options = { * query parameter */ fullBody: boolean; + + /** + * By default the Browser will hide links from the 'Links' table that will + * be rendered as 'navigation buttons', forms (templated links), or are + * considered special (the 'self' link). + * + * While this might be a nicer interface for an average user browsing the + * hypermedia graph, as a developer you might just want to see all the links + * + * Turning 'allLinks' on ensures that everything always shows. + */ + allLinks: boolean; }; /**