@red-hat-developer-hub/backstage-plugin-global-header 0.0.2 → 0.0.3

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @red-hat-developer-hub/backstage-plugin-global-header
2
2
 
3
+ ## 0.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 4959ebb: add new notificationbanner component
8
+
3
9
  ## 0.0.2
4
10
 
5
11
  ### Patch Changes
@@ -0,0 +1,10 @@
1
+ # please keep this in sync with rhdh/dynamic-plugins.default.yaml
2
+ dynamicPlugins:
3
+ frontend:
4
+ red-hat-developer-hub.backstage-plugin-global-header:
5
+ mountPoints:
6
+ - mountPoint: application/header
7
+ importName: GlobalHeader
8
+ config:
9
+ layout:
10
+ position: above-main-content
@@ -0,0 +1,66 @@
1
+ import React from 'react';
2
+ import Alert from '@mui/material/Alert';
3
+ import { MarkdownContent } from '@backstage/core-components';
4
+
5
+ const NotificationBanner = (props) => {
6
+ const [dismissed, setDismissed] = React.useState(() => {
7
+ if (props.dismiss === "localstorage") {
8
+ try {
9
+ const dismissedString = localStorage.getItem("global-header/NotificationBanner") ?? "{}";
10
+ const dismissedObject = JSON.parse(dismissedString);
11
+ return dismissedObject[props.id ?? props.title] === "dismissed";
12
+ } catch (error) {
13
+ return false;
14
+ }
15
+ } else {
16
+ return false;
17
+ }
18
+ });
19
+ const onClose = React.useMemo(() => {
20
+ if (!props.dismiss || props.dismiss === "none") {
21
+ return void 0;
22
+ } else if (props.dismiss === "session") {
23
+ return () => setDismissed(true);
24
+ } else if (props.dismiss === "localstorage") {
25
+ return () => {
26
+ try {
27
+ const dismissedString = localStorage.getItem("global-header/NotificationBanner") ?? "{}";
28
+ const dismissedObject = JSON.parse(dismissedString);
29
+ dismissedObject[props.id ?? props.title] = "dismissed";
30
+ localStorage.setItem(
31
+ "global-header/NotificationBanner",
32
+ JSON.stringify(dismissedObject)
33
+ );
34
+ } catch (error) {
35
+ }
36
+ setDismissed(true);
37
+ };
38
+ }
39
+ console.warn(
40
+ `Unsupported dismiss option "${props.dismiss}", currently supported "none", "session" or "localstorage"!`
41
+ );
42
+ return void 0;
43
+ }, [props.id, props.title, props.dismiss]);
44
+ if (dismissed || !props.title) {
45
+ return null;
46
+ }
47
+ return /* @__PURE__ */ React.createElement(
48
+ Alert,
49
+ {
50
+ icon: false,
51
+ onClose,
52
+ sx: {
53
+ color: props.textColor ?? "text.primary",
54
+ backgroundColor: props.backgroundColor ?? "background.paper",
55
+ border: props.border,
56
+ borderRadius: props.borderRadius,
57
+ justifyContent: "center",
58
+ textAlign: "center"
59
+ }
60
+ },
61
+ props.markdown ? /* @__PURE__ */ React.createElement(MarkdownContent, { content: props.title, dialect: "gfm" }) : props.title
62
+ );
63
+ };
64
+
65
+ export { NotificationBanner };
66
+ //# sourceMappingURL=NotificationBanner.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NotificationBanner.esm.js","sources":["../../src/components/NotificationBanner.tsx"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 Alert from '@mui/material/Alert';\nimport { MarkdownContent } from '@backstage/core-components';\n\n// export type NotificationBannerColor = 'success' | 'info' | 'warning' | 'error';\n// export type NotificationBannerIcon = 'success' | 'info' | 'warning' | 'error';\n// export type NotificationBannerVariant = 'standard' | 'filled' | 'outlined';\n\n/**\n * @public\n */\nexport type NotificationBannerDismiss = 'none' | 'session' | 'localstorage';\n\n/**\n * @public\n */\nexport interface NotificationBannerProps {\n id?: string;\n title: string;\n markdown?: boolean;\n\n textColor?: string;\n backgroundColor?: string;\n border?: string;\n borderRadius?: string;\n\n // color?: NotificationBannerColor;\n // icon?: NotificationBannerIcon;\n // variant?: NotificationBannerVariant;\n\n dismiss?: NotificationBannerDismiss;\n}\n\nexport const NotificationBanner = (props: NotificationBannerProps) => {\n const [dismissed, setDismissed] = React.useState<boolean>(() => {\n if (props.dismiss === 'localstorage') {\n try {\n const dismissedString =\n localStorage.getItem('global-header/NotificationBanner') ?? '{}';\n const dismissedObject = JSON.parse(dismissedString);\n return dismissedObject[props.id ?? props.title] === 'dismissed';\n } catch (error) {\n // nothing\n return false;\n }\n } else {\n return false;\n }\n });\n\n const onClose = React.useMemo<(() => void) | undefined>(() => {\n if (!props.dismiss || props.dismiss === 'none') {\n return undefined;\n } else if (props.dismiss === 'session') {\n return () => setDismissed(true);\n } else if (props.dismiss === 'localstorage') {\n return () => {\n try {\n const dismissedString =\n localStorage.getItem('global-header/NotificationBanner') ?? '{}';\n const dismissedObject = JSON.parse(dismissedString);\n dismissedObject[props.id ?? props.title] = 'dismissed';\n localStorage.setItem(\n 'global-header/NotificationBanner',\n JSON.stringify(dismissedObject),\n );\n } catch (error) {\n // nothing\n }\n setDismissed(true);\n };\n }\n // eslint-disable-next-line no-console\n console.warn(\n `Unsupported dismiss option \"${props.dismiss}\", currently supported \"none\", \"session\" or \"localstorage\"!`,\n );\n return undefined;\n }, [props.id, props.title, props.dismiss]);\n\n if (dismissed || !props.title) {\n return null;\n }\n\n return (\n <Alert\n // color={props.color}\n // severity={props.icon}\n icon={false}\n // variant={props.variant}\n onClose={onClose}\n sx={{\n color: props.textColor ?? 'text.primary',\n backgroundColor: props.backgroundColor ?? 'background.paper',\n border: props.border,\n borderRadius: props.borderRadius,\n justifyContent: 'center',\n textAlign: 'center',\n }}\n >\n {props.markdown ? (\n <MarkdownContent content={props.title} dialect=\"gfm\" />\n ) : (\n props.title\n )}\n </Alert>\n );\n};\n"],"names":[],"mappings":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,CAAK,UAAU,eAAe;AAAA,WAChC;AAAA,iBACO,KAAO,EAAA;AAAA;AAGhB,QAAA,YAAA,CAAa,IAAI,CAAA;AAAA,OACnB;AAAA;AAGF,IAAQ,OAAA,CAAA,IAAA;AAAA,MACN,CAAA,4BAAA,EAA+B,MAAM,OAAO,CAAA,2DAAA;AAAA,KAC9C;AACA,IAAO,OAAA,KAAA,CAAA;AAAA,GACT,EAAG,CAAC,KAAM,CAAA,EAAA,EAAI,MAAM,KAAO,EAAA,KAAA,CAAM,OAAO,CAAC,CAAA;AAEzC,EAAI,IAAA,SAAA,IAAa,CAAC,KAAA,CAAM,KAAO,EAAA;AAC7B,IAAO,OAAA,IAAA;AAAA;AAGT,EACE,uBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MAGC,IAAM,EAAA,KAAA;AAAA,MAEN,OAAA;AAAA,MACA,EAAI,EAAA;AAAA,QACF,KAAA,EAAO,MAAM,SAAa,IAAA,cAAA;AAAA,QAC1B,eAAA,EAAiB,MAAM,eAAmB,IAAA,kBAAA;AAAA,QAC1C,QAAQ,KAAM,CAAA,MAAA;AAAA,QACd,cAAc,KAAM,CAAA,YAAA;AAAA,QACpB,cAAgB,EAAA,QAAA;AAAA,QAChB,SAAW,EAAA;AAAA;AACb,KAAA;AAAA,IAEC,KAAA,CAAM,QACL,mBAAA,KAAA,CAAA,aAAA,CAAC,eAAgB,EAAA,EAAA,OAAA,EAAS,MAAM,KAAO,EAAA,OAAA,EAAQ,KAAM,EAAA,CAAA,GAErD,KAAM,CAAA;AAAA,GAEV;AAEJ;;;;"}
package/dist/index.d.ts CHANGED
@@ -4,13 +4,39 @@ import * as _backstage_core_plugin_api from '@backstage/core-plugin-api';
4
4
 
5
5
  /**
6
6
  * @public
7
+ */
8
+ type NotificationBannerDismiss = 'none' | 'session' | 'localstorage';
9
+ /**
10
+ * @public
11
+ */
12
+ interface NotificationBannerProps {
13
+ id?: string;
14
+ title: string;
15
+ markdown?: boolean;
16
+ textColor?: string;
17
+ backgroundColor?: string;
18
+ border?: string;
19
+ borderRadius?: string;
20
+ dismiss?: NotificationBannerDismiss;
21
+ }
22
+
23
+ /**
7
24
  * Global Header Plugin
25
+ *
26
+ * @public
8
27
  */
9
28
  declare const globalHeaderPlugin: _backstage_core_plugin_api.BackstagePlugin<{}, {}, {}>;
10
29
  /**
11
- * @public
12
30
  * Global Header
31
+ *
32
+ * @public
13
33
  */
14
34
  declare const GlobalHeader: () => react.JSX.Element;
35
+ /**
36
+ * NotificationBanner
37
+ *
38
+ * @public
39
+ */
40
+ declare const NotificationBanner: (props: NotificationBannerProps) => react.JSX.Element | null;
15
41
 
16
- export { GlobalHeader, globalHeaderPlugin };
42
+ export { GlobalHeader, NotificationBanner, type NotificationBannerDismiss, type NotificationBannerProps, globalHeaderPlugin };
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { unstable_ClassNameGenerator } from '@mui/material/className';
2
- export { GlobalHeader, globalHeaderPlugin } from './plugin.esm.js';
2
+ export { GlobalHeader, NotificationBanner, globalHeaderPlugin } from './plugin.esm.js';
3
3
 
4
4
  unstable_ClassNameGenerator.configure((componentName) => {
5
5
  return componentName.startsWith("v5-") ? componentName : `v5-${componentName}`;
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 */\nimport { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/material/className';\n\nClassNameGenerator.configure(componentName => {\n return componentName.startsWith('v5-')\n ? componentName\n : `v5-${componentName}`;\n});\n\nexport { globalHeaderPlugin, GlobalHeader } from './plugin';\n"],"names":["ClassNameGenerator"],"mappings":";;;AAiBAA,2BAAA,CAAmB,UAAU,CAAiB,aAAA,KAAA;AAC5C,EAAA,OAAO,cAAc,UAAW,CAAA,KAAK,CACjC,GAAA,aAAA,GACA,MAAM,aAAa,CAAA,CAAA;AACzB,CAAC,CAAA"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 */\nimport { unstable_ClassNameGenerator as ClassNameGenerator } from '@mui/material/className';\n\nClassNameGenerator.configure(componentName => {\n return componentName.startsWith('v5-')\n ? componentName\n : `v5-${componentName}`;\n});\n\nexport * from './plugin';\n"],"names":["ClassNameGenerator"],"mappings":";;;AAiBAA,2BAAA,CAAmB,UAAU,CAAiB,aAAA,KAAA;AAC5C,EAAA,OAAO,cAAc,UAAW,CAAA,KAAK,CACjC,GAAA,aAAA,GACA,MAAM,aAAa,CAAA,CAAA;AACzB,CAAC,CAAA"}
@@ -11,6 +11,16 @@ const GlobalHeader = globalHeaderPlugin.provide(
11
11
  }
12
12
  })
13
13
  );
14
+ const NotificationBanner = globalHeaderPlugin.provide(
15
+ createComponentExtension({
16
+ name: "NotificationBanner",
17
+ component: {
18
+ lazy: () => import('./components/NotificationBanner.esm.js').then(
19
+ (m) => m.NotificationBanner
20
+ )
21
+ }
22
+ })
23
+ );
14
24
 
15
- export { GlobalHeader, globalHeaderPlugin };
25
+ export { GlobalHeader, NotificationBanner, globalHeaderPlugin };
16
26
  //# sourceMappingURL=plugin.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.esm.js","sources":["../src/plugin.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 {\n createPlugin,\n createComponentExtension,\n} from '@backstage/core-plugin-api';\n\n/**\n * @public\n * Global Header Plugin\n */\nexport const globalHeaderPlugin = createPlugin({\n id: 'global-header',\n});\n\n/**\n * @public\n * Global Header\n */\nexport const GlobalHeader = globalHeaderPlugin.provide(\n createComponentExtension({\n name: 'GlobalHeader',\n component: {\n lazy: () => import('./components/GlobalHeader').then(m => m.GlobalHeader),\n },\n }),\n);\n"],"names":[],"mappings":";;AAyBO,MAAM,qBAAqB,YAAa,CAAA;AAAA,EAC7C,EAAI,EAAA;AACN,CAAC;AAMM,MAAM,eAAe,kBAAmB,CAAA,OAAA;AAAA,EAC7C,wBAAyB,CAAA;AAAA,IACvB,IAAM,EAAA,cAAA;AAAA,IACN,SAAW,EAAA;AAAA,MACT,IAAA,EAAM,MAAM,OAAO,kCAA2B,EAAE,IAAK,CAAA,CAAA,CAAA,KAAK,EAAE,YAAY;AAAA;AAC1E,GACD;AACH;;;;"}
1
+ {"version":3,"file":"plugin.esm.js","sources":["../src/plugin.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\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 {\n createPlugin,\n createComponentExtension,\n} from '@backstage/core-plugin-api';\n\nexport type {\n NotificationBannerProps,\n NotificationBannerDismiss,\n} from './components/NotificationBanner';\n\n/**\n * Global Header Plugin\n *\n * @public\n */\nexport const globalHeaderPlugin = createPlugin({\n id: 'global-header',\n});\n\n/**\n * Global Header\n *\n * @public\n */\nexport const GlobalHeader = globalHeaderPlugin.provide(\n createComponentExtension({\n name: 'GlobalHeader',\n component: {\n lazy: () => import('./components/GlobalHeader').then(m => m.GlobalHeader),\n },\n }),\n);\n\n/**\n * NotificationBanner\n *\n * @public\n */\nexport const NotificationBanner = globalHeaderPlugin.provide(\n createComponentExtension({\n name: 'NotificationBanner',\n component: {\n lazy: () =>\n import('./components/NotificationBanner').then(\n m => m.NotificationBanner,\n ),\n },\n }),\n);\n"],"names":[],"mappings":";;AA+BO,MAAM,qBAAqB,YAAa,CAAA;AAAA,EAC7C,EAAI,EAAA;AACN,CAAC;AAOM,MAAM,eAAe,kBAAmB,CAAA,OAAA;AAAA,EAC7C,wBAAyB,CAAA;AAAA,IACvB,IAAM,EAAA,cAAA;AAAA,IACN,SAAW,EAAA;AAAA,MACT,IAAA,EAAM,MAAM,OAAO,kCAA2B,EAAE,IAAK,CAAA,CAAA,CAAA,KAAK,EAAE,YAAY;AAAA;AAC1E,GACD;AACH;AAOO,MAAM,qBAAqB,kBAAmB,CAAA,OAAA;AAAA,EACnD,wBAAyB,CAAA;AAAA,IACvB,IAAM,EAAA,oBAAA;AAAA,IACN,SAAW,EAAA;AAAA,MACT,IAAM,EAAA,MACJ,OAAO,wCAAiC,CAAE,CAAA,IAAA;AAAA,QACxC,OAAK,CAAE,CAAA;AAAA;AACT;AACJ,GACD;AACH;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@red-hat-developer-hub/backstage-plugin-global-header",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "main": "dist/index.esm.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -68,6 +68,7 @@
68
68
  "react-router-dom": "^6.0.0"
69
69
  },
70
70
  "files": [
71
+ "app-config.dynamic.yaml",
71
72
  "dist"
72
73
  ],
73
74
  "typesVersions": {