@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,14 @@
|
|
|
1
|
+
import { FrameworkEvent, FrameworkEventInit } from '@equinor/fusion-framework-module-event';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
3
|
+
export declare const BookmarkProvider: ({ children }: PropsWithChildren<unknown>) => 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 @@
|
|
|
1
|
+
export * from './CreateBookmark';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './EditBookmark';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { GroupingKeys } from '../../hooks/useBookmarkGrouping';
|
|
3
|
+
type BookmarkFilterProps = {
|
|
4
|
+
searchText: string;
|
|
5
|
+
setSearchText: (newVal: string | null) => void;
|
|
6
|
+
setGroupBy: (groupBy: GroupingKeys) => void;
|
|
7
|
+
groupingModes: string[];
|
|
8
|
+
groupBy: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const BookmarkFilter: ({ searchText, setGroupBy, setSearchText, groupingModes, groupBy, }: BookmarkFilterProps) => JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ImportBookmark';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
|
+
import { MenuOption } from './Row';
|
|
3
|
+
type MenuProps = {
|
|
4
|
+
pRef: MutableRefObject<HTMLElement | null>;
|
|
5
|
+
onClose: VoidFunction;
|
|
6
|
+
open: boolean;
|
|
7
|
+
options: MenuOption[];
|
|
8
|
+
};
|
|
9
|
+
export declare const MoreMenu: ({ pRef, onClose, open, options }: MenuProps) => 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
|
+
name: string;
|
|
10
|
+
id: string;
|
|
11
|
+
menuOpen: boolean;
|
|
12
|
+
onMenuOpen: (id: string) => void;
|
|
13
|
+
menuOptions: MenuOption[];
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
};
|
|
16
|
+
export declare const Row: ({ name, menuOptions, children, id, menuOpen, onMenuOpen }: RowProps) => JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { useBookmarkGrouping } from '../../hooks';
|
|
3
|
+
type SectionListProps = {
|
|
4
|
+
bookmarkGroups: ReturnType<typeof useBookmarkGrouping>['bookmarkGroups'];
|
|
5
|
+
};
|
|
6
|
+
export declare const SectionList: ({ bookmarkGroups }: SectionListProps) => JSX.Element;
|
|
7
|
+
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 @@
|
|
|
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;
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@equinor/fusion-framework-react-components-bookmark",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/esm/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/esm/index.js"
|
|
8
|
+
},
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc -b",
|
|
12
|
+
"prepack": "yarn build"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/equinor/fusion-framework.git",
|
|
23
|
+
"directory": "packages/react/components/bookmark"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@equinor/eds-utils": "^0.7.0",
|
|
27
|
+
"@equinor/fusion-framework-react-module-bookmark": "^1.0.5"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@emotion/css": "^11.10.6",
|
|
31
|
+
"@emotion/react": "^11.10.6",
|
|
32
|
+
"@emotion/styled": "^11.10.6",
|
|
33
|
+
"@equinor/eds-core-react": "^0.30.0",
|
|
34
|
+
"@equinor/eds-icons": "^0.19.1",
|
|
35
|
+
"@equinor/eds-tokens": "^0.9.0",
|
|
36
|
+
"@types/react": "^17.0.11",
|
|
37
|
+
"react": "^17.0.2",
|
|
38
|
+
"react-dom": "^17.0.2",
|
|
39
|
+
"styled-components": "^5.3.9",
|
|
40
|
+
"typescript": "^4.9.3"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@emotion/css": "^11.10.6",
|
|
44
|
+
"@emotion/styled": "^11.10.6",
|
|
45
|
+
"@equinor/eds-core-react": "^0.30.0",
|
|
46
|
+
"@equinor/eds-icons": "^0.19.1",
|
|
47
|
+
"@equinor/eds-tokens": "^0.9.0",
|
|
48
|
+
"@types/react": "^17.0.0 || ^18.0.0",
|
|
49
|
+
"react": "^17.0.0 || ^18.0.0",
|
|
50
|
+
"styled-components": "^5.3.9"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"@types/react": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"react-dom": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"gitHead": "6983a4f2bf1fb24c086abcba53c2349d39f34a21"
|
|
61
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 { css } from '@emotion/css';
|
|
6
|
+
import { useEffect } from 'react';
|
|
7
|
+
|
|
8
|
+
import { Icon } from '@equinor/eds-core-react';
|
|
9
|
+
import { chevron_down, chevron_right, share, more_vertical, add } from '@equinor/eds-icons';
|
|
10
|
+
|
|
11
|
+
Icon.add({
|
|
12
|
+
chevron_down,
|
|
13
|
+
chevron_right,
|
|
14
|
+
share,
|
|
15
|
+
more_vertical,
|
|
16
|
+
add,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const style = {
|
|
20
|
+
wrapper: css`
|
|
21
|
+
padding-right: 1rem;
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
gap: 1rem;
|
|
25
|
+
`,
|
|
26
|
+
list: css`
|
|
27
|
+
overflow-y: auto;
|
|
28
|
+
overflow-x: hidden;
|
|
29
|
+
height: calc((100vh - 85px) - 3rem);
|
|
30
|
+
`,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const Bookmark = () => {
|
|
34
|
+
const { bookmarks, getAllBookmarks } = useBookmark();
|
|
35
|
+
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
getAllBookmarks();
|
|
38
|
+
}, [getAllBookmarks]);
|
|
39
|
+
|
|
40
|
+
const { bookmarkGroups, groupingModes, searchText, setGroupBy, setSearchText, groupByKey } =
|
|
41
|
+
useBookmarkGrouping(bookmarks);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className={style.wrapper}>
|
|
45
|
+
<BookmarkFilter
|
|
46
|
+
groupBy={groupByKey}
|
|
47
|
+
groupingModes={Object.keys(groupingModes)}
|
|
48
|
+
searchText={searchText ?? ''}
|
|
49
|
+
setGroupBy={setGroupBy}
|
|
50
|
+
setSearchText={setSearchText}
|
|
51
|
+
/>
|
|
52
|
+
<div className={style.list}>
|
|
53
|
+
<SectionList bookmarkGroups={bookmarkGroups} />
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default Bookmark;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Snackbar } from '@equinor/eds-core-react';
|
|
2
|
+
import { 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,92 @@
|
|
|
1
|
+
import styled from '@emotion/styled';
|
|
2
|
+
import { Button, Checkbox, Dialog, Input, Label, TextField } from '@equinor/eds-core-react';
|
|
3
|
+
import { AppModule } from '@equinor/fusion-framework-module-app';
|
|
4
|
+
import { useFramework } from '@equinor/fusion-framework-react';
|
|
5
|
+
import { useBookmark } from '@equinor/fusion-framework-react-module-bookmark';
|
|
6
|
+
import { ChangeEvent, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
const StyledContent = styled(Dialog.Content)`
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
gap: 1rem;
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export const CreateBookmarkModal = ({
|
|
15
|
+
isOpen,
|
|
16
|
+
onClose,
|
|
17
|
+
}: {
|
|
18
|
+
isOpen: boolean;
|
|
19
|
+
onClose: (b: boolean) => void;
|
|
20
|
+
}) => {
|
|
21
|
+
const [state, setState] = useState<{ name: string; description: string; isShared: boolean }>({
|
|
22
|
+
name: '',
|
|
23
|
+
description: '',
|
|
24
|
+
isShared: false,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const { current } = useFramework<[AppModule]>().modules.app;
|
|
28
|
+
|
|
29
|
+
const { createBookmark } = useBookmark();
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Dialog style={{ width: '400px' }} open={isOpen}>
|
|
33
|
+
<Dialog.Header>Create bookmark</Dialog.Header>
|
|
34
|
+
<StyledContent>
|
|
35
|
+
<div>
|
|
36
|
+
<Label htmlFor="name" label="Name" />
|
|
37
|
+
<Input
|
|
38
|
+
id="name"
|
|
39
|
+
autoComplete="off"
|
|
40
|
+
value={state?.name}
|
|
41
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
42
|
+
setState((s) => ({ ...s, name: event.target.value }));
|
|
43
|
+
}}
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
46
|
+
<div>
|
|
47
|
+
<TextField
|
|
48
|
+
id="storybook-multiline-three"
|
|
49
|
+
label="Description"
|
|
50
|
+
multiline
|
|
51
|
+
rows={3}
|
|
52
|
+
rowsMax={10}
|
|
53
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
54
|
+
setState((s) => ({ ...s, description: event.target.value }));
|
|
55
|
+
}}
|
|
56
|
+
/>
|
|
57
|
+
</div>
|
|
58
|
+
<div>
|
|
59
|
+
<Label htmlFor="app" label="App" />
|
|
60
|
+
<Input readOnly={true} value={current?.manifest?.name || ''} />
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<div>
|
|
64
|
+
<Checkbox
|
|
65
|
+
label="Is Shared"
|
|
66
|
+
checked={state.isShared}
|
|
67
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
68
|
+
setState((s) => ({ ...s, isShared: event.target.checked }));
|
|
69
|
+
}}
|
|
70
|
+
/>
|
|
71
|
+
</div>
|
|
72
|
+
</StyledContent>
|
|
73
|
+
<Dialog.Actions>
|
|
74
|
+
<div style={{ display: 'flex', gap: '0.2em' }}>
|
|
75
|
+
<Button onClick={() => onClose(false)} variant="ghost">
|
|
76
|
+
Cancel
|
|
77
|
+
</Button>
|
|
78
|
+
<Button
|
|
79
|
+
onClick={() => {
|
|
80
|
+
state &&
|
|
81
|
+
createBookmark(state).then(() => {
|
|
82
|
+
onClose(false);
|
|
83
|
+
});
|
|
84
|
+
}}
|
|
85
|
+
>
|
|
86
|
+
Create
|
|
87
|
+
</Button>
|
|
88
|
+
</div>
|
|
89
|
+
</Dialog.Actions>
|
|
90
|
+
</Dialog>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CreateBookmark';
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { css } from '@emotion/css';
|
|
2
|
+
import styled from '@emotion/styled';
|
|
3
|
+
import { Button, Checkbox, Dialog, Input, Label, TextField } from '@equinor/eds-core-react';
|
|
4
|
+
import { AppModule } from '@equinor/fusion-framework-module-app';
|
|
5
|
+
import { PatchBookmark } from '@equinor/fusion-framework-module-bookmark';
|
|
6
|
+
import { useFramework } from '@equinor/fusion-framework-react';
|
|
7
|
+
import { useBookmark } from '@equinor/fusion-framework-react-module-bookmark';
|
|
8
|
+
import { ChangeEvent, useEffect, useState } from 'react';
|
|
9
|
+
import { appendBookmarkIdToUrl } from '../../utils/append-bookmark-to-uri';
|
|
10
|
+
|
|
11
|
+
const StyledContent = styled(Dialog.Content)`
|
|
12
|
+
display: flex;
|
|
13
|
+
flex-direction: column;
|
|
14
|
+
gap: 1rem;
|
|
15
|
+
`;
|
|
16
|
+
const StyledDialog = styled(Dialog)`
|
|
17
|
+
width: 500px;
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
const styles = {
|
|
21
|
+
checkboxWrapper: css`
|
|
22
|
+
display: flex;
|
|
23
|
+
gap: 1rem;
|
|
24
|
+
`,
|
|
25
|
+
actions: css`
|
|
26
|
+
display: 'flex';
|
|
27
|
+
gap: 0.2em;
|
|
28
|
+
`,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const EditBookmarkModal = ({
|
|
32
|
+
isOpen,
|
|
33
|
+
onClose,
|
|
34
|
+
bookmarkId,
|
|
35
|
+
}: {
|
|
36
|
+
isOpen: boolean;
|
|
37
|
+
onClose: (b: boolean) => void;
|
|
38
|
+
bookmarkId?: string;
|
|
39
|
+
}) => {
|
|
40
|
+
const [state, setState] = useState<PatchBookmark>({
|
|
41
|
+
id: '',
|
|
42
|
+
appKey: '',
|
|
43
|
+
name: '',
|
|
44
|
+
description: '',
|
|
45
|
+
isShared: false,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const [updatePayload, setUpdatePayload] = useState(false);
|
|
49
|
+
|
|
50
|
+
const { app, event } = useFramework<[AppModule]>().modules;
|
|
51
|
+
const { current } = app;
|
|
52
|
+
|
|
53
|
+
const { updateBookmark, bookmarks } = useBookmark();
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const bookmark = bookmarks.find((b) => b.id === bookmarkId);
|
|
57
|
+
if (bookmark) {
|
|
58
|
+
setState(bookmark);
|
|
59
|
+
}
|
|
60
|
+
}, [bookmarkId, bookmarks]);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<StyledDialog open={isOpen}>
|
|
64
|
+
<Dialog.Header>Edit bookmark</Dialog.Header>
|
|
65
|
+
<StyledContent>
|
|
66
|
+
<div>
|
|
67
|
+
<Label htmlFor="name" label="Name" />
|
|
68
|
+
<Input
|
|
69
|
+
id="name"
|
|
70
|
+
autoComplete="off"
|
|
71
|
+
value={state?.name}
|
|
72
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
73
|
+
setState((s) => ({ ...s, name: event.target.value }));
|
|
74
|
+
}}
|
|
75
|
+
/>
|
|
76
|
+
</div>
|
|
77
|
+
<div>
|
|
78
|
+
<TextField
|
|
79
|
+
id="storybook-multiline-three"
|
|
80
|
+
label="Description"
|
|
81
|
+
value={state?.description}
|
|
82
|
+
multiline
|
|
83
|
+
rows={3}
|
|
84
|
+
rowsMax={10}
|
|
85
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
86
|
+
setState((s) => ({ ...s, description: event.target.value }));
|
|
87
|
+
}}
|
|
88
|
+
/>
|
|
89
|
+
</div>
|
|
90
|
+
<div>
|
|
91
|
+
<Label htmlFor="app" label="App" />
|
|
92
|
+
<Input readOnly={true} value={current?.manifest?.name || ''} />
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<div className={styles.checkboxWrapper}>
|
|
96
|
+
<Checkbox
|
|
97
|
+
label="Is Shared"
|
|
98
|
+
checked={state.isShared}
|
|
99
|
+
onChange={(changeEvent: ChangeEvent<HTMLInputElement>) => {
|
|
100
|
+
if (changeEvent.target.checked) {
|
|
101
|
+
const url = appendBookmarkIdToUrl(state.id);
|
|
102
|
+
navigator.clipboard.writeText(url);
|
|
103
|
+
event.dispatchEvent('onBookmarkUrlCopy', { detail: { url } });
|
|
104
|
+
}
|
|
105
|
+
setState((s) => ({ ...s, isShared: changeEvent.target.checked }));
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
<Checkbox
|
|
109
|
+
label="Update bookmark with current view"
|
|
110
|
+
checked={updatePayload}
|
|
111
|
+
onChange={() => {
|
|
112
|
+
setUpdatePayload((s) => !s);
|
|
113
|
+
}}
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
</StyledContent>
|
|
117
|
+
<Dialog.Actions>
|
|
118
|
+
<div className={styles.actions}>
|
|
119
|
+
<Button onClick={() => onClose(false)} variant="ghost">
|
|
120
|
+
Cancel
|
|
121
|
+
</Button>
|
|
122
|
+
<Button
|
|
123
|
+
onClick={() => {
|
|
124
|
+
state &&
|
|
125
|
+
updateBookmark(state, { updatePayload }).then(() => {
|
|
126
|
+
onClose(false);
|
|
127
|
+
});
|
|
128
|
+
}}
|
|
129
|
+
>
|
|
130
|
+
Save
|
|
131
|
+
</Button>
|
|
132
|
+
</div>
|
|
133
|
+
</Dialog.Actions>
|
|
134
|
+
</StyledDialog>
|
|
135
|
+
);
|
|
136
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './EditBookmark';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { css } from '@emotion/css';
|
|
2
|
+
import { Search, Autocomplete } from '@equinor/eds-core-react';
|
|
3
|
+
import { GroupingKeys } from '../../hooks/useBookmarkGrouping';
|
|
4
|
+
|
|
5
|
+
type BookmarkFilterProps = {
|
|
6
|
+
searchText: string;
|
|
7
|
+
setSearchText: (newVal: string | null) => void;
|
|
8
|
+
setGroupBy: (groupBy: GroupingKeys) => void;
|
|
9
|
+
groupingModes: string[];
|
|
10
|
+
groupBy: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const styles = {
|
|
14
|
+
row: css`
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
justify-content: space-between;
|
|
18
|
+
`,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const BookmarkFilter = ({
|
|
22
|
+
searchText,
|
|
23
|
+
setGroupBy,
|
|
24
|
+
setSearchText,
|
|
25
|
+
groupingModes,
|
|
26
|
+
groupBy,
|
|
27
|
+
}: BookmarkFilterProps) => {
|
|
28
|
+
return (
|
|
29
|
+
<div className={styles.row}>
|
|
30
|
+
<Search
|
|
31
|
+
placeholder="Search in my bookmarks"
|
|
32
|
+
value={searchText ?? ''}
|
|
33
|
+
onChange={(e) => {
|
|
34
|
+
setSearchText(e.currentTarget.value.length ? e.currentTarget.value : null);
|
|
35
|
+
}}
|
|
36
|
+
/>
|
|
37
|
+
<Autocomplete
|
|
38
|
+
options={groupingModes}
|
|
39
|
+
selectedOptions={[groupBy]}
|
|
40
|
+
multiple={false}
|
|
41
|
+
hideClearButton
|
|
42
|
+
autoWidth
|
|
43
|
+
onOptionsChange={(changes) => setGroupBy(changes.selectedItems[0] as GroupingKeys)}
|
|
44
|
+
label={''}
|
|
45
|
+
/>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
};
|