@equinor/fusion-framework-react-components-bookmark 0.5.3 → 1.0.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/CHANGELOG.md +20 -0
- package/dist/esm/components/Bookmark.js +29 -17
- package/dist/esm/components/Bookmark.js.map +1 -1
- package/dist/esm/components/BookmarkProvider.js +47 -9
- package/dist/esm/components/BookmarkProvider.js.map +1 -1
- package/dist/esm/components/create-bookmark/CreateBookmark.js +31 -12
- package/dist/esm/components/create-bookmark/CreateBookmark.js.map +1 -1
- package/dist/esm/components/create-bookmark/index.js +1 -1
- package/dist/esm/components/create-bookmark/index.js.map +1 -1
- package/dist/esm/components/edit-bookmark/EditBookmark.js +44 -19
- package/dist/esm/components/edit-bookmark/EditBookmark.js.map +1 -1
- package/dist/esm/components/import-bookmark/ImportBookmark.js +42 -13
- package/dist/esm/components/import-bookmark/ImportBookmark.js.map +1 -1
- package/dist/esm/components/row/Row.js +3 -3
- package/dist/esm/components/row/Row.js.map +1 -1
- package/dist/esm/components/sectionList/SectionList.js +69 -67
- package/dist/esm/components/sectionList/SectionList.js.map +1 -1
- package/dist/esm/hooks/useBookmarkGrouping.js.map +1 -1
- package/dist/esm/utils/utils.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/components/BookmarkProvider.d.ts +16 -1
- package/dist/types/components/create-bookmark/index.d.ts +1 -1
- package/dist/types/components/edit-bookmark/EditBookmark.d.ts +1 -1
- package/dist/types/hooks/useBookmarkGrouping.d.ts +40 -4
- package/dist/types/utils/utils.d.ts +3 -3
- package/dist/types/version.d.ts +1 -1
- package/package.json +6 -4
- package/src/components/Bookmark.tsx +42 -31
- package/src/components/BookmarkProvider.tsx +74 -14
- package/src/components/create-bookmark/CreateBookmark.tsx +30 -13
- package/src/components/create-bookmark/index.ts +1 -1
- package/src/components/edit-bookmark/EditBookmark.tsx +60 -23
- package/src/components/import-bookmark/ImportBookmark.tsx +35 -15
- package/src/components/row/Row.tsx +3 -3
- package/src/components/sectionList/SectionList.tsx +77 -97
- package/src/hooks/useBookmarkGrouping.ts +6 -6
- package/src/utils/utils.ts +4 -3
- package/src/version.ts +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Icon, Typography } from '@equinor/eds-core-react';
|
|
2
2
|
import { tokens } from '@equinor/eds-tokens';
|
|
3
3
|
import { useOutsideClick } from '@equinor/eds-utils';
|
|
4
|
-
import { useBookmark } from '@equinor/fusion-framework-react-module-bookmark';
|
|
5
4
|
import { MutableRefObject, ReactNode, useRef } from 'react';
|
|
6
5
|
import { MoreMenu } from './MoreMenu';
|
|
7
6
|
|
|
8
7
|
import styled from 'styled-components';
|
|
8
|
+
import { useBookmarkComponentContext } from '../BookmarkProvider';
|
|
9
9
|
|
|
10
10
|
export type MenuOption = {
|
|
11
11
|
name: string;
|
|
@@ -48,7 +48,7 @@ const Styled = {
|
|
|
48
48
|
|
|
49
49
|
export const Row = ({ name, menuOptions, children, id, menuOpen, onMenuOpen }: RowProps) => {
|
|
50
50
|
const pRef = useRef<HTMLElement | null>(null);
|
|
51
|
-
const {
|
|
51
|
+
const { provider } = useBookmarkComponentContext();
|
|
52
52
|
|
|
53
53
|
useOutsideClick(pRef.current, () => onMenuOpen(''));
|
|
54
54
|
|
|
@@ -59,7 +59,7 @@ export const Row = ({ name, menuOptions, children, id, menuOpen, onMenuOpen }: R
|
|
|
59
59
|
onClick={(e) => {
|
|
60
60
|
e.preventDefault();
|
|
61
61
|
e.stopPropagation();
|
|
62
|
-
|
|
62
|
+
provider.setCurrentBookmarkAsync(id);
|
|
63
63
|
}}
|
|
64
64
|
>
|
|
65
65
|
<Typography>{name}</Typography>
|
|
@@ -4,14 +4,15 @@ import { Row } from '../row/Row';
|
|
|
4
4
|
import { Section } from '../section/Section';
|
|
5
5
|
import { SharedIcon } from '../shared/SharedIcon';
|
|
6
6
|
// TODO - export from `@equinor/fusion-framework-react-module-bookmark`
|
|
7
|
-
import type {
|
|
8
|
-
import { useBookmark } from '@equinor/fusion-framework-react-module-bookmark';
|
|
7
|
+
import type { BookmarkWithoutData } from '@equinor/fusion-framework-module-bookmark';
|
|
9
8
|
import { useCurrentUser } from '@equinor/fusion-framework-react/hooks';
|
|
10
9
|
import { useCallback, useState } from 'react';
|
|
11
10
|
import { delete_to_trash, share, edit, close, update } from '@equinor/eds-icons';
|
|
12
11
|
import { useFramework } from '@equinor/fusion-framework-react';
|
|
13
12
|
import { appendBookmarkIdToUrl } from '../../utils/append-bookmark-to-uri';
|
|
14
13
|
import { filterEmptyGroups, sortByName, toHumanReadable } from '../../utils/utils';
|
|
14
|
+
import { AppModule } from '@equinor/fusion-framework-module-app';
|
|
15
|
+
import { useBookmarkComponentContext } from '../BookmarkProvider';
|
|
15
16
|
|
|
16
17
|
Icon.add({
|
|
17
18
|
delete_to_trash,
|
|
@@ -26,52 +27,90 @@ type SectionListProps = {
|
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
export const SectionList = ({ bookmarkGroups }: SectionListProps) => {
|
|
29
|
-
const { deleteBookmarkById,
|
|
30
|
-
useBookmark();
|
|
30
|
+
// const { deleteBookmarkById, updateBookmark, removeBookmarkFavorite } = useBookmark();
|
|
31
31
|
|
|
32
|
+
const { provider: bookmarkProvider, currentApp } = useBookmarkComponentContext();
|
|
33
|
+
|
|
34
|
+
// TODO - should be removed when bookmark has property for isOwner
|
|
32
35
|
const user = useCurrentUser();
|
|
36
|
+
|
|
33
37
|
const [isMenuByIdOpen, setIsMenuByIdOpen] = useState('');
|
|
34
38
|
|
|
35
|
-
const { event } = useFramework().modules;
|
|
39
|
+
const { event: eventProvider } = useFramework<[AppModule]>().modules;
|
|
36
40
|
|
|
37
|
-
const
|
|
38
|
-
(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const createMenuOptions = useCallback(
|
|
42
|
+
(bookmark: BookmarkWithoutData) => {
|
|
43
|
+
const appKey = currentApp?.appKey;
|
|
44
|
+
const bookmarkId = bookmark.id;
|
|
45
|
+
const isOwner = bookmark.createdBy.azureUniqueId === user?.localAccountId;
|
|
46
|
+
if (isOwner) {
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
name: 'Edit',
|
|
50
|
+
disabled: appKey !== bookmark.appKey,
|
|
51
|
+
onClick: () => {
|
|
52
|
+
eventProvider.dispatchEvent('onBookmarkEdit', {
|
|
53
|
+
detail: { bookmarkId },
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
Icon: <Icon name="edit" />,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'Update with current view',
|
|
60
|
+
disabled: appKey !== bookmark.appKey,
|
|
61
|
+
onClick: () => {
|
|
62
|
+
bookmarkProvider.updateBookmarkAsync(bookmark.id);
|
|
63
|
+
// TODO: add success and failure message
|
|
64
|
+
},
|
|
65
|
+
Icon: <Icon name="update" />,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'Remove',
|
|
69
|
+
disabled: false,
|
|
70
|
+
onClick: () => {
|
|
71
|
+
bookmarkProvider.deleteBookmarkAsync(bookmark.id);
|
|
72
|
+
// TODO: add success and failure message
|
|
73
|
+
},
|
|
74
|
+
Icon: <Icon name="delete_to_trash" />,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: bookmark.isShared ? 'Unshare' : 'Share',
|
|
78
|
+
disabled: false,
|
|
79
|
+
onClick: () => {
|
|
80
|
+
if (!bookmark.isShared) {
|
|
81
|
+
const url = appendBookmarkIdToUrl(bookmark.id);
|
|
82
|
+
navigator.clipboard.writeText(url);
|
|
83
|
+
eventProvider.dispatchEvent('onBookmarkUrlCopy', {
|
|
84
|
+
detail: { url },
|
|
85
|
+
});
|
|
86
|
+
}
|
|
43
87
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
88
|
+
// TODO - this flag should only be set by backend when sharing is successful
|
|
89
|
+
bookmarkProvider.updateBookmarkAsync(
|
|
90
|
+
bookmark.id,
|
|
91
|
+
{ isShared: !bookmark.isShared },
|
|
92
|
+
{ excludePayloadGeneration: true },
|
|
93
|
+
);
|
|
94
|
+
},
|
|
95
|
+
Icon: <Icon name="share" />,
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
} else {
|
|
99
|
+
return [
|
|
100
|
+
{
|
|
101
|
+
name: 'Unfavourite',
|
|
102
|
+
disabled: false,
|
|
103
|
+
onClick: () => {
|
|
104
|
+
bookmarkProvider.deleteBookmarkAsync(bookmark.id);
|
|
105
|
+
},
|
|
106
|
+
Icon: <Icon name="close" />,
|
|
107
|
+
},
|
|
108
|
+
];
|
|
50
109
|
}
|
|
51
|
-
updateBookmark({ ...bookmark, isShared: !bookmark.isShared });
|
|
52
110
|
},
|
|
53
|
-
[
|
|
111
|
+
[eventProvider, bookmarkProvider, user, currentApp?.appKey],
|
|
54
112
|
);
|
|
55
113
|
|
|
56
|
-
const updateBookmarkWithCurrentView = useCallback(
|
|
57
|
-
(bookmark: Bookmark) => {
|
|
58
|
-
updateBookmark({ ...bookmark }, { updatePayload: true });
|
|
59
|
-
},
|
|
60
|
-
[updateBookmark],
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const createMenuOptions = (bookmark: Bookmark) =>
|
|
64
|
-
createBookmarkActions(
|
|
65
|
-
bookmark,
|
|
66
|
-
deleteBookmarkById,
|
|
67
|
-
editBookmark,
|
|
68
|
-
shareBookmark,
|
|
69
|
-
removeBookmarkFavorite,
|
|
70
|
-
updateBookmarkWithCurrentView,
|
|
71
|
-
getCurrentAppKey(),
|
|
72
|
-
user?.localAccountId,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
114
|
return (
|
|
76
115
|
<>
|
|
77
116
|
{bookmarkGroups.filter(filterEmptyGroups).map(({ groupingProperty, values }) => (
|
|
@@ -100,62 +139,3 @@ export const SectionList = ({ bookmarkGroups }: SectionListProps) => {
|
|
|
100
139
|
</>
|
|
101
140
|
);
|
|
102
141
|
};
|
|
103
|
-
|
|
104
|
-
function createBookmarkActions(
|
|
105
|
-
bookmark: Bookmark,
|
|
106
|
-
deleteBookmarkById: (bookmarkId: string) => Promise<string | undefined>,
|
|
107
|
-
editBookmark: (bookmark: string) => void,
|
|
108
|
-
shareBookmark: (bookmark: Bookmark) => void,
|
|
109
|
-
removeBookmarkFavorite: (bookmarkId: string) => void,
|
|
110
|
-
updateBookmarkWithCurrentView: (bookmark: Bookmark) => void,
|
|
111
|
-
appKey?: string,
|
|
112
|
-
localAccountId?: string,
|
|
113
|
-
) {
|
|
114
|
-
if (bookmark.createdBy.azureUniqueId === localAccountId) {
|
|
115
|
-
return [
|
|
116
|
-
{
|
|
117
|
-
name: 'Edit',
|
|
118
|
-
disabled: appKey !== bookmark.appKey,
|
|
119
|
-
onClick: () => {
|
|
120
|
-
editBookmark(bookmark.id);
|
|
121
|
-
},
|
|
122
|
-
Icon: <Icon name="edit" />,
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
name: 'Update with current view',
|
|
126
|
-
disabled: appKey !== bookmark.appKey,
|
|
127
|
-
onClick: () => {
|
|
128
|
-
updateBookmarkWithCurrentView(bookmark);
|
|
129
|
-
},
|
|
130
|
-
Icon: <Icon name="update" />,
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
name: 'Remove',
|
|
134
|
-
disabled: false,
|
|
135
|
-
onClick: () => {
|
|
136
|
-
deleteBookmarkById(bookmark.id);
|
|
137
|
-
},
|
|
138
|
-
Icon: <Icon name="delete_to_trash" />,
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
name: bookmark.isShared ? 'Unshare' : 'Share',
|
|
142
|
-
disabled: false,
|
|
143
|
-
onClick: () => {
|
|
144
|
-
shareBookmark(bookmark);
|
|
145
|
-
},
|
|
146
|
-
Icon: <Icon name="share" />,
|
|
147
|
-
},
|
|
148
|
-
];
|
|
149
|
-
} else {
|
|
150
|
-
return [
|
|
151
|
-
{
|
|
152
|
-
name: 'Unfavourite',
|
|
153
|
-
disabled: false,
|
|
154
|
-
onClick: () => {
|
|
155
|
-
removeBookmarkFavorite(bookmark.id);
|
|
156
|
-
},
|
|
157
|
-
Icon: <Icon name="close" />,
|
|
158
|
-
},
|
|
159
|
-
];
|
|
160
|
-
}
|
|
161
|
-
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Bookmarks, BookmarkWithoutData } from '@equinor/fusion-framework-module-bookmark';
|
|
2
2
|
|
|
3
3
|
import { useState } from 'react';
|
|
4
4
|
|
|
5
5
|
export type GroupingKeys = 'Group by app' | 'Created by' | 'Group by Context';
|
|
6
6
|
|
|
7
|
-
const groupingModes: Record<GroupingKeys, (_item:
|
|
8
|
-
'Group by app': (item:
|
|
9
|
-
'Created by': (item:
|
|
10
|
-
'Group by Context': (item:
|
|
7
|
+
const groupingModes: Record<GroupingKeys, (_item: BookmarkWithoutData) => string> = {
|
|
8
|
+
'Group by app': (item: BookmarkWithoutData) => item.appKey,
|
|
9
|
+
'Created by': (item: BookmarkWithoutData) => item.createdBy.name,
|
|
10
|
+
'Group by Context': (item: BookmarkWithoutData) => item?.context?.name ?? 'Unknown',
|
|
11
11
|
} as const;
|
|
12
12
|
|
|
13
|
-
export const useBookmarkGrouping = (bookmarks?:
|
|
13
|
+
export const useBookmarkGrouping = (bookmarks?: Bookmarks) => {
|
|
14
14
|
const [searchText, setSearchText] = useState<string | null>(null);
|
|
15
15
|
|
|
16
16
|
const [groupByKey, setGroupBy] = useState<keyof typeof groupingModes>('Group by app');
|
package/src/utils/utils.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Bookmarks, BookmarkWithoutData } from '@equinor/fusion-framework-module-bookmark';
|
|
2
2
|
|
|
3
3
|
/** Helpers.. */
|
|
4
|
-
export const filterEmptyGroups = (i: { values:
|
|
5
|
-
export const sortByName = (a:
|
|
4
|
+
export const filterEmptyGroups = (i: { values: Bookmarks }) => i.values.length;
|
|
5
|
+
export const sortByName = (a: BookmarkWithoutData, b: BookmarkWithoutData) =>
|
|
6
|
+
a.name.localeCompare(b.name);
|
|
6
7
|
// const extractNameFromMail = (mail: string) => mail.split('@')[0].toLowerCase();
|
|
7
8
|
|
|
8
9
|
export const toHumanReadable = (val: string) =>
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '0.
|
|
2
|
+
export const version = '1.0.0';
|