UNPKG

@o2xp/react-datatable

Version:

@o2xp/react-datatable is a modulable component to render data in a table with some nice features !

200 lines (165 loc) 3.82 kB
import { enqueueSnackbar } from "./notifierActions"; export const initializeOptions = payload => ({ type: "INITIALIZE_OPTIONS", payload }); export const updateComponentSize = () => ({ type: "UPDATE_COMPONENT_SIZE" }); export const sortColumns = payload => ({ type: "SORT_COLUMNS", payload }); export const setRowsPerPage = payload => ({ type: "SET_ROWS_PER_PAGE", payload }); export const setPage = payload => ({ type: "SET_PAGE", payload }); export const setIsScrolling = payload => ({ type: "SET_IS_SCROLLING", payload }); export const addRowEdited = payload => ({ type: "ADD_ROW_EDITED", payload }); export const addNewRow = payload => ({ type: "ADD_NEW_ROW", payload }); export const addAllRowsToEdited = () => ({ type: "ADD_ALL_ROWS_TO_EDITED" }); export const setRowEdited = payload => ({ type: "SET_ROW_EDITED", payload }); export const saveRowEdited = payload => ({ type: "SAVE_ROW_EDITED", payload }); export const saveAllRowsEdited = () => ({ type: "SAVE_ALL_ROWS_EDITED" }); export const revertRowEdited = payload => ({ type: "REVERT_ROW_EDITED", payload }); export const revertAllRowsToEdited = () => ({ type: "REVERT_ALL_ROWS_TO_EDITED" }); export const deleteRow = payload => ({ type: "DELETE_ROW", payload }); export const addToDeleteRow = payload => ({ type: "ADD_TO_DELETE_ROW", payload }); export const selectRow = payload => ({ type: "SELECT_ROW", payload }); export const setRowsSelected = payload => ({ type: "SET_ROWS_SELECTED", payload }); export const setRowsGlobalSelected = payload => ({ type: "SET_ROWS_GLOBAL_SELECTED", payload }); export const search = payload => ({ type: "SEARCH", payload }); export const toggleFilterFieldsDisplay = () => ({ type: "TOGGLE_FILTERFIELDS_DISPLAY" }); export const toggleSearchFieldDisplay = () => ({ type: "TOGGLE_SEARCHFIELD_DISPLAY" }); export const filterInColumn = payload => ({ type: "SEARCH_IN_COLUMN", payload }); export const setColumnVisibilty = payload => ({ type: "SET_COLUMN_VISIBILITY", payload }); export const handlePresetDisplay = payload => ({ type: "HANDLE_PRESET_DISPLAY", payload }); export const notifyOnPresetCreation = payload => { return dispatch => { dispatch( enqueueSnackbar({ message: payload.message, options: { key: new Date().getTime() + Math.random(), variant: payload.variant } }) ); }; }; export const setUserConfiguration = payload => ({ type: "SET_USER_CONFIGURATION", payload }); export const refreshRowsSuccess = payload => ({ type: "REFRESH_ROWS_SUCCESS", payload }); export const refreshRowsError = () => ({ type: "REFRESH_ROWS_ERROR" }); export const refreshRowsStarted = () => ({ type: "REFRESH_ROWS_STARTED" }); export const refreshRows = payload => { const key = new Date().getTime() + Math.random(); return dispatch => { dispatch(refreshRowsStarted()); return Promise.resolve(payload()) .then(res => { dispatch( enqueueSnackbar({ message: "Rows have been refreshed.", options: { key, variant: "success" } }) ); dispatch(refreshRowsSuccess(res)); }) .catch(err => { dispatch( enqueueSnackbar({ message: "Rows couldn't be refreshed.", options: { key, variant: "error" } }) ); dispatch(refreshRowsError(err)); }); }; }; export const orderByColumns = payload => ({ type: "ORDER_BY_COLUMNS", payload }); export const updateOptions = payload => ({ type: "UPDATE", payload }); export const duplicateRow = payload => ({ type: "DUPLICATE_ROW", payload });