0.1.6 • Published 1 year ago

savvycom-dynamic-filter v0.1.6

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

Installation

// with npm

npm i savvycom-dynamic-filter

// with yarn

yarn add savvycom-dynamic-filter

Usage

Here is a quick example to get you started, it's all you need:

Yes, it's really all you need to get started as you can see in the interactive demo:

Demo

Components

NameDescription
DynamicTableTable data
useDynamicTableThis is a hook for dynamic table

API

Dynamic Table

NameTypeRequireDefaultDescription
columnsrefer to column configYes-column names of table
dataArray< object >Yes-The data of table that will be show
paginationobject or falseYes-Config of pagination. You can ref table pagination config, hide it by setting it to false
stateQueryStateQueryInterfaceYes-state of filters
setStateQueryFunctionYes-This is a function that used set stateQuery
filtersFilterPayloadInterface[]if showFilter = true, it's required, else not required-This is a array that contains user-selected filters
setFiltersFunctionif showFilter = true, it's required, else not required-This is a function that used set filters
showFilterbooleanif showFilter = true, it's required, else not requiredtrueEnable filter
propertiesPropertyInterface[]if showFilter = true, it's required, else not required-This is column names
metricsMetricInterface[]if showFilter = true, it's required, else not requiredThis is conditios of the filter.
loadingbooleanNo-Loading status of table
sizesmall or middle or largeNomiddleSize of table
rowSelectionobjectNo-Row selection config
idstringNo-The id of table element
classNamestringNo-The class name of table element
componentsTableComponentsNo-Override default table elements
expandableexapndableNo-Config expandable content
rowClassNamefunction(record, index): stringNo-Row's className
rowKeystring or function(record): stringNo-Row's unique key, could be a string or function that returns a string
onRowfunction(record, index)No-Set props on per row
onChangefunction(pagination, filters, sorter, extra: { currentDataSource: [], action: paginate or sort or filter })No-Callback executed when pagination, filters or sorter is changed

useDynamicTable Hook

NameTypeRequireDescription
headerUrlstringYesthis is url path that used to get header data
dataTableUrlstringYesthis is url path that used to get table data
baseURLstringYesthis is base url that used to merge with headerUrl and dataTableUrl
customColumnsrefer to column configNoIt will custom columns which defined in DynamicTable component

This hook will export under data:

NameTypeDescription
recordsArrayThis is a table data that get from dataTableUrl
columnsArrayThis is a header data that get from headerUrl
paginationobject or falseConfig of pagination. You can ref table pagination config, hide it by setting it to false
propertiesPropertyInterface[]This is column names
metricsMetricInterface[]This is conditios of the filter
filtersFilterPayloadInterface[]This is a array that contains user-selected filters
setFiltersfunctionThis is a function that used set filters
stateQueryStateQueryInterfacestate of filters
setStateQueryfunctionThis is a function that used set stateQuery
isLoadingbooleanLoading status of table
queriesobjectThis is value of stateQuery when converted to string
handleChangefunctionCallback executed when pagination, filters or sorter is changed

Note

Please define response of api headerUrl is HeaderResponse and dataTableUrl is TableDataResponse

Interface

// FilterInterface

FilterInterface {
  field: string;
  value: string;
  operator: string;
  logic: 'AND' | 'OR'
}

// FilterPayloadInterface

FilterPayloadInterface extends FilterInterface {
  labelField: string;
  labelOperator: string;
}

// SortInterface

SortInterface {
  field: string;
  orderBy: 'asc' | 'desc'
}

// StateQueryInterface

StateQueryInterface {
  pagination?: {
    limit: number;
    page: number;
  },
  filters?: FilterInterface[],
  sorts?: SortInterface[]
}

// PropertyInterface

PropertyInterface {
  label: string;
  value: string;
}

// MetricInterface

MetricInterface {
  label: string;
  value: string;
}

// HeaderResponse

HeaderResponse {
  meta: {
    code: number;
    status: string;
    message: string;
  };
  data: {
    columns: {
      dataIndex: string;
      type: string;
      name: string;
    }[];
    operators: {
      key: string;
      value: string;
    }[];
    logics: string[]
  }
}

// TableDataResponse

TableDataResponse {
  meta: {
    code: number;
    status: string;
    message: string;
    pagination: {
      page: number;
      limit: number;
      totalPage: number;
      hasPreviousPage: boolean;
      hasNextPage: boolean;
    }
  };
  data: []
}

License

This project is licensed under the terms of the

MIT license.