From fd89f85cc19af99692fb2809b5041e983a1c8c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Wed, 17 Mar 2021 07:27:57 +0100 Subject: [PATCH] Add "links" collection to index resources, again --- .../fix_index_links_in_ui_extensions.yaml | 2 ++ scm-ui/ui-extensions/src/ExtensionPoint.tsx | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 gradle/changelog/fix_index_links_in_ui_extensions.yaml diff --git a/gradle/changelog/fix_index_links_in_ui_extensions.yaml b/gradle/changelog/fix_index_links_in_ui_extensions.yaml new file mode 100644 index 0000000000..886de235f1 --- /dev/null +++ b/gradle/changelog/fix_index_links_in_ui_extensions.yaml @@ -0,0 +1,2 @@ +- type: fixed + description: Index link collection in ui extensions ([#1594](https://github.com/scm-manager/scm-manager/issues/1588) and [#1587](https://github.com/scm-manager/scm-manager/issues/1594)) diff --git a/scm-ui/ui-extensions/src/ExtensionPoint.tsx b/scm-ui/ui-extensions/src/ExtensionPoint.tsx index f6a1dde719..d7317cfc23 100644 --- a/scm-ui/ui-extensions/src/ExtensionPoint.tsx +++ b/scm-ui/ui-extensions/src/ExtensionPoint.tsx @@ -23,7 +23,7 @@ */ import * as React from "react"; import { Binder } from "./binder"; -import { Component, FC, ReactNode } from "react"; +import { FC, ReactNode } from "react"; import useBinder from "./useBinder"; type PropTransformer = (props: object) => object; @@ -48,17 +48,30 @@ const createInstance = (Component: any, props: object, key?: number) => { const renderAllExtensions = (binder: Binder, name: string, props: object) => { const extensions = binder.getExtensions(name, props); - return <>{extensions.map((cmp, index) => createInstance(cmp, props, index))}; + return <>{extensions.map((cmp, index) => createInstance(cmp, fixLinksInProps(props), index))}; }; const renderSingleExtension = (binder: Binder, name: string, props: object) => { - const cmp = binder.getExtension(name, props); + const cmp = binder.getExtension(name, fixLinksInProps(props)); if (!cmp) { return null; } return createInstance(cmp, props, undefined); }; +// In release 2.14.0, the link collection in the index resource is no longer available under 'links', but +// only under '_links". Therefore plugins expecting the collection in the property without the underscore +// did no longer work properly. This copies the link collection from '_links' to 'links' to fix this issue. +const fixLinksInProps = (props: object) => { + // @ts-ignore + if (props?.indexResources?._links) { + // @ts-ignore + return { ...props, indexResources: { ...props.indexResources, links: props.indexResources._links } }; + } else { + return props; + } +}; + const renderDefault = (children: ReactNode) => { if (children) { return <>{children};