Skip to main content

dashboardConfigCacheManager

Reference

  • The dashboardConfigCacheManager is a utility function that retrieve of dashboard configurations, such as filters, sorting, and selected widgets, using local storage.
  • It is used to retrieve dashboard state for a specific typeName.
  • It retrieve previously saved filters, sorting, and selected widgets.

Props

  1. typeName
    • Type: string
    • Description: The name of the data type for which the dashboard configuration is being managed.
    • Example: "Project", "Task".

Methods

  1. hydrateFiltersAndSort(widgetConfig)

    • Description: Retrieves the saved filters and sorting for a widget. If no cached data exists, it returns the default filters and sorting from widgetConfig.
    • Parameters:
      • widgetConfig: The widget's configuration object.
    • Returns: An object with filter and sort.
  2. hydrateSelectedWidget()

    • Description: Retrieves the ID of the previously selected widget from the cache.
    • Returns: The ID of the selected widget or null if not found.

Usage Example

const typeName = 'Project';
const cacheManager = dashboardConfigCacheManager(typeName);

// Retrieve filters and sorting for a widget
const widgetConfig = { id: 'widget1', stateFilter: 'All', sortBy: 'Name' };
const { filter, sort } = cacheManager.hydrateFiltersAndSort(widgetConfig);
console.log(filter, sort);

// Retrieve the selected widget
const selectedWidget = cacheManager.hydrateSelectedWidget();
console.log(selectedWidget);