Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(bookmark): align with existing code #2691

Merged
merged 21 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
303a8fd
refactor(bookmarks): update BookmarkProvider references to use IBookm…
odinr Dec 11, 2024
c252f9e
feat(bookmarks): add enableBookmark function for application integration
odinr Dec 11, 2024
6273ff8
refactor(cli): update BookmarkSideSheet to use component context
odinr Dec 11, 2024
a743f27
refactor(bookmarks): align React wiring with IBookmarkProvider interface
odinr Dec 11, 2024
7ffc348
fix(component-bookmark): minor adjustments
odinr Jan 6, 2025
a7ed939
fix(cli): updated bookmark component
odinr Jan 6, 2025
d4afa12
fix: updated bookmark cookbook
odinr Jan 6, 2025
e8356c6
chore: update lock file
odinr Jan 6, 2025
8539faa
fix(App): change console.log to console.warn for missing entryPoint
odinr Jan 20, 2025
e113b7d
fix(enable-bookmark): remove console.log for disposing bookmark module
odinr Jan 20, 2025
e3375ec
fix(cli): replace console.log with console.error for error handling i…
odinr Jan 20, 2025
ad669cd
fix(CreateBookmark): improve error handling and logging in createBook…
odinr Jan 20, 2025
dce9368
fix(bookmark): improve provider handling and update logging in bookma…
odinr Jan 20, 2025
a74deb3
fix(bookmark): enhance typing and conversion from API, update bookmar…
odinr Jan 20, 2025
cd5cef5
feat(bookmark): add support for user bookmarks v2 with enhanced filte…
odinr Jan 20, 2025
156d0f5
feat(Header): implement HeaderActions component and improve bookmark …
odinr Jan 20, 2025
4e08b7b
fix(flows): replace console.log with console.error for better error l…
odinr Jan 20, 2025
5689a67
refactor(bookmark): update bookmark parsing logic and deprecate outda…
odinr Jan 24, 2025
fab9525
docs(bookmark): add usage tips and examples for shared payload manage…
odinr Jan 24, 2025
0655e4f
fix(bookmark): improve handling of generator return values in Bookmar…
odinr Jan 24, 2025
f4e98bc
fix(header): update Icon usage for tag in Header.Actions component
odinr Jan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
refactor(bookmarks): update BookmarkProvider references to use IBookm…
…arkProvider interface
  • Loading branch information
odinr committed Jan 27, 2025
commit 303a8fd5fc2269a7599a3221264000bc65c7a73d
9 changes: 9 additions & 0 deletions .changeset/unlucky-drinks-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@equinor/fusion-framework-module-bookmark': minor
---

- Exposed the `IBookmarkProvider` interface and updated references.
- Improved handling of the parent provider in `BookmarkProvider`.
- Fixed `BookmarkProvider.on` to only emit when the source of the event is the provider.
- Refactored `BookmarkProvider.generatePayload` to better handle the creation and update of bookmark payloads.
- Ensured all observable executions to the API are terminated after the first successful or failed response.
6 changes: 5 additions & 1 deletion packages/modules/bookmark/src/BookmarkConfigurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { BookmarkClient } from './BookmarkClient';
import type { BookmarkModule } from './bookmark-module';
import { bookmarkConfigSchema } from './bookmark-config.schema';
import type { BookmarkModuleConfig } from './types';
import { BookmarkProvider } from './BookmarkProvider';

const initialBookmarkConfig = bookmarkConfigSchema
.pick({
Expand Down Expand Up @@ -199,7 +200,10 @@ export class BookmarkModuleConfigurator extends BaseConfigBuilder<BookmarkModule
const parentModules = init.ref as ModulesInstanceType<[BookmarkModule]>;
if (parentModules && 'bookmark' in parentModules) {
const parent = parentModules.bookmark;
if ('version' in parent && parent.version.satisfies('>=2.0.0')) {
if (
'version' in parent &&
(parent as unknown as BookmarkProvider).version.satisfies('>=2.0.0')
) {
this._set('parent', async () => parent);
} else {
this.#log?.warn('invalid version of parent BookmarkProvider provided');
Expand Down
30 changes: 15 additions & 15 deletions packages/modules/bookmark/src/BookmarkProvider.events.ts
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
import type { FrameworkEventInit, IFrameworkEvent } from '@equinor/fusion-framework-module-event';
import type { Bookmark } from './types';
import type { BookmarkPayloadGenerator, BookmarkProvider } from './BookmarkProvider';
import { BookmarkNew, BookmarkUpdate } from './BookmarkClient.interface';
import type { BookmarkPayloadGenerator, IBookmarkProvider } from './BookmarkProvider.interface';
import type { BookmarkNew, BookmarkUpdate } from './BookmarkClient.interface';

export interface BookmarkProviderEventMap {
/**
* An event that is emitted before current bookmark is changed.
*/
onCurrentBookmarkChange: IFrameworkEvent<
FrameworkEventInit<{ current?: Bookmark | null; next: Bookmark | null }, BookmarkProvider>
FrameworkEventInit<{ current?: Bookmark | null; next: Bookmark | null }, IBookmarkProvider>
>;

/**
* An event that is emitted when the current bookmark has changed.
*/
onCurrentBookmarkChanged: IFrameworkEvent<
FrameworkEventInit<Bookmark | null, BookmarkProvider>
FrameworkEventInit<Bookmark | null | undefined, IBookmarkProvider>
>;

/**
* An event that is emitted before a bookmark is created.
*/
onBookmarkCreate: IFrameworkEvent<FrameworkEventInit<BookmarkNew, BookmarkProvider>>;
onBookmarkCreate: IFrameworkEvent<FrameworkEventInit<BookmarkNew, IBookmarkProvider>>;

/**
* An event that is emitted when a bookmark has been created.
*/
onBookmarkCreated: IFrameworkEvent<FrameworkEventInit<Bookmark, BookmarkProvider>>;
onBookmarkCreated: IFrameworkEvent<FrameworkEventInit<Bookmark, IBookmarkProvider>>;

/**
* An event that is emitted before a bookmark is updated.
*/
onBookmarkUpdate: IFrameworkEvent<
FrameworkEventInit<{ current?: Bookmark; updates: BookmarkUpdate }, BookmarkProvider>
FrameworkEventInit<{ current?: Bookmark; updates: BookmarkUpdate }, IBookmarkProvider>
>;

/**
* An event that is emitted before a bookmark is updated.
*/
onBookmarkUpdated: IFrameworkEvent<FrameworkEventInit<Bookmark, BookmarkProvider>>;
onBookmarkUpdated: IFrameworkEvent<FrameworkEventInit<Bookmark, IBookmarkProvider>>;

/**
* An event that is emitted before a bookmark is removed.
*/
onBookmarkDelete: IFrameworkEvent<FrameworkEventInit<{ id: string }, BookmarkProvider>>;
onBookmarkDelete: IFrameworkEvent<FrameworkEventInit<{ id: string }, IBookmarkProvider>>;

/**
* An event that is emitted before a bookmark is removed.
*/
onBookmarkDeleted: IFrameworkEvent<FrameworkEventInit<{ id: string }, BookmarkProvider>>;
onBookmarkDeleted: IFrameworkEvent<FrameworkEventInit<{ id: string }, IBookmarkProvider>>;

/**
* An event that is emitted before a bookmark is added to the user's favorites.
*/
onBookmarkFavouriteRemove: IFrameworkEvent<
FrameworkEventInit<{ id: string }, BookmarkProvider>
FrameworkEventInit<{ id: string }, IBookmarkProvider>
>;

/**
* An event that is emitted when a bookmark is removed from the user's favorites.
*/
onBookmarkFavouriteRemoved: IFrameworkEvent<
FrameworkEventInit<{ id: string }, BookmarkProvider>
FrameworkEventInit<{ id: string }, IBookmarkProvider>
>;

/**
* An event that is emitted before a bookmark is added to the user's favorites.
*/
onBookmarkFavouriteAdd: IFrameworkEvent<FrameworkEventInit<{ id: string }, BookmarkProvider>>;
onBookmarkFavouriteAdd: IFrameworkEvent<FrameworkEventInit<{ id: string }, IBookmarkProvider>>;

/**
* An event that is emitted when a bookmark is added to the user's favorites.
*/
onBookmarkFavouriteAdded: IFrameworkEvent<
FrameworkEventInit<Bookmark | undefined, BookmarkProvider>
FrameworkEventInit<Bookmark | undefined, IBookmarkProvider>
>;

/**
* An event that is emitted when a new bookmark payload generator is added.
*/
onBookmarkPayloadCreatorAdded: IFrameworkEvent<
FrameworkEventInit<BookmarkPayloadGenerator, BookmarkProvider>
FrameworkEventInit<BookmarkPayloadGenerator, IBookmarkProvider>
>;
}

Expand Down
142 changes: 142 additions & 0 deletions packages/modules/bookmark/src/BookmarkProvider.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Observable, ObservableInput } from 'rxjs';
import type { Bookmark, BookmarkData, BookmarkWithoutData } from './types';
import { BookmarkNew, BookmarkUpdate } from './BookmarkClient.interface';
import { BookmarkProviderEventMap } from './BookmarkProvider.events';
import { BookmarkState } from './BookmarkProvider.store';

export type BookmarkCreateArgs<T extends BookmarkData = any> = Omit<
BookmarkNew<T>,
'appKey' | 'contextId' | 'sourceSystem'
> &
Partial<Pick<BookmarkNew<T>, 'appKey'>>;

export type BookmarkUpdateOptions = {
excludePayloadGeneration?: boolean;
};

export type BookmarkPayloadGenerator<TData extends BookmarkData = any> = (
payload?: Partial<TData> | null,
initial?: Partial<TData> | null,
) => Promise<Partial<TData> | void> | Partial<TData> | void;

/**
* Interface representing a Bookmark Provider.
*/
export interface IBookmarkProvider {
readonly currentBookmark: Bookmark | null | undefined;
/**
* Observable of the current bookmark.
*
* @type {ObservableInput<Bookmark | null | undefined>}
*/
readonly currentBookmark$: Observable<Bookmark | null | undefined>;

readonly bookmarks$: Observable<BookmarkWithoutData[]>;

/**
* Observable status of the bookmark provider.
*/
readonly status$: Observable<BookmarkState['status']>;

/**
* Indicates whether the user can create bookmarks.
* If no payload generator is provided, this will always be false.
*
* @type {boolean}
*/
readonly canCreateBookmarks: boolean;

/**
* fetch a bookmark by its ID.
*
* @param {string} bookmarkId - The ID of the bookmark to fetch.
* @returns {ObservableInput<Bookmark>} An observable input of the bookmark.
*/
getBookmark(bookmarkId: string): ObservableInput<Bookmark>;

/**
* Fetches all bookmarks.
*
* @returns {ObservableInput<Bookmark[]>} An observable input of the bookmarks.
*/
getAllBookmarks(): ObservableInput<Bookmark[]>;

/**
* Sets the current bookmark.
*
* @param {Bookmark | string | null} bookmark_or_id - The bookmark or its ID to set as current.
* @returns {ObservableInput<Bookmark | null>} An observable input of the current bookmark.
*/
setCurrentBookmark(bookmark_or_id: Bookmark | string | null): ObservableInput<Bookmark | null>;

/**
* Creates a new bookmark.
*
* @param {BookmarkCreateArgs} newBookmarkData - The data for the new bookmark.
* @returns {ObservableInput<Bookmark>} An observable input of the created bookmark.
*/
createBookmark(newBookmarkData: BookmarkCreateArgs): ObservableInput<Bookmark>;

/**
* Updates an existing bookmark.
*
* @param {string} bookmarkId - The ID of the bookmark to update.
* @param {BookmarkUpdate} [bookmarkUpdates] - The updates to apply to the bookmark.
* @param {BookmarkUpdateOptions} [options] - Additional options for the update.
* @returns {ObservableInput<Bookmark>} An observable input of the updated bookmark.
*/
updateBookmark(
bookmarkId: string,
bookmarkUpdates?: BookmarkUpdate,
options?: BookmarkUpdateOptions,
): ObservableInput<Bookmark>;

/**
* Deletes a bookmark.
*
* @param {string} bookmarkId - The ID of the bookmark to delete.
* @returns {ObservableInput<void>} An observable input indicating the deletion.
*/
deleteBookmark(bookmarkId: string): ObservableInput<void>;

/**
* Adds a bookmark to the favorites.
*
* @param {string} bookmarkId - The ID of the bookmark to add to favorites.
* @returns {ObservableInput<void>} An observable input indicating the addition.
*/
addBookmarkToFavorites(bookmarkId: string): ObservableInput<BookmarkWithoutData | undefined>;

/**
* Removes a bookmark from the favorites.
*
* @param {string} bookmarkId - The ID of the bookmark to remove from favorites.
* @returns {ObservableInput<void>} An observable input indicating the removal.
*/
removeBookmarkAsFavorite(bookmarkId: string): ObservableInput<void>;

/**
* Checks if a bookmark is in the favorites.
*
* @param bookmarkId
* @returns {ObservableInput<boolean>} An observable input indicating whether the bookmark is in the favorites.
*/
isBookmarkInFavorites(bookmarkId: string): ObservableInput<boolean>;

addPayloadGenerator<TData extends BookmarkData>(
generator: BookmarkPayloadGenerator<TData>,
): VoidFunction;

/**
* Registers an event listener for bookmark provider events.
*
* @param {TType} eventName - The name of the event to listen for.
* @param {(event: BookmarkProviderEventMap[TType]) => void} callback - The callback to invoke when the event is triggered.
* @returns {VoidFunction} A function to unregister the event listener.
*/
on<TType extends keyof BookmarkProviderEventMap>(
eventName: TType,
callback: (event: BookmarkProviderEventMap[TType]) => void,
): VoidFunction;
}
5 changes: 2 additions & 3 deletions packages/modules/bookmark/src/BookmarkProvider.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ export const bookmarkSelector = <T extends BookmarkData>(
*/
export const activeBookmarkSelector = <T extends BookmarkData>(
state: BookmarkState,
): Bookmark<T> | null => {
const selectedBookmark = state.currentBookmark as Bookmark<T>;
return selectedBookmark || null;
): Bookmark<T> | null | undefined => {
return state.currentBookmark as Bookmark<T> | null | undefined;
};

/**
Expand Down
Loading