@camunda/camunda-composite-components 0.0.41 → 0.0.42

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 (64) hide show
  1. package/README.md +2 -1
  2. package/lib/esm/api/api.d.ts +19 -19
  3. package/lib/esm/api/api.js +65 -67
  4. package/lib/esm/api/endpoints.const.d.ts +12 -12
  5. package/lib/esm/api/endpoints.const.js +24 -25
  6. package/lib/esm/api/jwt.utils.d.ts +3 -3
  7. package/lib/esm/api/jwt.utils.js +23 -21
  8. package/lib/esm/api/notifications.d.ts +64 -35
  9. package/lib/esm/api/notifications.js +168 -159
  10. package/lib/esm/components/c3-empty-state/c3-empty-state.d.ts +8 -2
  11. package/lib/esm/components/c3-empty-state/c3-empty-state.js +58 -17
  12. package/lib/esm/components/c3-empty-state/c3-empty-state.types.d.ts +19 -19
  13. package/lib/esm/components/c3-empty-state/c3-empty-state.types.js +1 -1
  14. package/lib/esm/components/c3-navigation/c3-info-button.d.ts +3 -3
  15. package/lib/esm/components/c3-navigation/c3-info-button.js +13 -5
  16. package/lib/esm/components/c3-navigation/c3-navigation-actions/c3-action-buttons.d.ts +5 -5
  17. package/lib/esm/components/c3-navigation/c3-navigation-actions/c3-action-buttons.js +21 -8
  18. package/lib/esm/components/c3-navigation/c3-navigation-actions/c3-action-buttons.types.d.ts +5 -5
  19. package/lib/esm/components/c3-navigation/c3-navigation-actions/c3-action-buttons.types.js +1 -1
  20. package/lib/esm/components/c3-navigation/c3-navigation-appbar.d.ts +3 -3
  21. package/lib/esm/components/c3-navigation/c3-navigation-appbar.js +157 -68
  22. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-info-sidebar.d.ts +5 -5
  23. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-info-sidebar.js +58 -37
  24. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar-element.d.ts +9 -9
  25. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar-element.js +56 -33
  26. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar.d.ts +8 -8
  27. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar.js +114 -54
  28. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar.types.d.ts +70 -60
  29. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar.types.js +1 -1
  30. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-notification-sidebar.d.ts +4 -4
  31. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-notification-sidebar.js +142 -88
  32. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-org-sidebar.d.ts +5 -5
  33. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-org-sidebar.js +105 -51
  34. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-sidebar-state-provider.d.ts +26 -24
  35. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-sidebar-state-provider.js +38 -25
  36. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-user-sidebar.d.ts +5 -5
  37. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/c3-user-sidebar.js +125 -43
  38. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/components.d.ts +6 -1
  39. package/lib/esm/components/c3-navigation/c3-navigation-sidebar/components.js +4 -4
  40. package/lib/esm/components/c3-navigation/c3-navigation.d.ts +13 -2
  41. package/lib/esm/components/c3-navigation/c3-navigation.js +210 -88
  42. package/lib/esm/components/c3-navigation/c3-navigation.types.d.ts +69 -63
  43. package/lib/esm/components/c3-navigation/c3-navigation.types.js +1 -1
  44. package/lib/esm/components/c3-navigation/c3-notification-provider/c3-notification-container.d.ts +30 -13
  45. package/lib/esm/components/c3-navigation/c3-notification-provider/c3-notification-container.js +114 -70
  46. package/lib/esm/components/c3-navigation/c3-notification-provider/c3-notification-provider.d.ts +29 -27
  47. package/lib/esm/components/c3-navigation/c3-notification-provider/c3-notification-provider.js +118 -90
  48. package/lib/esm/components/c3-navigation/helpers.d.ts +5 -3
  49. package/lib/esm/components/c3-navigation/helpers.js +53 -49
  50. package/lib/esm/components/c3-navigation/index.d.ts +4 -2
  51. package/lib/esm/components/c3-navigation/index.js +3 -3
  52. package/lib/esm/components/c3-navigation/story-helpers.d.ts +23 -18
  53. package/lib/esm/components/c3-navigation/story-helpers.js +189 -186
  54. package/lib/esm/components/c3-navigation/story-templates.d.ts +8 -8
  55. package/lib/esm/components/c3-navigation/story-templates.js +66 -33
  56. package/lib/esm/components/c3-user-configuration/c3-user-configuration-provider.d.ts +20 -16
  57. package/lib/esm/components/c3-user-configuration/c3-user-configuration-provider.js +9 -4
  58. package/lib/esm/icons/c3-icons.d.ts +7 -5
  59. package/lib/esm/icons/c3-icons.js +82 -14
  60. package/lib/esm/icons/c3-icons.types.d.ts +1 -1
  61. package/lib/esm/icons/c3-icons.types.js +1 -1
  62. package/lib/esm/index.d.ts +14 -9
  63. package/lib/esm/index.js +4 -4
  64. package/package.json +2 -1
@@ -1,64 +1,124 @@
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 `
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`
8
14
  .cds--popover * {
9
15
  z-index: 9000;
10
16
  }
11
- `;
12
- const HeaderPanel = styled(CarbonHeaderPanel) `
17
+ `
18
+ const HeaderPanel = styled(CarbonHeaderPanel)`
13
19
  visibility: ${({ expanded }) => (expanded ? "visible" : "hidden")};
14
20
  display: grid;
15
21
  grid-auto-flow: row;
16
22
  grid-auto-rows: max-content 1fr;
17
23
  overflow-y: auto;
18
24
  overflow-x: hidden;
19
- `;
25
+ `
26
+ const BottomElements = styled.div`
27
+ align-self: end;
28
+
29
+ button {
30
+ padding-top: 6px;
31
+ }
32
+ `
20
33
  const C3NavigationSideBar = (props) => {
21
- const { icon, sideBar, children, bottomChildren } = props;
22
- const { callbacks, onOpen } = sideBar;
23
- const { isOpen, setIsOpen: setOpenState } = useSidebarState()[sideBar.type];
24
- const setIsOpen = (open) => {
25
- if (open) {
26
- callbacks?.beforeOpening?.();
27
- onOpen?.();
28
- }
29
- setOpenState(open);
30
- if (!open)
31
- callbacks?.afterClosing?.();
32
- };
33
- const itemTabIndex = isOpen ? undefined : -1;
34
- const [panelRef, iconRef] = useOnClickOutside(() => setIsOpen(false));
35
- const id = `c3-${sideBar.type}-sidebar`;
36
- return (React.createElement(Wrapper, null,
37
- React.createElement(HeaderGlobalAction, { ref: iconRef, "aria-label": `Open ${sideBar.ariaLabel}`, "aria-expanded": isOpen, "aria-controls": id, onClick: () => {
38
- setIsOpen(!isOpen);
39
- }, isActive: isOpen, tooltipAlignment: sideBar.type === "user" ? "end" : "center",
40
- /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
41
- /* @ts-ignore */
42
- leaveDelayMs: 100 }, icon),
43
- React.createElement(HeaderPanel, { ref: panelRef, expanded: isOpen, id: id },
44
- React.createElement(Stack, null,
45
- children,
46
- sideBar.elements &&
47
- sideBar.elements.length > 0 &&
48
- "customElements" in sideBar &&
49
- sideBar.customElements &&
50
- "activeOrganization" in sideBar.customElements &&
51
- !sideBar.customElements?.activeOrganization && React.createElement(SwitcherDivider, null),
52
- sideBar.elements?.map((element, index) => (React.createElement(C3NavigationSidebarElement, { key: element.key, element: element, index: index, sideBar: sideBar, setSideBarOpen: setIsOpen, itemTabIndex: itemTabIndex }))),
53
- bottomChildren),
54
- sideBar.bottomElements &&
55
- sideBar.bottomElements.map((element) => (React.createElement(Button, { kind: element.kind, key: element.key, className: "cds--switcher__item", renderIcon: element.renderIcon, onClick: () => {
56
- if (element.onClick) {
57
- element.onClick();
58
- }
59
- if (sideBar.closeOnClick !== false) {
60
- setIsOpen(false);
61
- }
62
- }, style: { alignSelf: "end" }, tabIndex: itemTabIndex }, element.label))))));
63
- };
64
- export default C3NavigationSideBar;
34
+ const { icon, sideBar, children, bottomChildren } = props
35
+ const { callbacks, onOpen } = sideBar
36
+ const { isOpen, setIsOpen: setOpenState } = useSidebarState()[sideBar.type]
37
+ const setIsOpen = (open) => {
38
+ if (open) {
39
+ callbacks?.beforeOpening?.()
40
+ onOpen?.()
41
+ }
42
+ setOpenState(open)
43
+ if (!open) callbacks?.afterClosing?.()
44
+ }
45
+ const itemTabIndex = isOpen ? undefined : -1
46
+ const [panelRef, iconRef] = useOnClickOutside(() => setIsOpen(false))
47
+ const id = `c3-${sideBar.type}-sidebar`
48
+ return React.createElement(
49
+ Wrapper,
50
+ null,
51
+ React.createElement(
52
+ HeaderGlobalAction,
53
+ {
54
+ ref: iconRef,
55
+ "aria-label": `Open ${sideBar.ariaLabel}`,
56
+ "aria-expanded": isOpen,
57
+ "aria-controls": id,
58
+ onClick: () => {
59
+ setIsOpen(!isOpen)
60
+ },
61
+ isActive: isOpen,
62
+ tooltipAlignment: sideBar.type === "user" ? "end" : "center",
63
+ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
64
+ /* @ts-ignore */
65
+ leaveDelayMs: 100,
66
+ },
67
+ icon,
68
+ ),
69
+ React.createElement(
70
+ HeaderPanel,
71
+ { ref: panelRef, expanded: isOpen, id: id },
72
+ React.createElement(
73
+ Stack,
74
+ null,
75
+ children,
76
+ sideBar.elements &&
77
+ sideBar.elements.length > 0 &&
78
+ "customElements" in sideBar &&
79
+ sideBar.customElements &&
80
+ "activeOrganization" in sideBar.customElements &&
81
+ !sideBar.customElements?.activeOrganization &&
82
+ React.createElement(SwitcherDivider, null),
83
+ sideBar.elements?.map((element, index) =>
84
+ React.createElement(C3NavigationSidebarElement, {
85
+ key: element.key,
86
+ element: element,
87
+ index: index,
88
+ sideBar: sideBar,
89
+ setSideBarOpen: setIsOpen,
90
+ itemTabIndex: itemTabIndex,
91
+ }),
92
+ ),
93
+ bottomChildren,
94
+ ),
95
+ React.createElement(
96
+ BottomElements,
97
+ null,
98
+ sideBar.bottomElements &&
99
+ sideBar.bottomElements.map((element) =>
100
+ React.createElement(
101
+ Button,
102
+ {
103
+ kind: element.kind,
104
+ key: element.key,
105
+ className: "cds--switcher__item",
106
+ renderIcon: element.renderIcon,
107
+ onClick: () => {
108
+ if (element.onClick) {
109
+ element.onClick()
110
+ }
111
+ if (sideBar.closeOnClick !== false) {
112
+ setIsOpen(false)
113
+ }
114
+ },
115
+ tabIndex: itemTabIndex,
116
+ },
117
+ element.label,
118
+ ),
119
+ ),
120
+ ),
121
+ ),
122
+ )
123
+ }
124
+ export default C3NavigationSideBar
@@ -1,64 +1,74 @@
1
1
  /// <reference types="react" />
2
- import { C3NavigationElementProps } from "../c3-navigation.types";
3
- import { Notification } from "../../../api/notifications";
2
+ import { C3NavigationElementProps } from "../c3-navigation.types"
3
+ import { Notification } from "../../../api/notifications"
4
4
  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 = C3NavigationSideBarBaseProps & {
14
- type: "org";
15
- customElements?: {
16
- activeOrganization?: {
17
- activeLabel: string;
18
- otherLabel: string;
19
- orgName: string;
20
- action: {
21
- label: string;
22
- onClick: () => void;
23
- };
24
- };
25
- };
26
- };
27
- export declare type C3NavigationInfoSideBarProps = C3NavigationSideBarBaseProps & {
28
- type: "info";
29
- version?: string;
30
- };
31
- export declare type C3NavigationUserSideBarProps = C3NavigationSideBarBaseProps & {
32
- type: "user";
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
- };
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
+ customElements?: {
37
+ customSection?: JSX.Element
38
+ profile?: {
39
+ label: string
40
+ user: {
41
+ name: string
42
+ email: string
43
+ }
44
+ }
45
+ themeSelector?: {
46
+ currentTheme: string
47
+ onChange: (newValue: string) => void
48
+ }
49
+ stageToggle?: {
50
+ prodFeaturesEnabled: boolean
51
+ toggle: () => void
52
+ }
53
+ }
54
+ }
55
+ export declare type C3NavigationNotificationsSideBarProps =
56
+ C3NavigationSideBarBaseProps & {
57
+ type: "notifications"
58
+ onLinkClick?: (meta: Notification["meta"]) => void
59
+ }
56
60
  export declare type C3NavigationAppBarProps = C3NavigationSideBarBaseProps & {
57
- type: "app";
58
- };
61
+ type: "app"
62
+ }
59
63
  export declare type C3NavigationSideBarProps = {
60
- callbacks?: {
61
- beforeOpening?: () => void;
62
- afterClosing?: () => void;
63
- };
64
- } & (C3NavigationOrgSideBarProps | C3NavigationInfoSideBarProps | C3NavigationUserSideBarProps | C3NavigationNotificationsSideBarProps | C3NavigationAppBarProps);
64
+ callbacks?: {
65
+ beforeOpening?: () => void
66
+ afterClosing?: () => void
67
+ }
68
+ } & (
69
+ | C3NavigationOrgSideBarProps
70
+ | C3NavigationInfoSideBarProps
71
+ | C3NavigationUserSideBarProps
72
+ | C3NavigationNotificationsSideBarProps
73
+ | C3NavigationAppBarProps
74
+ )
@@ -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,13 +1,16 @@
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 `
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`
11
14
  background: var(--cds-layer-01);
12
15
  box-shadow: inset 0px -1px 0px var(--cds-border-subtle-01);
13
16
  width: 100%;
@@ -17,95 +20,146 @@ const PanelHeader = styled.div `
17
20
  flex-direction: row;
18
21
  justify-content: space-between;
19
22
  align-items: center;
20
- `;
21
- const PanelTitle = styled.span `
23
+ `
24
+ const PanelTitle = styled.span`
22
25
  color: var(--cds-text-primary);
23
26
  font-size: var(--cds-body-01-font-size);
24
27
  font-weight: var(--cds-body-01-font-weight);
25
28
  line-height: var(--cds-body-01-line-height);
26
29
  letter-spacing: var(--cds-body-01-letter-spacing);
27
- `;
28
- const DismissAllButton = styled(Button) `
30
+ `
31
+ const DismissAllButton = styled(Button)`
29
32
  font-size: var(--cds-helper-text-01-font-size);
30
33
  font-weight: var(--cds-helper-text-01-font-weight);
31
34
  line-height: var(--cds-helper-text-01-line-height);
32
35
  letter-spacing: var(--cds-helper-text-01-letter-spacing);
33
- `;
34
- const EmptyState = styled.div `
36
+ `
37
+ const EmptyState = styled.div`
35
38
  padding: 16px;
36
- `;
37
- const EmptyStateTitle = styled(NotificationTitle) `
39
+ `
40
+ const EmptyStateTitle = styled(NotificationTitle)`
38
41
  margin-top: 24px;
39
- `;
40
- const EmptyStateDescription = styled(NotificationDescription) `
42
+ `
43
+ const EmptyStateDescription = styled(NotificationDescription)`
41
44
  color: var(--cds-text-secondary);
42
45
  margin-top: 8px;
43
- `;
46
+ `
44
47
  export const C3NotificationSidebar = ({ sideBar }) => {
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
- };
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
+ }
@@ -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