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": { "options": {
"increments": true, "increments": true,
"timestamps": true, "timestamps": [
"created_at",
"updated_at"
],
"comment": "" "comment": ""
}, },
"attributes": { "attributes": {
"name": { "name": {
"type": "string" "type": "string"
}, },
"rocketshipmaker": { "pic": {
"model": "rocketshipmaker", "model": "file",
"via": "rocketships" "via": "related",
"plugin": "upload"
},
"pictures": {
"collection": "file",
"via": "related",
"plugin": "upload"
} }
} }
} }

View File

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

View File

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

View File

@ -7,6 +7,7 @@ import {
GET_LAYOUT_SUCCEEDED, GET_LAYOUT_SUCCEEDED,
ON_CHANGE_LIST_LABELS, ON_CHANGE_LIST_LABELS,
RESET_LIST_LABELS, RESET_LIST_LABELS,
RESET_PROPS,
} from './constants'; } from './constants';
export function deleteLayout(uid) { export function deleteLayout(uid) {
@ -67,3 +68,9 @@ export function resetListLabels(slug) {
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 = export const ON_CHANGE_LIST_LABELS =
'ContentManager/Main/ON_CHANGE_LIST_LABELS'; 'ContentManager/Main/ON_CHANGE_LIST_LABELS';
export const RESET_LIST_LABELS = 'ContentManager/Main/RESET_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 SettingViewGroup from '../SettingViewGroup';
import SettingsView from '../SettingsView'; import SettingsView from '../SettingsView';
import { getData, getLayout } from './actions'; import { getData, getLayout, resetProps } from './actions';
import reducer from './reducer'; import reducer from './reducer';
import saga from './saga'; import saga from './saga';
import makeSelectMain from './selectors'; import makeSelectMain from './selectors';
@ -33,6 +33,7 @@ function Main({
location: { pathname, search }, location: { pathname, search },
global: { plugins }, global: { plugins },
models, models,
resetProps,
}) { }) {
strapi.useInjectReducer({ key: 'main', reducer, pluginId }); strapi.useInjectReducer({ key: 'main', reducer, pluginId });
strapi.useInjectSaga({ key: 'main', saga, pluginId }); strapi.useInjectSaga({ key: 'main', saga, pluginId });
@ -40,15 +41,21 @@ function Main({
const source = getQueryParameters(search, 'source'); const source = getQueryParameters(search, 'source');
const getDataRef = useRef(); const getDataRef = useRef();
const getLayoutRef = useRef(); const getLayoutRef = useRef();
const resetPropsRef = useRef();
getDataRef.current = getData; getDataRef.current = getData;
getLayoutRef.current = getLayout; getLayoutRef.current = getLayout;
resetPropsRef.current = resetProps;
const shouldShowLoader = const shouldShowLoader =
slug !== 'ctm-configurations' && layouts[slug] === undefined; slug !== 'ctm-configurations' && layouts[slug] === undefined;
useEffect(() => { useEffect(() => {
getDataRef.current(); getDataRef.current();
return () => {
resetPropsRef.current();
};
}, [getDataRef]); }, [getDataRef]);
useEffect(() => { useEffect(() => {
if (shouldShowLoader) { if (shouldShowLoader) {
@ -118,6 +125,7 @@ Main.propTypes = {
search: PropTypes.string, search: PropTypes.string,
}), }),
models: PropTypes.array.isRequired, models: PropTypes.array.isRequired,
resetProps: PropTypes.func.isRequired,
}; };
const mapStateToProps = makeSelectMain(); const mapStateToProps = makeSelectMain();
@ -127,6 +135,7 @@ export function mapDispatchToProps(dispatch) {
{ {
getData, getData,
getLayout, getLayout,
resetProps,
}, },
dispatch dispatch
); );

View File

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

View File

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