@equinor/fusion-framework-react-components-bookmark 0.1.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 +18 -0
- package/LICENSE +21 -0
- package/dist/esm/components/Bookmark.js +39 -0
- package/dist/esm/components/Bookmark.js.map +1 -0
- package/dist/esm/components/BookmarkProvider.js +33 -0
- package/dist/esm/components/BookmarkProvider.js.map +1 -0
- package/dist/esm/components/create-bookmark/CreateBookmark.js +34 -0
- package/dist/esm/components/create-bookmark/CreateBookmark.js.map +1 -0
- package/dist/esm/components/create-bookmark/index.js +2 -0
- package/dist/esm/components/create-bookmark/index.js.map +1 -0
- package/dist/esm/components/edit-bookmark/EditBookmark.js +66 -0
- package/dist/esm/components/edit-bookmark/EditBookmark.js.map +1 -0
- package/dist/esm/components/edit-bookmark/index.js +2 -0
- package/dist/esm/components/edit-bookmark/index.js.map +1 -0
- package/dist/esm/components/filter/Filter.js +16 -0
- package/dist/esm/components/filter/Filter.js.map +1 -0
- package/dist/esm/components/import-bookmark/ImportBookmark.js +28 -0
- package/dist/esm/components/import-bookmark/ImportBookmark.js.map +1 -0
- package/dist/esm/components/import-bookmark/index.js +2 -0
- package/dist/esm/components/import-bookmark/index.js.map +1 -0
- package/dist/esm/components/loading/Loading.js +10 -0
- package/dist/esm/components/loading/Loading.js.map +1 -0
- package/dist/esm/components/row/MoreMenu.js +11 -0
- package/dist/esm/components/row/MoreMenu.js.map +1 -0
- package/dist/esm/components/row/Row.js +47 -0
- package/dist/esm/components/row/Row.js.map +1 -0
- package/dist/esm/components/section/Section.js +42 -0
- package/dist/esm/components/section/Section.js.map +1 -0
- package/dist/esm/components/sectionList/SectionList.js +103 -0
- package/dist/esm/components/sectionList/SectionList.js.map +1 -0
- package/dist/esm/components/shared/SharedIcon.js +26 -0
- package/dist/esm/components/shared/SharedIcon.js.map +1 -0
- package/dist/esm/hooks/index.js +2 -0
- package/dist/esm/hooks/index.js.map +1 -0
- package/dist/esm/hooks/useBookmarkGrouping.js +35 -0
- package/dist/esm/hooks/useBookmarkGrouping.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/utils/append-bookmark-to-uri.js +6 -0
- package/dist/esm/utils/append-bookmark-to-uri.js.map +1 -0
- package/dist/esm/utils/utils.js +7 -0
- package/dist/esm/utils/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/components/Bookmark.d.ts +3 -0
- package/dist/types/components/BookmarkProvider.d.ts +14 -0
- package/dist/types/components/create-bookmark/CreateBookmark.d.ts +5 -0
- package/dist/types/components/create-bookmark/index.d.ts +1 -0
- package/dist/types/components/edit-bookmark/EditBookmark.d.ts +6 -0
- package/dist/types/components/edit-bookmark/index.d.ts +1 -0
- package/dist/types/components/filter/Filter.d.ts +11 -0
- package/dist/types/components/import-bookmark/ImportBookmark.d.ts +2 -0
- package/dist/types/components/import-bookmark/index.d.ts +1 -0
- package/dist/types/components/loading/Loading.d.ts +2 -0
- package/dist/types/components/row/MoreMenu.d.ts +10 -0
- package/dist/types/components/row/Row.d.ts +17 -0
- package/dist/types/components/section/Section.d.ts +7 -0
- package/dist/types/components/sectionList/SectionList.d.ts +7 -0
- package/dist/types/components/shared/SharedIcon.d.ts +7 -0
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/hooks/useBookmarkGrouping.d.ts +14 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/utils/append-bookmark-to-uri.d.ts +1 -0
- package/dist/types/utils/utils.d.ts +6 -0
- package/package.json +61 -0
- package/src/components/Bookmark.tsx +59 -0
- package/src/components/BookmarkProvider.tsx +65 -0
- package/src/components/create-bookmark/CreateBookmark.tsx +92 -0
- package/src/components/create-bookmark/index.ts +1 -0
- package/src/components/edit-bookmark/EditBookmark.tsx +136 -0
- package/src/components/edit-bookmark/index.ts +1 -0
- package/src/components/filter/Filter.tsx +48 -0
- package/src/components/import-bookmark/ImportBookmark.tsx +56 -0
- package/src/components/import-bookmark/index.ts +1 -0
- package/src/components/loading/Loading.tsx +16 -0
- package/src/components/row/MoreMenu.tsx +32 -0
- package/src/components/row/Row.tsx +90 -0
- package/src/components/section/Section.tsx +59 -0
- package/src/components/sectionList/SectionList.tsx +171 -0
- package/src/components/shared/SharedIcon.tsx +43 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useBookmarkGrouping.ts +54 -0
- package/src/index.ts +2 -0
- package/src/utils/append-bookmark-to-uri.ts +5 -0
- package/src/utils/utils.ts +12 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { css } from '@emotion/css';
|
|
2
|
+
import { Button, Dialog } from '@equinor/eds-core-react';
|
|
3
|
+
import { useBookmark } from '@equinor/fusion-framework-react-module-bookmark';
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
|
|
6
|
+
const styles = {
|
|
7
|
+
actionWrapper: css`
|
|
8
|
+
display: flex;
|
|
9
|
+
gap: 1rem;
|
|
10
|
+
`,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const ImportBookmarkModal = () => {
|
|
14
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
15
|
+
|
|
16
|
+
const { currentBookmark, bookmarks, addBookmarkFavorite } = useBookmark();
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!bookmarks || !currentBookmark || bookmarks.length === 0) return;
|
|
20
|
+
|
|
21
|
+
if (bookmarks.findIndex(({ id }) => id === currentBookmark.id) === -1) {
|
|
22
|
+
setIsOpen(true);
|
|
23
|
+
}
|
|
24
|
+
}, [bookmarks, currentBookmark]);
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Dialog style={{ width: '600px' }} open={isOpen}>
|
|
28
|
+
<Dialog.Header>Import bookmark</Dialog.Header>
|
|
29
|
+
<Dialog.Content>
|
|
30
|
+
<p>This bookmark was created by {currentBookmark?.createdBy.name}</p>
|
|
31
|
+
<p>Would you like to import it?</p>
|
|
32
|
+
</Dialog.Content>
|
|
33
|
+
<Dialog.Actions>
|
|
34
|
+
<div className={styles.actionWrapper}>
|
|
35
|
+
<Button
|
|
36
|
+
onClick={() => setIsOpen(false)}
|
|
37
|
+
variant={'ghost'}
|
|
38
|
+
style={{ width: '70px' }}
|
|
39
|
+
>
|
|
40
|
+
No
|
|
41
|
+
</Button>
|
|
42
|
+
<Button
|
|
43
|
+
onClick={() => {
|
|
44
|
+
console.log(currentBookmark?.id);
|
|
45
|
+
currentBookmark && addBookmarkFavorite(currentBookmark.id);
|
|
46
|
+
setIsOpen(false);
|
|
47
|
+
}}
|
|
48
|
+
variant="ghost"
|
|
49
|
+
>
|
|
50
|
+
Import
|
|
51
|
+
</Button>
|
|
52
|
+
</div>
|
|
53
|
+
</Dialog.Actions>
|
|
54
|
+
</Dialog>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ImportBookmark';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CircularProgress } from '@equinor/eds-core-react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
export const Loading = () => (
|
|
5
|
+
<div
|
|
6
|
+
style={{
|
|
7
|
+
display: 'flex',
|
|
8
|
+
alignItems: 'center',
|
|
9
|
+
justifyContent: 'center',
|
|
10
|
+
height: '100%',
|
|
11
|
+
width: '100%',
|
|
12
|
+
}}
|
|
13
|
+
>
|
|
14
|
+
<CircularProgress />
|
|
15
|
+
</div>
|
|
16
|
+
);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Menu } from '@equinor/eds-core-react';
|
|
2
|
+
import { MutableRefObject } from 'react';
|
|
3
|
+
import { MenuOption } from './Row';
|
|
4
|
+
|
|
5
|
+
type MenuProps = {
|
|
6
|
+
pRef: MutableRefObject<HTMLElement | null>;
|
|
7
|
+
onClose: VoidFunction;
|
|
8
|
+
open: boolean;
|
|
9
|
+
options: MenuOption[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const MoreMenu = ({ pRef, onClose, open, options }: MenuProps) => {
|
|
13
|
+
return (
|
|
14
|
+
<Menu open={open} anchorEl={pRef.current}>
|
|
15
|
+
{options.map(({ onClick, name, disabled, Icon }) => (
|
|
16
|
+
<Menu.Item
|
|
17
|
+
disabled={disabled}
|
|
18
|
+
onClick={(e) => {
|
|
19
|
+
e.stopPropagation();
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
onClick();
|
|
22
|
+
onClose();
|
|
23
|
+
}}
|
|
24
|
+
key={name}
|
|
25
|
+
>
|
|
26
|
+
{Icon && Icon}
|
|
27
|
+
{name}
|
|
28
|
+
</Menu.Item>
|
|
29
|
+
))}
|
|
30
|
+
</Menu>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { css } from '@emotion/css';
|
|
2
|
+
import { Icon, Typography } from '@equinor/eds-core-react';
|
|
3
|
+
import { tokens } from '@equinor/eds-tokens';
|
|
4
|
+
import { useOutsideClick } from '@equinor/eds-utils';
|
|
5
|
+
import { useBookmark } from '@equinor/fusion-framework-react-module-bookmark';
|
|
6
|
+
import { MutableRefObject, ReactNode, useRef } from 'react';
|
|
7
|
+
import { MoreMenu } from './MoreMenu';
|
|
8
|
+
|
|
9
|
+
export type MenuOption = {
|
|
10
|
+
name: string;
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
onClick: VoidFunction;
|
|
13
|
+
Icon?: ReactNode;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type RowProps = {
|
|
17
|
+
name: string;
|
|
18
|
+
id: string;
|
|
19
|
+
menuOpen: boolean;
|
|
20
|
+
onMenuOpen: (id: string) => void;
|
|
21
|
+
menuOptions: MenuOption[];
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const styles = {
|
|
26
|
+
iconRow: css`
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: row;
|
|
29
|
+
gap: 0.2em;
|
|
30
|
+
align-items: center;
|
|
31
|
+
`,
|
|
32
|
+
row: css`
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
&:hover {
|
|
35
|
+
background-color: ${tokens.colors.ui.background__light.hex};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
display: flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
height: 32px;
|
|
41
|
+
min-height: 32px;
|
|
42
|
+
max-height: 32px;
|
|
43
|
+
justify-content: space-between;
|
|
44
|
+
border-bottom: 1px solid ${tokens.colors.ui.background__medium.hex};
|
|
45
|
+
`,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const Row = ({ name, menuOptions, children, id, menuOpen, onMenuOpen }: RowProps) => {
|
|
49
|
+
const pRef = useRef<HTMLElement | null>(null);
|
|
50
|
+
const { setCurrentBookmark } = useBookmark();
|
|
51
|
+
|
|
52
|
+
useOutsideClick(pRef.current, () => onMenuOpen(''));
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<li
|
|
56
|
+
className={styles.row}
|
|
57
|
+
onClick={(e) => {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
e.stopPropagation();
|
|
60
|
+
setCurrentBookmark(id);
|
|
61
|
+
}}
|
|
62
|
+
>
|
|
63
|
+
<Typography>{name}</Typography>
|
|
64
|
+
<div className={styles.iconRow}>
|
|
65
|
+
{children}
|
|
66
|
+
{!!menuOptions?.length && (
|
|
67
|
+
<Icon
|
|
68
|
+
name="more_vertical"
|
|
69
|
+
onClick={(e) => {
|
|
70
|
+
e.preventDefault();
|
|
71
|
+
e.stopPropagation();
|
|
72
|
+
onMenuOpen(id);
|
|
73
|
+
}}
|
|
74
|
+
color={tokens.colors.interactive.primary__resting.hex}
|
|
75
|
+
ref={pRef as unknown as MutableRefObject<SVGSVGElement>}
|
|
76
|
+
/>
|
|
77
|
+
)}
|
|
78
|
+
|
|
79
|
+
<MoreMenu
|
|
80
|
+
open={menuOpen}
|
|
81
|
+
options={menuOptions}
|
|
82
|
+
onClose={() => {
|
|
83
|
+
onMenuOpen('');
|
|
84
|
+
}}
|
|
85
|
+
pRef={pRef}
|
|
86
|
+
/>
|
|
87
|
+
</div>
|
|
88
|
+
</li>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { Button, Icon, Typography } from '@equinor/eds-core-react';
|
|
4
|
+
import { chevron_down, chevron_right } from '@equinor/eds-icons';
|
|
5
|
+
|
|
6
|
+
import { css } from '@emotion/css';
|
|
7
|
+
import { tokens } from '@equinor/eds-tokens';
|
|
8
|
+
import styled from '@emotion/styled';
|
|
9
|
+
|
|
10
|
+
const styles = {
|
|
11
|
+
childrenFlex: css`
|
|
12
|
+
margin-left: 0.7rem;
|
|
13
|
+
padding-left: 1rem;
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
gap: 1rem;
|
|
17
|
+
border-left: 1px solid ${tokens.colors.infographic.primary__moss_green_100.hex};
|
|
18
|
+
`,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const StyledButton = styled(Button)`
|
|
22
|
+
width: 100%;
|
|
23
|
+
padding: 0;
|
|
24
|
+
padding-top: 0.5rem;
|
|
25
|
+
margin-bottom: 0.5rem;
|
|
26
|
+
display: flex;
|
|
27
|
+
justify-content: space-between;
|
|
28
|
+
align-items: center;
|
|
29
|
+
background: none;
|
|
30
|
+
border: none;
|
|
31
|
+
color: ${tokens.colors.infographic.primary__moss_green_100.hex};
|
|
32
|
+
cursor: pointer;
|
|
33
|
+
:hover {
|
|
34
|
+
background: none;
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
Icon.add({
|
|
39
|
+
chevron_down,
|
|
40
|
+
chevron_right,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
type SectionProps = {
|
|
44
|
+
name: string;
|
|
45
|
+
children: ReactNode;
|
|
46
|
+
};
|
|
47
|
+
export const Section = ({ children, name }: SectionProps) => {
|
|
48
|
+
const [isExpanded, setIsExpanded] = useState(true);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div>
|
|
52
|
+
<StyledButton variant="ghost" onClick={() => setIsExpanded((s) => !s)}>
|
|
53
|
+
<Icon name={isExpanded ? chevron_down.name : chevron_right.name} />
|
|
54
|
+
<Typography variant="h6">{name}</Typography>
|
|
55
|
+
</StyledButton>
|
|
56
|
+
{isExpanded && <ol className={styles.childrenFlex}>{children}</ol>}
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { Icon } from '@equinor/eds-core-react';
|
|
2
|
+
import { useBookmarkGrouping } from '../../hooks';
|
|
3
|
+
import { Row } from '../row/Row';
|
|
4
|
+
import { Section } from '../section/Section';
|
|
5
|
+
import { SharedIcon } from '../shared/SharedIcon';
|
|
6
|
+
import { Bookmark } from '@equinor/fusion-framework-module-bookmark';
|
|
7
|
+
import { useBookmark } from '@equinor/fusion-framework-react-module-bookmark';
|
|
8
|
+
import { useCurrentUser } from '@equinor/fusion-framework-react/hooks';
|
|
9
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
10
|
+
import { delete_to_trash, share, edit, close, update } from '@equinor/eds-icons';
|
|
11
|
+
import { useFramework } from '@equinor/fusion-framework-react';
|
|
12
|
+
import { appendBookmarkIdToUrl } from '../../utils/append-bookmark-to-uri';
|
|
13
|
+
import { filterEmptyGroups, sortByName, toHumanReadable } from '../../utils/utils';
|
|
14
|
+
import { Loading } from '../loading/Loading';
|
|
15
|
+
|
|
16
|
+
Icon.add({
|
|
17
|
+
delete_to_trash,
|
|
18
|
+
edit,
|
|
19
|
+
share,
|
|
20
|
+
close,
|
|
21
|
+
update,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
type SectionListProps = {
|
|
25
|
+
bookmarkGroups: ReturnType<typeof useBookmarkGrouping>['bookmarkGroups'];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const SectionList = ({ bookmarkGroups }: SectionListProps) => {
|
|
29
|
+
const { deleteBookmarkById, getCurrentAppKey, updateBookmark, removeBookmarkFavorite } =
|
|
30
|
+
useBookmark();
|
|
31
|
+
|
|
32
|
+
const [loading, setLoading] = useState(true);
|
|
33
|
+
|
|
34
|
+
const user = useCurrentUser();
|
|
35
|
+
const [isMenuByIdOpen, setIsMenuByIdOpen] = useState('');
|
|
36
|
+
|
|
37
|
+
const { event } = useFramework().modules;
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
return event.addEventListener('onBookmarksChanged', () => {
|
|
41
|
+
setLoading(false);
|
|
42
|
+
});
|
|
43
|
+
}, [event]);
|
|
44
|
+
|
|
45
|
+
const editBookmark = useCallback(
|
|
46
|
+
(bookmarkId: string) => {
|
|
47
|
+
event.dispatchEvent('onBookmarkEdit', { detail: { bookmarkId } });
|
|
48
|
+
},
|
|
49
|
+
[event]
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const shareBookmark = useCallback(
|
|
53
|
+
(bookmark: Bookmark) => {
|
|
54
|
+
if (!bookmark.isShared) {
|
|
55
|
+
const url = appendBookmarkIdToUrl(bookmark.id);
|
|
56
|
+
navigator.clipboard.writeText(url);
|
|
57
|
+
event.dispatchEvent('onBookmarkUrlCopy', { detail: { url } });
|
|
58
|
+
}
|
|
59
|
+
updateBookmark({ ...bookmark, isShared: !bookmark.isShared });
|
|
60
|
+
},
|
|
61
|
+
[event, updateBookmark]
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const updateBookmarkWithCurrentView = useCallback(
|
|
65
|
+
(bookmark: Bookmark) => {
|
|
66
|
+
updateBookmark({ ...bookmark }, { updatePayload: true });
|
|
67
|
+
},
|
|
68
|
+
[updateBookmark]
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const createMenuOptions = (bookmark: Bookmark) =>
|
|
72
|
+
createBookmarkActions(
|
|
73
|
+
bookmark,
|
|
74
|
+
deleteBookmarkById,
|
|
75
|
+
editBookmark,
|
|
76
|
+
shareBookmark,
|
|
77
|
+
removeBookmarkFavorite,
|
|
78
|
+
updateBookmarkWithCurrentView,
|
|
79
|
+
getCurrentAppKey(),
|
|
80
|
+
user?.localAccountId
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
if (loading) return <Loading />;
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<>
|
|
87
|
+
{bookmarkGroups.filter(filterEmptyGroups).map(({ groupingProperty, values }) => (
|
|
88
|
+
<Section key={groupingProperty} name={toHumanReadable(groupingProperty)}>
|
|
89
|
+
{values.sort(sortByName).map((b) => (
|
|
90
|
+
<Row
|
|
91
|
+
menuOptions={createMenuOptions(b)}
|
|
92
|
+
key={b.id}
|
|
93
|
+
name={b.name}
|
|
94
|
+
id={b.id}
|
|
95
|
+
menuOpen={isMenuByIdOpen === b.id}
|
|
96
|
+
onMenuOpen={(id: string) => {
|
|
97
|
+
setIsMenuByIdOpen(id);
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
{b.isShared && (
|
|
101
|
+
<SharedIcon
|
|
102
|
+
createdById={b.createdBy.azureUniqueId}
|
|
103
|
+
createdBy={b.createdBy.name}
|
|
104
|
+
/>
|
|
105
|
+
)}
|
|
106
|
+
</Row>
|
|
107
|
+
))}
|
|
108
|
+
</Section>
|
|
109
|
+
))}
|
|
110
|
+
</>
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
function createBookmarkActions(
|
|
115
|
+
bookmark: Bookmark,
|
|
116
|
+
deleteBookmarkById: (bookmarkId: string) => Promise<string>,
|
|
117
|
+
editBookmark: (bookmark: string) => void,
|
|
118
|
+
shareBookmark: (bookmark: Bookmark) => void,
|
|
119
|
+
removeBookmarkFavorite: (bookmarkId: string) => void,
|
|
120
|
+
updateBookmarkWithCurrentView: (bookmark: Bookmark) => void,
|
|
121
|
+
appKey?: string,
|
|
122
|
+
localAccountId?: string
|
|
123
|
+
) {
|
|
124
|
+
if (bookmark.createdBy.azureUniqueId === localAccountId) {
|
|
125
|
+
return [
|
|
126
|
+
{
|
|
127
|
+
name: 'Edit',
|
|
128
|
+
disabled: appKey !== bookmark.appKey,
|
|
129
|
+
onClick: () => {
|
|
130
|
+
editBookmark(bookmark.id);
|
|
131
|
+
},
|
|
132
|
+
Icon: <Icon name="edit" />,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'Update with current view',
|
|
136
|
+
disabled: appKey !== bookmark.appKey,
|
|
137
|
+
onClick: () => {
|
|
138
|
+
updateBookmarkWithCurrentView(bookmark);
|
|
139
|
+
},
|
|
140
|
+
Icon: <Icon name="update" />,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: 'Remove',
|
|
144
|
+
disabled: false,
|
|
145
|
+
onClick: () => {
|
|
146
|
+
deleteBookmarkById(bookmark.id);
|
|
147
|
+
},
|
|
148
|
+
Icon: <Icon name="delete_to_trash" />,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: bookmark.isShared ? 'Unshare' : 'Share',
|
|
152
|
+
disabled: false,
|
|
153
|
+
onClick: () => {
|
|
154
|
+
shareBookmark(bookmark);
|
|
155
|
+
},
|
|
156
|
+
Icon: <Icon name="share" />,
|
|
157
|
+
},
|
|
158
|
+
];
|
|
159
|
+
} else {
|
|
160
|
+
return [
|
|
161
|
+
{
|
|
162
|
+
name: 'Unfavourite',
|
|
163
|
+
disabled: false,
|
|
164
|
+
onClick: () => {
|
|
165
|
+
removeBookmarkFavorite(bookmark.id);
|
|
166
|
+
},
|
|
167
|
+
Icon: <Icon name="close" />,
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import styled from '@emotion/styled';
|
|
2
|
+
import { Icon } from '@equinor/eds-core-react';
|
|
3
|
+
import { tokens } from '@equinor/eds-tokens';
|
|
4
|
+
import { useFramework } from '@equinor/fusion-framework-react';
|
|
5
|
+
|
|
6
|
+
type SharedIconProps = {
|
|
7
|
+
createdBy: string;
|
|
8
|
+
createdById: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const SharedIcon = ({ createdBy, createdById }: SharedIconProps) => {
|
|
12
|
+
const myId = useFramework().modules.auth.defaultAccount?.localAccountId;
|
|
13
|
+
|
|
14
|
+
const isMe = createdById === myId;
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<StyledRow>
|
|
18
|
+
{!isMe && <StyledCreatedBy>shared by {createdBy}</StyledCreatedBy>}
|
|
19
|
+
<Icon
|
|
20
|
+
name="share"
|
|
21
|
+
color={
|
|
22
|
+
isMe
|
|
23
|
+
? tokens.colors.interactive.primary__resting.hex
|
|
24
|
+
: tokens.colors.interactive.disabled__border.hex
|
|
25
|
+
}
|
|
26
|
+
/>
|
|
27
|
+
</StyledRow>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const StyledRow = styled.div`
|
|
32
|
+
display: flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
gap: 0.2em;
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
const StyledCreatedBy = styled.p`
|
|
38
|
+
font-size: 12px;
|
|
39
|
+
font-weight: 500;
|
|
40
|
+
line-height: 16px;
|
|
41
|
+
letter-spacing: 0em;
|
|
42
|
+
text-align: right;
|
|
43
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useBookmarkGrouping';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Bookmark } from '@equinor/fusion-framework-module-bookmark';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
|
|
5
|
+
export type GroupingKeys = 'Group by app' | 'Created by' | 'Group by Context';
|
|
6
|
+
|
|
7
|
+
const groupingModes: Record<GroupingKeys, (item: Bookmark) => string> = {
|
|
8
|
+
'Group by app': (item: Bookmark) => item.appKey,
|
|
9
|
+
'Created by': (item: Bookmark) => item.createdBy.name,
|
|
10
|
+
'Group by Context': (item: Bookmark) => item?.context?.name ?? 'Unknown',
|
|
11
|
+
} as const;
|
|
12
|
+
|
|
13
|
+
export const useBookmarkGrouping = (bookmarks?: Bookmark[]) => {
|
|
14
|
+
const [searchText, setSearchText] = useState<string | null>(null);
|
|
15
|
+
|
|
16
|
+
const [groupByKey, setGroupBy] = useState<keyof typeof groupingModes>('Group by app');
|
|
17
|
+
|
|
18
|
+
const bookmarkGroups = groupBy(bookmarks || [], groupingModes[groupByKey], searchText, 'name');
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
setGroupBy,
|
|
22
|
+
setSearchText,
|
|
23
|
+
searchText,
|
|
24
|
+
bookmarkGroups,
|
|
25
|
+
groupingModes,
|
|
26
|
+
groupByKey,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const groupBy = <T>(
|
|
31
|
+
array: T[],
|
|
32
|
+
getKey: (item: T) => string,
|
|
33
|
+
searchText: string | null,
|
|
34
|
+
field: keyof T
|
|
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
|
+
);
|
|
54
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Bookmark } from '@equinor/fusion-framework-module-bookmark';
|
|
2
|
+
|
|
3
|
+
/** Helpers.. */
|
|
4
|
+
export const filterEmptyGroups = (i: { values: Bookmark[] }) => i.values.length;
|
|
5
|
+
export const sortByName = (a: Bookmark, b: Bookmark) => a.name.localeCompare(b.name);
|
|
6
|
+
// const extractNameFromMail = (mail: string) => mail.split('@')[0].toLowerCase();
|
|
7
|
+
|
|
8
|
+
export const toHumanReadable = (val: string) =>
|
|
9
|
+
val
|
|
10
|
+
.split('-')
|
|
11
|
+
.map((s) => `${s[0].toUpperCase()}${s.slice(1)}`)
|
|
12
|
+
.join(' ');
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.react.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "dist/esm",
|
|
5
|
+
"rootDir": "src",
|
|
6
|
+
"declarationDir": "./dist/types",
|
|
7
|
+
"baseUrl": "src",
|
|
8
|
+
},
|
|
9
|
+
"references": [
|
|
10
|
+
|
|
11
|
+
],
|
|
12
|
+
"include": [
|
|
13
|
+
"src/**/*"
|
|
14
|
+
],
|
|
15
|
+
"exclude": [
|
|
16
|
+
"node_modules",
|
|
17
|
+
"lib"
|
|
18
|
+
]
|
|
19
|
+
}
|