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

@veeqo/custom-views

v1.3.57

Published

veeqo custom views

Downloads

11

Readme

Custom Views

Implement Views from veeqo-components library

Installation

Using npm:

npm install @veeqo/components
npm install @veeqo/custom-views

Using yarn:

yarn add @veeqo/components
yarn add @veeqo/custom-views

Step by step Custom Views implementing to your project:

Step 1: Go to your root file where you call ReactDOM render

Step 2: Create fixedViews array

It's fixed views so the user can't delete them

Example of fixed views:

const fixedViews = [
  {
    id: 'default1',
    key: 'default1',
    label: 'First default',
    type: 'fixed',
  },
  {
    id: 'default1',
    key: 'default2',
    label: 'Second default',
    type: 'fixed',
  },
];

Also, you can provide some additional info:

  • duplicatable. This prop control is Duplicate item visible in options. By default it's true
  • filters. This prop can be any type you want, this is what you will get at some points when you need to change the saved filters

Example of fixed view with those props:

{
  id: 'default',
  key: 'default',
  label: 'Not duplicatable default',
  type: 'fixed',
  duplicatable: false,
  filters: {
    metric: 'units_sold',
    groupBy: 'by_variants',
  },
},

Step 3: Create apiHandlers object

Example of apiHandlers:


const apiHandlers = {
  fetch: (customViewModelType) => new Promise((resolve) => (
    fetchViews(customViewModelType)
      .then((result) => resolve({ data: result })))),
  post: (view) => new Promise((resolve) => (
    saveView(view, store.dispatch)
      .then(((result) => {
        resolve({
          data: {
            id: result.body.data.id,
          },
        });
      }))
  )),
  patch: (view) => {
    saveView(view);
    setFiltersToView(view.key, view.attributes.filters);
  },
  delete: (viewId) => deleteView(viewId),
};

This object should have 4 functions:

  • fetch. Used when the store started initialization. Should be a Promise. Arguments:

  1. customViewModelType, string. Name of your page, for example: inventory or sales
  • persist. Used when view saved and its type was draft so you need to send this new view to server. Should be a Promise and resolve with id that you will get from the server. Arguments:

  1. view, object. View with all attributes. Example:
{
  type: 'custom_view',
  key: 'l6PJGo-UKXeGJNFBFzCde',
  user: {
    userId: 'XOBDXR15v0mkOoNaYp24K',
  },
  attributes: {
    title: 'Some Draft Tab',
    type: 'sales',
    filters: {
      metric: 'units_sold',
      groupBy: 'by_variants',
    },
    editable: true,
    shared: true,
  },
}
  • patch. Same as persist, but view already has saved type so you don't need to return Promise and resolve id, but you still should send changed view to server. Arguments are the same as in persist

  • delete. Used when saved view deleted. Arguments:

  1. viewId, string

Step 4: Create CustomViewsProviderFactory

This factory will create a store and pass the first data to it. Here you should use variables that you create in step 3 and step 4

Example:

const CustomViewsContextProvider = CustomViewsProviderFactory({
  customViewModelType: getLocation(),
  apiHandlers,
  fixedViews,
});

Step 5: Add provider to your ReactDOM render

Example:

ReactDOM.render(
  <Provider store={store}>
    <CustomViewsContextProvider>
      <App />
    </CustomViewsContextProvider>
  </Provider>,
  root,
);

Step 6: Create CustomViews component

Example:


import React from 'react';

import { CustomViews } from '@veeqo/custom-views';

const CustomViewsComponent = (props) => (
  <CustomViews {...props} />
);

export default CustomViewsComponent;

Step 7: Pass props to component

Props required for initialization

Those props you should get from user XHR, until you don't, pass null. You can't change those values inside store after initialization

| Name | Type | Description | |---------------------|------------------|-------------------------------------------------------------| | customViewPositions | string[] | null | Initialization doesn't start until you don't pass an array | | defaultViewId | string | null | Initialization doesn't start until you don't pass a string |

Props required for proper work

| Name | Type | Description | Example | |-------------------|-----------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------| | filters | any | This prop can be any type you want, this is what you will get at some points when you need to change the saved filters | | | includedFilters | { label: string, text: string }[] | Used to show filter values in edit/save dropdown | [{ label: 'filter name', text: 'filter values' }] | | hasUnsavedChanges | boolean | Used to understand should we should show unsaved changes pill. You need just to check the equality of your current filters and filters inside the current view | |

Optional props

| Name | Type | Description | Example | |--------------------------|---------|-------------------------------------------------------------------|---------| | user | any | Adds user info to view attributes | | | isLoading | boolean | | | | pageName | string | Adds page name to success notifications | 'sales' | | currentView | string | You should pass view key. Used to the manual set current view | | | isSortingDropdownEnabled | boolean | | |

Handlers

You should use those handlers to keep your store actual

| Name | Type | Description | |-----------------------------------------|----------------------------------------------------------------|-------------------------------------------------------------| | handleChangeActiveView | (key: string) => void | | | handleDiscardUnsavedChanges | () => void | | | handleCreateDraftView | (key: string) => void | Used when draft view created from plus button in controls | | handleCreateDraftViewWithCurrentFilters | (key: string) => void | Used when draft view created from unsaved changes pill | | handleDuplicateView | (key: string, newViewKey: string) => void | | | handleCustomViewPositionsChange | (viewPositions: string[], customViewModelType: string) => void | | | handleDefaultViewChange | (id: string, customViewModelType: string) => void | | | handleSaveView | (key: string, filters: any) => void | Used when draft view saved | | handleSaveToCurrentView | (key: string, filters: any) => void | |