@equinor/fusion-framework-react-components-bookmark 0.0.0-context-error-20240131144633

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 (93) hide show
  1. package/CHANGELOG.md +317 -0
  2. package/LICENSE +21 -0
  3. package/dist/esm/components/Bookmark.js +61 -0
  4. package/dist/esm/components/Bookmark.js.map +1 -0
  5. package/dist/esm/components/BookmarkProvider.js +33 -0
  6. package/dist/esm/components/BookmarkProvider.js.map +1 -0
  7. package/dist/esm/components/create-bookmark/CreateBookmark.js +34 -0
  8. package/dist/esm/components/create-bookmark/CreateBookmark.js.map +1 -0
  9. package/dist/esm/components/create-bookmark/index.js +2 -0
  10. package/dist/esm/components/create-bookmark/index.js.map +1 -0
  11. package/dist/esm/components/edit-bookmark/EditBookmark.js +65 -0
  12. package/dist/esm/components/edit-bookmark/EditBookmark.js.map +1 -0
  13. package/dist/esm/components/edit-bookmark/index.js +2 -0
  14. package/dist/esm/components/edit-bookmark/index.js.map +1 -0
  15. package/dist/esm/components/filter/Filter.js +19 -0
  16. package/dist/esm/components/filter/Filter.js.map +1 -0
  17. package/dist/esm/components/import-bookmark/ImportBookmark.js +28 -0
  18. package/dist/esm/components/import-bookmark/ImportBookmark.js.map +1 -0
  19. package/dist/esm/components/import-bookmark/index.js +2 -0
  20. package/dist/esm/components/import-bookmark/index.js.map +1 -0
  21. package/dist/esm/components/loading/Loading.js +10 -0
  22. package/dist/esm/components/loading/Loading.js.map +1 -0
  23. package/dist/esm/components/messages/Message.js +45 -0
  24. package/dist/esm/components/messages/Message.js.map +1 -0
  25. package/dist/esm/components/row/MoreMenu.js +11 -0
  26. package/dist/esm/components/row/MoreMenu.js.map +1 -0
  27. package/dist/esm/components/row/Row.js +47 -0
  28. package/dist/esm/components/row/Row.js.map +1 -0
  29. package/dist/esm/components/section/Section.js +41 -0
  30. package/dist/esm/components/section/Section.js.map +1 -0
  31. package/dist/esm/components/sectionList/SectionList.js +94 -0
  32. package/dist/esm/components/sectionList/SectionList.js.map +1 -0
  33. package/dist/esm/components/shared/SharedIcon.js +28 -0
  34. package/dist/esm/components/shared/SharedIcon.js.map +1 -0
  35. package/dist/esm/hooks/index.js +2 -0
  36. package/dist/esm/hooks/index.js.map +1 -0
  37. package/dist/esm/hooks/useBookmarkGrouping.js +35 -0
  38. package/dist/esm/hooks/useBookmarkGrouping.js.map +1 -0
  39. package/dist/esm/index.js +3 -0
  40. package/dist/esm/index.js.map +1 -0
  41. package/dist/esm/utils/append-bookmark-to-uri.js +6 -0
  42. package/dist/esm/utils/append-bookmark-to-uri.js.map +1 -0
  43. package/dist/esm/utils/utils.js +7 -0
  44. package/dist/esm/utils/utils.js.map +1 -0
  45. package/dist/esm/version.js +2 -0
  46. package/dist/esm/version.js.map +1 -0
  47. package/dist/tsconfig.tsbuildinfo +1 -0
  48. package/dist/types/components/Bookmark.d.ts +2 -0
  49. package/dist/types/components/BookmarkProvider.d.ts +14 -0
  50. package/dist/types/components/create-bookmark/CreateBookmark.d.ts +4 -0
  51. package/dist/types/components/create-bookmark/index.d.ts +1 -0
  52. package/dist/types/components/edit-bookmark/EditBookmark.d.ts +5 -0
  53. package/dist/types/components/edit-bookmark/index.d.ts +1 -0
  54. package/dist/types/components/filter/Filter.d.ts +10 -0
  55. package/dist/types/components/import-bookmark/ImportBookmark.d.ts +1 -0
  56. package/dist/types/components/import-bookmark/index.d.ts +1 -0
  57. package/dist/types/components/loading/Loading.d.ts +1 -0
  58. package/dist/types/components/messages/Message.d.ts +10 -0
  59. package/dist/types/components/row/MoreMenu.d.ts +10 -0
  60. package/dist/types/components/row/Row.d.ts +17 -0
  61. package/dist/types/components/section/Section.d.ts +7 -0
  62. package/dist/types/components/sectionList/SectionList.d.ts +6 -0
  63. package/dist/types/components/shared/SharedIcon.d.ts +6 -0
  64. package/dist/types/hooks/index.d.ts +1 -0
  65. package/dist/types/hooks/useBookmarkGrouping.d.ts +14 -0
  66. package/dist/types/index.d.ts +2 -0
  67. package/dist/types/utils/append-bookmark-to-uri.d.ts +1 -0
  68. package/dist/types/utils/utils.d.ts +6 -0
  69. package/dist/types/version.d.ts +1 -0
  70. package/package.json +55 -0
  71. package/src/components/Bookmark.tsx +95 -0
  72. package/src/components/BookmarkProvider.tsx +65 -0
  73. package/src/components/create-bookmark/CreateBookmark.tsx +93 -0
  74. package/src/components/create-bookmark/index.ts +1 -0
  75. package/src/components/edit-bookmark/EditBookmark.tsx +137 -0
  76. package/src/components/edit-bookmark/index.ts +1 -0
  77. package/src/components/filter/Filter.tsx +58 -0
  78. package/src/components/import-bookmark/ImportBookmark.tsx +57 -0
  79. package/src/components/import-bookmark/index.ts +1 -0
  80. package/src/components/loading/Loading.tsx +16 -0
  81. package/src/components/messages/Message.tsx +82 -0
  82. package/src/components/row/MoreMenu.tsx +34 -0
  83. package/src/components/row/Row.tsx +92 -0
  84. package/src/components/section/Section.tsx +57 -0
  85. package/src/components/sectionList/SectionList.tsx +161 -0
  86. package/src/components/shared/SharedIcon.tsx +45 -0
  87. package/src/hooks/index.ts +1 -0
  88. package/src/hooks/useBookmarkGrouping.ts +54 -0
  89. package/src/index.ts +2 -0
  90. package/src/utils/append-bookmark-to-uri.ts +5 -0
  91. package/src/utils/utils.ts +12 -0
  92. package/src/version.ts +2 -0
  93. package/tsconfig.json +23 -0
@@ -0,0 +1,2 @@
1
+ export declare const Bookmark: () => import("react/jsx-runtime").JSX.Element;
2
+ export default Bookmark;
@@ -0,0 +1,14 @@
1
+ import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
2
+ import { PropsWithChildren } from 'react';
3
+ export declare const BookmarkProvider: ({ children }: PropsWithChildren<unknown>) => import("react/jsx-runtime").JSX.Element;
4
+ declare module '@equinor/fusion-framework-module-event' {
5
+ interface FrameworkEventMap {
6
+ onBookmarkOpen: FrameworkEvent<FrameworkEventInit<boolean, unknown>>;
7
+ onBookmarkEdit: FrameworkEvent<FrameworkEventInit<{
8
+ bookmarkId: string;
9
+ }, unknown>>;
10
+ onBookmarkUrlCopy: FrameworkEvent<FrameworkEventInit<{
11
+ url: string;
12
+ }, unknown>>;
13
+ }
14
+ }
@@ -0,0 +1,4 @@
1
+ export declare const CreateBookmarkModal: ({ isOpen, onClose, }: {
2
+ readonly isOpen: boolean;
3
+ readonly onClose: (b: boolean) => void;
4
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './CreateBookmark';
@@ -0,0 +1,5 @@
1
+ export declare const EditBookmarkModal: ({ isOpen, onClose, bookmarkId, }: {
2
+ readonly isOpen: boolean;
3
+ readonly onClose: (b: boolean) => void;
4
+ readonly bookmarkId?: string | undefined;
5
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './EditBookmark';
@@ -0,0 +1,10 @@
1
+ import { GroupingKeys } from '../../hooks/useBookmarkGrouping';
2
+ type BookmarkFilterProps = {
3
+ readonly searchText: string;
4
+ readonly setSearchText: (newVal: string | null) => void;
5
+ readonly setGroupBy: (groupBy: GroupingKeys) => void;
6
+ readonly groupingModes: string[];
7
+ readonly groupBy: string;
8
+ };
9
+ export declare const BookmarkFilter: ({ searchText, setGroupBy, setSearchText, groupingModes, groupBy, }: BookmarkFilterProps) => import("react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1 @@
1
+ export declare const ImportBookmarkModal: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './ImportBookmark';
@@ -0,0 +1 @@
1
+ export declare const Loading: () => import("react/jsx-runtime").JSX.Element;
@@ -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 {};
@@ -0,0 +1,10 @@
1
+ import { MutableRefObject } from 'react';
2
+ import { MenuOption } from './Row';
3
+ type MenuProps = {
4
+ readonly pRef: MutableRefObject<HTMLElement | null>;
5
+ readonly onClose: VoidFunction;
6
+ readonly open: boolean;
7
+ readonly options: MenuOption[];
8
+ };
9
+ export declare const MoreMenu: ({ pRef, onClose, open, options }: MenuProps) => import("react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1,17 @@
1
+ import { ReactNode } from 'react';
2
+ export type MenuOption = {
3
+ name: string;
4
+ disabled: boolean;
5
+ onClick: VoidFunction;
6
+ Icon?: ReactNode;
7
+ };
8
+ type RowProps = {
9
+ readonly name: string;
10
+ readonly id: string;
11
+ readonly menuOpen: boolean;
12
+ readonly onMenuOpen: (id: string) => void;
13
+ readonly menuOptions: MenuOption[];
14
+ readonly children?: ReactNode;
15
+ };
16
+ export declare const Row: ({ name, menuOptions, children, id, menuOpen, onMenuOpen }: RowProps) => import("react/jsx-runtime").JSX.Element;
17
+ export {};
@@ -0,0 +1,7 @@
1
+ import { ReactNode } from 'react';
2
+ type SectionProps = {
3
+ readonly name: string;
4
+ readonly children: ReactNode;
5
+ };
6
+ export declare const Section: ({ children, name }: SectionProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,6 @@
1
+ import { useBookmarkGrouping } from '../../hooks';
2
+ type SectionListProps = {
3
+ readonly bookmarkGroups: ReturnType<typeof useBookmarkGrouping>['bookmarkGroups'];
4
+ };
5
+ export declare const SectionList: ({ bookmarkGroups }: SectionListProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,6 @@
1
+ type SharedIconProps = {
2
+ readonly createdBy: string;
3
+ readonly createdById: string;
4
+ };
5
+ export declare const SharedIcon: ({ createdBy, createdById }: SharedIconProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1 @@
1
+ export * from './useBookmarkGrouping';
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { Bookmark } from '@equinor/fusion-framework-module-bookmark';
3
+ export type GroupingKeys = 'Group by app' | 'Created by' | 'Group by Context';
4
+ export declare const useBookmarkGrouping: (bookmarks?: Bookmark[]) => {
5
+ setGroupBy: import("react").Dispatch<import("react").SetStateAction<GroupingKeys>>;
6
+ setSearchText: import("react").Dispatch<import("react").SetStateAction<string | null>>;
7
+ searchText: string | null;
8
+ bookmarkGroups: {
9
+ groupingProperty: string;
10
+ values: Bookmark<unknown>[];
11
+ }[];
12
+ groupingModes: Record<GroupingKeys, (_item: Bookmark) => string>;
13
+ groupByKey: GroupingKeys;
14
+ };
@@ -0,0 +1,2 @@
1
+ export { Bookmark } from './components/Bookmark';
2
+ export { BookmarkProvider } from './components/BookmarkProvider';
@@ -0,0 +1 @@
1
+ export declare const appendBookmarkIdToUrl: (id: string) => string;
@@ -0,0 +1,6 @@
1
+ import { Bookmark } from '@equinor/fusion-framework-module-bookmark';
2
+ export declare const filterEmptyGroups: (i: {
3
+ values: Bookmark[];
4
+ }) => number;
5
+ export declare const sortByName: (a: Bookmark, b: Bookmark) => number;
6
+ export declare const toHumanReadable: (val: string) => string;
@@ -0,0 +1 @@
1
+ export declare const version = "0.3.5";
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@equinor/fusion-framework-react-components-bookmark",
3
+ "version": "0.0.0-context-error-20240131144633",
4
+ "description": "",
5
+ "main": "dist/esm/index.js",
6
+ "exports": {
7
+ ".": "./dist/esm/index.js"
8
+ },
9
+ "types": "./dist/types/index.d.ts",
10
+ "keywords": [],
11
+ "author": "",
12
+ "license": "ISC",
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/equinor/fusion-framework.git",
19
+ "directory": "packages/react/components/bookmark"
20
+ },
21
+ "dependencies": {
22
+ "@equinor/fusion-framework-react": "^0.0.0-context-error-20240131144633",
23
+ "@equinor/fusion-framework-react-module-bookmark": "^0.0.0-context-error-20240131144633"
24
+ },
25
+ "devDependencies": {
26
+ "@equinor/eds-core-react": "^0.35.1",
27
+ "@equinor/eds-icons": "^0.21.0",
28
+ "@equinor/eds-tokens": "^0.9.2",
29
+ "@equinor/eds-utils": "^0.8.3",
30
+ "@types/react": "^18.2.20",
31
+ "react": "^18.2.0",
32
+ "styled-components": "^6.0.7",
33
+ "typescript": "^5.1.3",
34
+ "@equinor/fusion-framework-module-bookmark": "^1.1.0",
35
+ "@equinor/fusion-framework-module-app": "^5.2.12",
36
+ "@equinor/fusion-framework-module-event": "^4.0.7"
37
+ },
38
+ "peerDependencies": {
39
+ "@equinor/eds-core-react": "^0.35.1",
40
+ "@equinor/eds-icons": "^0.21.0",
41
+ "@equinor/eds-tokens": "^0.9.2",
42
+ "@equinor/eds-utils": "^0.8.3",
43
+ "@types/react": "^17.0.0 || ^18.0.0",
44
+ "react": "^17.0.0 || ^18.0.0",
45
+ "styled-components": "^6.0.7"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "@types/react": {
49
+ "optional": true
50
+ }
51
+ },
52
+ "scripts": {
53
+ "build": "tsc -b"
54
+ }
55
+ }
@@ -0,0 +1,95 @@
1
+ import { useBookmark } from '@equinor/fusion-framework-react-module-bookmark';
2
+ import { useBookmarkGrouping } from '../hooks';
3
+ import { BookmarkFilter } from './filter/Filter';
4
+ import { SectionList } from './sectionList/SectionList';
5
+ import { useEffect, useState } from 'react';
6
+
7
+ import { Icon } from '@equinor/eds-core-react';
8
+ import { chevron_down, chevron_right, share, more_vertical, add } from '@equinor/eds-icons';
9
+
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';
14
+
15
+ Icon.add({
16
+ chevron_down,
17
+ chevron_right,
18
+ share,
19
+ more_vertical,
20
+ add,
21
+ });
22
+
23
+ const Styled = {
24
+ Wrapper: styled.div`
25
+ padding-right: 1rem;
26
+ display: flex;
27
+ flex-direction: column;
28
+ gap: 1rem;
29
+ `,
30
+ List: styled.div`
31
+ overflow-y: auto;
32
+ overflow-x: hidden;
33
+ height: calc((100vh - 85px) - 3rem);
34
+ `,
35
+ NoContentWrapper: styled.div`
36
+ position: absolute;
37
+ top: 150px;
38
+ bottom: 200px;
39
+ left: 0px;
40
+ right: 0px;
41
+ `,
42
+ };
43
+
44
+ export const Bookmark = () => {
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]);
61
+
62
+ useEffect(() => {
63
+ getAllBookmarks();
64
+ }, [getAllBookmarks]);
65
+
66
+ const { bookmarkGroups, groupingModes, searchText, setGroupBy, setSearchText, groupByKey } =
67
+ useBookmarkGrouping(bookmarks);
68
+
69
+ return (
70
+ <Styled.Wrapper>
71
+ <BookmarkFilter
72
+ groupBy={groupByKey}
73
+ groupingModes={Object.keys(groupingModes)}
74
+ searchText={searchText ?? ''}
75
+ setGroupBy={setGroupBy}
76
+ setSearchText={setSearchText}
77
+ />
78
+ <Styled.List>
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
+ )}
90
+ </Styled.List>
91
+ </Styled.Wrapper>
92
+ );
93
+ };
94
+
95
+ export default Bookmark;
@@ -0,0 +1,65 @@
1
+ import { Snackbar } from '@equinor/eds-core-react';
2
+ import type { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
3
+ import { useFramework } from '@equinor/fusion-framework-react';
4
+ import { PropsWithChildren, useEffect, useState } from 'react';
5
+ import { CreateBookmarkModal } from './create-bookmark';
6
+ import { EditBookmarkModal } from './edit-bookmark';
7
+ import { ImportBookmarkModal } from './import-bookmark';
8
+
9
+ export const BookmarkProvider = ({ children }: PropsWithChildren<unknown>) => {
10
+ const [isCreateBookmarkOpen, setIsCreateBookmarkOpen] = useState(false);
11
+ const [isEditBookmarkOpen, setIsEditBookmarkOpen] = useState(false);
12
+ const [editBookmarkId, setEditBookmarkId] = useState<string | undefined>();
13
+ const [isBookmarkCopy, setIsBookmarkCopy] = useState(false);
14
+
15
+ const { event } = useFramework().modules;
16
+
17
+ useEffect(() => {
18
+ const subOnBookmarkOpen = event.addEventListener('onBookmarkOpen', (e) => {
19
+ setIsCreateBookmarkOpen(e.detail);
20
+ });
21
+
22
+ const subOnBookmarkEdit = event.addEventListener('onBookmarkEdit', (e) => {
23
+ setEditBookmarkId(e.detail.bookmarkId);
24
+ setIsEditBookmarkOpen(true);
25
+ });
26
+
27
+ const subOnBookmarkUrlCopy = event.addEventListener('onBookmarkUrlCopy', () => {
28
+ setIsBookmarkCopy(true);
29
+ });
30
+
31
+ return () => {
32
+ subOnBookmarkEdit();
33
+ subOnBookmarkOpen();
34
+ subOnBookmarkUrlCopy();
35
+ };
36
+ }, [event]);
37
+
38
+ return (
39
+ <>
40
+ <CreateBookmarkModal isOpen={isCreateBookmarkOpen} onClose={setIsCreateBookmarkOpen} />
41
+ <EditBookmarkModal
42
+ isOpen={isEditBookmarkOpen}
43
+ onClose={setIsEditBookmarkOpen}
44
+ bookmarkId={editBookmarkId}
45
+ />
46
+ <ImportBookmarkModal />
47
+ <Snackbar
48
+ autoHideDuration={2000}
49
+ onClose={() => setIsBookmarkCopy(false)}
50
+ open={isBookmarkCopy}
51
+ >
52
+ Bookmark url copied to clipboard
53
+ </Snackbar>
54
+ {children}
55
+ </>
56
+ );
57
+ };
58
+
59
+ declare module '@equinor/fusion-framework-module-event' {
60
+ interface FrameworkEventMap {
61
+ onBookmarkOpen: FrameworkEvent<FrameworkEventInit<boolean, unknown>>;
62
+ onBookmarkEdit: FrameworkEvent<FrameworkEventInit<{ bookmarkId: string }, unknown>>;
63
+ onBookmarkUrlCopy: FrameworkEvent<FrameworkEventInit<{ url: string }, unknown>>;
64
+ }
65
+ }
@@ -0,0 +1,93 @@
1
+ import { Button, Checkbox, Dialog, Input, Label, TextField } from '@equinor/eds-core-react';
2
+ import type { AppModule } from '@equinor/fusion-framework-module-app';
3
+ import { useFramework } from '@equinor/fusion-framework-react';
4
+ import { useBookmark } from '@equinor/fusion-framework-react-module-bookmark';
5
+ import { ChangeEvent, useState } from 'react';
6
+
7
+ import styled from 'styled-components';
8
+ // TODO
9
+ const StyledContent = styled(Dialog.Content)`
10
+ display: flex;
11
+ flex-direction: column;
12
+ gap: 1rem;
13
+ `;
14
+
15
+ export const CreateBookmarkModal = ({
16
+ isOpen,
17
+ onClose,
18
+ }: {
19
+ readonly isOpen: boolean;
20
+ readonly onClose: (b: boolean) => void;
21
+ }) => {
22
+ const [state, setState] = useState<{ name: string; description: string; isShared: boolean }>({
23
+ name: '',
24
+ description: '',
25
+ isShared: false,
26
+ });
27
+
28
+ const { current } = useFramework<[AppModule]>().modules.app;
29
+
30
+ const { createBookmark } = useBookmark();
31
+
32
+ return (
33
+ <Dialog style={{ width: '400px' }} open={isOpen}>
34
+ <Dialog.Header>Create bookmark</Dialog.Header>
35
+ <StyledContent>
36
+ <div>
37
+ <Label htmlFor="name" label="Name" />
38
+ <Input
39
+ id="name"
40
+ autoComplete="off"
41
+ value={state?.name}
42
+ onChange={(event: ChangeEvent<HTMLInputElement>) => {
43
+ setState((s) => ({ ...s, name: event.target.value }));
44
+ }}
45
+ />
46
+ </div>
47
+ <div>
48
+ <TextField
49
+ id="storybook-multiline-three"
50
+ label="Description"
51
+ multiline
52
+ rows={3}
53
+ rowsMax={10}
54
+ onChange={(event: ChangeEvent<HTMLInputElement>) => {
55
+ setState((s) => ({ ...s, description: event.target.value }));
56
+ }}
57
+ />
58
+ </div>
59
+ <div>
60
+ <Label htmlFor="app" label="App" />
61
+ <Input readOnly={true} value={current?.manifest?.name || ''} />
62
+ </div>
63
+
64
+ <div>
65
+ <Checkbox
66
+ label="Is Shared"
67
+ checked={state.isShared}
68
+ onChange={(event: ChangeEvent<HTMLInputElement>) => {
69
+ setState((s) => ({ ...s, isShared: event.target.checked }));
70
+ }}
71
+ />
72
+ </div>
73
+ </StyledContent>
74
+ <Dialog.Actions>
75
+ <div style={{ display: 'flex', gap: '0.2em' }}>
76
+ <Button onClick={() => onClose(false)} variant="ghost">
77
+ Cancel
78
+ </Button>
79
+ <Button
80
+ onClick={() => {
81
+ state &&
82
+ createBookmark(state).then(() => {
83
+ onClose(false);
84
+ });
85
+ }}
86
+ >
87
+ Create
88
+ </Button>
89
+ </div>
90
+ </Dialog.Actions>
91
+ </Dialog>
92
+ );
93
+ };
@@ -0,0 +1 @@
1
+ export * from './CreateBookmark';
@@ -0,0 +1,137 @@
1
+ import { ChangeEvent, useEffect, useState } from 'react';
2
+
3
+ import { Button, Checkbox, Dialog, Input, Label, TextField } from '@equinor/eds-core-react';
4
+ import type { AppModule } from '@equinor/fusion-framework-module-app';
5
+ // TODO - export from `@equinor/fusion-framework-react-module-bookmark`
6
+ import type { PatchBookmark } from '@equinor/fusion-framework-module-bookmark';
7
+ import { useFramework } from '@equinor/fusion-framework-react';
8
+ import { useBookmark } from '@equinor/fusion-framework-react-module-bookmark';
9
+ import { appendBookmarkIdToUrl } from '../../utils/append-bookmark-to-uri';
10
+
11
+ import styled from 'styled-components';
12
+
13
+ const Styled = {
14
+ Dialog: styled(Dialog)`
15
+ width: 500px;
16
+ `,
17
+ DialogContent: styled(Dialog.Content)`
18
+ display: flex;
19
+ flex-direction: column;
20
+ gap: 1rem;
21
+ `,
22
+ CheckboxWrapper: styled.div`
23
+ display: flex;
24
+ gap: 1rem;
25
+ `,
26
+ Actions: styled.div`
27
+ display: flex;
28
+ gap: 0.2em;
29
+ `,
30
+ };
31
+
32
+ export const EditBookmarkModal = ({
33
+ isOpen,
34
+ onClose,
35
+ bookmarkId,
36
+ }: {
37
+ readonly isOpen: boolean;
38
+ readonly onClose: (b: boolean) => void;
39
+ readonly bookmarkId?: string;
40
+ }) => {
41
+ const [state, setState] = useState<PatchBookmark>({
42
+ id: '',
43
+ appKey: '',
44
+ name: '',
45
+ description: '',
46
+ isShared: false,
47
+ });
48
+
49
+ const [updatePayload, setUpdatePayload] = useState(false);
50
+
51
+ const { app, event } = useFramework<[AppModule]>().modules;
52
+ const { current } = app;
53
+
54
+ const { updateBookmark, bookmarks } = useBookmark();
55
+
56
+ useEffect(() => {
57
+ const bookmark = bookmarks.find((b) => b.id === bookmarkId);
58
+ if (bookmark) {
59
+ setState(bookmark);
60
+ }
61
+ }, [bookmarkId, bookmarks]);
62
+
63
+ return (
64
+ <Styled.Dialog open={isOpen}>
65
+ <Dialog.Header>Edit bookmark</Dialog.Header>
66
+ <Styled.DialogContent>
67
+ <div>
68
+ <Label htmlFor="name" label="Name" />
69
+ <Input
70
+ id="name"
71
+ autoComplete="off"
72
+ value={state?.name}
73
+ onChange={(event: ChangeEvent<HTMLInputElement>) => {
74
+ setState((s) => ({ ...s, name: event.target.value }));
75
+ }}
76
+ />
77
+ </div>
78
+ <div>
79
+ <TextField
80
+ id="storybook-multiline-three"
81
+ label="Description"
82
+ value={state?.description}
83
+ multiline
84
+ rows={3}
85
+ rowsMax={10}
86
+ onChange={(event: ChangeEvent<HTMLInputElement>) => {
87
+ setState((s) => ({ ...s, description: event.target.value }));
88
+ }}
89
+ />
90
+ </div>
91
+ <div>
92
+ <Label htmlFor="app" label="App" />
93
+ <Input readOnly={true} value={current?.manifest?.name || ''} />
94
+ </div>
95
+
96
+ <Styled.CheckboxWrapper>
97
+ <Checkbox
98
+ label="Is Shared"
99
+ checked={state.isShared}
100
+ onChange={(changeEvent: ChangeEvent<HTMLInputElement>) => {
101
+ if (changeEvent.target.checked) {
102
+ const url = appendBookmarkIdToUrl(state.id);
103
+ navigator.clipboard.writeText(url);
104
+ event.dispatchEvent('onBookmarkUrlCopy', { detail: { url } });
105
+ }
106
+ setState((s) => ({ ...s, isShared: changeEvent.target.checked }));
107
+ }}
108
+ />
109
+ <Checkbox
110
+ label="Update bookmark with current view"
111
+ checked={updatePayload}
112
+ onChange={() => {
113
+ setUpdatePayload((s) => !s);
114
+ }}
115
+ />
116
+ </Styled.CheckboxWrapper>
117
+ </Styled.DialogContent>
118
+ <Dialog.Actions>
119
+ <Styled.Actions>
120
+ <Button onClick={() => onClose(false)} variant="ghost">
121
+ Cancel
122
+ </Button>
123
+ <Button
124
+ onClick={() => {
125
+ state &&
126
+ updateBookmark(state, { updatePayload }).then(() => {
127
+ onClose(false);
128
+ });
129
+ }}
130
+ >
131
+ Save
132
+ </Button>
133
+ </Styled.Actions>
134
+ </Dialog.Actions>
135
+ </Styled.Dialog>
136
+ );
137
+ };
@@ -0,0 +1 @@
1
+ export * from './EditBookmark';