@backstage/core-components 0.14.6 → 0.14.7
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 +32 -4
- package/alpha/package.json +1 -1
- package/dist/alpha.esm.js +1 -2
- package/dist/alpha.esm.js.map +1 -1
- package/dist/components/AlertDisplay/AlertDisplay.esm.js +67 -0
- package/dist/components/AlertDisplay/AlertDisplay.esm.js.map +1 -0
- package/dist/components/AutoLogout/AutoLogout.esm.js +169 -0
- package/dist/components/AutoLogout/AutoLogout.esm.js.map +1 -0
- package/dist/components/AutoLogout/StillTherePrompt.esm.js +51 -0
- package/dist/components/AutoLogout/StillTherePrompt.esm.js.map +1 -0
- package/dist/components/AutoLogout/disconnectedUsers.esm.js +38 -0
- package/dist/components/AutoLogout/disconnectedUsers.esm.js.map +1 -0
- package/dist/components/AutoLogout/timestampStore.esm.js +18 -0
- package/dist/components/AutoLogout/timestampStore.esm.js.map +1 -0
- package/dist/components/Avatar/Avatar.esm.js +63 -0
- package/dist/components/Avatar/Avatar.esm.js.map +1 -0
- package/dist/components/Avatar/utils.esm.js +22 -0
- package/dist/components/Avatar/utils.esm.js.map +1 -0
- package/dist/components/CodeSnippet/CodeSnippet.esm.js +41 -0
- package/dist/components/CodeSnippet/CodeSnippet.esm.js.map +1 -0
- package/dist/components/CopyTextButton/CopyTextButton.esm.js +46 -0
- package/dist/components/CopyTextButton/CopyTextButton.esm.js.map +1 -0
- package/dist/components/CreateButton/CreateButton.esm.js +30 -0
- package/dist/components/CreateButton/CreateButton.esm.js.map +1 -0
- package/dist/components/DependencyGraph/DefaultLabel.esm.js +18 -0
- package/dist/components/DependencyGraph/DefaultLabel.esm.js.map +1 -0
- package/dist/components/DependencyGraph/DefaultNode.esm.js +58 -0
- package/dist/components/DependencyGraph/DefaultNode.esm.js.map +1 -0
- package/dist/components/DependencyGraph/DependencyGraph.esm.js +267 -0
- package/dist/components/DependencyGraph/DependencyGraph.esm.js.map +1 -0
- package/dist/components/DependencyGraph/Edge.esm.js +81 -0
- package/dist/components/DependencyGraph/Edge.esm.js.map +1 -0
- package/dist/components/DependencyGraph/Node.esm.js +51 -0
- package/dist/components/DependencyGraph/Node.esm.js.map +1 -0
- package/dist/components/DependencyGraph/constants.esm.js +7 -0
- package/dist/components/DependencyGraph/constants.esm.js.map +1 -0
- package/dist/components/DependencyGraph/types.esm.js +28 -0
- package/dist/components/DependencyGraph/types.esm.js.map +1 -0
- package/dist/components/DismissableBanner/DismissableBanner.esm.js +119 -0
- package/dist/components/DismissableBanner/DismissableBanner.esm.js.map +1 -0
- package/dist/components/EmptyState/EmptyState.esm.js +41 -0
- package/dist/components/EmptyState/EmptyState.esm.js.map +1 -0
- package/dist/components/EmptyState/EmptyStateImage.esm.js +59 -0
- package/dist/components/EmptyState/EmptyStateImage.esm.js.map +1 -0
- package/dist/components/EmptyState/MissingAnnotationEmptyState.esm.js +76 -0
- package/dist/components/EmptyState/MissingAnnotationEmptyState.esm.js.map +1 -0
- package/dist/components/ErrorPanel/ErrorPanel.esm.js +76 -0
- package/dist/components/ErrorPanel/ErrorPanel.esm.js.map +1 -0
- package/dist/components/FeatureDiscovery/FeatureCalloutCircular.esm.js +139 -0
- package/dist/components/FeatureDiscovery/FeatureCalloutCircular.esm.js.map +1 -0
- package/dist/components/FeatureDiscovery/lib/usePortal.esm.js +43 -0
- package/dist/components/FeatureDiscovery/lib/usePortal.esm.js.map +1 -0
- package/dist/components/FeatureDiscovery/lib/useShowCallout.esm.js +31 -0
- package/dist/components/FeatureDiscovery/lib/useShowCallout.esm.js.map +1 -0
- package/dist/components/HeaderIconLinkRow/HeaderIconLinkRow.esm.js +24 -0
- package/dist/components/HeaderIconLinkRow/HeaderIconLinkRow.esm.js.map +1 -0
- package/dist/components/HeaderIconLinkRow/IconLinkVertical.esm.js +70 -0
- package/dist/components/HeaderIconLinkRow/IconLinkVertical.esm.js.map +1 -0
- package/dist/components/HorizontalScrollGrid/HorizontalScrollGrid.esm.js +197 -0
- package/dist/components/HorizontalScrollGrid/HorizontalScrollGrid.esm.js.map +1 -0
- package/dist/components/Lifecycle/Lifecycle.esm.js +37 -0
- package/dist/components/Lifecycle/Lifecycle.esm.js.map +1 -0
- package/dist/components/Link/Link.esm.js +141 -0
- package/dist/components/Link/Link.esm.js.map +1 -0
- package/dist/components/LinkButton/LinkButton.esm.js +12 -0
- package/dist/components/LinkButton/LinkButton.esm.js.map +1 -0
- package/dist/components/LogViewer/AnsiProcessor.esm.js +145 -0
- package/dist/components/LogViewer/AnsiProcessor.esm.js.map +1 -0
- package/dist/components/LogViewer/LogLine.esm.js +139 -0
- package/dist/components/LogViewer/LogLine.esm.js.map +1 -0
- package/dist/components/LogViewer/LogViewer.esm.js +13 -0
- package/dist/components/LogViewer/LogViewer.esm.js.map +1 -0
- package/dist/components/LogViewer/LogViewerControls.esm.js +36 -0
- package/dist/components/LogViewer/LogViewerControls.esm.js.map +1 -0
- package/dist/components/LogViewer/RealLogViewer.esm.js +97 -0
- package/dist/components/LogViewer/RealLogViewer.esm.js.map +1 -0
- package/dist/components/LogViewer/styles.esm.js +119 -0
- package/dist/components/LogViewer/styles.esm.js.map +1 -0
- package/dist/components/LogViewer/useLogViewerSearch.esm.js +74 -0
- package/dist/components/LogViewer/useLogViewerSearch.esm.js.map +1 -0
- package/dist/components/LogViewer/useLogViewerSelection.esm.js +48 -0
- package/dist/components/LogViewer/useLogViewerSelection.esm.js.map +1 -0
- package/dist/components/MarkdownContent/MarkdownContent.esm.js +95 -0
- package/dist/components/MarkdownContent/MarkdownContent.esm.js.map +1 -0
- package/dist/components/OAuthRequestDialog/LoginRequestListItem.esm.js +45 -0
- package/dist/components/OAuthRequestDialog/LoginRequestListItem.esm.js.map +1 -0
- package/dist/components/OAuthRequestDialog/OAuthRequestDialog.esm.js +90 -0
- package/dist/components/OAuthRequestDialog/OAuthRequestDialog.esm.js.map +1 -0
- package/dist/components/OverflowTooltip/OverflowTooltip.esm.js +35 -0
- package/dist/components/OverflowTooltip/OverflowTooltip.esm.js.map +1 -0
- package/dist/components/Progress/Progress.esm.js +20 -0
- package/dist/components/Progress/Progress.esm.js.map +1 -0
- package/dist/components/ProgressBars/Gauge.esm.js +116 -0
- package/dist/components/ProgressBars/Gauge.esm.js.map +1 -0
- package/dist/components/ProgressBars/GaugeCard.esm.js +62 -0
- package/dist/components/ProgressBars/GaugeCard.esm.js.map +1 -0
- package/dist/components/ProgressBars/LinearGauge.esm.js +37 -0
- package/dist/components/ProgressBars/LinearGauge.esm.js.map +1 -0
- package/dist/components/ResponseErrorPanel/ResponseErrorPanel.esm.js +71 -0
- package/dist/components/ResponseErrorPanel/ResponseErrorPanel.esm.js.map +1 -0
- package/dist/components/Select/Select.esm.js +189 -0
- package/dist/components/Select/Select.esm.js.map +1 -0
- package/dist/components/Select/static/ClosedDropdown.esm.js +36 -0
- package/dist/components/Select/static/ClosedDropdown.esm.js.map +1 -0
- package/dist/components/Select/static/OpenedDropdown.esm.js +36 -0
- package/dist/components/Select/static/OpenedDropdown.esm.js.map +1 -0
- package/dist/components/SimpleStepper/SimpleStepper.esm.js +57 -0
- package/dist/components/SimpleStepper/SimpleStepper.esm.js.map +1 -0
- package/dist/components/SimpleStepper/SimpleStepperFooter.esm.js +141 -0
- package/dist/components/SimpleStepper/SimpleStepperFooter.esm.js.map +1 -0
- package/dist/components/SimpleStepper/SimpleStepperStep.esm.js +25 -0
- package/dist/components/SimpleStepper/SimpleStepperStep.esm.js.map +1 -0
- package/dist/components/Status/Status.esm.js +132 -0
- package/dist/components/Status/Status.esm.js.map +1 -0
- package/dist/components/StructuredMetadataTable/MetadataTable.esm.js +59 -0
- package/dist/components/StructuredMetadataTable/MetadataTable.esm.js.map +1 -0
- package/dist/components/StructuredMetadataTable/StructuredMetadataTable.esm.js +72 -0
- package/dist/components/StructuredMetadataTable/StructuredMetadataTable.esm.js.map +1 -0
- package/dist/components/SupportButton/SupportButton.esm.js +148 -0
- package/dist/components/SupportButton/SupportButton.esm.js.map +1 -0
- package/dist/components/TabbedLayout/RoutedTabs.esm.js +63 -0
- package/dist/components/TabbedLayout/RoutedTabs.esm.js.map +1 -0
- package/dist/components/TabbedLayout/TabbedLayout.esm.js +30 -0
- package/dist/components/TabbedLayout/TabbedLayout.esm.js.map +1 -0
- package/dist/components/Table/Filters.esm.js +71 -0
- package/dist/components/Table/Filters.esm.js.map +1 -0
- package/dist/components/Table/SubvalueCell.esm.js +24 -0
- package/dist/components/Table/SubvalueCell.esm.js.map +1 -0
- package/dist/components/Table/Table.esm.js +370 -0
- package/dist/components/Table/Table.esm.js.map +1 -0
- package/dist/components/Table/TableLoadingBody.esm.js +22 -0
- package/dist/components/Table/TableLoadingBody.esm.js.map +1 -0
- package/dist/components/TrendLine/TrendLine.esm.js +24 -0
- package/dist/components/TrendLine/TrendLine.esm.js.map +1 -0
- package/dist/components/WarningPanel/WarningPanel.esm.js +131 -0
- package/dist/components/WarningPanel/WarningPanel.esm.js.map +1 -0
- package/dist/hooks/useQueryParamState.esm.js +59 -0
- package/dist/hooks/useQueryParamState.esm.js.map +1 -0
- package/dist/hooks/useSupportConfig.esm.js +51 -0
- package/dist/hooks/useSupportConfig.esm.js.map +1 -0
- package/dist/icons/icons.esm.js +47 -0
- package/dist/icons/icons.esm.js.map +1 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.esm.js +73 -7280
- package/dist/index.esm.js.map +1 -1
- package/dist/layout/BottomLink/BottomLink.esm.js +32 -0
- package/dist/layout/BottomLink/BottomLink.esm.js.map +1 -0
- package/dist/layout/Breadcrumbs/Breadcrumbs.esm.js +72 -0
- package/dist/layout/Breadcrumbs/Breadcrumbs.esm.js.map +1 -0
- package/dist/layout/Content/Content.esm.js +47 -0
- package/dist/layout/Content/Content.esm.js.map +1 -0
- package/dist/layout/ContentHeader/ContentHeader.esm.js +69 -0
- package/dist/layout/ContentHeader/ContentHeader.esm.js.map +1 -0
- package/dist/layout/ErrorBoundary/ErrorBoundary.esm.js +45 -0
- package/dist/layout/ErrorBoundary/ErrorBoundary.esm.js.map +1 -0
- package/dist/layout/ErrorPage/ErrorPage.esm.js +61 -0
- package/dist/layout/ErrorPage/ErrorPage.esm.js.map +1 -0
- package/dist/layout/ErrorPage/MicDrop.esm.js +34 -0
- package/dist/layout/ErrorPage/MicDrop.esm.js.map +1 -0
- package/dist/layout/ErrorPage/StackDetails.esm.js +102 -0
- package/dist/layout/ErrorPage/StackDetails.esm.js.map +1 -0
- package/dist/layout/Header/Header.esm.js +172 -0
- package/dist/layout/Header/Header.esm.js.map +1 -0
- package/dist/layout/HeaderActionMenu/HeaderActionMenu.esm.js +74 -0
- package/dist/layout/HeaderActionMenu/HeaderActionMenu.esm.js.map +1 -0
- package/dist/layout/HeaderLabel/HeaderLabel.esm.js +57 -0
- package/dist/layout/HeaderLabel/HeaderLabel.esm.js.map +1 -0
- package/dist/layout/HeaderTabs/HeaderTabs.esm.js +86 -0
- package/dist/layout/HeaderTabs/HeaderTabs.esm.js.map +1 -0
- package/dist/layout/InfoCard/InfoCard.esm.js +164 -0
- package/dist/layout/InfoCard/InfoCard.esm.js.map +1 -0
- package/dist/layout/ItemCard/ItemCard.esm.js +17 -0
- package/dist/layout/ItemCard/ItemCard.esm.js.map +1 -0
- package/dist/layout/ItemCard/ItemCardGrid.esm.js +21 -0
- package/dist/layout/ItemCard/ItemCardGrid.esm.js.map +1 -0
- package/dist/layout/ItemCard/ItemCardHeader.esm.js +23 -0
- package/dist/layout/ItemCard/ItemCardHeader.esm.js.map +1 -0
- package/dist/layout/Page/Page.esm.js +41 -0
- package/dist/layout/Page/Page.esm.js.map +1 -0
- package/dist/layout/Page/PageWithHeader.esm.js +11 -0
- package/dist/layout/Page/PageWithHeader.esm.js.map +1 -0
- package/dist/layout/ProxiedSignInPage/ProxiedSignInIdentity.esm.js +143 -0
- package/dist/layout/ProxiedSignInPage/ProxiedSignInIdentity.esm.js.map +1 -0
- package/dist/layout/ProxiedSignInPage/ProxiedSignInPage.esm.js +32 -0
- package/dist/layout/ProxiedSignInPage/ProxiedSignInPage.esm.js.map +1 -0
- package/dist/layout/ProxiedSignInPage/types.esm.js +21 -0
- package/dist/layout/ProxiedSignInPage/types.esm.js.map +1 -0
- package/dist/layout/Sidebar/Bar.esm.js +190 -0
- package/dist/layout/Sidebar/Bar.esm.js.map +1 -0
- package/dist/layout/Sidebar/Items.esm.js +505 -0
- package/dist/layout/Sidebar/Items.esm.js.map +1 -0
- package/dist/layout/Sidebar/MobileSidebar.esm.js +147 -0
- package/dist/layout/Sidebar/MobileSidebar.esm.js.map +1 -0
- package/dist/layout/Sidebar/MobileSidebarContext.esm.js +10 -0
- package/dist/layout/Sidebar/MobileSidebarContext.esm.js.map +1 -0
- package/dist/layout/Sidebar/Page.esm.js +84 -0
- package/dist/layout/Sidebar/Page.esm.js.map +1 -0
- package/dist/layout/Sidebar/SidebarGroup.esm.js +66 -0
- package/dist/layout/Sidebar/SidebarGroup.esm.js.map +1 -0
- package/dist/layout/Sidebar/SidebarOpenStateContext.esm.js +37 -0
- package/dist/layout/Sidebar/SidebarOpenStateContext.esm.js.map +1 -0
- package/dist/layout/Sidebar/SidebarPinStateContext.esm.js +36 -0
- package/dist/layout/Sidebar/SidebarPinStateContext.esm.js.map +1 -0
- package/dist/layout/Sidebar/SidebarSubmenu.esm.js +94 -0
- package/dist/layout/Sidebar/SidebarSubmenu.esm.js.map +1 -0
- package/dist/layout/Sidebar/SidebarSubmenuItem.esm.js +199 -0
- package/dist/layout/Sidebar/SidebarSubmenuItem.esm.js.map +1 -0
- package/dist/layout/Sidebar/config.esm.js +51 -0
- package/dist/layout/Sidebar/config.esm.js.map +1 -0
- package/dist/layout/Sidebar/icons/DoubleArrowLeft.esm.js +23 -0
- package/dist/layout/Sidebar/icons/DoubleArrowLeft.esm.js.map +1 -0
- package/dist/layout/Sidebar/icons/DoubleArrowRight.esm.js +23 -0
- package/dist/layout/Sidebar/icons/DoubleArrowRight.esm.js.map +1 -0
- package/dist/layout/Sidebar/localStorage.esm.js +22 -0
- package/dist/layout/Sidebar/localStorage.esm.js.map +1 -0
- package/dist/layout/Sidebar/utils.esm.js +17 -0
- package/dist/layout/Sidebar/utils.esm.js.map +1 -0
- package/dist/layout/SignInPage/GuestUserIdentity.esm.js +36 -0
- package/dist/layout/SignInPage/GuestUserIdentity.esm.js.map +1 -0
- package/dist/layout/SignInPage/IdentityApiSignOutProxy.esm.js +41 -0
- package/dist/layout/SignInPage/IdentityApiSignOutProxy.esm.js.map +1 -0
- package/dist/layout/SignInPage/LegacyUserIdentity.esm.js +54 -0
- package/dist/layout/SignInPage/LegacyUserIdentity.esm.js.map +1 -0
- package/dist/layout/SignInPage/SignInPage.esm.js +134 -0
- package/dist/layout/SignInPage/SignInPage.esm.js.map +1 -0
- package/dist/layout/SignInPage/UserIdentity.esm.js +94 -0
- package/dist/layout/SignInPage/UserIdentity.esm.js.map +1 -0
- package/dist/layout/SignInPage/commonProvider.esm.js +75 -0
- package/dist/layout/SignInPage/commonProvider.esm.js.map +1 -0
- package/dist/layout/SignInPage/customProvider.esm.js +97 -0
- package/dist/layout/SignInPage/customProvider.esm.js.map +1 -0
- package/dist/layout/SignInPage/guestProvider.esm.js +97 -0
- package/dist/layout/SignInPage/guestProvider.esm.js.map +1 -0
- package/dist/layout/SignInPage/providers.esm.js +137 -0
- package/dist/layout/SignInPage/providers.esm.js.map +1 -0
- package/dist/layout/SignInPage/styles.esm.js +28 -0
- package/dist/layout/SignInPage/styles.esm.js.map +1 -0
- package/dist/layout/TabbedCard/TabbedCard.esm.js +100 -0
- package/dist/layout/TabbedCard/TabbedCard.esm.js.map +1 -0
- package/dist/{esm/translation-p8_bRQW1.esm.js → translation.esm.js} +2 -2
- package/dist/translation.esm.js.map +1 -0
- package/package.json +26 -28
- package/testUtils/package.json +1 -1
- package/dist/esm/RealLogViewer-ByaGXy8y.esm.js +0 -747
- package/dist/esm/RealLogViewer-ByaGXy8y.esm.js.map +0 -1
- package/dist/esm/translation-p8_bRQW1.esm.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,16 +1,44 @@
|
|
|
1
1
|
# @backstage/core-components
|
|
2
2
|
|
|
3
|
-
## 0.14.
|
|
3
|
+
## 0.14.7
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- e42779e: Properly log the `errorInfo` in `ErrorBoundary`
|
|
8
|
+
- 5223c4c: Fixed an internal circular import that broke Jest mocks.
|
|
9
|
+
- 71e4229: Added optional `initialShowDropDown` prop to `SidebarSubmenuItem` to internally manage the initial display state of the dropdown items.
|
|
10
|
+
- a2ee4df: Add `alignGauge` prop to the `GaugeCard`, and a small size version. When `alignGauge` is `'bottom'` the gauge will vertically align the gauge in the cards, even when the card titles span across multiple lines.
|
|
11
|
+
Add `alignContent` prop to the `InfoCard`, defaulting to `'normal'` with the option of `'bottom'` which vertically aligns the content to the bottom of the card.
|
|
12
|
+
- 5b7b49b: The `SignInPage` guest provider will now fall back to legacy guest auth if the backend request fails, allowing guest auth without a running backend.
|
|
13
|
+
- 359376a: Removing react-text-truncate with css styles.
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @backstage/theme@0.5.4
|
|
16
|
+
|
|
17
|
+
## 0.14.7-next.2
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- a2ee4df: Add `alignGauge` prop to the `GaugeCard`, and a small size version. When `alignGauge` is `'bottom'` the gauge will vertically align the gauge in the cards, even when the card titles span across multiple lines.
|
|
22
|
+
Add `alignContent` prop to the `InfoCard`, defaulting to `'normal'` with the option of `'bottom'` which vertically aligns the content to the bottom of the card.
|
|
23
|
+
|
|
24
|
+
## 0.14.6-next.1
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- 5223c4c: Fixed an internal circular import that broke Jest mocks.
|
|
29
|
+
- 5b7b49b: The `SignInPage` guest provider will now fall back to legacy guest auth if the backend request fails, allowing guest auth without a running backend.
|
|
8
30
|
|
|
9
|
-
## 0.14.5
|
|
31
|
+
## 0.14.5-next.0
|
|
10
32
|
|
|
11
33
|
### Patch Changes
|
|
12
34
|
|
|
13
|
-
-
|
|
35
|
+
- 71e4229: Added optional `initialShowDropDown` prop to `SidebarSubmenuItem` to internally manage the initial display state of the dropdown items.
|
|
36
|
+
- Updated dependencies
|
|
37
|
+
- @backstage/theme@0.5.4-next.0
|
|
38
|
+
- @backstage/config@1.2.0
|
|
39
|
+
- @backstage/core-plugin-api@1.9.2
|
|
40
|
+
- @backstage/errors@1.2.4
|
|
41
|
+
- @backstage/version-bridge@1.0.8
|
|
14
42
|
|
|
15
43
|
## 0.14.4
|
|
16
44
|
|
package/alpha/package.json
CHANGED
package/dist/alpha.esm.js
CHANGED
package/dist/alpha.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alpha.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"alpha.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useApi, alertApiRef } from '@backstage/core-plugin-api';
|
|
2
|
+
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
3
|
+
import IconButton from '@material-ui/core/IconButton';
|
|
4
|
+
import Snackbar from '@material-ui/core/Snackbar';
|
|
5
|
+
import Typography from '@material-ui/core/Typography';
|
|
6
|
+
import CloseIcon from '@material-ui/icons/Close';
|
|
7
|
+
import Alert from '@material-ui/lab/Alert';
|
|
8
|
+
import React, { useState, useEffect } from 'react';
|
|
9
|
+
import { coreComponentsTranslationRef } from '../../translation.esm.js';
|
|
10
|
+
|
|
11
|
+
function AlertDisplay(props) {
|
|
12
|
+
const [messages, setMessages] = useState([]);
|
|
13
|
+
const alertApi = useApi(alertApiRef);
|
|
14
|
+
const { t } = useTranslationRef(coreComponentsTranslationRef);
|
|
15
|
+
const {
|
|
16
|
+
anchorOrigin = { vertical: "top", horizontal: "center" },
|
|
17
|
+
transientTimeoutMs
|
|
18
|
+
} = props;
|
|
19
|
+
const timeoutMs = transientTimeoutMs != null ? transientTimeoutMs : 5e3;
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const subscription = alertApi.alert$().subscribe((message) => setMessages((msgs) => msgs.concat(message)));
|
|
22
|
+
return () => {
|
|
23
|
+
subscription.unsubscribe();
|
|
24
|
+
};
|
|
25
|
+
}, [alertApi]);
|
|
26
|
+
const [firstMessage] = messages;
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (firstMessage && firstMessage.display === "transient") {
|
|
29
|
+
const timeout = setTimeout(() => {
|
|
30
|
+
setMessages((msgs) => {
|
|
31
|
+
const newMsgs = msgs.filter((msg) => msg !== firstMessage);
|
|
32
|
+
return newMsgs.length === msgs.length ? msgs : newMsgs;
|
|
33
|
+
});
|
|
34
|
+
}, timeoutMs);
|
|
35
|
+
return () => clearTimeout(timeout);
|
|
36
|
+
}
|
|
37
|
+
return void 0;
|
|
38
|
+
}, [firstMessage, timeoutMs]);
|
|
39
|
+
if (messages.length === 0) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const handleClose = () => {
|
|
43
|
+
setMessages((msgs) => msgs.filter((msg) => msg !== firstMessage));
|
|
44
|
+
};
|
|
45
|
+
return /* @__PURE__ */ React.createElement(Snackbar, { open: true, anchorOrigin }, /* @__PURE__ */ React.createElement(
|
|
46
|
+
Alert,
|
|
47
|
+
{
|
|
48
|
+
action: /* @__PURE__ */ React.createElement(
|
|
49
|
+
IconButton,
|
|
50
|
+
{
|
|
51
|
+
color: "inherit",
|
|
52
|
+
size: "small",
|
|
53
|
+
onClick: handleClose,
|
|
54
|
+
"data-testid": "error-button-close"
|
|
55
|
+
},
|
|
56
|
+
/* @__PURE__ */ React.createElement(CloseIcon, null)
|
|
57
|
+
),
|
|
58
|
+
severity: firstMessage.severity
|
|
59
|
+
},
|
|
60
|
+
/* @__PURE__ */ React.createElement(Typography, { component: "span" }, String(firstMessage.message), messages.length > 1 && /* @__PURE__ */ React.createElement("em", null, t("alertDisplay.message", {
|
|
61
|
+
count: messages.length - 1
|
|
62
|
+
})))
|
|
63
|
+
));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { AlertDisplay };
|
|
67
|
+
//# sourceMappingURL=AlertDisplay.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AlertDisplay.esm.js","sources":["../../../src/components/AlertDisplay/AlertDisplay.tsx"],"sourcesContent":["/*\n * Copyright 2020 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 */\nimport { alertApiRef, AlertMessage, useApi } from '@backstage/core-plugin-api';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport IconButton from '@material-ui/core/IconButton';\nimport Snackbar from '@material-ui/core/Snackbar';\nimport Typography from '@material-ui/core/Typography';\nimport CloseIcon from '@material-ui/icons/Close';\nimport Alert from '@material-ui/lab/Alert';\nimport React, { useEffect, useState } from 'react';\nimport { coreComponentsTranslationRef } from '../../translation';\n\n/**\n * Properties for {@link AlertDisplay}\n *\n * @public\n */\nexport type AlertDisplayProps = {\n anchorOrigin?: {\n vertical: 'top' | 'bottom';\n horizontal: 'left' | 'center' | 'right';\n };\n transientTimeoutMs?: number;\n};\n\n/**\n * Displays alerts from {@link @backstage/core-plugin-api#AlertApi}\n *\n * @public\n * @remarks\n *\n * Shown as SnackBar at the center top of the page by default. Configurable with props.\n *\n * @param anchorOrigin - The `vertical` property will set the vertical orientation of where the AlertDisplay will be located\n * and the `horizontal` property will set the horizontal orientation of where the AlertDisplay will be located\n * @param transientTimeoutMs - Number of milliseconds a transient alert will stay open for. Default value is 5000\n *\n * @example\n * Here's some examples:\n * ```\n * // This example shows the default usage, the SnackBar will show up at the top in the center and any transient messages will stay open for 5000ms\n * <AlertDisplay />\n *\n * // With this example the SnackBar will show up in the bottom right hand corner and any transient messages will stay open for 2500ms\n * <AlertDisplay transientTimeoutMs={2500} anchorOrigin={{vertical: 'bottom', horizontal: 'right'}}/>\n *\n * // If you want to just set the time a transientTimeoutMs, you can do that like this:\n * <AlertDisplay transientTimeoutMs={10000} />\n * ```\n */\nexport function AlertDisplay(props: AlertDisplayProps) {\n const [messages, setMessages] = useState<Array<AlertMessage>>([]);\n const alertApi = useApi(alertApiRef);\n const { t } = useTranslationRef(coreComponentsTranslationRef);\n\n const {\n anchorOrigin = { vertical: 'top', horizontal: 'center' },\n transientTimeoutMs,\n } = props;\n const timeoutMs = transientTimeoutMs ?? 5000;\n\n useEffect(() => {\n const subscription = alertApi\n .alert$()\n .subscribe(message => setMessages(msgs => msgs.concat(message)));\n\n return () => {\n subscription.unsubscribe();\n };\n }, [alertApi]);\n\n const [firstMessage] = messages;\n\n useEffect(() => {\n if (firstMessage && firstMessage.display === 'transient') {\n const timeout = setTimeout(() => {\n setMessages(msgs => {\n const newMsgs = msgs.filter(msg => msg !== firstMessage);\n return newMsgs.length === msgs.length ? msgs : newMsgs;\n });\n }, timeoutMs);\n return () => clearTimeout(timeout);\n }\n return undefined;\n }, [firstMessage, timeoutMs]);\n\n if (messages.length === 0) {\n return null;\n }\n\n const handleClose = () => {\n setMessages(msgs => msgs.filter(msg => msg !== firstMessage));\n };\n\n return (\n <Snackbar open anchorOrigin={anchorOrigin}>\n <Alert\n action={\n <IconButton\n color=\"inherit\"\n size=\"small\"\n onClick={handleClose}\n data-testid=\"error-button-close\"\n >\n <CloseIcon />\n </IconButton>\n }\n severity={firstMessage.severity}\n >\n <Typography component=\"span\">\n {String(firstMessage.message)}\n {messages.length > 1 && (\n <em>\n {t('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A;AAAA,MACzB,KAAA,EAAO,SAAS,MAAS,GAAA,CAAA;AAAA,KAC1B,CACH,CAEJ,CAAA;AAAA,GAEJ,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { useApi, identityApiRef, configApiRef } from '@backstage/core-plugin-api';
|
|
2
|
+
import React, { useState, useEffect, useMemo } from 'react';
|
|
3
|
+
import { useIdleTimer, workerTimers } from 'react-idle-timer';
|
|
4
|
+
import { LAST_SEEN_ONLINE_STORAGE_KEY, useLogoutDisconnectedUserEffect } from './disconnectedUsers.esm.js';
|
|
5
|
+
import { StillTherePrompt } from './StillTherePrompt.esm.js';
|
|
6
|
+
import { DefaultTimestampStore } from './timestampStore.esm.js';
|
|
7
|
+
|
|
8
|
+
const ConditionalAutoLogout = ({
|
|
9
|
+
idleTimeoutMinutes,
|
|
10
|
+
events,
|
|
11
|
+
useWorkerTimers,
|
|
12
|
+
logoutIfDisconnected,
|
|
13
|
+
promptBeforeIdleSeconds,
|
|
14
|
+
promptOpen,
|
|
15
|
+
setPromptOpen,
|
|
16
|
+
remainingTimeCountdown,
|
|
17
|
+
setRemainingTimeCountdown,
|
|
18
|
+
identityApi,
|
|
19
|
+
lastSeenOnlineStore
|
|
20
|
+
}) => {
|
|
21
|
+
const promptBeforeIdleMillis = promptBeforeIdleSeconds * 1e3;
|
|
22
|
+
const promptBeforeIdle = promptBeforeIdleMillis > 0 ? true : false;
|
|
23
|
+
const onPrompt = async () => {
|
|
24
|
+
setPromptOpen(true);
|
|
25
|
+
setRemainingTimeCountdown(promptBeforeIdleMillis);
|
|
26
|
+
};
|
|
27
|
+
const onIdle = () => {
|
|
28
|
+
setPromptOpen(false);
|
|
29
|
+
setRemainingTimeCountdown(0);
|
|
30
|
+
identityApi.signOut();
|
|
31
|
+
};
|
|
32
|
+
const onActive = () => {
|
|
33
|
+
setPromptOpen(false);
|
|
34
|
+
setRemainingTimeCountdown(0);
|
|
35
|
+
};
|
|
36
|
+
const onAction = (_event, _idleTimer) => {
|
|
37
|
+
lastSeenOnlineStore.save(/* @__PURE__ */ new Date());
|
|
38
|
+
};
|
|
39
|
+
const timer = useIdleTimer({
|
|
40
|
+
timeout: idleTimeoutMinutes * 60 * 1e3,
|
|
41
|
+
events,
|
|
42
|
+
crossTab: true,
|
|
43
|
+
name: "autologout-timer",
|
|
44
|
+
timers: useWorkerTimers ? workerTimers : void 0,
|
|
45
|
+
onIdle,
|
|
46
|
+
onActive: promptBeforeIdle ? onActive : void 0,
|
|
47
|
+
onAction: logoutIfDisconnected ? onAction : void 0,
|
|
48
|
+
onPrompt: promptBeforeIdle ? onPrompt : void 0,
|
|
49
|
+
promptBeforeIdle: promptBeforeIdle ? promptBeforeIdleMillis : void 0,
|
|
50
|
+
syncTimers: 1e3
|
|
51
|
+
});
|
|
52
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, promptBeforeIdle && /* @__PURE__ */ React.createElement(
|
|
53
|
+
StillTherePrompt,
|
|
54
|
+
{
|
|
55
|
+
idleTimer: timer,
|
|
56
|
+
open: promptOpen,
|
|
57
|
+
setOpen: setPromptOpen,
|
|
58
|
+
remainingTime: remainingTimeCountdown,
|
|
59
|
+
setRemainingTime: setRemainingTimeCountdown,
|
|
60
|
+
promptTimeoutMillis: promptBeforeIdleMillis
|
|
61
|
+
}
|
|
62
|
+
));
|
|
63
|
+
};
|
|
64
|
+
const defaultConfig = {
|
|
65
|
+
enabled: true,
|
|
66
|
+
idleTimeoutMinutes: 0.5,
|
|
67
|
+
promptBeforeIdleSeconds: 10,
|
|
68
|
+
useWorkerTimers: true,
|
|
69
|
+
logoutIfDisconnected: true
|
|
70
|
+
};
|
|
71
|
+
const defaultTrackedEvents = [
|
|
72
|
+
"mousemove",
|
|
73
|
+
"keydown",
|
|
74
|
+
"wheel",
|
|
75
|
+
"DOMMouseScroll",
|
|
76
|
+
"mousewheel",
|
|
77
|
+
"mousedown",
|
|
78
|
+
"touchstart",
|
|
79
|
+
"touchmove",
|
|
80
|
+
"MSPointerDown",
|
|
81
|
+
"MSPointerMove",
|
|
82
|
+
"visibilitychange"
|
|
83
|
+
];
|
|
84
|
+
const parseConfig = (configApi, props) => {
|
|
85
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
86
|
+
return {
|
|
87
|
+
enabled: (_b = (_a = configApi.getOptionalBoolean("auth.autologout.enabled")) != null ? _a : props.enabled) != null ? _b : defaultConfig.enabled,
|
|
88
|
+
idleTimeoutMinutes: (_d = (_c = configApi.getOptionalNumber("auth.autologout.idleTimeoutMinutes")) != null ? _c : props.idleTimeoutMinutes) != null ? _d : defaultConfig.idleTimeoutMinutes,
|
|
89
|
+
promptBeforeIdleSeconds: (_f = (_e = configApi.getOptionalNumber("auth.autologout.promptBeforeIdleSeconds")) != null ? _e : props.promptBeforeIdleSeconds) != null ? _f : defaultConfig.promptBeforeIdleSeconds,
|
|
90
|
+
useWorkerTimers: (_h = (_g = configApi.getOptionalBoolean("auth.autologout.useWorkerTimers")) != null ? _g : props.useWorkerTimers) != null ? _h : defaultConfig.useWorkerTimers,
|
|
91
|
+
logoutIfDisconnected: (_j = (_i = configApi.getOptionalBoolean("auth.autologout.logoutIfDisconnected")) != null ? _i : props.logoutIfDisconnected) != null ? _j : defaultConfig.logoutIfDisconnected
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
const AutoLogout = (props) => {
|
|
95
|
+
const identityApi = useApi(identityApiRef);
|
|
96
|
+
const configApi = useApi(configApiRef);
|
|
97
|
+
const [isLogged, setIsLogged] = useState(false);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
async function isLoggedIn(identity) {
|
|
100
|
+
if ((await identity.getCredentials()).token) {
|
|
101
|
+
setIsLogged(true);
|
|
102
|
+
} else {
|
|
103
|
+
setIsLogged(false);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
isLoggedIn(identityApi);
|
|
107
|
+
}, [identityApi]);
|
|
108
|
+
const {
|
|
109
|
+
enabled,
|
|
110
|
+
idleTimeoutMinutes,
|
|
111
|
+
promptBeforeIdleSeconds,
|
|
112
|
+
logoutIfDisconnected,
|
|
113
|
+
useWorkerTimers
|
|
114
|
+
} = useMemo(() => {
|
|
115
|
+
return parseConfig(configApi, props);
|
|
116
|
+
}, [configApi, props]);
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (idleTimeoutMinutes < 0.5) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
"\u274C idleTimeoutMinutes property should be >= 0.5 minutes (30 seconds)."
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
if (promptBeforeIdleSeconds < 0) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
"\u274C promptBeforeIdleSeconds property should be >= 0 seconds. Set to 0 to disable the prompt."
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
if (idleTimeoutMinutes * 60 <= promptBeforeIdleSeconds) {
|
|
129
|
+
throw new Error(
|
|
130
|
+
`\u274C promptBeforeIdleSeconds should be smaller than idleTimeoutMinutes`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}, [idleTimeoutMinutes, promptBeforeIdleSeconds]);
|
|
134
|
+
const lastSeenOnlineStore = useMemo(
|
|
135
|
+
() => new DefaultTimestampStore(LAST_SEEN_ONLINE_STORAGE_KEY),
|
|
136
|
+
[]
|
|
137
|
+
);
|
|
138
|
+
const [promptOpen, setPromptOpen] = useState(false);
|
|
139
|
+
const [remainingTimeCountdown, setRemainingTimeCountdown] = useState(0);
|
|
140
|
+
useLogoutDisconnectedUserEffect({
|
|
141
|
+
enableEffect: logoutIfDisconnected,
|
|
142
|
+
autologoutIsEnabled: enabled && isLogged,
|
|
143
|
+
idleTimeoutSeconds: idleTimeoutMinutes * 60,
|
|
144
|
+
lastSeenOnlineStore,
|
|
145
|
+
identityApi
|
|
146
|
+
});
|
|
147
|
+
if (!enabled || !isLogged) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
return /* @__PURE__ */ React.createElement(
|
|
151
|
+
ConditionalAutoLogout,
|
|
152
|
+
{
|
|
153
|
+
idleTimeoutMinutes,
|
|
154
|
+
promptBeforeIdleSeconds,
|
|
155
|
+
useWorkerTimers,
|
|
156
|
+
events: defaultTrackedEvents,
|
|
157
|
+
logoutIfDisconnected,
|
|
158
|
+
promptOpen,
|
|
159
|
+
setPromptOpen,
|
|
160
|
+
remainingTimeCountdown,
|
|
161
|
+
setRemainingTimeCountdown,
|
|
162
|
+
identityApi,
|
|
163
|
+
lastSeenOnlineStore
|
|
164
|
+
}
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export { AutoLogout };
|
|
169
|
+
//# sourceMappingURL=AutoLogout.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoLogout.esm.js","sources":["../../../src/components/AutoLogout/AutoLogout.tsx"],"sourcesContent":["/*\n * Copyright 2023 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 {\n ConfigApi,\n configApiRef,\n IdentityApi,\n identityApiRef,\n useApi,\n} from '@backstage/core-plugin-api';\nimport React, { useEffect, useMemo, useState } from 'react';\nimport {\n EventsType,\n IIdleTimer,\n workerTimers,\n useIdleTimer,\n} from 'react-idle-timer';\n\nimport {\n LAST_SEEN_ONLINE_STORAGE_KEY,\n useLogoutDisconnectedUserEffect,\n} from './disconnectedUsers';\nimport { StillTherePrompt } from './StillTherePrompt';\nimport { DefaultTimestampStore, TimestampStore } from './timestampStore';\n\ntype AutoLogoutTrackableEvent = EventsType;\n\n/** @public */\nexport type AutoLogoutProps = {\n /**\n * Enable/disable the AutoLogoutMechanism.\n * defauls to true.\n */\n enabled?: boolean;\n /**\n * The amount of time (in minutes) of inactivity\n * after which the user is automatically logged out.\n * defaults to 60 minutes.\n */\n idleTimeoutMinutes?: number;\n /**\n * The number of seconds before the idleTimeout expires,\n * at which the user will be alerted by a Dialog that\n * they are about to be logged out.\n * defaults to 10 seconds\n */\n promptBeforeIdleSeconds?: number;\n /**\n * Enable/disable the usage of Node's worker thread timers instead of main thread timers.\n * This is helpful if you notice that the your browser is killing inactive tab's timers, like the one used by AutoLogout.\n * If you experience some browser incompatibility, you may try to set this to false.\n * defaults to true.\n */\n useWorkerTimers?: boolean;\n /**\n * Enable/disable the autologout for disconnected users.\n * disconnected users are the ones that are logged in but have no Backstage tab open in their browsers.\n * If enabled, disconnected users will be automatically logged out after `idleTimeoutMinutes`\n * defaults to true\n */\n logoutIfDisconnected?: boolean;\n};\n\ntype AutoLogoutInternalProps = Omit<Required<AutoLogoutProps>, 'enabled'> & {\n events: AutoLogoutTrackableEvent[];\n promptOpen: boolean;\n setPromptOpen: (value: boolean) => void;\n remainingTimeCountdown: number;\n setRemainingTimeCountdown: (amount: number) => void;\n identityApi: IdentityApi;\n lastSeenOnlineStore: TimestampStore;\n};\n\nconst ConditionalAutoLogout = ({\n idleTimeoutMinutes,\n events,\n useWorkerTimers,\n logoutIfDisconnected,\n promptBeforeIdleSeconds,\n promptOpen,\n setPromptOpen,\n remainingTimeCountdown,\n setRemainingTimeCountdown,\n identityApi,\n lastSeenOnlineStore,\n}: AutoLogoutInternalProps): JSX.Element => {\n const promptBeforeIdleMillis = promptBeforeIdleSeconds * 1000;\n const promptBeforeIdle = promptBeforeIdleMillis > 0 ? true : false;\n\n const onPrompt = async () => {\n // onPrompt will be called `promptBeforeIdle` milliseconds before `timeout`.\n // All events are disabled while the prompt is active.\n // If the user wishes to stay active, call the `activate()` method.\n // You can get the remaining prompt time with the `getRemainingTime()` method,\n setPromptOpen(true);\n setRemainingTimeCountdown(promptBeforeIdleMillis);\n };\n\n const onIdle = () => {\n // onIdle will be called after the timeout is reached.\n // Events will be rebound as long as `stopOnMount` is not set.\n setPromptOpen(false);\n setRemainingTimeCountdown(0);\n identityApi.signOut();\n };\n\n const onActive = () => {\n // onActive will only be called if `activate()` is called while `isPrompted()`\n // is true. Here you will also want to close your modal and perform\n // any active actions.\n setPromptOpen(false);\n setRemainingTimeCountdown(0);\n };\n\n const onAction = (\n _event?: Event | undefined,\n _idleTimer?: IIdleTimer | null,\n ) => {\n // onAction will be called if any user event is detected. The list of events that triggers a user event detection is the list of configured events\n // If any user event is detected we update the Last seen online in storage\n lastSeenOnlineStore.save(new Date());\n };\n\n const timer = useIdleTimer({\n timeout: idleTimeoutMinutes * 60 * 1000,\n events: events,\n crossTab: true,\n name: 'autologout-timer',\n timers: useWorkerTimers ? workerTimers : undefined,\n onIdle: onIdle,\n onActive: promptBeforeIdle ? onActive : undefined,\n onAction: logoutIfDisconnected ? onAction : undefined,\n onPrompt: promptBeforeIdle ? onPrompt : undefined,\n promptBeforeIdle: promptBeforeIdle ? promptBeforeIdleMillis : undefined,\n syncTimers: 1000,\n });\n\n return (\n <>\n {promptBeforeIdle && (\n <StillTherePrompt\n idleTimer={timer}\n open={promptOpen}\n setOpen={setPromptOpen}\n remainingTime={remainingTimeCountdown}\n setRemainingTime={setRemainingTimeCountdown}\n promptTimeoutMillis={promptBeforeIdleMillis}\n />\n )}\n </>\n );\n};\n\nconst defaultConfig: Required<AutoLogoutProps> = {\n enabled: true,\n idleTimeoutMinutes: 0.5,\n promptBeforeIdleSeconds: 10,\n useWorkerTimers: true,\n logoutIfDisconnected: true,\n};\n\n/**\n * A list of DOM events that the activity tracker will use to determine if the user is active or not.\n */\nconst defaultTrackedEvents: AutoLogoutTrackableEvent[] = [\n 'mousemove',\n 'keydown',\n 'wheel',\n 'DOMMouseScroll',\n 'mousewheel',\n 'mousedown',\n 'touchstart',\n 'touchmove',\n 'MSPointerDown',\n 'MSPointerMove',\n 'visibilitychange',\n];\n\n/**\n * Parses configuration for the AutoLogout. Properties configured in `app-config` take precedence over the props passed to the React component.\n * If neither props nor config properties are found, a default value will be set accordingly.\n */\nconst parseConfig = (\n configApi: ConfigApi,\n props: AutoLogoutProps,\n): Required<AutoLogoutProps> => {\n return {\n enabled:\n configApi.getOptionalBoolean('auth.autologout.enabled') ??\n props.enabled ??\n defaultConfig.enabled,\n idleTimeoutMinutes:\n configApi.getOptionalNumber('auth.autologout.idleTimeoutMinutes') ??\n props.idleTimeoutMinutes ??\n defaultConfig.idleTimeoutMinutes,\n promptBeforeIdleSeconds:\n configApi.getOptionalNumber('auth.autologout.promptBeforeIdleSeconds') ??\n props.promptBeforeIdleSeconds ??\n defaultConfig.promptBeforeIdleSeconds,\n useWorkerTimers:\n configApi.getOptionalBoolean('auth.autologout.useWorkerTimers') ??\n props.useWorkerTimers ??\n defaultConfig.useWorkerTimers,\n logoutIfDisconnected:\n configApi.getOptionalBoolean('auth.autologout.logoutIfDisconnected') ??\n props.logoutIfDisconnected ??\n defaultConfig.logoutIfDisconnected,\n };\n};\n\n/**\n * The Autologout feature enables platform engineers to add a mechanism to log out users after a configurable amount of time of inactivity.\n * When enabled, the mechanism will track user actions (mouse movement, mouse click, key pressing, taps, etc.) in order to determine if they are active or not.\n * After a certain amount of inactivity/idle time, the user session is invalidated and they are required to sign in again.\n *\n * @public\n */\nexport const AutoLogout = (props: AutoLogoutProps): JSX.Element | null => {\n const identityApi = useApi(identityApiRef);\n const configApi = useApi(configApiRef);\n const [isLogged, setIsLogged] = useState(false);\n useEffect(() => {\n // if the user is not logged in, the autologout feature won't affect the app even if enabled\n async function isLoggedIn(identity: IdentityApi) {\n if ((await identity.getCredentials()).token) {\n setIsLogged(true);\n } else {\n setIsLogged(false);\n }\n }\n isLoggedIn(identityApi);\n }, [identityApi]);\n\n const {\n enabled,\n idleTimeoutMinutes,\n promptBeforeIdleSeconds,\n logoutIfDisconnected,\n useWorkerTimers,\n }: AutoLogoutProps = useMemo(() => {\n return parseConfig(configApi, props);\n }, [configApi, props]);\n\n useEffect(() => {\n if (idleTimeoutMinutes < 0.5) {\n throw new Error(\n '❌ idleTimeoutMinutes property should be >= 0.5 minutes (30 seconds).',\n );\n }\n\n if (promptBeforeIdleSeconds < 0) {\n throw new Error(\n '❌ promptBeforeIdleSeconds property should be >= 0 seconds. Set to 0 to disable the prompt.',\n );\n }\n\n if (idleTimeoutMinutes * 60 <= promptBeforeIdleSeconds) {\n throw new Error(\n `❌ promptBeforeIdleSeconds should be smaller than idleTimeoutMinutes`,\n );\n }\n }, [idleTimeoutMinutes, promptBeforeIdleSeconds]);\n\n const lastSeenOnlineStore: TimestampStore = useMemo(\n () => new DefaultTimestampStore(LAST_SEEN_ONLINE_STORAGE_KEY),\n [],\n );\n const [promptOpen, setPromptOpen] = useState<boolean>(false);\n\n const [remainingTimeCountdown, setRemainingTimeCountdown] =\n useState<number>(0);\n\n useLogoutDisconnectedUserEffect({\n enableEffect: logoutIfDisconnected,\n autologoutIsEnabled: enabled && isLogged,\n idleTimeoutSeconds: idleTimeoutMinutes * 60,\n lastSeenOnlineStore,\n identityApi,\n });\n\n if (!enabled || !isLogged) {\n return null;\n }\n\n return (\n <ConditionalAutoLogout\n idleTimeoutMinutes={idleTimeoutMinutes}\n promptBeforeIdleSeconds={promptBeforeIdleSeconds}\n useWorkerTimers={useWorkerTimers}\n events={defaultTrackedEvents}\n logoutIfDisconnected={logoutIfDisconnected}\n promptOpen={promptOpen}\n setPromptOpen={setPromptOpen}\n remainingTimeCountdown={remainingTimeCountdown}\n setRemainingTimeCountdown={setRemainingTimeCountdown}\n identityApi={identityApi}\n lastSeenOnlineStore={lastSeenOnlineStore}\n />\n );\n};\n"],"names":[],"mappings":";;;;;;;AAsFA,MAAM,wBAAwB,CAAC;AAAA,EAC7B,kBAAA;AAAA,EACA,MAAA;AAAA,EACA,eAAA;AAAA,EACA,oBAAA;AAAA,EACA,uBAAA;AAAA,EACA,UAAA;AAAA,EACA,aAAA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AED,EAAI,IAAA,CAAC,OAAW,IAAA,CAAC,QAAU,EAAA;AACzB,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAEA,EACE,uBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,qBAAA;AAAA,IAAA;AAAA,MACC,kBAAA;AAAA,MACA,uBAAA;AAAA,MACA,eAAA;AAAA,MACA,MAAQ,EAAA,oBAAA;AAAA,MACR,oBAAA;AAAA,MACA,UAAA;AAAA,MACA,aAAA;AAAA,MACA,sBAAA;AAAA,MACA,yBAAA;AAAA,MACA,WAAA;AAAA,MACA,mBAAA;AAAA,KAAA;AAAA,GACF,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import Button from '@material-ui/core/Button';
|
|
2
|
+
import Dialog from '@material-ui/core/Dialog';
|
|
3
|
+
import DialogActions from '@material-ui/core/DialogActions';
|
|
4
|
+
import DialogContent from '@material-ui/core/DialogContent';
|
|
5
|
+
import DialogContentText from '@material-ui/core/DialogContentText';
|
|
6
|
+
import DialogTitle from '@material-ui/core/DialogTitle';
|
|
7
|
+
import React, { useEffect } from 'react';
|
|
8
|
+
import { coreComponentsTranslationRef } from '../../translation.esm.js';
|
|
9
|
+
import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
|
10
|
+
|
|
11
|
+
const StillTherePrompt = (props) => {
|
|
12
|
+
const {
|
|
13
|
+
idleTimer,
|
|
14
|
+
setOpen,
|
|
15
|
+
open,
|
|
16
|
+
promptTimeoutMillis,
|
|
17
|
+
remainingTime,
|
|
18
|
+
setRemainingTime
|
|
19
|
+
} = props;
|
|
20
|
+
const { t } = useTranslationRef(coreComponentsTranslationRef);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const interval = setInterval(() => {
|
|
23
|
+
setRemainingTime(Math.ceil(idleTimer.getRemainingTime()));
|
|
24
|
+
}, 500);
|
|
25
|
+
return () => {
|
|
26
|
+
clearInterval(interval);
|
|
27
|
+
};
|
|
28
|
+
}, [idleTimer, setRemainingTime]);
|
|
29
|
+
const handleStillHere = () => {
|
|
30
|
+
setOpen(false);
|
|
31
|
+
idleTimer.activate();
|
|
32
|
+
};
|
|
33
|
+
const timeTillPrompt = Math.max(
|
|
34
|
+
remainingTime - promptTimeoutMillis / 1e3,
|
|
35
|
+
0
|
|
36
|
+
);
|
|
37
|
+
const seconds = timeTillPrompt > 1 ? "seconds" : "second";
|
|
38
|
+
return /* @__PURE__ */ React.createElement(Dialog, { open, "data-testid": "inactivity-prompt-dialog" }, /* @__PURE__ */ React.createElement(DialogTitle, null, t("autoLogout.stillTherePrompt.title")), /* @__PURE__ */ React.createElement(DialogContent, null, /* @__PURE__ */ React.createElement(DialogContentText, null, "You are about to be disconnected in", " ", /* @__PURE__ */ React.createElement("b", null, Math.ceil(remainingTime / 1e3), " ", seconds), ". Are you still there?")), /* @__PURE__ */ React.createElement(DialogActions, null, /* @__PURE__ */ React.createElement(
|
|
39
|
+
Button,
|
|
40
|
+
{
|
|
41
|
+
onClick: handleStillHere,
|
|
42
|
+
color: "secondary",
|
|
43
|
+
variant: "contained",
|
|
44
|
+
size: "small"
|
|
45
|
+
},
|
|
46
|
+
t("autoLogout.stillTherePrompt.buttonText")
|
|
47
|
+
)));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { StillTherePrompt };
|
|
51
|
+
//# sourceMappingURL=StillTherePrompt.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StillTherePrompt.esm.js","sources":["../../../src/components/AutoLogout/StillTherePrompt.tsx"],"sourcesContent":["/*\n * Copyright 2023 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 Button from '@material-ui/core/Button';\nimport Dialog from '@material-ui/core/Dialog';\nimport DialogActions from '@material-ui/core/DialogActions';\nimport DialogContent from '@material-ui/core/DialogContent';\nimport DialogContentText from '@material-ui/core/DialogContentText';\nimport DialogTitle from '@material-ui/core/DialogTitle';\nimport React, { useEffect } from 'react';\nimport { IIdleTimer } from 'react-idle-timer';\nimport { coreComponentsTranslationRef } from '../../translation';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\n\nexport interface StillTherePromptProps {\n idleTimer: IIdleTimer;\n promptTimeoutMillis: number;\n remainingTime: number;\n setRemainingTime: (amount: number) => void;\n open: boolean;\n setOpen: (value: boolean) => void;\n}\n\nexport const StillTherePrompt = (props: StillTherePromptProps) => {\n const {\n idleTimer,\n setOpen,\n open,\n promptTimeoutMillis,\n remainingTime,\n setRemainingTime,\n } = props;\n const { t } = useTranslationRef(coreComponentsTranslationRef);\n\n useEffect(() => {\n const interval = setInterval(() => {\n setRemainingTime(Math.ceil(idleTimer.getRemainingTime()));\n }, 500);\n\n return () => {\n clearInterval(interval);\n };\n }, [idleTimer, setRemainingTime]);\n\n const handleStillHere = () => {\n setOpen(false);\n idleTimer.activate();\n };\n\n const timeTillPrompt = Math.max(\n remainingTime - promptTimeoutMillis / 1000,\n 0,\n );\n const seconds = timeTillPrompt > 1 ? 'seconds' : 'second';\n\n return (\n <Dialog open={open} data-testid=\"inactivity-prompt-dialog\">\n <DialogTitle>{t('autoLogout.stillTherePrompt.title')}</DialogTitle>\n <DialogContent>\n <DialogContentText>\n You are about to be disconnected in{' '}\n <b>\n {Math.ceil(remainingTime / 1000)} {seconds}\n </b>\n . Are you still there?\n </DialogContentText>\n </DialogContent>\n <DialogActions>\n <Button\n onClick={handleStillHere}\n color=\"secondary\"\n variant=\"contained\"\n size=\"small\"\n >\n {t('autoLogout.stillTherePrompt.buttonText')}\n </Button>\n </DialogActions>\n </Dialog>\n );\n};\n"],"names":[],"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A,IAAA,EAAkB,qCACmB,EAAA,GAAA,kBACnC,KAAA,CAAA,aAAA,CAAA,GAAA,EAAA,IAAA,EACE,IAAK,CAAA,IAAA,CAAK,gBAAgB,GAAI,CAAA,EAAE,GAAE,EAAA,OACrC,CAAI,EAAA,wBAEN,CACF,CAAA,sCACC,aACC,EAAA,IAAA,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,MAAA;AAAA,IAAA;AAAA,MACC,OAAS,EAAA,eAAA;AAAA,MACT,KAAM,EAAA,WAAA;AAAA,MACN,OAAQ,EAAA,WAAA;AAAA,MACR,IAAK,EAAA,OAAA;AAAA,KAAA;AAAA,IAEJ,EAAE,wCAAwC,CAAA;AAAA,GAE/C,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const LAST_SEEN_ONLINE_STORAGE_KEY = "@backstage/autologout:lastSeenOnline";
|
|
4
|
+
const useLogoutDisconnectedUserEffect = ({
|
|
5
|
+
enableEffect,
|
|
6
|
+
autologoutIsEnabled,
|
|
7
|
+
idleTimeoutSeconds,
|
|
8
|
+
lastSeenOnlineStore,
|
|
9
|
+
identityApi
|
|
10
|
+
}) => {
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (autologoutIsEnabled && enableEffect) {
|
|
13
|
+
const lastSeenOnline = lastSeenOnlineStore.get();
|
|
14
|
+
if (lastSeenOnline) {
|
|
15
|
+
const now = /* @__PURE__ */ new Date();
|
|
16
|
+
const nowSeconds = Math.ceil(now.getTime() / 1e3);
|
|
17
|
+
const lastSeenOnlineSeconds = Math.ceil(
|
|
18
|
+
lastSeenOnline.getTime() / 1e3
|
|
19
|
+
);
|
|
20
|
+
if (nowSeconds - lastSeenOnlineSeconds > idleTimeoutSeconds) {
|
|
21
|
+
identityApi.signOut();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
lastSeenOnlineStore.save(/* @__PURE__ */ new Date());
|
|
25
|
+
} else {
|
|
26
|
+
lastSeenOnlineStore.delete();
|
|
27
|
+
}
|
|
28
|
+
}, [
|
|
29
|
+
autologoutIsEnabled,
|
|
30
|
+
enableEffect,
|
|
31
|
+
identityApi,
|
|
32
|
+
idleTimeoutSeconds,
|
|
33
|
+
lastSeenOnlineStore
|
|
34
|
+
]);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { LAST_SEEN_ONLINE_STORAGE_KEY, useLogoutDisconnectedUserEffect };
|
|
38
|
+
//# sourceMappingURL=disconnectedUsers.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disconnectedUsers.esm.js","sources":["../../../src/components/AutoLogout/disconnectedUsers.ts"],"sourcesContent":["/*\n * Copyright 2023 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 */\nimport { IdentityApi } from '@backstage/core-plugin-api';\nimport { useEffect } from 'react';\n\nimport { TimestampStore } from './timestampStore';\n\nexport const LAST_SEEN_ONLINE_STORAGE_KEY =\n '@backstage/autologout:lastSeenOnline';\n\nexport type UseLogoutDisconnectedUserEffectProps = {\n enableEffect: boolean;\n autologoutIsEnabled: boolean;\n idleTimeoutSeconds: number;\n lastSeenOnlineStore: TimestampStore;\n identityApi: IdentityApi;\n};\n\nexport const useLogoutDisconnectedUserEffect = ({\n enableEffect,\n autologoutIsEnabled,\n idleTimeoutSeconds,\n lastSeenOnlineStore,\n identityApi,\n}: UseLogoutDisconnectedUserEffectProps) => {\n useEffect(() => {\n /**\n * Considers disconnected users as inactive users.\n * If all Backstage tabs are closed and idleTimeoutMinutes are passed then logout the user anyway.\n */\n if (autologoutIsEnabled && enableEffect) {\n const lastSeenOnline = lastSeenOnlineStore.get();\n if (lastSeenOnline) {\n const now = new Date();\n const nowSeconds = Math.ceil(now.getTime() / 1000);\n const lastSeenOnlineSeconds = Math.ceil(\n lastSeenOnline.getTime() / 1000,\n );\n if (nowSeconds - lastSeenOnlineSeconds > idleTimeoutSeconds) {\n identityApi.signOut();\n }\n }\n /**\n * save for the first time when app is loaded, so that\n * if user logs in and does nothing we still have a\n * lastSeenOnline value in store\n */\n lastSeenOnlineStore.save(new Date());\n } else {\n lastSeenOnlineStore.delete();\n }\n }, [\n autologoutIsEnabled,\n enableEffect,\n identityApi,\n idleTimeoutSeconds,\n lastSeenOnlineStore,\n ]);\n};\n"],"names":[],"mappings":";;AAoBO,MAAM,4BACX,GAAA,uCAAA;AAUK,MAAM,kCAAkC,CAAC;AAAA,EAC9C,YAAA;AAAA,EACA,mBAAA;AAAA,EACA,kBAAA;AAAA,EACA,mBAAA;AAAA,EACA,WAAA;AACF,CAA4C,KAAA;AAC1C,EAAA,SAAA,CAAU,MAAM;AAKd,IAAA,IAAI,uBAAuB,YAAc,EAAA;AACvC,MAAM,MAAA,cAAA,GAAiB,oBAAoB,GAAI,EAAA,CAAA;AAC/C,MAAA,IAAI,cAAgB,EAAA;AAClB,QAAM,MAAA,GAAA,uBAAU,IAAK,EAAA,CAAA;AACrB,QAAA,MAAM,aAAa,IAAK,CAAA,IAAA,CAAK,GAAI,CAAA,OAAA,KAAY,GAAI,CAAA,CAAA;AACjD,QAAA,MAAM,wBAAwB,IAAK,CAAA,IAAA;AAAA,UACjC,cAAA,CAAe,SAAY,GAAA,GAAA;AAAA,SAC7B,CAAA;AACA,QAAI,IAAA,UAAA,GAAa,wBAAwB,kBAAoB,EAAA;AAC3D,UAAA,WAAA,CAAY,OAAQ,EAAA,CAAA;AAAA,SACtB;AAAA,OACF;AAMA,MAAoB,mBAAA,CAAA,IAAA,iBAAS,IAAA,IAAA,EAAM,CAAA,CAAA;AAAA,KAC9B,MAAA;AACL,MAAA,mBAAA,CAAoB,MAAO,EAAA,CAAA;AAAA,KAC7B;AAAA,GACC,EAAA;AAAA,IACD,mBAAA;AAAA,IACA,YAAA;AAAA,IACA,WAAA;AAAA,IACA,kBAAA;AAAA,IACA,mBAAA;AAAA,GACD,CAAA,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class DefaultTimestampStore {
|
|
2
|
+
constructor(key) {
|
|
3
|
+
this.key = key;
|
|
4
|
+
}
|
|
5
|
+
save(date) {
|
|
6
|
+
localStorage.setItem(this.key, date.toJSON());
|
|
7
|
+
}
|
|
8
|
+
delete() {
|
|
9
|
+
localStorage.removeItem(this.key);
|
|
10
|
+
}
|
|
11
|
+
get() {
|
|
12
|
+
const timestamp = localStorage.getItem(this.key);
|
|
13
|
+
return timestamp !== null ? new Date(Date.parse(timestamp)) : null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { DefaultTimestampStore };
|
|
18
|
+
//# sourceMappingURL=timestampStore.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestampStore.esm.js","sources":["../../../src/components/AutoLogout/timestampStore.ts"],"sourcesContent":["/*\n * Copyright 2023 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\nexport interface TimestampStore {\n save(date: Date): void;\n delete(): void;\n get(): Date | null;\n}\n\nexport class DefaultTimestampStore implements TimestampStore {\n constructor(private readonly key: string) {}\n\n save(date: Date): void {\n localStorage.setItem(this.key, date.toJSON());\n }\n\n delete(): void {\n localStorage.removeItem(this.key);\n }\n\n get(): Date | null {\n const timestamp = localStorage.getItem(this.key);\n\n return timestamp !== null ? new Date(Date.parse(timestamp)) : null;\n }\n}\n"],"names":[],"mappings":"AAsBO,MAAM,qBAAgD,CAAA;AAAA,EAC3D,YAA6B,GAAa,EAAA;AAAb,IAAA,IAAA,CAAA,GAAA,GAAA,GAAA,CAAA;AAAA,GAAc;AAAA,EAE3C,KAAK,IAAkB,EAAA;AACrB,IAAA,YAAA,CAAa,OAAQ,CAAA,IAAA,CAAK,GAAK,EAAA,IAAA,CAAK,QAAQ,CAAA,CAAA;AAAA,GAC9C;AAAA,EAEA,MAAe,GAAA;AACb,IAAa,YAAA,CAAA,UAAA,CAAW,KAAK,GAAG,CAAA,CAAA;AAAA,GAClC;AAAA,EAEA,GAAmB,GAAA;AACjB,IAAA,MAAM,SAAY,GAAA,YAAA,CAAa,OAAQ,CAAA,IAAA,CAAK,GAAG,CAAA,CAAA;AAE/C,IAAO,OAAA,SAAA,KAAc,OAAO,IAAI,IAAA,CAAK,KAAK,KAAM,CAAA,SAAS,CAAC,CAAI,GAAA,IAAA,CAAA;AAAA,GAChE;AACF;;;;"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import MaterialAvatar from '@material-ui/core/Avatar';
|
|
2
|
+
import { makeStyles } from '@material-ui/core/styles';
|
|
3
|
+
import Typography from '@material-ui/core/Typography';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { stringToColor, extractInitials } from './utils.esm.js';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
|
|
8
|
+
const useStyles = makeStyles(
|
|
9
|
+
(theme) => ({
|
|
10
|
+
avatar: {
|
|
11
|
+
width: "4rem",
|
|
12
|
+
height: "4rem",
|
|
13
|
+
color: theme.palette.common.white,
|
|
14
|
+
backgroundColor: (props) => props.backgroundColor
|
|
15
|
+
},
|
|
16
|
+
avatarText: {
|
|
17
|
+
fontWeight: theme.typography.fontWeightBold,
|
|
18
|
+
letterSpacing: "1px",
|
|
19
|
+
textTransform: "uppercase"
|
|
20
|
+
}
|
|
21
|
+
}),
|
|
22
|
+
{ name: "BackstageAvatar" }
|
|
23
|
+
);
|
|
24
|
+
function Avatar(props) {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
const { displayName, picture, customStyles } = props;
|
|
27
|
+
const styles = { ...customStyles };
|
|
28
|
+
const fontStyles = {
|
|
29
|
+
fontFamily: styles.fontFamily,
|
|
30
|
+
fontSize: styles.fontSize,
|
|
31
|
+
fontWeight: styles.fontWeight
|
|
32
|
+
};
|
|
33
|
+
const classes = useStyles(
|
|
34
|
+
!picture ? { backgroundColor: stringToColor(displayName || "") } : {}
|
|
35
|
+
);
|
|
36
|
+
const avatarClassNames = classNames((_a = props.classes) == null ? void 0 : _a.avatar, classes.avatar);
|
|
37
|
+
const avatarTextClassNames = classNames(
|
|
38
|
+
(_b = props.classes) == null ? void 0 : _b.avatarText,
|
|
39
|
+
classes.avatarText
|
|
40
|
+
);
|
|
41
|
+
return /* @__PURE__ */ React.createElement(
|
|
42
|
+
MaterialAvatar,
|
|
43
|
+
{
|
|
44
|
+
alt: displayName,
|
|
45
|
+
src: picture,
|
|
46
|
+
className: avatarClassNames,
|
|
47
|
+
style: styles
|
|
48
|
+
},
|
|
49
|
+
displayName && /* @__PURE__ */ React.createElement(
|
|
50
|
+
Typography,
|
|
51
|
+
{
|
|
52
|
+
variant: "h6",
|
|
53
|
+
component: "span",
|
|
54
|
+
className: avatarTextClassNames,
|
|
55
|
+
style: fontStyles
|
|
56
|
+
},
|
|
57
|
+
extractInitials(displayName)
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { Avatar };
|
|
63
|
+
//# sourceMappingURL=Avatar.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Avatar.esm.js","sources":["../../../src/components/Avatar/Avatar.tsx"],"sourcesContent":["/*\n * Copyright 2020 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 */\nimport MaterialAvatar from '@material-ui/core/Avatar';\nimport { makeStyles, Theme } from '@material-ui/core/styles';\nimport Typography from '@material-ui/core/Typography';\nimport React, { CSSProperties } from 'react';\n\nimport { extractInitials, stringToColor } from './utils';\nimport classNames from 'classnames';\n\n/** @public */\nexport type AvatarClassKey = 'avatar';\n\nconst useStyles = makeStyles(\n (theme: Theme) => ({\n avatar: {\n width: '4rem',\n height: '4rem',\n color: theme.palette.common.white,\n backgroundColor: (props: { backgroundColor?: string }) =>\n props.backgroundColor,\n },\n avatarText: {\n fontWeight: theme.typography.fontWeightBold,\n letterSpacing: '1px',\n textTransform: 'uppercase',\n },\n }),\n { name: 'BackstageAvatar' },\n);\n\n/**\n * Properties for {@link Avatar}.\n *\n * @public\n */\nexport interface AvatarProps {\n /**\n * A display name, which will be used to generate initials as a fallback in case a picture is not provided.\n */\n displayName?: string;\n /**\n * URL to avatar image source\n */\n picture?: string;\n /**\n * Custom styles applied to avatar\n * @deprecated - use the classes property instead\n */\n customStyles?: CSSProperties;\n\n /**\n * Custom styles applied to avatar\n */\n classes?: { [key in 'avatar' | 'avatarText']?: string };\n}\n\n/**\n * Component rendering an Avatar\n *\n * @public\n * @remarks\n *\n * Based on https://v4.mui.com/components/avatars/#avatar with some styling adjustment and two-letter initials\n */\nexport function Avatar(props: AvatarProps) {\n const { displayName, picture, customStyles } = props;\n const styles = { ...customStyles };\n\n // TODO: Remove this with the customStyles deprecation\n const fontStyles = {\n fontFamily: styles.fontFamily,\n fontSize: styles.fontSize,\n fontWeight: styles.fontWeight,\n };\n\n // We only calculate the background color if there's not an avatar\n // picture. If there is a picture, it might have a transparent\n // background and we don't know whether the calculated background\n // color will clash.\n const classes = useStyles(\n !picture ? { backgroundColor: stringToColor(displayName || '') } : {},\n );\n\n const avatarClassNames = classNames(props.classes?.avatar, classes.avatar);\n const avatarTextClassNames = classNames(\n props.classes?.avatarText,\n classes.avatarText,\n );\n\n return (\n <MaterialAvatar\n alt={displayName}\n src={picture}\n className={avatarClassNames}\n style={styles}\n >\n {displayName && (\n <Typography\n variant=\"h6\"\n component=\"span\"\n className={avatarTextClassNames}\n style={fontStyles}\n >\n {extractInitials(displayName)}\n </Typography>\n )}\n </MaterialAvatar>\n );\n}\n"],"names":[],"mappings":";;;;;;;AA0BA,MAAM,SAAY,GAAA,UAAA;AAAA,EAChB,CAAC,KAAkB,MAAA;AAAA,IACjB,MAAQ,EAAA;AAAA,MACN,KAAO,EAAA,MAAA;AAAA,MACP,MAAQ,EAAA,MAAA;AAAA,MACR,KAAA,EAAO,KAAM,CAAA,OAAA,CAAQ,MAAO,CAAA,KAAA;AAAA,MAC5B,eAAA,EAAiB,CAAC,KAAA,KAChB,KAAM,CAAA,eAAA;AAAA,KACV;AAAA,IACA,UAAY,EAAA;AAAA,MACV,UAAA,EAAY,MAAM,UAAW,CAAA,cAAA;AAAA,MAC7B,aAAe,EAAA,KAAA;AAAA,MACf,aAAe,EAAA,WAAA;AAAA,KACjB;AAAA,GACF,CAAA;AAAA,EACA,EAAE,MAAM,iBAAkB,EAAA;AAC5B,CAAA,CAAA;AAoCO,SAAS,OAAO,KAAoB,EAAA;AA9E3C,EAAA,IAAA,EAAA,EAAA,EAAA,CAAA;AA+EE,EAAA,MAAM,EAAE,WAAA,EAAa,OAAS,EAAA,YAAA,EAAiB,GAAA,KAAA,CAAA;AAC/C,EAAM,MAAA,MAAA,GAAS,EAAE,GAAG,YAAa,EAAA,CAAA;AAGjC,EAAA,MAAM,UAAa,GAAA;AAAA,IACjB,YAAY,MAAO,CAAA,UAAA;AAAA,IACnB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7
|
+
for (let i = 0; i < 3; i++) {
|
|
8
|
+
const value = hash >> i * 8 & 255;
|
|
9
|
+
color += `00${value.toString(16)}`.slice(-2);
|
|
10
|
+
}
|
|
11
|
+
return color;
|
|
12
|
+
}
|
|
13
|
+
function extractInitials(name) {
|
|
14
|
+
var _a;
|
|
15
|
+
const names = name.trim().split(" ");
|
|
16
|
+
const firstName = (_a = names[0]) != null ? _a : "";
|
|
17
|
+
const lastName = names.length > 1 ? names[names.length - 1] : "";
|
|
18
|
+
return firstName && lastName ? `${firstName.charAt(0)}${lastName.charAt(0)}` : firstName.charAt(0);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { extractInitials, stringToColor };
|
|
22
|
+
//# sourceMappingURL=utils.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.esm.js","sources":["../../../src/components/Avatar/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 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\nexport function stringToColor(str: string) {\n let hash = 0;\n for (let i = 0; i < str.length; i++) {\n hash = str.charCodeAt(i) + ((hash << 5) - hash);\n }\n let color = '#';\n for (let i = 0; i < 3; i++) {\n const value = (hash >> (i * 8)) & 0xff;\n color += `00${value.toString(16)}`.slice(-2);\n }\n return color;\n}\n\nexport function extractInitials(name: string) {\n const names = name.trim().split(' ');\n const firstName = names[0] ?? '';\n const lastName = names.length > 1 ? names[names.length - 1] : '';\n return firstName && lastName\n ? `${firstName.charAt(0)}${lastName.charAt(0)}`\n : firstName.charAt(0);\n}\n"],"names":[],"mappings":"AAgBO,SAA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