@camunda/camunda-composite-components 0.1.1 → 0.1.2

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.
Files changed (70) hide show
  1. package/README.md +60 -0
  2. package/lib/esm/api/api.d.ts +19 -19
  3. package/lib/esm/api/api.js +67 -65
  4. package/lib/esm/api/endpoints.const.d.ts +12 -12
  5. package/lib/esm/api/endpoints.const.js +25 -24
  6. package/lib/esm/api/jwt.utils.d.ts +3 -3
  7. package/lib/esm/api/jwt.utils.js +21 -23
  8. package/lib/esm/api/notifications.d.ts +35 -64
  9. package/lib/esm/api/notifications.js +159 -168
  10. package/lib/esm/components/c3-empty-state/c3-empty-state.d.ts +2 -9
  11. package/lib/esm/components/c3-empty-state/c3-empty-state.js +17 -58
  12. package/lib/esm/components/c3-empty-state/c3-empty-state.test.d.ts +1 -0
  13. package/lib/esm/components/c3-empty-state/c3-empty-state.test.js +12 -0
  14. package/lib/esm/components/c3-empty-state/c3-empty-state.types.d.ts +19 -19
  15. package/lib/esm/components/c3-empty-state/c3-empty-state.types.js +1 -1
  16. package/lib/esm/components/c3-navigation/c3-info-button.d.ts +3 -3
  17. package/lib/esm/components/c3-navigation/c3-info-button.js +5 -13
  18. package/lib/esm/components/c3-navigation/c3-navigation-actions/c3-action-buttons.d.ts +5 -5
  19. package/lib/esm/components/c3-navigation/c3-navigation-actions/c3-action-buttons.js +13 -21
  20. package/lib/esm/components/c3-navigation/c3-navigation-actions/c3-action-buttons.types.d.ts +10 -6
  21. package/lib/esm/components/c3-navigation/c3-navigation-actions/c3-action-buttons.types.js +1 -1
  22. package/lib/esm/components/c3-navigation/c3-navigation-appbar.d.ts +3 -3
  23. package/lib/esm/components/c3-navigation/c3-navigation-appbar.js +68 -157
  24. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-info-sidebar.d.ts +5 -5
  25. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-info-sidebar.js +39 -62
  26. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar-element.d.ts +9 -10
  27. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar-element.js +33 -56
  28. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar.d.ts +9 -9
  29. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar.js +57 -110
  30. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar.types.d.ts +61 -72
  31. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar.types.js +1 -1
  32. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-notification-sidebar.d.ts +4 -4
  33. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-notification-sidebar.js +88 -142
  34. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-org-sidebar.d.ts +5 -5
  35. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-org-sidebar.js +51 -105
  36. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-sidebar-state-provider.d.ts +24 -26
  37. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-sidebar-state-provider.js +25 -38
  38. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-user-sidebar.d.ts +5 -5
  39. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-user-sidebar.js +57 -146
  40. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/components.d.ts +2 -8
  41. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/components.js +4 -4
  42. package/lib/esm/components/c3-navigation/c3-navigation.d.ts +2 -14
  43. package/lib/esm/components/c3-navigation/c3-navigation.js +90 -214
  44. package/lib/esm/components/c3-navigation/c3-navigation.test.d.ts +1 -0
  45. package/lib/esm/components/c3-navigation/c3-navigation.test.js +80 -0
  46. package/lib/esm/components/c3-navigation/c3-navigation.types.d.ts +63 -70
  47. package/lib/esm/components/c3-navigation/c3-navigation.types.js +1 -1
  48. package/lib/esm/components/c3-navigation/c3-notification-provider/c3-notification-container.d.ts +13 -30
  49. package/lib/esm/components/c3-navigation/c3-notification-provider/c3-notification-container.js +70 -114
  50. package/lib/esm/components/c3-navigation/c3-notification-provider/c3-notification-provider.d.ts +27 -29
  51. package/lib/esm/components/c3-navigation/c3-notification-provider/c3-notification-provider.js +90 -118
  52. package/lib/esm/components/c3-navigation/helpers.d.ts +3 -5
  53. package/lib/esm/components/c3-navigation/helpers.js +49 -53
  54. package/lib/esm/components/c3-navigation/index.d.ts +2 -4
  55. package/lib/esm/components/c3-navigation/index.js +3 -3
  56. package/lib/esm/components/c3-navigation/story-helpers.d.ts +18 -24
  57. package/lib/esm/components/c3-navigation/story-helpers.js +197 -200
  58. package/lib/esm/components/c3-navigation/story-templates.d.ts +8 -8
  59. package/lib/esm/components/c3-navigation/story-templates.js +33 -66
  60. package/lib/esm/components/c3-user-configuration/c3-user-configuration-provider.d.ts +16 -20
  61. package/lib/esm/components/c3-user-configuration/c3-user-configuration-provider.js +4 -9
  62. package/lib/esm/components/test-utils.d.ts +3 -0
  63. package/lib/esm/components/test-utils.js +22 -0
  64. package/lib/esm/icons/c3-icons.d.ts +5 -8
  65. package/lib/esm/icons/c3-icons.js +14 -82
  66. package/lib/esm/icons/c3-icons.types.d.ts +1 -1
  67. package/lib/esm/icons/c3-icons.types.js +1 -1
  68. package/lib/esm/index.d.ts +9 -14
  69. package/lib/esm/index.js +4 -4
  70. package/package.json +30 -20
@@ -1,121 +1,68 @@
1
- import {
2
- Button,
3
- HeaderGlobalAction,
4
- HeaderPanel as CarbonHeaderPanel,
5
- Stack,
6
- SwitcherDivider,
7
- } from "@carbon/react"
8
- import React from "react"
9
- import { useOnClickOutside } from "../helpers"
10
- import C3NavigationSidebarElement from "./c3-navigation-sidebar-element"
11
- import styled from "styled-components"
12
- import { useSidebarState } from "./c3-sidebar-state-provider"
13
- const Wrapper = styled.div`
1
+ import { Button, HeaderGlobalAction, HeaderPanel as CarbonHeaderPanel, Stack, SwitcherDivider, } from "@carbon/react";
2
+ import React from "react";
3
+ import { useOnClickOutside } from "../helpers";
4
+ import C3NavigationSidebarElement from "./c3-navigation-sidebar-element";
5
+ import styled from "styled-components";
6
+ import { useSidebarState } from "./c3-sidebar-state-provider";
7
+ const Wrapper = styled.div `
14
8
  .cds--popover * {
15
9
  z-index: 9000;
16
10
  }
17
- `
18
- const HeaderPanel = styled(CarbonHeaderPanel)`
11
+ `;
12
+ const HeaderPanel = styled(CarbonHeaderPanel) `
19
13
  visibility: ${({ expanded }) => (expanded ? "visible" : "hidden")};
20
14
  display: grid;
21
15
  grid-auto-flow: row;
22
16
  grid-auto-rows: max-content 1fr;
23
17
  overflow-y: auto;
24
18
  overflow-x: hidden;
25
- `
26
- const BottomElements = styled.div`
19
+ `;
20
+ const BottomElements = styled.div `
27
21
  align-self: end;
28
- `
22
+ `;
29
23
  const C3NavigationSideBar = (props) => {
30
- const { icon, sideBar, children, version, bottomChildren } = props
31
- const { callbacks, onOpen } = sideBar
32
- const { isOpen, setIsOpen: setOpenState } = useSidebarState()[sideBar.type]
33
- const setIsOpen = (open) => {
34
- if (open) {
35
- callbacks?.beforeOpening?.()
36
- onOpen?.()
37
- }
38
- setOpenState(open)
39
- if (!open) callbacks?.afterClosing?.()
40
- }
41
- const itemTabIndex = isOpen ? undefined : -1
42
- const [panelRef, iconRef] = useOnClickOutside(() => setIsOpen(false))
43
- const id = `c3-${sideBar.type}-sidebar`
44
- return React.createElement(
45
- Wrapper,
46
- null,
47
- React.createElement(
48
- HeaderGlobalAction,
49
- {
50
- ref: iconRef,
51
- "aria-label": `Open ${sideBar.ariaLabel}`,
52
- "aria-expanded": isOpen,
53
- "aria-controls": id,
54
- onClick: () => {
55
- setIsOpen(!isOpen)
56
- },
57
- isActive: isOpen,
58
- tooltipAlignment: sideBar.type === "user" ? "end" : "center",
59
- /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
60
- /* @ts-ignore */
61
- leaveDelayMs: 100,
62
- },
63
- icon,
64
- ),
65
- React.createElement(
66
- HeaderPanel,
67
- { ref: panelRef, expanded: isOpen, id: id },
68
- React.createElement(
69
- Stack,
70
- null,
71
- children,
72
- sideBar.elements &&
73
- sideBar.elements.length > 0 &&
74
- "customElements" in sideBar &&
75
- sideBar.customElements &&
76
- "activeOrganization" in sideBar.customElements &&
77
- !sideBar.customElements?.activeOrganization &&
78
- React.createElement(SwitcherDivider, null),
79
- sideBar.elements?.map((element, index) =>
80
- React.createElement(C3NavigationSidebarElement, {
81
- key: element.key,
82
- element: element,
83
- index: index,
84
- sideBar: sideBar,
85
- setSideBarOpen: setIsOpen,
86
- itemTabIndex: itemTabIndex,
87
- }),
88
- ),
89
- bottomChildren,
90
- ),
91
- version,
92
- React.createElement(
93
- BottomElements,
94
- null,
95
- sideBar.bottomElements &&
96
- sideBar.bottomElements.map((element) =>
97
- React.createElement(
98
- Button,
99
- {
100
- kind: element.kind,
101
- key: element.key,
102
- className: "cds--switcher__item",
103
- renderIcon: element.renderIcon,
104
- onClick: () => {
105
- if (element.onClick) {
106
- element.onClick()
107
- }
108
- if (sideBar.closeOnClick !== false) {
109
- setIsOpen(false)
110
- }
111
- },
112
- tabIndex: itemTabIndex,
113
- },
114
- element.label,
115
- ),
116
- ),
117
- ),
118
- ),
119
- )
120
- }
121
- export default C3NavigationSideBar
24
+ const { icon, sideBar, children, version, bottomChildren } = props;
25
+ const { callbacks, onOpen } = sideBar;
26
+ const { isOpen, setIsOpen: setOpenState } = useSidebarState()[sideBar.type];
27
+ const setIsOpen = (open) => {
28
+ if (open) {
29
+ callbacks?.beforeOpening?.();
30
+ onOpen?.();
31
+ }
32
+ setOpenState(open);
33
+ if (!open)
34
+ callbacks?.afterClosing?.();
35
+ };
36
+ const itemTabIndex = isOpen ? undefined : -1;
37
+ const [panelRef, iconRef] = useOnClickOutside(() => setIsOpen(false));
38
+ const id = `c3-${sideBar.type}-sidebar`;
39
+ return (React.createElement(Wrapper, null,
40
+ React.createElement(HeaderGlobalAction, { ref: iconRef, "aria-label": `Open ${sideBar.ariaLabel}`, "aria-expanded": isOpen, "aria-controls": id, onClick: () => {
41
+ setIsOpen(!isOpen);
42
+ }, isActive: isOpen, tooltipAlignment: sideBar.type === "user" ? "end" : "center",
43
+ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
44
+ /* @ts-ignore */
45
+ leaveDelayMs: 100 }, icon),
46
+ React.createElement(HeaderPanel, { ref: panelRef, expanded: isOpen, id: id },
47
+ React.createElement(Stack, null,
48
+ children,
49
+ sideBar.elements &&
50
+ sideBar.elements.length > 0 &&
51
+ "customElements" in sideBar &&
52
+ sideBar.customElements &&
53
+ "activeOrganization" in sideBar.customElements &&
54
+ !sideBar.customElements?.activeOrganization && React.createElement(SwitcherDivider, null),
55
+ sideBar.elements?.map((element, index) => (React.createElement(C3NavigationSidebarElement, { key: element.key, element: element, index: index, sideBar: sideBar, setSideBarOpen: setIsOpen, itemTabIndex: itemTabIndex }))),
56
+ bottomChildren),
57
+ version,
58
+ React.createElement(BottomElements, null, sideBar.bottomElements &&
59
+ sideBar.bottomElements.map((element) => (React.createElement(Button, { kind: element.kind, key: element.key, className: "cds--switcher__item", renderIcon: element.renderIcon, onClick: () => {
60
+ if (element.onClick) {
61
+ element.onClick();
62
+ }
63
+ if (sideBar.closeOnClick !== false) {
64
+ setIsOpen(false);
65
+ }
66
+ }, tabIndex: itemTabIndex }, element.label)))))));
67
+ };
68
+ export default C3NavigationSideBar;
@@ -1,75 +1,64 @@
1
- /// <reference types="react" />
2
- import { C3NavigationElementProps } from "../c3-navigation.types"
3
- import { Notification } from "../../../api/notifications"
1
+ import { C3NavigationElementProps } from "../c3-navigation.types";
2
+ import { Notification } from "../../../api/notifications";
4
3
  export declare type C3NavigationSideBarBaseProps = {
5
- ariaLabel?: string
6
- isOpen?: boolean
7
- onOpen?: () => void
8
- closeOnClick?: boolean
9
- elementClicked?: (key: string) => void
10
- elements?: C3NavigationElementProps[]
11
- bottomElements?: C3NavigationElementProps[]
12
- }
13
- export declare type C3NavigationOrgSideBarProps =
14
- C3NavigationSideBarBaseProps & {
15
- type: "org"
16
- customElements?: {
17
- activeOrganization?: {
18
- activeLabel: string
19
- otherLabel: string
20
- orgName: string
21
- action: {
22
- label: string
23
- onClick: () => void
24
- }
25
- }
26
- }
27
- }
28
- export declare type C3NavigationInfoSideBarProps =
29
- C3NavigationSideBarBaseProps & {
30
- type: "info"
31
- version?: string
32
- }
33
- export declare type C3NavigationUserSideBarProps =
34
- C3NavigationSideBarBaseProps & {
35
- type: "user"
36
- version?: string
37
- customElements?: {
38
- customSection?: JSX.Element
39
- profile?: {
40
- label: string
41
- user: {
42
- name: string
43
- email: string
44
- }
45
- }
46
- themeSelector?: {
47
- currentTheme: string
48
- onChange: (newValue: string) => void
49
- }
50
- stageToggle?: {
51
- prodFeaturesEnabled: boolean
52
- toggle: () => void
53
- }
54
- }
55
- }
56
- export declare type C3NavigationNotificationsSideBarProps =
57
- C3NavigationSideBarBaseProps & {
58
- type: "notifications"
59
- onLinkClick?: (meta: Notification["meta"]) => void
60
- }
4
+ ariaLabel?: string;
5
+ isOpen?: boolean;
6
+ onOpen?: () => void;
7
+ closeOnClick?: boolean;
8
+ elementClicked?: (key: string) => void;
9
+ elements?: C3NavigationElementProps[];
10
+ bottomElements?: C3NavigationElementProps[];
11
+ };
12
+ export declare type C3NavigationOrgSideBarProps = C3NavigationSideBarBaseProps & {
13
+ type: "org";
14
+ customElements?: {
15
+ activeOrganization?: {
16
+ activeLabel: string;
17
+ otherLabel: string;
18
+ orgName: string;
19
+ action: {
20
+ label: string;
21
+ onClick: () => void;
22
+ };
23
+ };
24
+ };
25
+ };
26
+ export declare type C3NavigationInfoSideBarProps = C3NavigationSideBarBaseProps & {
27
+ type: "info";
28
+ version?: string;
29
+ };
30
+ export declare type C3NavigationUserSideBarProps = C3NavigationSideBarBaseProps & {
31
+ type: "user";
32
+ version?: string;
33
+ customElements?: {
34
+ customSection?: JSX.Element;
35
+ profile?: {
36
+ label: string;
37
+ user: {
38
+ name: string;
39
+ email: string;
40
+ };
41
+ };
42
+ themeSelector?: {
43
+ currentTheme: string;
44
+ onChange: (newValue: string) => void;
45
+ };
46
+ stageToggle?: {
47
+ prodFeaturesEnabled: boolean;
48
+ toggle: () => void;
49
+ };
50
+ };
51
+ };
52
+ export declare type C3NavigationNotificationsSideBarProps = C3NavigationSideBarBaseProps & {
53
+ type: "notifications";
54
+ onLinkClick?: (meta: Notification["meta"]) => void;
55
+ };
61
56
  export declare type C3NavigationAppBarProps = C3NavigationSideBarBaseProps & {
62
- type: "app"
63
- }
57
+ type: "app";
58
+ };
64
59
  export declare type C3NavigationSideBarProps = {
65
- callbacks?: {
66
- beforeOpening?: () => void
67
- afterClosing?: () => void
68
- }
69
- } & (
70
- | C3NavigationOrgSideBarProps
71
- | C3NavigationInfoSideBarProps
72
- | C3NavigationUserSideBarProps
73
- | C3NavigationNotificationsSideBarProps
74
- | C3NavigationAppBarProps
75
- )
60
+ callbacks?: {
61
+ beforeOpening?: () => void;
62
+ afterClosing?: () => void;
63
+ };
64
+ } & (C3NavigationOrgSideBarProps | C3NavigationInfoSideBarProps | C3NavigationUserSideBarProps | C3NavigationNotificationsSideBarProps | C3NavigationAppBarProps);
@@ -1,5 +1,5 @@
1
- import { FC } from "react"
2
- import { C3NavigationNotificationsSideBarProps } from "./c3-navigation-sidebar.types"
1
+ import { FC } from "react";
2
+ import { C3NavigationNotificationsSideBarProps } from "./c3-navigation-sidebar.types";
3
3
  export declare const C3NotificationSidebar: FC<{
4
- sideBar: C3NavigationNotificationsSideBarProps
5
- }>
4
+ sideBar: C3NavigationNotificationsSideBarProps;
5
+ }>;
@@ -1,16 +1,13 @@
1
- import { Button } from "@carbon/react"
2
- import { Notification as NotificationIcon } from "@carbon/react/icons"
3
- import React, { useContext, useEffect, useRef, useState } from "react"
4
- import styled from "styled-components"
5
- import { C3BellIcon, C3NotificationsUnreadIcon } from "../../../icons/c3-icons"
6
- import C3NotificationContainer, {
7
- NotificationDescription,
8
- NotificationTitle,
9
- } from "../c3-notification-provider/c3-notification-container"
10
- import { C3NotificationContext } from "../c3-notification-provider/c3-notification-provider"
11
- import C3NavigationSideBar from "./c3-navigation-sidebar"
12
- import { useNotificationSidebarState } from "./c3-sidebar-state-provider"
13
- const PanelHeader = styled.div`
1
+ import { Button } from "@carbon/react";
2
+ import { Notification as NotificationIcon } from "@carbon/react/icons";
3
+ import React, { useContext, useEffect, useRef, useState } from "react";
4
+ import styled from "styled-components";
5
+ import { C3BellIcon, C3NotificationsUnreadIcon } from "../../../icons/c3-icons";
6
+ import C3NotificationContainer, { NotificationDescription, NotificationTitle, } from "../c3-notification-provider/c3-notification-container";
7
+ import { C3NotificationContext } from "../c3-notification-provider/c3-notification-provider";
8
+ import C3NavigationSideBar from "./c3-navigation-sidebar";
9
+ import { useNotificationSidebarState } from "./c3-sidebar-state-provider";
10
+ const PanelHeader = styled.div `
14
11
  background: var(--cds-layer-01);
15
12
  box-shadow: inset 0px -1px 0px var(--cds-border-subtle-01);
16
13
  width: 100%;
@@ -20,146 +17,95 @@ const PanelHeader = styled.div`
20
17
  flex-direction: row;
21
18
  justify-content: space-between;
22
19
  align-items: center;
23
- `
24
- const PanelTitle = styled.span`
20
+ `;
21
+ const PanelTitle = styled.span `
25
22
  color: var(--cds-text-primary);
26
23
  font-size: var(--cds-body-01-font-size);
27
24
  font-weight: var(--cds-body-01-font-weight);
28
25
  line-height: var(--cds-body-01-line-height);
29
26
  letter-spacing: var(--cds-body-01-letter-spacing);
30
- `
31
- const DismissAllButton = styled(Button)`
27
+ `;
28
+ const DismissAllButton = styled(Button) `
32
29
  font-size: var(--cds-helper-text-01-font-size);
33
30
  font-weight: var(--cds-helper-text-01-font-weight);
34
31
  line-height: var(--cds-helper-text-01-line-height);
35
32
  letter-spacing: var(--cds-helper-text-01-letter-spacing);
36
- `
37
- const EmptyState = styled.div`
33
+ `;
34
+ const EmptyState = styled.div `
38
35
  padding: 16px;
39
- `
40
- const EmptyStateTitle = styled(NotificationTitle)`
36
+ `;
37
+ const EmptyStateTitle = styled(NotificationTitle) `
41
38
  margin-top: 24px;
42
- `
43
- const EmptyStateDescription = styled(NotificationDescription)`
39
+ `;
40
+ const EmptyStateDescription = styled(NotificationDescription) `
44
41
  color: var(--cds-text-secondary);
45
42
  margin-top: 8px;
46
- `
43
+ `;
47
44
  export const C3NotificationSidebar = ({ sideBar }) => {
48
- const { onLinkClick } = sideBar
49
- const {
50
- notifications,
51
- markAsRead,
52
- dismiss,
53
- markAllAsRead,
54
- dismissAll,
55
- analytics,
56
- enabled,
57
- } = useContext(C3NotificationContext)
58
- const [unreadNotifications, setUnreadNotifications] = useState([])
59
- const hasUnreadNotifications = notifications.some(
60
- ({ state }) => state === "new",
61
- )
62
- const { isOpen } = useNotificationSidebarState()
63
- const notificationsRef = useRef()
64
- notificationsRef.current = notifications
65
- const markAllAsReadSidebar = () => {
66
- const newNotifications = notificationsRef.current?.filter(
67
- (notification) => notification.state === "new",
68
- )
69
- if (newNotifications) markAllAsRead(newNotifications)
70
- }
71
- const dismissAllSidebar = () => dismissAll(notifications)
72
- const beforeOpening = () => {
73
- // remember new notifications, so the dots can be displayed
74
- if (notificationsRef.current)
75
- setUnreadNotifications(
76
- notificationsRef.current
77
- .filter(({ state }) => state === "new")
78
- .map(({ uuid }) => uuid),
79
- )
80
- markAllAsReadSidebar()
81
- if (enabled && analytics) {
82
- analytics("notification-panel-opened")
83
- }
84
- }
85
- const afterClosing = () => {
86
- markAllAsReadSidebar()
87
- setUnreadNotifications([])
88
- }
89
- const sortNotificationsDescending = (a, b) => {
90
- if (new Date(a.timestamp) > new Date(b.timestamp)) return -1
91
- return 0
92
- }
93
- useEffect(() => {
94
- // mark notifications as read on unmount
95
- return () => {
96
- if (isOpen) markAllAsReadSidebar()
97
- }
98
- }, [])
99
- return React.createElement(
100
- C3NavigationSideBar,
101
- {
102
- sideBar: {
103
- ...sideBar,
104
- ariaLabel: sideBar.ariaLabel || "Notification Sidebar",
105
- callbacks: { beforeOpening, afterClosing },
106
- },
107
- icon: hasUnreadNotifications
108
- ? React.createElement(C3NotificationsUnreadIcon, { size: 20 })
109
- : React.createElement(NotificationIcon, {
110
- size: 20,
111
- label: "Notifications",
112
- }),
113
- },
114
- React.createElement(
115
- PanelHeader,
116
- null,
117
- React.createElement(PanelTitle, null, "Notifications"),
118
- notifications.length > 0 &&
119
- // eslint-disable-next-line
120
- // @ts-ignore
121
- React.createElement(
122
- DismissAllButton,
123
- { kind: "ghost", size: "sm", onClick: dismissAllSidebar },
124
- "Dismiss all",
125
- ),
126
- ),
127
- notifications.length > 0
128
- ? notifications.sort(sortNotificationsDescending).map((notification) =>
129
- React.createElement(C3NotificationContainer, {
130
- key: notification.uuid,
131
- onRead: () => {
132
- if (notification.state === "new") {
133
- markAsRead(notification)
134
- }
135
- },
136
- onDismiss: () => dismiss(notification),
137
- originalOnLinkClick: onLinkClick,
138
- onLinkClick: () => {
139
- if (enabled && analytics) {
140
- analytics(
141
- "notification-clicked-cta",
142
- notification.meta?.identifier,
143
- )
144
- }
145
- if (onLinkClick) {
146
- onLinkClick(notification.meta)
147
- }
148
- },
149
- unread: unreadNotifications.some((id) => id === notification.uuid),
150
- ...notification,
151
- }),
152
- )
153
- : React.createElement(
154
- EmptyState,
155
- null,
156
- React.createElement(C3BellIcon, { size: 56 }),
157
- React.createElement(EmptyStateTitle, null, "No notifications"),
158
- React.createElement(
159
- EmptyStateDescription,
160
- null,
161
- "New updates regarding your processes, clusters and more will appear here.",
162
- ),
163
- ),
164
- )
165
- }
45
+ const { onLinkClick } = sideBar;
46
+ const { notifications, markAsRead, dismiss, markAllAsRead, dismissAll, analytics, enabled, } = useContext(C3NotificationContext);
47
+ const [unreadNotifications, setUnreadNotifications] = useState([]);
48
+ const hasUnreadNotifications = notifications.some(({ state }) => state === "new");
49
+ const { isOpen } = useNotificationSidebarState();
50
+ const notificationsRef = useRef();
51
+ notificationsRef.current = notifications;
52
+ const markAllAsReadSidebar = () => {
53
+ const newNotifications = notificationsRef.current?.filter((notification) => notification.state === "new");
54
+ if (newNotifications)
55
+ markAllAsRead(newNotifications);
56
+ };
57
+ const dismissAllSidebar = () => dismissAll(notifications);
58
+ const beforeOpening = () => {
59
+ // remember new notifications, so the dots can be displayed
60
+ if (notificationsRef.current)
61
+ setUnreadNotifications(notificationsRef.current
62
+ .filter(({ state }) => state === "new")
63
+ .map(({ uuid }) => uuid));
64
+ markAllAsReadSidebar();
65
+ if (enabled && analytics) {
66
+ analytics("notification-panel-opened");
67
+ }
68
+ };
69
+ const afterClosing = () => {
70
+ markAllAsReadSidebar();
71
+ setUnreadNotifications([]);
72
+ };
73
+ const sortNotificationsDescending = (a, b) => {
74
+ if (new Date(a.timestamp) > new Date(b.timestamp))
75
+ return -1;
76
+ return 0;
77
+ };
78
+ useEffect(() => {
79
+ // mark notifications as read on unmount
80
+ return () => {
81
+ if (isOpen)
82
+ markAllAsReadSidebar();
83
+ };
84
+ }, []);
85
+ return (React.createElement(C3NavigationSideBar, { sideBar: {
86
+ ...sideBar,
87
+ ariaLabel: sideBar.ariaLabel || "Notification Sidebar",
88
+ callbacks: { beforeOpening, afterClosing },
89
+ }, icon: hasUnreadNotifications ? (React.createElement(C3NotificationsUnreadIcon, { size: 20 })) : (React.createElement(NotificationIcon, { size: 20, label: "Notifications" })) },
90
+ React.createElement(PanelHeader, null,
91
+ React.createElement(PanelTitle, null, "Notifications"),
92
+ notifications.length > 0 && (
93
+ // eslint-disable-next-line
94
+ // @ts-ignore
95
+ React.createElement(DismissAllButton, { kind: "ghost", size: "sm", onClick: dismissAllSidebar }, "Dismiss all"))),
96
+ notifications.length > 0 ? (notifications.sort(sortNotificationsDescending).map((notification) => (React.createElement(C3NotificationContainer, { key: notification.uuid, onRead: () => {
97
+ if (notification.state === "new") {
98
+ markAsRead(notification);
99
+ }
100
+ }, onDismiss: () => dismiss(notification), originalOnLinkClick: onLinkClick, onLinkClick: () => {
101
+ if (enabled && analytics) {
102
+ analytics("notification-clicked-cta", notification.meta?.identifier);
103
+ }
104
+ if (onLinkClick) {
105
+ onLinkClick(notification.meta);
106
+ }
107
+ }, unread: unreadNotifications.some((id) => id === notification.uuid), ...notification })))) : (React.createElement(EmptyState, null,
108
+ React.createElement(C3BellIcon, { size: 56 }),
109
+ React.createElement(EmptyStateTitle, null, "No notifications"),
110
+ React.createElement(EmptyStateDescription, null, "New updates regarding your processes, clusters and more will appear here.")))));
111
+ };
@@ -1,6 +1,6 @@
1
- import { FC } from "react"
2
- import { C3NavigationOrgSideBarProps } from "./c3-navigation-sidebar.types"
1
+ import { FC } from "react";
2
+ import { C3NavigationOrgSideBarProps } from "./c3-navigation-sidebar.types";
3
3
  declare const C3OrgSidebar: FC<{
4
- sideBar: C3NavigationOrgSideBarProps
5
- }>
6
- export default C3OrgSidebar
4
+ sideBar: C3NavigationOrgSideBarProps;
5
+ }>;
6
+ export default C3OrgSidebar;