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