@camunda/camunda-composite-components 0.0.29-np-rc13 → 0.0.29-np-rc15

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.
@@ -1,8 +1,8 @@
1
1
  export const NOTIFICATIONS = {
2
2
  id: "notifications",
3
3
  dev: "https://notifications.cloud.dev.ultrawombat.com",
4
- int: "todo",
5
- prod: "todo",
4
+ int: "https://notifications.cloud.ultrawombat.com",
5
+ prod: "https://notifications.cloud.camunda.io",
6
6
  };
7
7
  export function getEndpoint(stage, endpoint) {
8
8
  switch (stage) {
@@ -10,6 +10,7 @@ export interface Notification {
10
10
  description: string;
11
11
  state: string;
12
12
  meta?: {
13
+ identifier?: string;
13
14
  href?: string;
14
15
  label?: string;
15
16
  entity?: {
@@ -25,7 +26,9 @@ export interface Notification {
25
26
  export declare class NotificationService {
26
27
  static getNotifications(options: C3NotificationsProps): Promise<Notification[]>;
27
28
  static changeState(options: C3NotificationsProps, notificationId: string, operation: "read" | "dismiss"): void;
29
+ static changeManyStates(options: C3NotificationsProps, notificationIds: string[], operation: "read" | "dismiss"): void;
28
30
  static notificationsStream(options: C3NotificationsProps, handler: (notification: Notification) => void): void;
29
31
  static updateNotifications(allNotifications: Notification[], newNotification: Notification): Notification[];
30
32
  static updateNotificationState(allNotifications: Notification[], notificationId: string, newState: "read" | "dismiss"): Notification[];
33
+ static updateNotificationStates(allNotifications: Notification[], notificationIds: string[], newState: "read" | "dismiss"): Notification[];
31
34
  }
@@ -40,6 +40,27 @@ export class NotificationService {
40
40
  console.error(error);
41
41
  });
42
42
  }
43
+ static changeManyStates(options, notificationIds, operation) {
44
+ request({
45
+ method: "patch",
46
+ base: "notifications",
47
+ stage: options.stage,
48
+ camundaAuth: {
49
+ token: options.userToken,
50
+ refreshTokenMethod: options.getNewUserToken,
51
+ },
52
+ url: `notifications/batch/state/${operation}`,
53
+ body: {
54
+ uuids: notificationIds,
55
+ },
56
+ })
57
+ .then(() => {
58
+ // do nothing
59
+ })
60
+ .catch((error) => {
61
+ console.error(error);
62
+ });
63
+ }
43
64
  static notificationsStream(options, handler) {
44
65
  const source = new EventSourcePolyfill(`${getEndpoint(options.stage, NOTIFICATIONS)}/notifications/events`, {
45
66
  headers: {
@@ -88,4 +109,20 @@ export class NotificationService {
88
109
  }
89
110
  return updatedNotifications;
90
111
  }
112
+ static updateNotificationStates(allNotifications, notificationIds, newState) {
113
+ let updatedNotifications = allNotifications.slice();
114
+ let foundNotifications = [];
115
+ switch (newState) {
116
+ case "dismiss":
117
+ updatedNotifications = updatedNotifications.filter((notification) => !notificationIds.includes(notification.uuid));
118
+ break;
119
+ case "read":
120
+ foundNotifications = updatedNotifications.filter((notification) => !notificationIds.includes(notification.uuid));
121
+ foundNotifications.forEach((foundNotification) => {
122
+ foundNotification.state = newState;
123
+ });
124
+ break;
125
+ }
126
+ return updatedNotifications;
127
+ }
91
128
  }
@@ -1,10 +1,10 @@
1
1
  import { Button } from "@carbon/react";
2
2
  import { Notification as NotificationIcon } from "@carbon/react/icons";
3
3
  import React, { useContext, useEffect, useState } from "react";
4
+ import styled from "styled-components";
5
+ import { C3BellIcon, C3NotificationsUnreadIcon } from "../../../icons/c3-icons";
4
6
  import C3NotificationContainer, { NotificationDescription, NotificationTitle, } from "../c3-notification-provider/c3-notification-container";
5
7
  import { C3NotificationContext } from "../c3-notification-provider/c3-notification-provider";
6
- import { C3BellIcon, C3NotificationsUnreadIcon } from "../../../icons/c3-icons";
7
- import styled from "styled-components";
8
8
  import C3NavigationSideBar from "./c3-navigation-sidebar";
9
9
  const PanelHeader = styled.div `
10
10
  background: var(--cds-layer-01);
@@ -37,26 +37,25 @@ const EmptyStateDescription = styled(NotificationDescription) `
37
37
  export const C3NotificationSidebar = ({ sideBar }) => {
38
38
  const { isOpen, onLinkClick } = sideBar;
39
39
  const [isSidebarOpen, setIsSidebarOpen] = useState(isOpen);
40
- const { notifications, markAsRead, dismiss } = useContext(C3NotificationContext);
40
+ const { notifications, markAsRead, dismiss, markAllAsRead, dismissAll } = useContext(C3NotificationContext);
41
41
  const [unreadNotifications, setUnreadNotifications] = useState([]);
42
42
  const hasUnreadNotifications = notifications.some(({ state }) => state === "new");
43
- const markAllAsRead = () => notifications
44
- .filter((notification) => notification.state === "new")
45
- .forEach((notification) => {
46
- markAsRead(notification);
47
- });
48
- const dismissAll = () => notifications.forEach((notification) => dismiss(notification));
43
+ const markAllAsReadSidebar = () => {
44
+ const newNotifications = notifications.filter((notification) => notification.state === "new");
45
+ markAllAsRead(newNotifications);
46
+ };
47
+ const dismissAllSidebar = () => dismissAll(notifications);
49
48
  const setIsOpen = (open) => {
50
49
  if (open) {
51
50
  // remember new notifications, so the dots can be displayed
52
51
  setUnreadNotifications(notifications
53
52
  .filter(({ state }) => state === "new")
54
53
  .map(({ uuid }) => uuid));
55
- markAllAsRead();
54
+ markAllAsReadSidebar();
56
55
  }
57
56
  setIsSidebarOpen(open);
58
57
  if (!open) {
59
- markAllAsRead();
58
+ markAllAsReadSidebar();
60
59
  setUnreadNotifications([]);
61
60
  }
62
61
  };
@@ -69,7 +68,7 @@ export const C3NotificationSidebar = ({ sideBar }) => {
69
68
  // mark notifications as read on unmount
70
69
  return () => {
71
70
  if (isSidebarOpen)
72
- markAllAsRead();
71
+ markAllAsReadSidebar();
73
72
  };
74
73
  }, []);
75
74
  return (React.createElement(C3NavigationSideBar, { sideBar: {
@@ -79,7 +78,7 @@ export const C3NotificationSidebar = ({ sideBar }) => {
79
78
  }, icon: hasUnreadNotifications ? (React.createElement(C3NotificationsUnreadIcon, { size: 20 })) : (React.createElement(NotificationIcon, { size: 20, label: "Notifications" })) },
80
79
  React.createElement(PanelHeader, null,
81
80
  React.createElement(PanelTitle, null, "Notifications"),
82
- notifications.length > 0 && (React.createElement(Button, { kind: "ghost", size: "sm", onClick: dismissAll }, "Dismiss all"))),
81
+ notifications.length > 0 && (React.createElement(Button, { kind: "ghost", size: "sm", onClick: dismissAllSidebar }, "Dismiss all"))),
83
82
  notifications.length > 0 ? (notifications.sort(sortNotificationsDescending).map((notification) => (React.createElement(C3NotificationContainer, { key: notification.uuid, onRead: () => {
84
83
  if (notification.state === "new") {
85
84
  markAsRead(notification);
@@ -16,7 +16,9 @@ export declare type C3NotificationContextValue = {
16
16
  enabled: boolean;
17
17
  notifications: Notification[];
18
18
  markAsRead: (notification: Notification) => void;
19
+ markAllAsRead: (notifications: Notification[]) => void;
19
20
  dismiss: (notification: Notification) => void;
21
+ dismissAll: (notifications: Notification[]) => void;
20
22
  };
21
23
  export declare const C3NotificationContext: React.Context<C3NotificationContextValue>;
22
24
  export declare type C3NotificationProviderProps = {
@@ -5,7 +5,9 @@ export const C3NotificationContext = React.createContext({
5
5
  enabled: false,
6
6
  notifications: [],
7
7
  markAsRead: () => undefined,
8
+ markAllAsRead: () => undefined,
8
9
  dismiss: () => undefined,
10
+ dismissAll: () => undefined,
9
11
  });
10
12
  const C3NotificationProvider = ({ children, }) => {
11
13
  const [notifications, setNotifications] = useState([]);
@@ -46,13 +48,24 @@ const C3NotificationProvider = ({ children, }) => {
46
48
  NotificationService.changeState(config, uuid, newState);
47
49
  }
48
50
  };
51
+ const changeManyStates = (newState, notifications) => {
52
+ if (enabled) {
53
+ const notificationIds = notifications.map((notification) => notification.uuid);
54
+ setNotifications((allNotifications) => NotificationService.updateNotificationStates(allNotifications, notificationIds, newState));
55
+ NotificationService.changeManyStates(config, notificationIds, newState);
56
+ }
57
+ };
49
58
  const markAsRead = (notification) => changeState("read", notification);
59
+ const markAllAsRead = (notifications) => changeManyStates("read", notifications);
50
60
  const dismiss = (notification) => changeState("dismiss", notification);
61
+ const dismissAll = (notifications) => changeManyStates("dismiss", notifications);
51
62
  return (React.createElement(C3NotificationContext.Provider, { value: {
52
63
  enabled,
53
64
  notifications,
54
65
  markAsRead,
66
+ markAllAsRead,
55
67
  dismiss,
68
+ dismissAll,
56
69
  } }, children));
57
70
  };
58
71
  export function withNotifications(Component) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camunda/camunda-composite-components",
3
- "version": "0.0.29-np-rc13",
3
+ "version": "0.0.29-np-rc15",
4
4
  "scripts": {
5
5
  "clean": "rimraf lib/",
6
6
  "copy-css-files": "copyfiles -u 1 src/components/**/*.css lib/esm",