@equinor/fusion-framework-react-components-bookmark 0.2.13 → 0.3.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.
@@ -0,0 +1,10 @@
1
+ import { PropsWithChildren } from 'react';
2
+ export type PortalMessageType = 'Error' | 'Info' | 'Warning' | 'NoContent';
3
+ type MessageProps = {
4
+ readonly title: string;
5
+ readonly body?: React.FC | string;
6
+ readonly type?: PortalMessageType;
7
+ readonly color?: string;
8
+ };
9
+ export declare const Message: ({ title, type, color, children, }: PropsWithChildren<MessageProps>) => import("react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -1 +1 @@
1
- export declare const version = "0.2.13";
1
+ export declare const version = "0.3.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@equinor/fusion-framework-react-components-bookmark",
3
- "version": "0.2.13",
3
+ "version": "0.3.0",
4
4
  "description": "",
5
5
  "main": "dist/esm/index.js",
6
6
  "exports": {
@@ -19,8 +19,8 @@
19
19
  "directory": "packages/react/components/bookmark"
20
20
  },
21
21
  "dependencies": {
22
- "@equinor/fusion-framework-react": "^5.3.4",
23
- "@equinor/fusion-framework-react-module-bookmark": "^2.0.23"
22
+ "@equinor/fusion-framework-react": "^5.3.6",
23
+ "@equinor/fusion-framework-react-module-bookmark": "^2.0.25"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@equinor/eds-core-react": "^0.34.0",
@@ -31,8 +31,8 @@
31
31
  "react": "^18.2.0",
32
32
  "styled-components": "^6.0.7",
33
33
  "typescript": "^5.1.3",
34
- "@equinor/fusion-framework-module-app": "^5.2.11",
35
- "@equinor/fusion-framework-module-bookmark": "^1.0.16",
34
+ "@equinor/fusion-framework-module-app": "^5.2.12",
35
+ "@equinor/fusion-framework-module-bookmark": "^1.0.17",
36
36
  "@equinor/fusion-framework-module-event": "^4.0.7"
37
37
  },
38
38
  "peerDependencies": {
@@ -2,12 +2,15 @@ import { useBookmark } from '@equinor/fusion-framework-react-module-bookmark';
2
2
  import { useBookmarkGrouping } from '../hooks';
3
3
  import { BookmarkFilter } from './filter/Filter';
4
4
  import { SectionList } from './sectionList/SectionList';
5
- import { useEffect } from 'react';
5
+ import { useEffect, useState } from 'react';
6
6
 
7
7
  import { Icon } from '@equinor/eds-core-react';
8
8
  import { chevron_down, chevron_right, share, more_vertical, add } from '@equinor/eds-icons';
9
9
 
10
10
  import styled from 'styled-components';
11
+ import { Message } from './messages/Message';
12
+ import { Loading } from './loading/Loading';
13
+ import { useFramework } from '@equinor/fusion-framework-react';
11
14
 
12
15
  Icon.add({
13
16
  chevron_down,
@@ -29,10 +32,32 @@ const Styled = {
29
32
  overflow-x: hidden;
30
33
  height: calc((100vh - 85px) - 3rem);
31
34
  `,
35
+ NoContentWrapper: styled.div`
36
+ position: absolute;
37
+ top: 150px;
38
+ bottom: 200px;
39
+ left: 0px;
40
+ right: 0px;
41
+ `,
32
42
  };
33
43
 
34
44
  export const Bookmark = () => {
35
45
  const { bookmarks, getAllBookmarks } = useBookmark();
46
+ const [loading, setLoading] = useState(true);
47
+
48
+ const { event } = useFramework().modules;
49
+
50
+ useEffect(() => {
51
+ return event.addEventListener('onBookmarksChanged', () => {
52
+ setLoading(false);
53
+ });
54
+ }, [event]);
55
+
56
+ useEffect(() => {
57
+ if (bookmarks.length > 0) {
58
+ setLoading(false);
59
+ }
60
+ }, [bookmarks]);
36
61
 
37
62
  useEffect(() => {
38
63
  getAllBookmarks();
@@ -51,7 +76,17 @@ export const Bookmark = () => {
51
76
  setSearchText={setSearchText}
52
77
  />
53
78
  <Styled.List>
54
- <SectionList bookmarkGroups={bookmarkGroups} />
79
+ {bookmarkGroups.length > 0 ? (
80
+ <SectionList bookmarkGroups={bookmarkGroups} />
81
+ ) : loading ? (
82
+ <Loading />
83
+ ) : (
84
+ <Styled.NoContentWrapper>
85
+ <Message title="No Bookmarks" type="NoContent">
86
+ You have not created any bookmarks yet.
87
+ </Message>
88
+ </Styled.NoContentWrapper>
89
+ )}
55
90
  </Styled.List>
56
91
  </Styled.Wrapper>
57
92
  );
@@ -0,0 +1,82 @@
1
+ import { Icon, Typography } from '@equinor/eds-core-react';
2
+ import { tokens } from '@equinor/eds-tokens';
3
+ import { PropsWithChildren } from 'react';
4
+ import styled from 'styled-components';
5
+
6
+ import { error_outlined, file_description } from '@equinor/eds-icons';
7
+
8
+ export type PortalMessageType = 'Error' | 'Info' | 'Warning' | 'NoContent';
9
+
10
+ const getMessageType = (type?: PortalMessageType) => {
11
+ switch (type) {
12
+ case 'Error':
13
+ return { color: tokens.colors.interactive.danger__resting.hex, icon: error_outlined };
14
+ case 'Info':
15
+ return { color: tokens.colors.interactive.primary__resting.hex, icon: error_outlined };
16
+ case 'Warning':
17
+ return { color: tokens.colors.interactive.warning__resting.hex, icon: error_outlined };
18
+ case 'NoContent':
19
+ return {
20
+ color: tokens.colors.interactive.primary__resting.hex,
21
+ icon: file_description,
22
+ };
23
+ default:
24
+ return undefined;
25
+ }
26
+ };
27
+
28
+ const Styles = {
29
+ Wrapper: styled.div`
30
+ width: 100%;
31
+ height: 100%;
32
+ display: flex;
33
+ flex-direction: column;
34
+ align-items: center;
35
+ gap: 1rem;
36
+ justify-content: center;
37
+ `,
38
+ Content: styled.div`
39
+ display: flex;
40
+ flex-direction: column;
41
+ align-items: center;
42
+ gap: 0.5rem;
43
+ justify-content: center;
44
+ `,
45
+ };
46
+
47
+ type MessageProps = {
48
+ readonly title: string;
49
+ readonly body?: React.FC | string;
50
+ readonly type?: PortalMessageType;
51
+ readonly color?: string;
52
+ };
53
+
54
+ export const Message = ({
55
+ title,
56
+ type = 'Info',
57
+ color,
58
+ children,
59
+ }: PropsWithChildren<MessageProps>) => {
60
+ const currentType = getMessageType(type);
61
+ return (
62
+ <Styles.Wrapper>
63
+ <Icon
64
+ data-testid="icon"
65
+ size={40}
66
+ color={currentType?.color || color || tokens.colors.text.static_icons__tertiary.hex}
67
+ data={currentType?.icon || error_outlined}
68
+ />
69
+ <Styles.Content>
70
+ <Typography
71
+ color={tokens.colors.text.static_icons__default.hex}
72
+ variant={'h3'}
73
+ aria-label={`Title for ${type} message`}
74
+ >
75
+ {title}
76
+ </Typography>
77
+
78
+ <Typography>{children && children}</Typography>
79
+ </Styles.Content>
80
+ </Styles.Wrapper>
81
+ );
82
+ };
@@ -7,12 +7,11 @@ import { SharedIcon } from '../shared/SharedIcon';
7
7
  import type { Bookmark } from '@equinor/fusion-framework-module-bookmark';
8
8
  import { useBookmark } from '@equinor/fusion-framework-react-module-bookmark';
9
9
  import { useCurrentUser } from '@equinor/fusion-framework-react/hooks';
10
- import { useCallback, useEffect, useState } from 'react';
10
+ import { useCallback, useState } from 'react';
11
11
  import { delete_to_trash, share, edit, close, update } from '@equinor/eds-icons';
12
12
  import { useFramework } from '@equinor/fusion-framework-react';
13
13
  import { appendBookmarkIdToUrl } from '../../utils/append-bookmark-to-uri';
14
14
  import { filterEmptyGroups, sortByName, toHumanReadable } from '../../utils/utils';
15
- import { Loading } from '../loading/Loading';
16
15
 
17
16
  Icon.add({
18
17
  delete_to_trash,
@@ -30,19 +29,11 @@ export const SectionList = ({ bookmarkGroups }: SectionListProps) => {
30
29
  const { deleteBookmarkById, getCurrentAppKey, updateBookmark, removeBookmarkFavorite } =
31
30
  useBookmark();
32
31
 
33
- const [loading, setLoading] = useState(true);
34
-
35
32
  const user = useCurrentUser();
36
33
  const [isMenuByIdOpen, setIsMenuByIdOpen] = useState('');
37
34
 
38
35
  const { event } = useFramework().modules;
39
36
 
40
- useEffect(() => {
41
- return event.addEventListener('onBookmarksChanged', () => {
42
- setLoading(false);
43
- });
44
- }, [event]);
45
-
46
37
  const editBookmark = useCallback(
47
38
  (bookmarkId: string) => {
48
39
  event.dispatchEvent('onBookmarkEdit', { detail: { bookmarkId } });
@@ -81,8 +72,6 @@ export const SectionList = ({ bookmarkGroups }: SectionListProps) => {
81
72
  user?.localAccountId,
82
73
  );
83
74
 
84
- if (loading) return <Loading />;
85
-
86
75
  return (
87
76
  <>
88
77
  {bookmarkGroups.filter(filterEmptyGroups).map(({ groupingProperty, values }) => (
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '0.2.13';
2
+ export const version = '0.3.0';