@equinor/fusion-framework-react-components-bookmark 1.0.8 → 1.0.10
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 +234 -215
- package/dist/esm/components/Bookmark.js.map +1 -1
- package/dist/esm/components/BookmarkProvider.js.map +1 -1
- package/dist/esm/components/create-bookmark/CreateBookmark.js.map +1 -1
- package/dist/esm/components/edit-bookmark/EditBookmark.js +1 -3
- package/dist/esm/components/edit-bookmark/EditBookmark.js.map +1 -1
- package/dist/esm/components/filter/Filter.js +2 -5
- package/dist/esm/components/filter/Filter.js.map +1 -1
- package/dist/esm/components/import-bookmark/ImportBookmark.js.map +1 -1
- package/dist/esm/components/loading/Loading.js.map +1 -1
- package/dist/esm/components/messages/Message.js.map +1 -1
- package/dist/esm/components/row/MoreMenu.js.map +1 -1
- package/dist/esm/components/row/Row.js.map +1 -1
- package/dist/esm/components/section/Section.js.map +1 -1
- package/dist/esm/components/sectionList/SectionList.js.map +1 -1
- package/dist/esm/components/shared/SharedIcon.js.map +1 -1
- package/dist/esm/hooks/useBookmarkGrouping.js.map +1 -1
- package/dist/esm/utils/append-bookmark-to-uri.js.map +1 -1
- package/dist/esm/utils/utils.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/components/BookmarkProvider.d.ts +1 -1
- package/dist/types/components/filter/Filter.d.ts +1 -1
- package/dist/types/components/messages/Message.d.ts +1 -1
- package/dist/types/components/row/MoreMenu.d.ts +2 -2
- package/dist/types/components/row/Row.d.ts +1 -1
- package/dist/types/components/section/Section.d.ts +1 -1
- package/dist/types/components/sectionList/SectionList.d.ts +1 -1
- package/dist/types/hooks/useBookmarkGrouping.d.ts +1 -1
- package/dist/types/utils/utils.d.ts +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +8 -8
- package/src/components/Bookmark.tsx +46 -47
- package/src/components/BookmarkProvider.tsx +78 -78
- package/src/components/create-bookmark/CreateBookmark.tsx +96 -96
- package/src/components/edit-bookmark/EditBookmark.tsx +149 -152
- package/src/components/filter/Filter.tsx +21 -41
- package/src/components/import-bookmark/ImportBookmark.tsx +61 -65
- package/src/components/loading/Loading.tsx +11 -11
- package/src/components/messages/Message.tsx +47 -47
- package/src/components/row/MoreMenu.tsx +27 -27
- package/src/components/row/Row.tsx +56 -56
- package/src/components/section/Section.tsx +17 -17
- package/src/components/sectionList/SectionList.tsx +137 -143
- package/src/components/shared/SharedIcon.tsx +19 -19
- package/src/hooks/useBookmarkGrouping.ts +37 -37
- package/src/utils/append-bookmark-to-uri.ts +3 -3
- package/src/utils/utils.ts +6 -6
- package/src/version.ts +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Icon } from '@equinor/eds-core-react';
|
|
2
|
-
import { useBookmarkGrouping } from '../../hooks';
|
|
3
|
-
import { MenuOption, Row } from '../row/Row';
|
|
2
|
+
import type { useBookmarkGrouping } from '../../hooks';
|
|
3
|
+
import { type MenuOption, 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`
|
|
@@ -13,156 +13,150 @@ import { useBookmarkComponentContext } from '../BookmarkProvider';
|
|
|
13
13
|
import { from } from 'rxjs';
|
|
14
14
|
|
|
15
15
|
Icon.add({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
delete_to_trash,
|
|
17
|
+
edit,
|
|
18
|
+
share,
|
|
19
|
+
close,
|
|
20
|
+
update,
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
type SectionListProps = {
|
|
24
|
-
|
|
24
|
+
readonly bookmarkGroups: ReturnType<typeof useBookmarkGrouping>['bookmarkGroups'];
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export const SectionList = ({ bookmarkGroups }: SectionListProps) => {
|
|
28
|
-
|
|
28
|
+
// const { deleteBookmarkById, updateBookmark, removeBookmarkFavorite } = useBookmark();
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const { provider, currentApp, showEditBookmark, addBookmarkToClipboard } =
|
|
31
|
+
useBookmarkComponentContext();
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
// TODO - should be removed when bookmark has property for isOwner
|
|
34
|
+
const user = useCurrentUser();
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
const [isMenuByIdOpen, setIsMenuByIdOpen] = useState('');
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
},
|
|
138
|
-
[provider, showEditBookmark, addBookmarkToClipboard, user, currentApp?.appKey],
|
|
139
|
-
);
|
|
38
|
+
const createMenuOptions = useCallback(
|
|
39
|
+
(bookmark: BookmarkWithoutData) => {
|
|
40
|
+
if (!provider) return [];
|
|
41
|
+
const appKey = currentApp?.appKey;
|
|
42
|
+
const bookmarkId = bookmark.id;
|
|
43
|
+
const isOwner = bookmark.createdBy.id === user?.localAccountId;
|
|
44
|
+
if (isOwner) {
|
|
45
|
+
return [
|
|
46
|
+
{
|
|
47
|
+
name: 'Edit',
|
|
48
|
+
disabled: appKey !== bookmark.appKey,
|
|
49
|
+
onClick: () => {
|
|
50
|
+
showEditBookmark(bookmarkId);
|
|
51
|
+
},
|
|
52
|
+
Icon: <Icon name="edit" />,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'Update with current view',
|
|
56
|
+
disabled: appKey !== bookmark.appKey,
|
|
57
|
+
onClick: () => {
|
|
58
|
+
// TODO: add success and failure message
|
|
59
|
+
from(
|
|
60
|
+
provider.updateBookmark(bookmark.id, undefined, {
|
|
61
|
+
excludePayloadGeneration: false,
|
|
62
|
+
}),
|
|
63
|
+
).subscribe({
|
|
64
|
+
error(err) {
|
|
65
|
+
console.error('Failed to update bookmark with current view', err);
|
|
66
|
+
},
|
|
67
|
+
complete() {
|
|
68
|
+
console.debug('Bookmark updated with current view');
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
Icon: <Icon name="update" />,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'Remove',
|
|
76
|
+
disabled: false,
|
|
77
|
+
onClick: () => {
|
|
78
|
+
// TODO: add success and failure message
|
|
79
|
+
from(provider.deleteBookmark(bookmark.id)).subscribe({
|
|
80
|
+
error(err) {
|
|
81
|
+
console.error('Failed to remove bookmark', err);
|
|
82
|
+
},
|
|
83
|
+
complete() {
|
|
84
|
+
console.debug('Bookmark removed');
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
Icon: <Icon name="delete_to_trash" />,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: bookmark.isShared ? 'Unshare' : 'Share',
|
|
92
|
+
disabled: false,
|
|
93
|
+
onClick: async () => {
|
|
94
|
+
from(
|
|
95
|
+
provider.updateBookmark(bookmark.id, {
|
|
96
|
+
isShared: !bookmark.isShared,
|
|
97
|
+
}),
|
|
98
|
+
).subscribe({
|
|
99
|
+
next(value) {
|
|
100
|
+
if (value.isShared) {
|
|
101
|
+
addBookmarkToClipboard(value.id);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
error(err) {
|
|
105
|
+
console.error('Failed to update bookmark', err);
|
|
106
|
+
},
|
|
107
|
+
complete() {
|
|
108
|
+
console.debug('Bookmark updated');
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
Icon: <Icon name="share" />,
|
|
113
|
+
},
|
|
114
|
+
] as MenuOption[];
|
|
115
|
+
} else {
|
|
116
|
+
return [
|
|
117
|
+
{
|
|
118
|
+
name: 'Unfavourite',
|
|
119
|
+
disabled: false,
|
|
120
|
+
onClick: () => {
|
|
121
|
+
from(provider.removeBookmarkAsFavorite(bookmark.id)).subscribe({
|
|
122
|
+
error(err) {
|
|
123
|
+
console.error('Failed to remove bookmark from favorites', err);
|
|
124
|
+
},
|
|
125
|
+
complete() {
|
|
126
|
+
console.debug('Bookmark removed from favorites');
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
Icon: <Icon name="close" />,
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
[provider, showEditBookmark, addBookmarkToClipboard, user, currentApp?.appKey],
|
|
136
|
+
);
|
|
140
137
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
))}
|
|
166
|
-
</>
|
|
167
|
-
);
|
|
138
|
+
return (
|
|
139
|
+
<>
|
|
140
|
+
{bookmarkGroups.filter(filterEmptyGroups).map(({ groupingProperty, values }) => (
|
|
141
|
+
<Section key={groupingProperty} name={toHumanReadable(groupingProperty)}>
|
|
142
|
+
{values.sort(sortByName).map((b) => (
|
|
143
|
+
<Row
|
|
144
|
+
menuOptions={createMenuOptions(b)}
|
|
145
|
+
key={b.id}
|
|
146
|
+
name={b.name}
|
|
147
|
+
id={b.id}
|
|
148
|
+
menuOpen={isMenuByIdOpen === b.id}
|
|
149
|
+
onMenuOpen={(id: string) => {
|
|
150
|
+
setIsMenuByIdOpen(id);
|
|
151
|
+
}}
|
|
152
|
+
>
|
|
153
|
+
{b.isShared && (
|
|
154
|
+
<SharedIcon createdById={b.createdBy.id} createdBy={b.createdBy.name} />
|
|
155
|
+
)}
|
|
156
|
+
</Row>
|
|
157
|
+
))}
|
|
158
|
+
</Section>
|
|
159
|
+
))}
|
|
160
|
+
</>
|
|
161
|
+
);
|
|
168
162
|
};
|
|
@@ -5,12 +5,12 @@ import { useFramework } from '@equinor/fusion-framework-react';
|
|
|
5
5
|
import styled from 'styled-components';
|
|
6
6
|
|
|
7
7
|
const Styled = {
|
|
8
|
-
|
|
8
|
+
Row: styled.div`
|
|
9
9
|
display: flex;
|
|
10
10
|
align-items: center;
|
|
11
11
|
gap: 0.2em;
|
|
12
12
|
`,
|
|
13
|
-
|
|
13
|
+
CreatedBy: styled.p`
|
|
14
14
|
font-size: 12px;
|
|
15
15
|
font-weight: 500;
|
|
16
16
|
line-height: 16px;
|
|
@@ -20,26 +20,26 @@ const Styled = {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
type SharedIconProps = {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
readonly createdBy: string;
|
|
24
|
+
readonly createdById: string;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export const SharedIcon = ({ createdBy, createdById }: SharedIconProps) => {
|
|
28
|
-
|
|
28
|
+
const myId = useFramework().modules.auth.defaultAccount?.localAccountId;
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
const isMe = createdById === myId;
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
return (
|
|
33
|
+
<Styled.Row>
|
|
34
|
+
{!isMe && <Styled.CreatedBy>shared by {createdBy}</Styled.CreatedBy>}
|
|
35
|
+
<Icon
|
|
36
|
+
name="share"
|
|
37
|
+
color={
|
|
38
|
+
isMe
|
|
39
|
+
? tokens.colors.interactive.primary__resting.hex
|
|
40
|
+
: tokens.colors.interactive.disabled__border.hex
|
|
41
|
+
}
|
|
42
|
+
/>
|
|
43
|
+
</Styled.Row>
|
|
44
|
+
);
|
|
45
45
|
};
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { Bookmarks, BookmarkWithoutData } from '@equinor/fusion-framework-module-bookmark';
|
|
1
|
+
import type { 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
7
|
const groupingModes: Record<GroupingKeys, (_item: BookmarkWithoutData) => string> = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
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');
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const bookmarkGroups = groupBy(bookmarks || [], groupingModes[groupByKey], searchText, 'name');
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
return {
|
|
21
|
+
setGroupBy,
|
|
22
|
+
setSearchText,
|
|
23
|
+
searchText,
|
|
24
|
+
bookmarkGroups,
|
|
25
|
+
groupingModes,
|
|
26
|
+
groupByKey,
|
|
27
|
+
};
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
const groupBy = <T>(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
array: T[],
|
|
32
|
+
getKey: (item: T) => string,
|
|
33
|
+
searchText: string | null,
|
|
34
|
+
field: keyof T,
|
|
35
35
|
) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
36
|
+
return (
|
|
37
|
+
array
|
|
38
|
+
?.map(getKey)
|
|
39
|
+
.filter((v, i, a) => a.indexOf(v) === i)
|
|
40
|
+
.map((groupingProperty) => ({
|
|
41
|
+
groupingProperty,
|
|
42
|
+
values: array
|
|
43
|
+
.filter((s) => getKey(s) === groupingProperty)
|
|
44
|
+
.filter((s) => {
|
|
45
|
+
const fieldData = s[field];
|
|
46
|
+
if (typeof fieldData === 'string' && searchText) {
|
|
47
|
+
return fieldData.includes(searchText);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return true;
|
|
51
|
+
}),
|
|
52
|
+
})) ?? []
|
|
53
|
+
);
|
|
54
54
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const appendBookmarkIdToUrl = (id: string): string => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const url = new URL(window.location.toString());
|
|
3
|
+
url.searchParams.set('bookmarkId', id);
|
|
4
|
+
return url.toString();
|
|
5
5
|
};
|
package/src/utils/utils.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Bookmarks, BookmarkWithoutData } from '@equinor/fusion-framework-module-bookmark';
|
|
1
|
+
import type { Bookmarks, BookmarkWithoutData } from '@equinor/fusion-framework-module-bookmark';
|
|
2
2
|
|
|
3
3
|
/** Helpers.. */
|
|
4
4
|
export const filterEmptyGroups = (i: { values: Bookmarks }) => i.values.length;
|
|
5
5
|
export const sortByName = (a: BookmarkWithoutData, b: BookmarkWithoutData) =>
|
|
6
|
-
|
|
6
|
+
a.name.localeCompare(b.name);
|
|
7
7
|
// const extractNameFromMail = (mail: string) => mail.split('@')[0].toLowerCase();
|
|
8
8
|
|
|
9
9
|
export const toHumanReadable = (val: string) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
val
|
|
11
|
+
.split('-')
|
|
12
|
+
.map((s) => `${s[0].toUpperCase()}${s.slice(1)}`)
|
|
13
|
+
.join(' ');
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '1.0.
|
|
2
|
+
export const version = '1.0.10';
|