redux-admin
Build fast admin screen with full CRUD functionality inside your react apps
Updates:
- version 1.6.0
- Support rtl and localization
Basic example
import React Component from "react";import listViews docViews Admin fields from "redux-admin"; const getDocTitle = { if data && data_id return `Item `; else return "New Item"; }; const getListFields = { return title: "Title" key: "title" dataIndex: "title" width: 150 sorter: true type: String title: "Likes" key: "likes" dataIndex: "likes" width: 150 sorter: true type: Number ;}; const docFields = { return <div> <fields.Input = = /> <fields.InputNumber = = /> </div> ;}; const renderDocViewComponent = { return JSON;}; { return <div> <Admin = = ="classes/Post" = = = /> </div> ; } ;
Installation
-
You can install redux-admin with NPM, Yarn
npm install redux-admin --save -
Follow Net-Provider Installation instruction Net-provider is the connection to your api
-
Router configuration - we sync parameters with URL to achieve a better UX
// inside your root file (app.js) import { setRouteConfig } from 'redux-admin'; setRouteConfig({ onReplaceParams: () => {...}, onSetParams: : () => {...}, onBack: : () => {...}, goHome: : () => {...}, onGetParams: : () => {...}, });
Examples:
-
import style
import "redux-admin/lib/style.css";// -- or rtl style --import "redux-admin/lib/style.rtl.css"; -
Install antd
-
Optional - set diffrent locale- default is enUs
import setLocal locals from 'redux-admin';;You can create you own local file just copy this file and update the content
## Admin Component This is the main component that will render a list view and document view, sync the doc view with the list view and keep everything to work nice and updating, display notification, update the list when the document is updating. sync filters with URL. you can build your own list/doc view
import Admin from "redux-admin";
Props
AdminpropTypes = url: PropTypesstringisRequired // Api endpoint list: PropTypeselement renderList: PropTypesfunc // alternative to props.list doc: PropTypeselement renderDoc: PropTypesfunc // alternative to props.doc title: PropTypesstring getDocTitle: PropTypesfunc // function that get doc data and return the doc title that display inside the breadcrumb (DocData) => 'title' queryParamsPrefix: PropTypesstring // This is required when you render more then one component at the same page getListSource: PropTypesfunc getDocumentSource: PropTypesfunc allowViewMode: PropTypesbool // set false to block user from watching the document syncWithUrl: PropTypesbool // true by default, set false to disabled this feature showBreadcrumb: PropTypesbool // true by default, set false, relevant when you render more then one component at the same page editAfterSaved: PropTypesbool // true by default, when true new document will stay open after submit onChangeEnd: PropTypesfunc // optional Call back After create/update/delete initialSearchValue: PropTypesstring onSearchValueChange: PropTypesfunc // If You Want To Handle it By Your self searchValue: PropTypesstring // relevant when you pass onSearchValueChange initialLimit: PropTypesnumber // default is 5, query limit initialSort: PropTypesobject // { <field1>: 1, <field2>: -1 ... } initialSkip: PropTypesnumber // default is 0 listClearOnUnMount: PropTypesbool // true by default, when true we remove all data from store when componentWillUnmount adminWillUnmount: PropTypesfunc // optional Call back when componentWillUnmount roleConfig: PropTypes useDataFromList: PropTypesbool // false by default, set true to save query and use the data the from list as document data getParams: PropTypesfuncisRequired // pass function that build query params from the filters parameters getParams({skip, sort, limit, searchValue});
List Component
The default list view is Table From antd You can pass other component
How to use the default view?
import listViews Admin helpers from "redux-admin"; const getListFields = { return title:"Title" key:"title" dataIndex: "title" width:150 sorter:true type: String // You can use helper to save time helpers } { return <Admin ="classes/Post" = = =...
Each field inside the list columns need to contian this keys
- title: string
- key: string
- dataIndex: string
- width: number
- sorter: boolean
- type: one of: String | Object | Array | Number | Date
- render : optional fucntion (cell, row) => <MyComponent data={cell} />
listViews.Table props
<Admin /> will pass the data and handle the row clicks and so on, the is the relevant props to pass directly to the table component
ReTable.propTypes = {
getColumns: PropTypes.func.isRequired, // getColumns(this.props) -> [{value: 'title', label: 'Title', type: String, render: () => 'OPTIONAL'}]
getFilterFields: PropTypes.func, // if empty then we use getColumns
rowKey: PropTypes.string, // default is _id
renderInsideRowActions: PropTypes.func, // renderInsideRowActions(cell, row) => <button>Delete</button>
allowFilters: PropTypes.bool,
allowAdvanceFilters: PropTypes.bool, // true by default, allow the user to filter data with greater / less than, before/after and more...
showColumnFilters: PropTypes.bool, // true by default, allow user to hide some of the table columns
filtersFields: PropTypes.array, // when empty all table fields ar filters fields, pass array of fieldKeys to allow only some of them , Example [{key: 'status', options: {value: 'ctr', label: 'Create'}}]
allowExportToExcel: PropTypes.bool, // true by default,
onDownloadExcel: PropTypes.func, // to override local export pass function to handle this ({data, columnsToDisplay, onDownloadExcel}) => {....}
expandedRowRender: PropTypes.func, // antd table expandedRowRender
renderHeaders: PropTypes.func, // render content inside headers renderHeaders(props) => <div>Hello</div>
};
This is the full props option if you want to work with this component as a table outside of the <Admin /> component
ReTable.propTypes = {
data: PropTypes.array,
getColumns: PropTypes.func.isRequired, // getColumns(this.props) -> [{value: 'title', label: 'Title', type: String, render: () => 'OPTIONAL'}]
getFilterFields: PropTypes.func, // if empty then we use getColumns
rowKey: PropTypes.string,
editable: PropTypes.bool,
canUpdate: PropTypes.bool,
canDelete: PropTypes.bool,
renderInsideRowActions: PropTypes.func, // renderInsideRowActions(cell, row) => <button>Delete</button>
onEditClick: PropTypes.func,
onDeleteClick: PropTypes.func,
skip: PropTypes.number,
limit: PropTypes.number,
onRow: PropTypes.func,
onNewClick: PropTypes.func,
onRefreshClick: PropTypes.func,
enabledNew: PropTypes.bool,
searchValue: PropTypes.string,
showSearchField: PropTypes.bool,
onSearch: PropTypes.func,
onSearchValueChange: PropTypes.func,
onFiltersChanged: PropTypes.func,
allowAdvanceFilters: PropTypes.bool,
allowFilters: PropTypes.bool,
loading: PropTypes.bool,
count: PropTypes.number,
onPageChange: PropTypes.func,
onPageSizeChange: PropTypes.func,
onViewDocClick: PropTypes.func,
showColumnFilters: PropTypes.bool,
filtersFields: PropTypes.array, // when empty all table fields ar filters fields, pass array of fieldKeys to allow only some of them , Example [{key: 'status', options: {value: 'ctr', label: 'Create'}}]
allowExportToExcel: PropTypes.bool, // true by default,
onDownloadExcel: PropTypes.func, // to override local export pass function to handle this ({data, columnsToDisplay, onDownloadExcel}) => {....}
allowExportToPdf: PropTypes.bool, // false by default
onDownloadPdf: PropTypes.func, // pass function to handle this ({data, columnsToDisplay, onDownloadExcel}) => {....}
expandedRowRender: PropTypes.func, // antd table expandedRowRender
renderHeaders: PropTypes.func, // render content inside headers renderHeaders(props) => <div>Hello</div>
};
Document Component
This is the default doc view for edit&create mode. We use formik to handle hower form
You can pass other components if you want to take the controls to your hands
How to use the default document?
import docViews Admin helpers fields from "redux-admin"; const getDocFields = { return <div> <fields.Input = =
getDocFields()
getDocfields - return the element that we will render inside the edit/create doc view.
the element can be any HTML element, we wrap your element with Formik/Form to handle the form state, your inputs need to include name, see Formik guide.
you can use redux-admin fields or use any fields that wrapped by Formik/Field
Examples-
- Simple inputimport Field from 'formik';const getDocFields = <Field ="email" ="email" ="Email" />
Fields - to use only inside Formik
import fields from 'redux-admin'; const Input InputNumber MultiSelect Reference ParseServerReference FireStoreReference Select ArrayInput Consumer CheckBox DatePicker TimePicker Password TextArea Media AutoComplete ObjectEditor Dropzone BoxSelect CheckboxWithIcon } = fields;