npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@equinor/fusion-framework-module-bookmark

v2.0.1

Published

The Bookmark module provides a way to manage bookmarks in the application. It allows users to create, update, and remove bookmarks, as well as manage the current bookmark and the list of bookmarks.

Downloads

2,323

Readme

Bookmark Module

The Bookmark module provides a way to manage bookmarks in the application. It allows users to create, update, and remove bookmarks, as well as manage the current bookmark and the list of bookmarks.

Features

  • Create, update, and delete bookmarks
  • Manage current bookmark
  • Add and remove bookmarks from favorites
  • Event listeners for bookmark-related events

Setup

pnpm install @equinor/fusion-framework-module-bookmark
import { enableBookmarkModule } from ' @equinor/fusion-framework-module-bookmark'
const configure = (configurator) => {
  // simplest setup
  enableBookmarkModule(configurator);
}

Configuration

/** example of configuration */
enableBookmarkModule(configurator, async(builder) => {
    /** Set source system of bookmark, note used for queries and creation */
    builder.setSourceSystem({
        id: 'source-system-id',
        name: 'Source System Name',
    });

    /** apply filters for current application */
    builder.setFilter('application', true);

    /** apply filters for current context */
    builder.setFilter('context', true);

    /** === Advance Configuration === */

    /** override default implementations */
    builder.setClient(/** custom client implementation */)
    builder.setParent(/** custom parent implementation */)

    /** override default resolvers */
    builder.setContextResolver(/** custom context resolver implementation */)
    builder.setApplicationResolver(/** custom application resolver implementation */)
});

[!NOTE] When not providing configuration, the configurator will use the parent (ref initiator, example portal framework) configuration, then fallback to default configuration.

  • SourceSystem
  • Filter
  • ContextResolver
  • ApplicationResolver

BookmarkProvider

The BookmarkProvider class is responsible for managing bookmarks in the application. It provides methods for creating, updating, and removing bookmarks, as well as managing the current bookmark and the list of bookmarks.

Usage

Creating a Bookmark

To create a new bookmark, use the createBookmark method:

const newBookmark = {
    name: 'My Bookmark',
    payload: { /* Your bookmark data */ },
};

bookmarkProvider.createBookmark(newBookmark).subscribe({
    next: (bookmark) => {
        console.log('Bookmark created:', bookmark);
    },
    error: (err) => {
        console.error('Failed to create bookmark:', err);
    },
});

Updating a Bookmark

To update an existing bookmark, use the updateBookmark method:

const bookmarkId = 'bookmark-id';
const bookmarkUpdates = {
    name: 'Updated Bookmark Name',
    payload: { /* Updated bookmark data */ },
};

bookmarkProvider.updateBookmark(bookmarkId, bookmarkUpdates).subscribe({
    next: (updatedBookmark) => {
        console.log('Bookmark updated:', updatedBookmark);
    },
    error: (err) => {
        console.error('Failed to update bookmark:', err);
    },
});

Using payload generator

Callback function which triggers on creation or update of bookmark. It is used to modify the payload of the bookmark.

  • payload: The payload of the bookmark, which can be modified of other payload generators.
  • initial: The initial payload of the bookmark, which is the payload of the bookmark before any payload generators have been applied.
const bookmarkPayloadGenerator = (payload, initial) => {
    payload.counter = payload.counter ?? 0 + initial.counter;
};

Removing a Bookmark

To remove a bookmark, use the removeBookmark method:

const bookmarkId = 'bookmark-id';

bookmarkProvider.removeBookmark(bookmarkId).subscribe({
    next: (result) => {
        console.log('Bookmark removed:', result);
    },
    error: (err) => {
        console.error('Failed to remove bookmark:', err);
    },
});

Managing Favorites

To add a bookmark to favorites, use the addBookmarkToFavorites method:

const bookmarkId = 'bookmark-id';

bookmarkProvider.addBookmarkToFavorites(bookmarkId).subscribe({
    next: (bookmark) => {
        console.log('Bookmark added to favorites:', bookmark);
    },
    error: (err) => {
        console.error('Failed to add bookmark to favorites:', err);
    },
});

To remove a bookmark from favorites, use the removeBookmarkFromFavorites method:

const bookmarkId = 'bookmark-id';
bookmarkProvider.removeBookmarkFromFavorites(bookmarkId).subscribe({
    next: (bookmark) => {
        console.log('Bookmark removed from favorites:', bookmark);
    },
    error: (err) => {
        console.error('Failed to remove bookmark from favorites:', err);
    },
});

To check if a bookmark is in favorites, use the isBookmarkInFavorites method:

const bookmarkId = 'bookmark-id';

bookmarkProvider.isBookmarkInFavorites(bookmarkId).subscribe({
    next: (isFavorite) => {
        console.log('Is bookmark in favorites:', isFavorite);
    },
    error: (err) => {
        console.error('Failed to check if bookmark is in favorites:', err);
    },
});

Event Listeners

You can register event listeners for various bookmark-related events:

const removeListener = bookmarkProvider.on('onCurrentBookmarkChanged', (event) => {
    console.log('Current bookmark changed:', event.detail);
});

// To remove the event listener
removeListener();

Client

The BookmarkClient class is responsible for fetching bookmarks from the source system. It provides methods for fetching bookmarks by ID, fetching bookmarks by query, and fetching the current bookmark. This is the default implementation of the client and created if not overridden in the configuration.

/** Example usage with BookmarkClient as stand alone */
import { BookmarkClient } from '@equinor/fusion-bookmark';
import { BookmarksApiClient } from '@equinor/fusion-framework-module-services/bookmarks';
import { HttpClient } from '@equinor/fusion-framework-module-http/client';

const httpClient = new HttpClient('https://my-fusion-backend-url.com');
const apiClient = new BookmarksApiClient(httpClient, 'json$');
const client = new BookmarkClient(apiClient);

client.getAllBookmarks().subscribe(bookmarks => {
    // do something with bookmarks
});

client.getBookmarkById('bookmark-id').subscribe(bookmark => {
// do something with bookmark
});

Custom Client

By implementing the IBookmarkClient interface, you can create a custom client implementation.

import { IBookmarkClient } from '@equinor/fusion-bookmark';

export class CustomBookmarkClient implements IBookmarkClient {
    // Implement the interface methods
}

const configure = (configurator) => {
    enableBookmarkModule(configurator, async(builder) => {
        builder.setClient(new CustomBookmarkClient());
    });
};