@backstage/plugin-home-react 0.0.0-nightly-20230523021952

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # @backstage/plugin-home-react
2
+
3
+ ## 0.0.0-nightly-20230523021952
4
+
5
+ ### Minor Changes
6
+
7
+ - 41e8037a8a6d: Extract new plugin-home-react package and deprecate createCardExtension in plugin-home
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @backstage/core-components@0.13.1
13
+ - @backstage/core-plugin-api@1.5.1
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Home React
2
+
3
+ A new Library that contains React Components for [home plugin](/plugins/home/README.md) depend on.
@@ -0,0 +1,82 @@
1
+ /// <reference types="react" />
2
+ import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
3
+ import { RJSFSchema } from '@rjsf/utils';
4
+
5
+ /** @public */
6
+ declare const SettingsModal: (props: {
7
+ open: boolean;
8
+ close: Function;
9
+ componentName: string;
10
+ children: JSX.Element;
11
+ }) => JSX.Element;
12
+
13
+ /**
14
+ * @public
15
+ */
16
+ type ComponentRenderer = {
17
+ Renderer?: (props: RendererProps) => JSX.Element;
18
+ };
19
+ /**
20
+ * @public
21
+ */
22
+ type ComponentParts = {
23
+ Content: (props?: any) => JSX.Element;
24
+ Actions?: () => JSX.Element;
25
+ Settings?: () => JSX.Element;
26
+ ContextProvider?: (props: any) => JSX.Element;
27
+ };
28
+ /**
29
+ * @public
30
+ */
31
+ type RendererProps = {
32
+ title: string;
33
+ } & ComponentParts;
34
+ /**
35
+ * @public
36
+ */
37
+ type CardExtensionProps<T> = ComponentRenderer & {
38
+ title?: string;
39
+ } & T;
40
+ /**
41
+ * @public
42
+ */
43
+ type CardLayout = {
44
+ width?: {
45
+ minColumns?: number;
46
+ maxColumns?: number;
47
+ defaultColumns?: number;
48
+ };
49
+ height?: {
50
+ minRows?: number;
51
+ maxRows?: number;
52
+ defaultRows?: number;
53
+ };
54
+ };
55
+ /**
56
+ * @public
57
+ */
58
+ type CardSettings = {
59
+ schema?: RJSFSchema;
60
+ };
61
+ /**
62
+ * @public
63
+ */
64
+ type CardConfig = {
65
+ layout?: CardLayout;
66
+ settings?: CardSettings;
67
+ };
68
+ /**
69
+ * An extension creator to create card based components for the homepage
70
+ *
71
+ * @public
72
+ */
73
+ declare function createCardExtension<T>(options: {
74
+ title: string;
75
+ components: () => Promise<ComponentParts>;
76
+ name?: string;
77
+ description?: string;
78
+ layout?: CardLayout;
79
+ settings?: CardSettings;
80
+ }): _backstage_core_plugin_api.Extension<(props: CardExtensionProps<T>) => JSX.Element>;
81
+
82
+ export { CardConfig, CardExtensionProps, CardLayout, CardSettings, ComponentParts, ComponentRenderer, RendererProps, SettingsModal, createCardExtension };
@@ -0,0 +1,86 @@
1
+ import React, { Suspense } from 'react';
2
+ import { Dialog, DialogTitle, DialogContent, DialogActions, Button, IconButton } from '@material-ui/core';
3
+ import SettingsIcon from '@material-ui/icons/Settings';
4
+ import { InfoCard } from '@backstage/core-components';
5
+ import { createReactExtension, useApp } from '@backstage/core-plugin-api';
6
+
7
+ const SettingsModal = (props) => {
8
+ const { open, close, componentName, children } = props;
9
+ return /* @__PURE__ */ React.createElement(Dialog, { open, onClose: () => close() }, /* @__PURE__ */ React.createElement(DialogTitle, null, "Settings - ", componentName), /* @__PURE__ */ React.createElement(DialogContent, null, children), /* @__PURE__ */ React.createElement(DialogActions, null, /* @__PURE__ */ React.createElement(Button, { onClick: () => close(), color: "primary", variant: "contained" }, "Close")));
10
+ };
11
+
12
+ function createCardExtension(options) {
13
+ const { title, components, name, description, layout, settings } = options;
14
+ const isCustomizable = (settings == null ? void 0 : settings.schema) !== void 0;
15
+ return createReactExtension({
16
+ name,
17
+ data: { title, description, "home.widget.config": { layout, settings } },
18
+ component: {
19
+ lazy: () => components().then((componentParts) => {
20
+ return (props) => {
21
+ return /* @__PURE__ */ React.createElement(
22
+ CardExtension,
23
+ {
24
+ ...props,
25
+ ...componentParts,
26
+ title: props.title || title,
27
+ isCustomizable
28
+ }
29
+ );
30
+ };
31
+ })
32
+ }
33
+ });
34
+ }
35
+ function CardExtension(props) {
36
+ const {
37
+ Renderer,
38
+ Content,
39
+ Settings,
40
+ Actions,
41
+ ContextProvider,
42
+ isCustomizable,
43
+ title,
44
+ ...childProps
45
+ } = props;
46
+ const app = useApp();
47
+ const { Progress } = app.getComponents();
48
+ const [settingsOpen, setSettingsOpen] = React.useState(false);
49
+ if (Renderer) {
50
+ return /* @__PURE__ */ React.createElement(Suspense, { fallback: /* @__PURE__ */ React.createElement(Progress, null) }, /* @__PURE__ */ React.createElement(
51
+ Renderer,
52
+ {
53
+ title,
54
+ ...{
55
+ Content,
56
+ ...Actions ? { Actions } : {},
57
+ ...Settings && !isCustomizable ? { Settings } : {},
58
+ ...ContextProvider ? { ContextProvider } : {},
59
+ ...childProps
60
+ }
61
+ }
62
+ ));
63
+ }
64
+ const cardProps = {
65
+ title,
66
+ ...Settings && !isCustomizable ? {
67
+ action: /* @__PURE__ */ React.createElement(IconButton, { onClick: () => setSettingsOpen(true) }, /* @__PURE__ */ React.createElement(SettingsIcon, null, "Settings"))
68
+ } : {},
69
+ ...Actions ? {
70
+ actions: /* @__PURE__ */ React.createElement(Actions, null)
71
+ } : {}
72
+ };
73
+ const innerContent = /* @__PURE__ */ React.createElement(InfoCard, { ...cardProps }, Settings && !isCustomizable && /* @__PURE__ */ React.createElement(
74
+ SettingsModal,
75
+ {
76
+ open: settingsOpen,
77
+ componentName: title,
78
+ close: () => setSettingsOpen(false)
79
+ },
80
+ /* @__PURE__ */ React.createElement(Settings, null)
81
+ ), /* @__PURE__ */ React.createElement(Content, { ...childProps }));
82
+ return /* @__PURE__ */ React.createElement(Suspense, { fallback: /* @__PURE__ */ React.createElement(Progress, null) }, ContextProvider ? /* @__PURE__ */ React.createElement(ContextProvider, { ...childProps }, innerContent) : innerContent);
83
+ }
84
+
85
+ export { SettingsModal, createCardExtension };
86
+ //# sourceMappingURL=index.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.esm.js","sources":["../src/components/SettingsModal.tsx","../src/extensions.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React from 'react';\nimport {\n Button,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n} from '@material-ui/core';\n\n/** @public */\nexport const SettingsModal = (props: {\n open: boolean;\n close: Function;\n componentName: string;\n children: JSX.Element;\n}) => {\n const { open, close, componentName, children } = props;\n\n return (\n <Dialog open={open} onClose={() => close()}>\n <DialogTitle>Settings - {componentName}</DialogTitle>\n <DialogContent>{children}</DialogContent>\n <DialogActions>\n <Button onClick={() => close()} color=\"primary\" variant=\"contained\">\n Close\n </Button>\n </DialogActions>\n </Dialog>\n );\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { Suspense } from 'react';\nimport { IconButton } from '@material-ui/core';\nimport SettingsIcon from '@material-ui/icons/Settings';\nimport { InfoCard } from '@backstage/core-components';\nimport { SettingsModal } from './components';\nimport { createReactExtension, useApp } from '@backstage/core-plugin-api';\nimport { RJSFSchema } from '@rjsf/utils';\n\n/**\n * @public\n */\nexport type ComponentRenderer = {\n Renderer?: (props: RendererProps) => JSX.Element;\n};\n\n/**\n * @public\n */\nexport type ComponentParts = {\n Content: (props?: any) => JSX.Element;\n Actions?: () => JSX.Element;\n Settings?: () => JSX.Element;\n ContextProvider?: (props: any) => JSX.Element;\n};\n\n/**\n * @public\n */\nexport type RendererProps = { title: string } & ComponentParts;\n\n/**\n * @public\n */\nexport type CardExtensionProps<T> = ComponentRenderer & { title?: string } & T;\n\n/**\n * @public\n */\nexport type CardLayout = {\n width?: { minColumns?: number; maxColumns?: number; defaultColumns?: number };\n height?: { minRows?: number; maxRows?: number; defaultRows?: number };\n};\n\n/**\n * @public\n */\nexport type CardSettings = {\n schema?: RJSFSchema;\n};\n\n/**\n * @public\n */\nexport type CardConfig = {\n layout?: CardLayout;\n settings?: CardSettings;\n};\n\n/**\n * An extension creator to create card based components for the homepage\n *\n * @public\n */\nexport function createCardExtension<T>(options: {\n title: string;\n components: () => Promise<ComponentParts>;\n name?: string;\n description?: string;\n layout?: CardLayout;\n settings?: CardSettings;\n}) {\n const { title, components, name, description, layout, settings } = options;\n // If widget settings schema is defined, we don't want to show the Settings icon or dialog\n const isCustomizable = settings?.schema !== undefined;\n\n return createReactExtension({\n name,\n data: { title, description, 'home.widget.config': { layout, settings } },\n component: {\n lazy: () =>\n components().then(componentParts => {\n return (props: CardExtensionProps<T>) => {\n return (\n <CardExtension\n {...props}\n {...componentParts}\n title={props.title || title}\n isCustomizable={isCustomizable}\n />\n );\n };\n }),\n },\n });\n}\n\ntype CardExtensionComponentProps<T> = CardExtensionProps<T> &\n ComponentParts & {\n title: string;\n isCustomizable?: boolean;\n overrideTitle?: string;\n };\n\nfunction CardExtension<T>(props: CardExtensionComponentProps<T>) {\n const {\n Renderer,\n Content,\n Settings,\n Actions,\n ContextProvider,\n isCustomizable,\n title,\n ...childProps\n } = props;\n const app = useApp();\n const { Progress } = app.getComponents();\n const [settingsOpen, setSettingsOpen] = React.useState(false);\n\n if (Renderer) {\n return (\n <Suspense fallback={<Progress />}>\n <Renderer\n title={title}\n {...{\n Content,\n ...(Actions ? { Actions } : {}),\n ...(Settings && !isCustomizable ? { Settings } : {}),\n ...(ContextProvider ? { ContextProvider } : {}),\n ...childProps,\n }}\n />\n </Suspense>\n );\n }\n\n const cardProps = {\n title: title,\n ...(Settings && !isCustomizable\n ? {\n action: (\n <IconButton onClick={() => setSettingsOpen(true)}>\n <SettingsIcon>Settings</SettingsIcon>\n </IconButton>\n ),\n }\n : {}),\n ...(Actions\n ? {\n actions: <Actions />,\n }\n : {}),\n };\n\n const innerContent = (\n <InfoCard {...cardProps}>\n {Settings && !isCustomizable && (\n <SettingsModal\n open={settingsOpen}\n componentName={title}\n close={() => setSettingsOpen(false)}\n >\n <Settings />\n </SettingsModal>\n )}\n <Content {...childProps} />\n </InfoCard>\n );\n\n return (\n <Suspense fallback={<Progress />}>\n {ContextProvider ? (\n <ContextProvider {...childProps}>{innerContent}</ContextProvider>\n ) : (\n innerContent\n )}\n </Suspense>\n );\n}\n"],"names":[],"mappings":";;;;;;AA0Ba,MAAA,aAAA,GAAgB,CAAC,KAKxB,KAAA;AACJ,EAAA,MAAM,EAAE,IAAA,EAAM,KAAO,EAAA,aAAA,EAAe,UAAa,GAAA,KAAA,CAAA;AAEjD,EAAA,uBACG,KAAA,CAAA,aAAA,CAAA,MAAA,EAAA,EAAO,IAAY,EAAA,OAAA,EAAS,MAAM,KAAA,EACjC,EAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,WAAY,EAAA,IAAA,EAAA,aAAA,EAAY,aAAc,CAAA,sCACtC,aAAe,EAAA,IAAA,EAAA,QAAS,CACzB,kBAAA,KAAA,CAAA,aAAA,CAAC,aACC,EAAA,IAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,MAAO,EAAA,EAAA,OAAA,EAAS,MAAM,KAAA,EAAS,EAAA,KAAA,EAAM,SAAU,EAAA,OAAA,EAAQ,W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KAAK,CAAA;AAAA,KAAA;AAAA,wCAEjC,QAAS,EAAA,IAAA,CAAA;AAAA,GAGd,kBAAA,KAAA,CAAA,aAAA,CAAC,OAAS,EAAA,EAAA,GAAG,YAAY,CAC3B,CAAA,CAAA;AAGF,EAAA,uBACG,KAAA,CAAA,aAAA,CAAA,QAAA,EAAA,EAAS,QAAU,kBAAA,KAAA,CAAA,aAAA,CAAC,QAAS,EAAA,IAAA,CAAA,EAAA,EAC3B,eACC,mBAAA,KAAA,CAAA,aAAA,CAAC,eAAiB,EAAA,EAAA,GAAG,UAAa,EAAA,EAAA,YAAa,IAE/C,YAEJ,CAAA,CAAA;AAEJ;;;;"}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@backstage/plugin-home-react",
3
+ "description": "A Backstage plugin that contains react components helps you build a home page",
4
+ "version": "0.0.0-nightly-20230523021952",
5
+ "main": "dist/index.esm.js",
6
+ "types": "dist/index.d.ts",
7
+ "license": "Apache-2.0",
8
+ "publishConfig": {
9
+ "access": "public",
10
+ "main": "dist/index.esm.js",
11
+ "types": "dist/index.d.ts"
12
+ },
13
+ "backstage": {
14
+ "role": "web-library"
15
+ },
16
+ "homepage": "https://github.com/backstage/backstage/tree/master/plugins/home-react#readme",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/backstage/backstage",
20
+ "directory": "plugins/home-react"
21
+ },
22
+ "keywords": [
23
+ "backstage",
24
+ "homepage"
25
+ ],
26
+ "scripts": {
27
+ "build": "backstage-cli package build",
28
+ "start": "backstage-cli package start",
29
+ "lint": "backstage-cli package lint",
30
+ "test": "backstage-cli package test",
31
+ "prepack": "backstage-cli package prepack",
32
+ "postpack": "backstage-cli package postpack",
33
+ "clean": "backstage-cli package clean"
34
+ },
35
+ "dependencies": {
36
+ "@backstage/core-components": "^0.13.1",
37
+ "@backstage/core-plugin-api": "^1.5.1",
38
+ "@material-ui/core": "^4.12.2",
39
+ "@material-ui/icons": "^4.9.1",
40
+ "@rjsf/utils": "5.6.0"
41
+ },
42
+ "peerDependencies": {
43
+ "react": "^16.13.1 || ^17.0.0",
44
+ "react-dom": "^16.13.1 || ^17.0.0",
45
+ "react-router-dom": "6.0.0-beta.0 || ^6.3.0"
46
+ },
47
+ "devDependencies": {
48
+ "@backstage/cli": "^0.0.0-nightly-20230523021952",
49
+ "@backstage/core-app-api": "^1.8.0",
50
+ "@backstage/dev-utils": "^0.0.0-nightly-20230523021952",
51
+ "@backstage/test-utils": "^1.3.1",
52
+ "@testing-library/dom": "^8.0.0",
53
+ "@testing-library/jest-dom": "^5.10.1",
54
+ "@testing-library/react": "^12.1.3",
55
+ "@testing-library/user-event": "^14.0.0",
56
+ "@types/node": "^16.11.26",
57
+ "@types/react": "^16.13.1 || ^17.0.0",
58
+ "@types/react-grid-layout": "^1.3.2",
59
+ "cross-fetch": "^3.1.5",
60
+ "msw": "^1.0.0"
61
+ },
62
+ "files": [
63
+ "dist"
64
+ ],
65
+ "module": "./dist/index.esm.js"
66
+ }