Fix layout update from ctb

This commit is contained in:
soupette 2019-07-30 09:08:10 +02:00
parent 53d0014dc2
commit 5e94cf56f7
8 changed files with 40 additions and 16 deletions

View File

@ -7,16 +7,25 @@
},
"options": {
"increments": true,
"timestamps": true,
"timestamps": [
"created_at",
"updated_at"
],
"comment": ""
},
"attributes": {
"name": {
"type": "string"
},
"rocketshipmaker": {
"model": "rocketshipmaker",
"via": "rocketships"
"pic": {
"model": "file",
"via": "related",
"plugin": "upload"
},
"pictures": {
"collection": "file",
"via": "related",
"plugin": "upload"
}
}
}

View File

@ -13,10 +13,6 @@
"attributes": {
"name": {
"type": "string"
},
"rocketships": {
"collection": "rocketship",
"via": "rocketshipmaker"
}
}
}

View File

@ -210,12 +210,12 @@ input editRecipeInput {
input editRocketshipInput {
name: String
rocketshipmaker: ID
pic: ID
pictures: [ID]
}
input editRocketshipmakerInput {
name: String
rocketships: [ID]
}
input editRoleInput {
@ -392,7 +392,8 @@ input RecipeInput {
type Rocketship {
name: String
rocketshipmaker: Rocketshipmaker
pic: UploadFile
pictures(sort: String, limit: Int, start: Int, where: JSON): [UploadFile]
id: ID!
created_at: DateTime!
updated_at: DateTime!
@ -400,12 +401,12 @@ type Rocketship {
input RocketshipInput {
name: String
rocketshipmaker: ID
pic: ID
pictures: [ID]
}
type Rocketshipmaker {
name: String
rocketships(sort: String, limit: Int, start: Int, where: JSON): [Rocketship]
id: ID!
created_at: DateTime!
updated_at: DateTime!
@ -413,7 +414,6 @@ type Rocketshipmaker {
input RocketshipmakerInput {
name: String
rocketships: [ID]
}
input RoleInput {

View File

@ -7,6 +7,7 @@ import {
GET_LAYOUT_SUCCEEDED,
ON_CHANGE_LIST_LABELS,
RESET_LIST_LABELS,
RESET_PROPS,
} from './constants';
export function deleteLayout(uid) {
@ -67,3 +68,9 @@ export function resetListLabels(slug) {
slug,
};
}
export function resetProps() {
return {
type: RESET_PROPS,
};
}

View File

@ -7,3 +7,4 @@ export const GET_LAYOUT_SUCCEEDED = 'ContentManager/Main/GET_LAYOUT_SUCCEEDED';
export const ON_CHANGE_LIST_LABELS =
'ContentManager/Main/ON_CHANGE_LIST_LABELS';
export const RESET_LIST_LABELS = 'ContentManager/Main/RESET_LIST_LABELS';
export const RESET_PROPS = 'ContentManager/Main/RESET_PROPS';

View File

@ -16,7 +16,7 @@ import SettingViewModel from '../SettingViewModel';
import SettingViewGroup from '../SettingViewGroup';
import SettingsView from '../SettingsView';
import { getData, getLayout } from './actions';
import { getData, getLayout, resetProps } from './actions';
import reducer from './reducer';
import saga from './saga';
import makeSelectMain from './selectors';
@ -33,6 +33,7 @@ function Main({
location: { pathname, search },
global: { plugins },
models,
resetProps,
}) {
strapi.useInjectReducer({ key: 'main', reducer, pluginId });
strapi.useInjectSaga({ key: 'main', saga, pluginId });
@ -40,15 +41,21 @@ function Main({
const source = getQueryParameters(search, 'source');
const getDataRef = useRef();
const getLayoutRef = useRef();
const resetPropsRef = useRef();
getDataRef.current = getData;
getLayoutRef.current = getLayout;
resetPropsRef.current = resetProps;
const shouldShowLoader =
slug !== 'ctm-configurations' && layouts[slug] === undefined;
useEffect(() => {
getDataRef.current();
return () => {
resetPropsRef.current();
};
}, [getDataRef]);
useEffect(() => {
if (shouldShowLoader) {
@ -118,6 +125,7 @@ Main.propTypes = {
search: PropTypes.string,
}),
models: PropTypes.array.isRequired,
resetProps: PropTypes.func.isRequired,
};
const mapStateToProps = makeSelectMain();
@ -127,6 +135,7 @@ export function mapDispatchToProps(dispatch) {
{
getData,
getLayout,
resetProps,
},
dispatch
);

View File

@ -11,6 +11,7 @@ import {
GET_LAYOUT_SUCCEEDED,
ON_CHANGE_LIST_LABELS,
RESET_LIST_LABELS,
RESET_PROPS,
} from './constants';
export const initialState = fromJS({
@ -58,6 +59,8 @@ function mainReducer(state = initialState, action) {
return state.updateIn(['layouts', action.slug], () =>
state.getIn(['initialLayouts', action.slug])
);
case RESET_PROPS:
return initialState;
default:
return state;
}

View File

@ -129,7 +129,6 @@ function SettingViewModel({
}, [modifiedData]);
// Retrieve the metadatas for the field's form of the edit view
// Doesn't need to be a function
const getSelectedItemMetas = useCallback(() => {
return get(modifiedData, ['metadatas', itemNameToSelect, 'edit'], null);
}, [modifiedData, itemNameToSelect]);