0.1.1 • Published 1 year ago

@lovelope/table-factory v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
1 year ago

@lovelope/table-factory

TableFactory is a combinable higher order components for list management page, in order to fetch list data and manage filter queries.

English 中文

Install

npm i -S @lovelope/table-factory
# OR
yarn add -S @lovelope/table-factory

Usage

import TableFactory from '@lovelope/table-factory';
import React from 'react';
import { getGoodsList } from './services';

@TableFactory({
  getAction: getGoodsList,
  params: { pid },
  mute: ['searchWords'],
})
class GoodsList extends React.Component {
  render() {
    const {
      data: { list },
      query,
      loadData,
      onFilter,
      onReset,
    } = this.props;
    return (
      <div>
        <div className="header">
          <YourFilter onFilter={onFilter} query={query} onReset={onReset} />
        </div>
        <div className="body">
          <Table dataSource={list} />
        </div>
      </div>
    );
  }
}

Options

TableFactory

PropertyDescriptiontyperequireddefault
immediateUsed to control whether requests for data are sent immediately when filter conditions changebooleanfalsetrue
enumsModify the request parameter name of the page number section of the page with a set of objects (page, page Size by default)objectfalse{ page: 'page', pageSize: 'pageSize' }
muteControl request parameters that do not immediately send requests (such as keyword search, which may not be immediately searched if you want to enter)string[]false'keyword'
getActionRequest for table data() => Promise\<object>true--
paramsAdditional Possible Parameters of getAction in addition to Screening Conditionsobjectfalse{}
formatData Processing Function of getAction before Initiating Requestfunctionfalsep => p

Tips

  • TableFactory injects data, query, onFilter, onReset and loadData five props into the component.
  • data is the data returned by getAction.
  • onFilter is a method of passing parameters to tableFactory. It receives two parameters. The first one is the parameter object, and the second one is the callback after reference.
  • onReset, if the page needs to reset all requests plus parameters, you can use this method;
  • loadData, an interface that actively calls table data;
  • query is the request parameter of getAction; you may need query to keep components under control.
  • If params sets additional request parameters, onReset will not empty these parameters, which is also helpful when the timeselector returns to some initial value.
0.1.1

1 year ago

0.1.0

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago