@gridsuite/commons-ui 0.99.0 → 0.100.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/announcement/AnnouncementBanner.d.ts +15 -0
- package/dist/components/announcement/AnnouncementBanner.js +87 -0
- package/dist/components/announcement/AnnouncementNotification.d.ts +7 -0
- package/dist/components/announcement/AnnouncementNotification.js +10 -0
- package/dist/components/announcement/index.d.ts +3 -0
- package/dist/components/announcement/index.js +8 -0
- package/dist/components/announcement/useGlobalAnnouncement.d.ts +10 -0
- package/dist/components/announcement/useGlobalAnnouncement.js +48 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +10 -2
- package/dist/components/inputs/reactHookForm/text/TextInput.d.ts +3 -1
- package/dist/components/inputs/reactHookForm/text/TextInput.js +4 -2
- package/dist/components/topBar/DevModeBanner.d.ts +1 -0
- package/dist/components/topBar/DevModeBanner.js +42 -0
- package/dist/components/topBar/TopBar.js +302 -305
- package/dist/components/topBar/UserInformationDialog.js +1 -1
- package/dist/components/topBar/index.d.ts +3 -2
- package/dist/components/topBar/index.js +4 -2
- package/dist/index.js +20 -2
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +3 -0
- package/dist/services/userAdmin.d.ts +3 -3
- package/dist/services/userAdmin.js +9 -1
- package/dist/utils/constants/notificationsProvider.d.ts +10 -0
- package/dist/utils/constants/notificationsProvider.js +17 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/types/index.js +2 -0
- package/dist/utils/types/metadata.d.ts +1 -0
- package/dist/utils/types/types.d.ts +12 -0
- package/dist/utils/types/types.js +8 -1
- package/package.json +1 -1
- package/dist/components/topBar/MessageBanner.d.ts +0 -6
- package/dist/components/topBar/MessageBanner.js +0 -54
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { UUID } from 'crypto';
|
|
2
|
+
import { PropsWithChildren, ReactNode } from 'react';
|
|
3
|
+
import { AlertProps } from '@mui/material';
|
|
4
|
+
import { User } from 'oidc-client';
|
|
5
|
+
import { AnnouncementSeverity } from '../../utils/types';
|
|
6
|
+
export type AnnouncementBannerProps = PropsWithChildren<{
|
|
7
|
+
user?: User | {};
|
|
8
|
+
/** only field used to detect if msg change */
|
|
9
|
+
id?: UUID;
|
|
10
|
+
duration?: number;
|
|
11
|
+
severity?: AnnouncementSeverity;
|
|
12
|
+
title?: ReactNode;
|
|
13
|
+
sx?: AlertProps['sx'];
|
|
14
|
+
}>;
|
|
15
|
+
export declare function AnnouncementBanner({ user, id, severity, title, children, duration, sx, }: Readonly<AnnouncementBannerProps>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useCallback } from "react";
|
|
3
|
+
import { useTheme, Collapse, Alert, AlertTitle, Tooltip } from "@mui/material";
|
|
4
|
+
import { Campaign } from "@mui/icons-material";
|
|
5
|
+
import "../../utils/types/equipmentType.js";
|
|
6
|
+
import { AnnouncementSeverity } from "../../utils/types/types.js";
|
|
7
|
+
const snackbarInfo = "#2196f3";
|
|
8
|
+
const snackbarWarning = "#ff9800";
|
|
9
|
+
const styles = {
|
|
10
|
+
alert: (theme) => ({
|
|
11
|
+
"&.MuiAlert-colorWarning": {
|
|
12
|
+
color: theme.palette.getContrastText(snackbarWarning),
|
|
13
|
+
backgroundColor: snackbarWarning
|
|
14
|
+
},
|
|
15
|
+
"&.MuiAlert-colorInfo": {
|
|
16
|
+
color: theme.palette.getContrastText(snackbarInfo),
|
|
17
|
+
backgroundColor: snackbarInfo
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
};
|
|
21
|
+
const iconMapping = {
|
|
22
|
+
info: /* @__PURE__ */ jsx(Campaign, {})
|
|
23
|
+
};
|
|
24
|
+
function convertSeverity(severity) {
|
|
25
|
+
switch (severity) {
|
|
26
|
+
case AnnouncementSeverity.INFO:
|
|
27
|
+
return "info";
|
|
28
|
+
case AnnouncementSeverity.WARN:
|
|
29
|
+
return "warning";
|
|
30
|
+
default:
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function AnnouncementBanner({
|
|
35
|
+
user,
|
|
36
|
+
id,
|
|
37
|
+
severity = AnnouncementSeverity.INFO,
|
|
38
|
+
title,
|
|
39
|
+
children,
|
|
40
|
+
duration,
|
|
41
|
+
sx
|
|
42
|
+
}) {
|
|
43
|
+
const theme = useTheme();
|
|
44
|
+
const [visible, setVisible] = useState(false);
|
|
45
|
+
useEffect(
|
|
46
|
+
() => {
|
|
47
|
+
if (id) {
|
|
48
|
+
setVisible(true);
|
|
49
|
+
if (duration) {
|
|
50
|
+
const bannerTimer = setTimeout(() => {
|
|
51
|
+
setVisible(false);
|
|
52
|
+
}, duration);
|
|
53
|
+
return () => {
|
|
54
|
+
clearTimeout(bannerTimer);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
setVisible(false);
|
|
59
|
+
}
|
|
60
|
+
return () => {
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- we check msg id in cas of an announcement
|
|
64
|
+
[id]
|
|
65
|
+
);
|
|
66
|
+
const handleClose = useCallback(() => setVisible(false), []);
|
|
67
|
+
return /* @__PURE__ */ jsx(Collapse, { in: user !== void 0 && visible, unmountOnExit: true, sx, style: { margin: theme.spacing(1) }, children: /* @__PURE__ */ jsxs(
|
|
68
|
+
Alert,
|
|
69
|
+
{
|
|
70
|
+
variant: "filled",
|
|
71
|
+
elevation: 0,
|
|
72
|
+
severity: convertSeverity(severity),
|
|
73
|
+
onClose: handleClose,
|
|
74
|
+
iconMapping,
|
|
75
|
+
hidden: !visible,
|
|
76
|
+
className: title ? void 0 : "no-title",
|
|
77
|
+
sx: styles.alert,
|
|
78
|
+
children: [
|
|
79
|
+
title && /* @__PURE__ */ jsx(AlertTitle, { children: title }),
|
|
80
|
+
/* @__PURE__ */ jsx(Tooltip, { title: children, placement: "bottom", children: /* @__PURE__ */ jsx("span", { children }) })
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
) });
|
|
84
|
+
}
|
|
85
|
+
export {
|
|
86
|
+
AnnouncementBanner
|
|
87
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { User } from 'oidc-client';
|
|
2
|
+
import { AnnouncementBannerProps } from './AnnouncementBanner';
|
|
3
|
+
export type AnnouncementNotificationProps = {
|
|
4
|
+
user: User | null;
|
|
5
|
+
sx?: AnnouncementBannerProps['sx'];
|
|
6
|
+
};
|
|
7
|
+
export declare function AnnouncementNotification({ user, sx }: Readonly<AnnouncementNotificationProps>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useGlobalAnnouncement } from "./useGlobalAnnouncement.js";
|
|
3
|
+
import { AnnouncementBanner } from "./AnnouncementBanner.js";
|
|
4
|
+
function AnnouncementNotification({ user, sx }) {
|
|
5
|
+
const { id, severity, message, duration } = useGlobalAnnouncement(user) ?? {};
|
|
6
|
+
return /* @__PURE__ */ jsx(AnnouncementBanner, { user: user ?? void 0, id, severity, duration, sx, children: message });
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
AnnouncementNotification
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AnnouncementBanner } from "./AnnouncementBanner.js";
|
|
2
|
+
import { AnnouncementNotification } from "./AnnouncementNotification.js";
|
|
3
|
+
import { useGlobalAnnouncement } from "./useGlobalAnnouncement.js";
|
|
4
|
+
export {
|
|
5
|
+
AnnouncementBanner,
|
|
6
|
+
AnnouncementNotification,
|
|
7
|
+
useGlobalAnnouncement
|
|
8
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { UUID } from 'crypto';
|
|
2
|
+
import { User } from 'oidc-client';
|
|
3
|
+
import { AnnouncementSeverity } from '../../utils/types';
|
|
4
|
+
export type AnnouncementProps = {
|
|
5
|
+
id: UUID;
|
|
6
|
+
message: string;
|
|
7
|
+
duration: number;
|
|
8
|
+
severity: AnnouncementSeverity;
|
|
9
|
+
};
|
|
10
|
+
export declare function useGlobalAnnouncement(user: User | null): AnnouncementProps | undefined;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { v4 } from "uuid";
|
|
2
|
+
import { useState, useEffect, useCallback } from "react";
|
|
3
|
+
import { fetchCurrentAnnouncement } from "../../services/userAdmin.js";
|
|
4
|
+
import { NotificationsUrlKeys } from "../../utils/constants/notificationsProvider.js";
|
|
5
|
+
import { useNotificationsListener } from "../notifications/hooks/useNotificationsListener.js";
|
|
6
|
+
function useGlobalAnnouncement(user) {
|
|
7
|
+
const [announcementInfos, setAnnouncementInfos] = useState();
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (user) {
|
|
10
|
+
fetchCurrentAnnouncement().then((announcementDto) => {
|
|
11
|
+
if (announcementDto) {
|
|
12
|
+
setAnnouncementInfos({
|
|
13
|
+
id: announcementDto.id,
|
|
14
|
+
message: announcementDto.message,
|
|
15
|
+
duration: announcementDto.remainingDuration,
|
|
16
|
+
severity: announcementDto.severity
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
setAnnouncementInfos(void 0);
|
|
20
|
+
}
|
|
21
|
+
}).catch((error) => console.error("Failed to retrieve global announcement:", error));
|
|
22
|
+
} else {
|
|
23
|
+
setAnnouncementInfos(void 0);
|
|
24
|
+
}
|
|
25
|
+
}, [user]);
|
|
26
|
+
const handleAnnouncementMessage = useCallback((event) => {
|
|
27
|
+
const eventData = JSON.parse(event.data);
|
|
28
|
+
if (eventData.headers.messageType === "announcement") {
|
|
29
|
+
const announcement = {
|
|
30
|
+
id: eventData.id ?? v4(),
|
|
31
|
+
message: eventData.payload,
|
|
32
|
+
severity: eventData.headers.severity,
|
|
33
|
+
duration: eventData.headers.duration
|
|
34
|
+
};
|
|
35
|
+
console.debug("announcement incoming:", announcement);
|
|
36
|
+
setAnnouncementInfos(announcement);
|
|
37
|
+
} else if (eventData.headers.messageType === "cancelAnnouncement") {
|
|
38
|
+
setAnnouncementInfos(void 0);
|
|
39
|
+
}
|
|
40
|
+
}, []);
|
|
41
|
+
useNotificationsListener(NotificationsUrlKeys.GLOBAL_CONFIG, {
|
|
42
|
+
listenerCallbackMessage: handleAnnouncementMessage
|
|
43
|
+
});
|
|
44
|
+
return announcementInfos;
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
useGlobalAnnouncement
|
|
48
|
+
};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
5
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
6
6
|
*/
|
|
7
|
+
export * from './announcement';
|
|
7
8
|
export * from './authentication';
|
|
8
9
|
export * from './cardErrorBoundary';
|
|
9
10
|
export * from './checkBoxList';
|
package/dist/components/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { AnnouncementBanner } from "./announcement/AnnouncementBanner.js";
|
|
2
|
+
import { AnnouncementNotification } from "./announcement/AnnouncementNotification.js";
|
|
3
|
+
import { useGlobalAnnouncement } from "./announcement/useGlobalAnnouncement.js";
|
|
1
4
|
import { AuthenticationRouter } from "./authentication/AuthenticationRouter.js";
|
|
2
5
|
import { default as default2 } from "./authentication/AuthenticationRouterErrorDisplay.js";
|
|
3
6
|
import { Login } from "./authentication/Login.js";
|
|
@@ -97,9 +100,10 @@ import { ActivableChip } from "./inputs/ActivableChip.js";
|
|
|
97
100
|
import { MultipleSelectionDialog } from "./multipleSelectionDialog/MultipleSelectionDialog.js";
|
|
98
101
|
import { OverflowableText } from "./overflowableText/OverflowableText.js";
|
|
99
102
|
import { SnackbarProvider } from "./snackbarProvider/SnackbarProvider.js";
|
|
100
|
-
import { TopBar } from "./topBar/TopBar.js";
|
|
101
|
-
import { GridLogo, LogoText } from "./topBar/GridLogo.js";
|
|
102
103
|
import { AboutDialog } from "./topBar/AboutDialog.js";
|
|
104
|
+
import { GridLogo, LogoText } from "./topBar/GridLogo.js";
|
|
105
|
+
import { DevModeBanner } from "./topBar/DevModeBanner.js";
|
|
106
|
+
import { TopBar } from "./topBar/TopBar.js";
|
|
103
107
|
import { TreeViewFinder, generateTreeViewFinderClass } from "./treeViewFinder/TreeViewFinder.js";
|
|
104
108
|
import { NotificationsProvider } from "./notifications/NotificationsProvider.js";
|
|
105
109
|
import { NotificationsContext } from "./notifications/contexts/NotificationsContext.js";
|
|
@@ -135,6 +139,8 @@ export {
|
|
|
135
139
|
AboutDialog,
|
|
136
140
|
ActivableChip,
|
|
137
141
|
AddButton,
|
|
142
|
+
AnnouncementBanner,
|
|
143
|
+
AnnouncementNotification,
|
|
138
144
|
AuthenticationRouter,
|
|
139
145
|
default2 as AuthenticationRouterErrorDisplay,
|
|
140
146
|
AutocompleteInput,
|
|
@@ -184,6 +190,7 @@ export {
|
|
|
184
190
|
DataType,
|
|
185
191
|
DescriptionField,
|
|
186
192
|
DescriptionModificationDialog,
|
|
193
|
+
DevModeBanner,
|
|
187
194
|
DirectoryItemSelector,
|
|
188
195
|
DirectoryItemsInput,
|
|
189
196
|
ENERGY_SOURCE_OPTIONS,
|
|
@@ -365,6 +372,7 @@ export {
|
|
|
365
372
|
useConvertValue,
|
|
366
373
|
useCustomFormContext,
|
|
367
374
|
useElementSearch,
|
|
375
|
+
useGlobalAnnouncement,
|
|
368
376
|
useListenerManager,
|
|
369
377
|
useNotificationsListener,
|
|
370
378
|
useValid
|
|
@@ -19,9 +19,11 @@ export interface TextInputProps {
|
|
|
19
19
|
clearable?: boolean;
|
|
20
20
|
formProps?: Omit<TextFieldWithAdornmentProps | TextFieldProps, 'value' | 'onChange' | 'inputRef' | 'inputProps' | 'InputProps'>;
|
|
21
21
|
disabledTooltip?: boolean;
|
|
22
|
+
disabled?: boolean;
|
|
22
23
|
}
|
|
23
24
|
export declare function TextInput({ name, label, labelValues, // this prop is used to add a value to label. this value is displayed without being translated
|
|
24
25
|
id, adornment, customAdornment, outputTransform, // transform materialUi input value before sending it to react hook form, mostly used to deal with number fields
|
|
25
26
|
inputTransform, // transform react hook form value before sending it to materialUi input, mostly used to deal with number fields
|
|
26
27
|
acceptValue, // used to check user entry before committing the input change, used mostly to prevent user from typing a character in number field
|
|
27
|
-
previousValue, clearable, formProps, disabledTooltip,
|
|
28
|
+
previousValue, clearable, formProps, disabledTooltip, // In case we don't want to show tooltip on the value and warning/info icons
|
|
29
|
+
disabled, }: TextInputProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -24,8 +24,9 @@ function TextInput({
|
|
|
24
24
|
previousValue,
|
|
25
25
|
clearable,
|
|
26
26
|
formProps,
|
|
27
|
-
disabledTooltip
|
|
27
|
+
disabledTooltip,
|
|
28
28
|
// In case we don't want to show tooltip on the value and warning/info icons
|
|
29
|
+
disabled
|
|
29
30
|
}) {
|
|
30
31
|
const { validationSchema, getValues, removeOptional, isNodeBuilt, isUpdate } = useCustomFormContext();
|
|
31
32
|
const {
|
|
@@ -81,7 +82,8 @@ function TextInput({
|
|
|
81
82
|
),
|
|
82
83
|
...genHelperError(error == null ? void 0 : error.message),
|
|
83
84
|
...formProps,
|
|
84
|
-
...adornment && { ...finalAdornment }
|
|
85
|
+
...adornment && { ...finalAdornment },
|
|
86
|
+
disabled
|
|
85
87
|
},
|
|
86
88
|
id ?? label
|
|
87
89
|
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function DevModeBanner(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useCallback } from "react";
|
|
3
|
+
import { Collapse, Alert, Typography } from "@mui/material";
|
|
4
|
+
import { FormattedMessage } from "react-intl";
|
|
5
|
+
const styles = {
|
|
6
|
+
alert: {
|
|
7
|
+
"& .MuiAlert-colorWarning": {
|
|
8
|
+
backgroundColor: "#f6b26b",
|
|
9
|
+
color: "black",
|
|
10
|
+
"& .MuiAlert-action .MuiIconButton-root:hover": {
|
|
11
|
+
backgroundColor: "#e39648"
|
|
12
|
+
},
|
|
13
|
+
"& .MuiAlert-icon": {
|
|
14
|
+
color: "red"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
// MUI IconButton: square ripple
|
|
18
|
+
"& .MuiAlert-action .MuiIconButton-root": {
|
|
19
|
+
borderRadius: 1,
|
|
20
|
+
"& .MuiTouchRipple-root .MuiTouchRipple-child ": {
|
|
21
|
+
borderRadius: "8px"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
function DevModeBanner() {
|
|
27
|
+
const [visible, setVisible] = useState(true);
|
|
28
|
+
return /* @__PURE__ */ jsx(Collapse, { in: visible, sx: styles.alert, children: /* @__PURE__ */ jsx(
|
|
29
|
+
Alert,
|
|
30
|
+
{
|
|
31
|
+
square: true,
|
|
32
|
+
severity: "warning",
|
|
33
|
+
variant: "filled",
|
|
34
|
+
elevation: 0,
|
|
35
|
+
onClose: useCallback(() => setVisible(false), []),
|
|
36
|
+
children: /* @__PURE__ */ jsx(Typography, { variant: "body1", children: /* @__PURE__ */ jsx(FormattedMessage, { id: "top-bar/developerModeWarning", defaultMessage: "Developer mode" }) })
|
|
37
|
+
}
|
|
38
|
+
) });
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
DevModeBanner
|
|
42
|
+
};
|