New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@veeqo/custom-views

Package Overview
Dependencies
Maintainers
6
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@veeqo/custom-views

veeqo custom views

  • 1.3.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-88.1%
Maintainers
6
Weekly downloads
 
Created
Source

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

NameTypeDescription
customViewPositionsstring[] | nullInitialization doesn't start until you don't pass an array
defaultViewIdstring | nullInitialization doesn't start until you don't pass a string

Props required for proper work

NameTypeDescriptionExample
filtersanyThis 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' }]
hasUnsavedChangesbooleanUsed 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

NameTypeDescriptionExample
useranyAdds user info to view attributes
isLoadingboolean
pageNamestringAdds page name to success notifications'sales'
currentViewstringYou should pass view key. Used to the manual set current view
isSortingDropdownEnabledboolean

Handlers

You should use those handlers to keep your store actual

NameTypeDescription
handleChangeActiveView(key: string) => void
handleDiscardUnsavedChanges() => void
handleCreateDraftView(key: string) => voidUsed when draft view created from plus button in controls
handleCreateDraftViewWithCurrentFilters(key: string) => voidUsed 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) => voidUsed when draft view saved
handleSaveToCurrentView(key: string, filters: any) => void

Keywords

FAQs

Package last updated on 09 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc