Fix desgin TableRow, add redirection after creating or updating a record

This commit is contained in:
cyril lopez 2017-09-19 17:10:14 +02:00
parent 302f92a1e3
commit 779b5da2d2
6 changed files with 50 additions and 46 deletions

View File

@ -8,8 +8,8 @@
}
td{
height: 54px;
line-height: 54px;
height: 53px;
line-height: 53px;
font-size: 1.3rem;
font-weight: 400;
color: #333740;

View File

@ -115,7 +115,7 @@ export function setFormErrors(formErrors) {
export function setFormValidations(data) {
const form = Object.keys(data).map(attr => {
return { name: attr, validations: get(data[attr], ['params']) || {} }
return { name: attr, validations: get(data, attr) || {} }
});
const formValidations = getValidationsFromForm(form, []);

View File

@ -44,6 +44,7 @@ import {
setFormValidations,
setForm,
setFormErrors,
recordEdited,
} from './actions';
// Selectors.
@ -116,6 +117,7 @@ export class Edit extends React.Component {
componentWillUnmount() {
document.removeEventListener('keydown', this.handleSubmitOnEnterPress);
this.props.recordEdited();
}
handleChange = (e) => {
@ -133,6 +135,7 @@ export class Edit extends React.Component {
if (isEmpty(formErrors)) {
this.props.editRecord();
router.goBack();
} else {
this.props.setFormErrors(formErrors);
}
@ -242,6 +245,7 @@ Edit.propTypes = {
PropTypes.object,
PropTypes.bool,
]).isRequired,
recordEdited: PropTypes.func,
schema: PropTypes.oneOfType([
PropTypes.object,
PropTypes.bool,
@ -286,6 +290,7 @@ function mapDispatchToProps(dispatch) {
setFormValidations,
setForm,
setFormErrors,
recordEdited,
},
dispatch
);

View File

@ -11,49 +11,20 @@ import {
} from '../Edit/constants';
import {
SET_CURRENT_MODEL_NAME,
LOAD_RECORDS,
LOADED_RECORDS,
LOAD_COUNT,
LOADED_COUNT,
CHANGE_LIMIT,
CHANGE_PAGE,
CHANGE_SORT,
CHANGE_LIMIT,
LOAD_COUNT,
LOAD_RECORDS,
LOADED_COUNT,
LOADED_RECORDS,
SET_CURRENT_MODEL_NAME,
} from './constants';
export function setCurrentModelName(modelName) {
export function changeLimit(limit) {
return {
type: SET_CURRENT_MODEL_NAME,
modelName,
modelNamePluralized: pluralize(modelName),
};
}
export function loadRecords() {
return {
type: LOAD_RECORDS,
};
}
export function loadedRecord(records) {
return {
type: LOADED_RECORDS,
records,
};
}
export function loadCount() {
return {
type: LOAD_COUNT,
};
}
export function loadedCount(count) {
return {
type: LOADED_COUNT,
count,
type: CHANGE_LIMIT,
limit,
};
}
@ -71,10 +42,37 @@ export function changeSort(sort) {
};
}
export function changeLimit(limit) {
export function loadCount() {
return {
type: CHANGE_LIMIT,
limit,
type: LOAD_COUNT,
};
}
export function loadRecords() {
return {
type: LOAD_RECORDS,
};
}
export function loadedCount(count) {
return {
type: LOADED_COUNT,
count,
};
}
export function loadedRecord(records) {
return {
type: LOADED_RECORDS,
records,
};
}
export function setCurrentModelName(modelName) {
return {
type: SET_CURRENT_MODEL_NAME,
modelName,
modelNamePluralized: pluralize(modelName),
};
}

View File

@ -105,7 +105,6 @@ export class List extends React.Component {
this.props.changeSort(sort);
// Load records
this.props.loadRecords();
@ -180,7 +179,7 @@ export class List extends React.Component {
type: this.props.schema[this.props.currentModelName].fields[value].type,
}));
tableHeaders.splice(0, 0, { name: currentModel.primaryKey || 'id', label: 'ID', type: 'string' });
tableHeaders.splice(0, 0, { name: currentModel.primaryKey || 'id', label: 'Id', type: 'string' });
content = (
<Table

View File

@ -35,6 +35,8 @@ const initialState = fromJS({
currentPage: 1,
limit: 10,
sort: 'id',
initLimit: 10,
initSort: 'id',
});
function listReducer(state = initialState, action) {