Skip to content

Commit

Permalink
Add "links" collection to index resources, again
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeuffer committed Mar 17, 2021
1 parent 48e9986 commit fd89f85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions 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))
19 changes: 16 additions & 3 deletions scm-ui/ui-extensions/src/ExtensionPoint.tsx
Expand Up @@ -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;
Expand All @@ -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}</>;
Expand Down

0 comments on commit fd89f85

Please sign in to comment.