@backstage/plugin-home 0.5.2 → 0.5.3-next.1

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/dist/index.esm.js CHANGED
@@ -1,16 +1,17 @@
1
- import { useElementFilter, useApi, storageApiRef, getComponentData, createReactExtension, useApp, createRouteRef, createPlugin, createRoutableExtension, createComponentExtension } from '@backstage/core-plugin-api';
2
- import React, { useCallback, useMemo, Suspense } from 'react';
3
- import { Dialog, DialogTitle, DialogContent, DialogActions, Button, makeStyles, createStyles, Grid, Tooltip, ListItemAvatar, IconButton as IconButton$1 } from '@material-ui/core';
4
- import SettingsIcon from '@material-ui/icons/Settings';
5
- import { ContentHeader, ErrorBoundary, InfoCard } from '@backstage/core-components';
1
+ import { createRouteRef, createPlugin, createRoutableExtension, createComponentExtension, useElementFilter, useApi, storageApiRef, getComponentData } from '@backstage/core-plugin-api';
2
+ import { createCardExtension as createCardExtension$1, SettingsModal as SettingsModal$1 } from '@backstage/plugin-home-react';
3
+ import React, { useCallback, useMemo } from 'react';
6
4
  import 'react-router-dom';
7
5
  import { WidthProvider, Responsive } from 'react-grid-layout';
8
6
  import 'react-grid-layout/css/styles.css';
9
7
  import 'react-resizable/css/styles.css';
8
+ import { makeStyles, createStyles, Dialog, DialogContent, Grid, Tooltip, DialogTitle, ListItemAvatar, useTheme } from '@material-ui/core';
10
9
  import { compact } from 'lodash';
11
10
  import useObservable from 'react-use/lib/useObservable';
11
+ import { ContentHeader, ErrorBoundary } from '@backstage/core-components';
12
12
  import Typography from '@material-ui/core/Typography';
13
13
  import IconButton from '@material-ui/core/IconButton';
14
+ import SettingsIcon from '@material-ui/icons/Settings';
14
15
  import DeleteIcon from '@material-ui/icons/Delete';
15
16
  import { withTheme } from '@rjsf/core-v5';
16
17
  import validator from '@rjsf/validator-ajv8';
@@ -18,15 +19,119 @@ import List from '@material-ui/core/List';
18
19
  import ListItem from '@material-ui/core/ListItem';
19
20
  import AddIcon from '@material-ui/icons/Add';
20
21
  import ListItemText from '@material-ui/core/ListItemText';
21
- import Button$1 from '@material-ui/core/Button';
22
+ import Button from '@material-ui/core/Button';
22
23
  import SaveIcon from '@material-ui/icons/Save';
23
24
  import EditIcon from '@material-ui/icons/Edit';
25
+ import CancelIcon from '@material-ui/icons/Cancel';
24
26
  import { z } from 'zod';
25
27
 
26
- const SettingsModal = (props) => {
27
- const { open, close, componentName, children } = props;
28
- 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")));
29
- };
28
+ const rootRouteRef = createRouteRef({
29
+ id: "home"
30
+ });
31
+
32
+ const homePlugin = createPlugin({
33
+ id: "home",
34
+ routes: {
35
+ root: rootRouteRef
36
+ }
37
+ });
38
+ const HomepageCompositionRoot = homePlugin.provide(
39
+ createRoutableExtension({
40
+ name: "HomepageCompositionRoot",
41
+ component: () => import('./esm/index-c05eb451.esm.js').then((m) => m.HomepageCompositionRoot),
42
+ mountPoint: rootRouteRef
43
+ })
44
+ );
45
+ const ComponentAccordion = homePlugin.provide(
46
+ createComponentExtension({
47
+ name: "ComponentAccordion",
48
+ component: {
49
+ lazy: () => import('./esm/index-3155d776.esm.js').then((m) => m.ComponentAccordion)
50
+ }
51
+ })
52
+ );
53
+ const ComponentTabs = homePlugin.provide(
54
+ createComponentExtension({
55
+ name: "ComponentTabs",
56
+ component: {
57
+ lazy: () => import('./esm/index-3155d776.esm.js').then((m) => m.ComponentTabs)
58
+ }
59
+ })
60
+ );
61
+ const ComponentTab = homePlugin.provide(
62
+ createComponentExtension({
63
+ name: "ComponentTab",
64
+ component: {
65
+ lazy: () => import('./esm/index-3155d776.esm.js').then((m) => m.ComponentTab)
66
+ }
67
+ })
68
+ );
69
+ const WelcomeTitle = homePlugin.provide(
70
+ createComponentExtension({
71
+ name: "WelcomeTitle",
72
+ component: {
73
+ lazy: () => import('./esm/index-87a51b51.esm.js').then((m) => m.WelcomeTitle)
74
+ }
75
+ })
76
+ );
77
+ const HomePageCompanyLogo = homePlugin.provide(
78
+ createComponentExtension({
79
+ name: "CompanyLogo",
80
+ component: {
81
+ lazy: () => import('./esm/index-476343c1.esm.js').then((m) => m.CompanyLogo)
82
+ }
83
+ })
84
+ );
85
+ const HomePageRandomJoke = homePlugin.provide(
86
+ createCardExtension$1({
87
+ name: "HomePageRandomJoke",
88
+ title: "Random Joke",
89
+ components: () => import('./esm/index-4517c5bc.esm.js'),
90
+ description: "Shows a random joke about optional category",
91
+ layout: {
92
+ height: { minRows: 4 },
93
+ width: { minColumns: 3 }
94
+ },
95
+ settings: {
96
+ schema: {
97
+ title: "Random Joke settings",
98
+ type: "object",
99
+ properties: {
100
+ defaultCategory: {
101
+ title: "Category",
102
+ type: "string",
103
+ enum: ["any", "programming", "dad"],
104
+ default: "any"
105
+ }
106
+ }
107
+ }
108
+ }
109
+ })
110
+ );
111
+ const HomePageToolkit = homePlugin.provide(
112
+ createCardExtension$1({
113
+ name: "HomePageToolkit",
114
+ title: "Toolkit",
115
+ components: () => import('./esm/index-40d9ffac.esm.js')
116
+ })
117
+ );
118
+ const HomePageStarredEntities = homePlugin.provide(
119
+ createCardExtension$1({
120
+ name: "HomePageStarredEntities",
121
+ title: "Your Starred Entities",
122
+ components: () => import('./esm/index-f5981b27.esm.js')
123
+ })
124
+ );
125
+ const HeaderWorldClock = homePlugin.provide(
126
+ createComponentExtension({
127
+ name: "HeaderWorldClock",
128
+ component: {
129
+ lazy: () => import('./esm/index-59fc0760.esm.js').then(
130
+ (m) => m.HeaderWorldClock
131
+ )
132
+ }
133
+ })
134
+ );
30
135
 
31
136
  const Form = withTheme(require("@rjsf/material-ui").Theme);
32
137
  const useStyles$3 = makeStyles(
@@ -150,44 +255,60 @@ const CustomHomepageButtons = (props) => {
150
255
  numWidgets,
151
256
  clearLayout,
152
257
  setAddWidgetDialogOpen,
153
- changeEditMode
258
+ changeEditMode,
259
+ defaultConfigAvailable,
260
+ restoreDefault
154
261
  } = props;
155
262
  const styles = useStyles$2();
156
263
  return /* @__PURE__ */ React.createElement(React.Fragment, null, !editMode && numWidgets > 0 ? /* @__PURE__ */ React.createElement(
157
- Button$1,
264
+ Button,
158
265
  {
159
266
  variant: "contained",
160
267
  color: "primary",
161
268
  onClick: () => changeEditMode(true),
269
+ size: "small",
162
270
  startIcon: /* @__PURE__ */ React.createElement(EditIcon, null)
163
271
  },
164
272
  "Edit"
165
- ) : /* @__PURE__ */ React.createElement(React.Fragment, null, numWidgets > 0 && /* @__PURE__ */ React.createElement(
166
- Button$1,
273
+ ) : /* @__PURE__ */ React.createElement(React.Fragment, null, defaultConfigAvailable && /* @__PURE__ */ React.createElement(
274
+ Button,
275
+ {
276
+ variant: "contained",
277
+ className: styles.contentHeaderBtn,
278
+ onClick: restoreDefault,
279
+ size: "small",
280
+ startIcon: /* @__PURE__ */ React.createElement(CancelIcon, null)
281
+ },
282
+ "Restore defaults"
283
+ ), numWidgets > 0 && /* @__PURE__ */ React.createElement(
284
+ Button,
167
285
  {
168
286
  variant: "contained",
169
287
  color: "secondary",
170
288
  className: styles.contentHeaderBtn,
171
289
  onClick: clearLayout,
290
+ size: "small",
172
291
  startIcon: /* @__PURE__ */ React.createElement(DeleteIcon, null)
173
292
  },
174
- "Clear"
293
+ "Clear all"
175
294
  ), /* @__PURE__ */ React.createElement(
176
- Button$1,
295
+ Button,
177
296
  {
178
297
  variant: "contained",
179
298
  className: styles.contentHeaderBtn,
180
299
  onClick: () => setAddWidgetDialogOpen(true),
300
+ size: "small",
181
301
  startIcon: /* @__PURE__ */ React.createElement(AddIcon, null)
182
302
  },
183
303
  "Add widget"
184
304
  ), numWidgets > 0 && /* @__PURE__ */ React.createElement(
185
- Button$1,
305
+ Button,
186
306
  {
187
307
  className: styles.contentHeaderBtn,
188
308
  variant: "contained",
189
309
  color: "primary",
190
310
  onClick: () => changeEditMode(false),
311
+ size: "small",
191
312
  startIcon: /* @__PURE__ */ React.createElement(SaveIcon, null)
192
313
  },
193
314
  "Save"
@@ -243,10 +364,14 @@ const useStyles$1 = makeStyles(
243
364
  marginLeft: theme.spacing(2)
244
365
  },
245
366
  widgetWrapper: {
246
- "& > *:first-child": {
367
+ overflow: "hidden",
368
+ '& > div[class*="MuiCard-root"]': {
247
369
  width: "100%",
248
370
  height: "100%"
249
371
  },
372
+ '& div[class*="MuiCardContent-root"]': {
373
+ overflow: "auto"
374
+ },
250
375
  "& + .react-grid-placeholder": {
251
376
  backgroundColor: theme.palette.primary.light
252
377
  },
@@ -347,6 +472,7 @@ const availableWidgetsFilter = (elements) => {
347
472
  const CustomHomepageGrid = (props) => {
348
473
  var _a;
349
474
  const styles = useStyles$1();
475
+ const theme = useTheme();
350
476
  const availableWidgets = useElementFilter(
351
477
  props.children,
352
478
  availableWidgetsFilter,
@@ -426,6 +552,9 @@ const CustomHomepageGrid = (props) => {
426
552
  setWidgets(newWidgets);
427
553
  }
428
554
  };
555
+ const handleRestoreDefaultConfig = () => {
556
+ setWidgets(defaultLayout);
557
+ };
429
558
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ContentHeader, { title: "" }, /* @__PURE__ */ React.createElement(
430
559
  CustomHomepageButtons,
431
560
  {
@@ -433,7 +562,9 @@ const CustomHomepageGrid = (props) => {
433
562
  numWidgets: widgets.length,
434
563
  clearLayout,
435
564
  setAddWidgetDialogOpen,
436
- changeEditMode
565
+ changeEditMode,
566
+ defaultConfigAvailable: props.config !== void 0,
567
+ restoreDefault: handleRestoreDefaultConfig
437
568
  }
438
569
  )), /* @__PURE__ */ React.createElement(
439
570
  Dialog,
@@ -447,10 +578,15 @@ const CustomHomepageGrid = (props) => {
447
578
  {
448
579
  className: styles.responsiveGrid,
449
580
  measureBeforeMount: true,
450
- compactType: "horizontal",
581
+ compactType: props.compactType,
582
+ style: props.style,
583
+ allowOverlap: props.allowOverlap,
584
+ preventCollision: props.preventCollision,
451
585
  draggableCancel: ".overlayGridItem,.widgetSettingsDialog",
452
- breakpoints: { lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 },
453
- cols: { lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 },
586
+ containerPadding: props.containerPadding,
587
+ margin: props.containerMargin,
588
+ breakpoints: props.breakpoints ? props.breakpoints : theme.breakpoints.values,
589
+ cols: props.cols ? props.cols : { lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 },
454
590
  rowHeight: (_a = props.rowHeight) != null ? _a : 60,
455
591
  onLayoutChange: handleLayoutChange,
456
592
  layouts: { lg: widgets.map((w) => w.layout) }
@@ -489,187 +625,6 @@ const CustomHomepageGrid = (props) => {
489
625
  ));
490
626
  };
491
627
 
492
- function createCardExtension(options) {
493
- const { title, components, name, description, layout, settings } = options;
494
- const isCustomizable = (settings == null ? void 0 : settings.schema) !== void 0;
495
- return createReactExtension({
496
- name,
497
- data: { title, description, "home.widget.config": { layout, settings } },
498
- component: {
499
- lazy: () => components().then((componentParts) => {
500
- return (props) => {
501
- return /* @__PURE__ */ React.createElement(
502
- CardExtension,
503
- {
504
- ...props,
505
- ...componentParts,
506
- title: props.title || title,
507
- isCustomizable
508
- }
509
- );
510
- };
511
- })
512
- }
513
- });
514
- }
515
- function CardExtension(props) {
516
- const {
517
- Renderer,
518
- Content,
519
- Settings,
520
- Actions,
521
- ContextProvider,
522
- isCustomizable,
523
- title,
524
- ...childProps
525
- } = props;
526
- const app = useApp();
527
- const { Progress } = app.getComponents();
528
- const [settingsOpen, setSettingsOpen] = React.useState(false);
529
- if (Renderer) {
530
- return /* @__PURE__ */ React.createElement(Suspense, { fallback: /* @__PURE__ */ React.createElement(Progress, null) }, /* @__PURE__ */ React.createElement(
531
- Renderer,
532
- {
533
- title,
534
- ...{
535
- Content,
536
- ...Actions ? { Actions } : {},
537
- ...Settings && !isCustomizable ? { Settings } : {},
538
- ...ContextProvider ? { ContextProvider } : {},
539
- ...childProps
540
- }
541
- }
542
- ));
543
- }
544
- const cardProps = {
545
- title,
546
- ...Settings && !isCustomizable ? {
547
- action: /* @__PURE__ */ React.createElement(IconButton$1, { onClick: () => setSettingsOpen(true) }, /* @__PURE__ */ React.createElement(SettingsIcon, null, "Settings"))
548
- } : {},
549
- ...Actions ? {
550
- actions: /* @__PURE__ */ React.createElement(Actions, null)
551
- } : {}
552
- };
553
- const innerContent = /* @__PURE__ */ React.createElement(InfoCard, { ...cardProps }, Settings && !isCustomizable && /* @__PURE__ */ React.createElement(
554
- SettingsModal,
555
- {
556
- open: settingsOpen,
557
- componentName: title,
558
- close: () => setSettingsOpen(false)
559
- },
560
- /* @__PURE__ */ React.createElement(Settings, null)
561
- ), /* @__PURE__ */ React.createElement(Content, { ...childProps }));
562
- return /* @__PURE__ */ React.createElement(Suspense, { fallback: /* @__PURE__ */ React.createElement(Progress, null) }, ContextProvider ? /* @__PURE__ */ React.createElement(ContextProvider, { ...childProps }, innerContent) : innerContent);
563
- }
564
-
565
- const rootRouteRef = createRouteRef({
566
- id: "home"
567
- });
568
-
569
- const homePlugin = createPlugin({
570
- id: "home",
571
- routes: {
572
- root: rootRouteRef
573
- }
574
- });
575
- const HomepageCompositionRoot = homePlugin.provide(
576
- createRoutableExtension({
577
- name: "HomepageCompositionRoot",
578
- component: () => import('./esm/index-966fb783.esm.js').then((m) => m.HomepageCompositionRoot),
579
- mountPoint: rootRouteRef
580
- })
581
- );
582
- const ComponentAccordion = homePlugin.provide(
583
- createComponentExtension({
584
- name: "ComponentAccordion",
585
- component: {
586
- lazy: () => import('./esm/index-287238a7.esm.js').then((m) => m.ComponentAccordion)
587
- }
588
- })
589
- );
590
- const ComponentTabs = homePlugin.provide(
591
- createComponentExtension({
592
- name: "ComponentTabs",
593
- component: {
594
- lazy: () => import('./esm/index-287238a7.esm.js').then((m) => m.ComponentTabs)
595
- }
596
- })
597
- );
598
- const ComponentTab = homePlugin.provide(
599
- createComponentExtension({
600
- name: "ComponentTab",
601
- component: {
602
- lazy: () => import('./esm/index-287238a7.esm.js').then((m) => m.ComponentTab)
603
- }
604
- })
605
- );
606
- const WelcomeTitle = homePlugin.provide(
607
- createComponentExtension({
608
- name: "WelcomeTitle",
609
- component: {
610
- lazy: () => import('./esm/index-87a51b51.esm.js').then((m) => m.WelcomeTitle)
611
- }
612
- })
613
- );
614
- const HomePageCompanyLogo = homePlugin.provide(
615
- createComponentExtension({
616
- name: "CompanyLogo",
617
- component: {
618
- lazy: () => import('./esm/index-476343c1.esm.js').then((m) => m.CompanyLogo)
619
- }
620
- })
621
- );
622
- const HomePageRandomJoke = homePlugin.provide(
623
- createCardExtension({
624
- name: "HomePageRandomJoke",
625
- title: "Random Joke",
626
- components: () => import('./esm/index-4517c5bc.esm.js'),
627
- description: "Shows a random joke about optional category",
628
- layout: {
629
- height: { minRows: 4 },
630
- width: { minColumns: 3 }
631
- },
632
- settings: {
633
- schema: {
634
- title: "Random Joke settings",
635
- type: "object",
636
- properties: {
637
- defaultCategory: {
638
- title: "Category",
639
- type: "string",
640
- enum: ["any", "programming", "dad"],
641
- default: "any"
642
- }
643
- }
644
- }
645
- }
646
- })
647
- );
648
- const HomePageToolkit = homePlugin.provide(
649
- createCardExtension({
650
- name: "HomePageToolkit",
651
- title: "Toolkit",
652
- components: () => import('./esm/index-40d9ffac.esm.js')
653
- })
654
- );
655
- const HomePageStarredEntities = homePlugin.provide(
656
- createCardExtension({
657
- name: "HomePageStarredEntities",
658
- title: "Your Starred Entities",
659
- components: () => import('./esm/index-f5981b27.esm.js')
660
- })
661
- );
662
- const HeaderWorldClock = homePlugin.provide(
663
- createComponentExtension({
664
- name: "HeaderWorldClock",
665
- component: {
666
- lazy: () => import('./esm/index-59fc0760.esm.js').then(
667
- (m) => m.HeaderWorldClock
668
- )
669
- }
670
- })
671
- );
672
-
673
628
  const TemplateBackstageLogo = (props) => {
674
629
  return /* @__PURE__ */ React.createElement(
675
630
  "svg",
@@ -716,5 +671,8 @@ const TemplateBackstageLogoIcon = () => {
716
671
  );
717
672
  };
718
673
 
674
+ const createCardExtension = createCardExtension$1;
675
+ const SettingsModal = SettingsModal$1;
676
+
719
677
  export { ComponentAccordion, ComponentTab, ComponentTabs, CustomHomepageGrid, HeaderWorldClock, HomePageCompanyLogo, HomePageRandomJoke, HomePageStarredEntities, HomePageToolkit, HomepageCompositionRoot, SettingsModal, TemplateBackstageLogo, TemplateBackstageLogoIcon, WelcomeTitle, createCardExtension, homePlugin };
720
678
  //# sourceMappingURL=index.esm.js.map