Init SettingsView

This commit is contained in:
soupette 2019-07-04 11:32:51 +02:00
parent c0a01f1e5a
commit 2d8f520ba7
19 changed files with 383 additions and 52 deletions

View File

@ -22,14 +22,16 @@ function LeftMenuLinkContainer({ plugins, ...rest }) {
acc[snakeCase(section.name)] = {
name: section.name,
links: get(acc[snakeCase(section.name)], 'links', []).concat(
section.links.map(link => {
link.source = current;
link.plugin = !isEmpty(plugins[link.plugin])
? link.plugin
: plugins[current].id;
section.links
.filter(link => link.isDisplayed !== false)
.map(link => {
link.source = link.source || current;
link.plugin = !isEmpty(plugins[link.plugin])
? link.plugin
: plugins[current].id;
return link;
})
return link;
})
),
};
}

View File

@ -8,20 +8,25 @@ export const BEGIN_MOVE = 'contentManager/App/BEGIN_MOVE';
export const EMPTY_STORE = 'contentManager/App/EMPTY_STORE';
export const END_MOVE = 'contentManager/App/END_MOVE';
export const GET_MODEL_ENTRIES = 'contentManager/App/GET_MODEL_ENTRIES';
export const GET_MODEL_ENTRIES_SUCCEEDED = 'contentManager/App/GET_MODEL_ENTRIES_SUCCEEDED';
export const GET_MODEL_ENTRIES_SUCCEEDED =
'contentManager/App/GET_MODEL_ENTRIES_SUCCEEDED';
export const LOAD_MODELS = 'contentManager/App/LOAD_MODELS';
export const LOADED_MODELS = 'contentManager/App/LOADED_MODELS';
export const MOVE_ATTR = 'contentManager/App/MOVE_ATTR';
export const MOVE_ATTR_EDIT_VIEW = 'contentManager/App/MOVE_ATTR_EDIT_VIEW';
export const MOVE_VARIABLE_ATTR_EDIT_VIEW = 'contentManager/App/MOVE_VARIABLE_ATTR_EDIT_VIEW';
export const MOVE_VARIABLE_ATTR_EDIT_VIEW =
'contentManager/App/MOVE_VARIABLE_ATTR_EDIT_VIEW';
export const ON_CHANGE = 'contentManager/App/ON_CHANGE';
export const ON_CHANGE_INPUT_TYPE = 'contentManager/App/ON_CHANGE_INPUT_TYPE';
export const ON_CHANGE_SETTINGS = 'contentManager/App/ON_CHANGE_SETTINGS';
export const ON_CLICK_ADD_ATTR = 'contentManager/App/ON_CLICK_ADD_ATTR';
export const ON_CLICK_ADD_ATTR_FIELD = 'contentManager/App/ON_CLICK_ADD_ATTR_FIELD';
export const ON_CLICK_ADD_ATTR_FIELD =
'contentManager/App/ON_CLICK_ADD_ATTR_FIELD';
export const ON_REMOVE = 'contentManager/App/ON_REMOVE';
export const ON_REMOVE_EDIT_VIEW_FIELD_ATTR = 'contentManager/App/ON_REMOVE_EDIT_VIEW_FIELD_ATTR';
export const ON_REMOVE_EDIT_VIEW_RELATION_ATTR = 'contentManager/App/ON_REMOVE_EDIT_VIEW_RELATION_ATTR';
export const ON_REMOVE_EDIT_VIEW_FIELD_ATTR =
'contentManager/App/ON_REMOVE_EDIT_VIEW_FIELD_ATTR';
export const ON_REMOVE_EDIT_VIEW_RELATION_ATTR =
'contentManager/App/ON_REMOVE_EDIT_VIEW_RELATION_ATTR';
export const ON_RESET = 'contentManager/App/ON_RESET';
export const ON_SUBMIT = 'contentManager/App/ON_SUBMIT';
export const SET_LAYOUT = 'contentManager/App/SET_LAYOUT';

View File

@ -0,0 +1,7 @@
import { DEFAULT_ACTION } from './constants';
export function defaultAction() {
return {
type: DEFAULT_ACTION,
};
}

View File

@ -0,0 +1 @@
export const DEFAULT_ACTION = 'ContentManager/Main/DEFAULT_ACTION';

View File

@ -0,0 +1,51 @@
import React, { memo } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { bindActionCreators, compose } from 'redux';
import { Switch, Route } from 'react-router-dom';
import { LoadingIndicatorPage } from 'strapi-helper-plugin';
import pluginId from '../../pluginId';
import SettingsView from '../SettingsView';
import reducer from './reducer';
import saga from './saga';
import makeSelectMain from './selectors';
function Main({ isLoading }) {
strapi.useInjectReducer({ key: 'main', reducer, pluginId });
strapi.useInjectSaga({ key: 'main', saga, pluginId });
if (isLoading) {
return <LoadingIndicatorPage />;
}
return (
<Switch>
<Route
path="/plugins/content-manager/ctm-configurations/:type"
component={SettingsView}
/>
</Switch>
);
}
Main.propTypes = {
isLoading: PropTypes.bool.isRequired,
};
const mapStateToProps = makeSelectMain();
export function mapDispatchToProps(dispatch) {
return bindActionCreators({}, dispatch);
}
const withConnect = connect(
mapStateToProps,
mapDispatchToProps
);
export default compose(
withConnect,
memo
)(Main);

View File

@ -0,0 +1,19 @@
/**
*
* main reducer
*/
import { fromJS } from 'immutable';
export const initialState = fromJS({
isLoading: false,
});
function mainReducer(state = initialState, action) {
switch (action.type) {
default:
return state;
}
}
export default mainReducer;

View File

@ -0,0 +1,12 @@
// import { all, fork, put, call, takeLatest } from 'redux-saga/effects';
// import { request } from 'strapi-helper-plugin';
// import pluginId from '../../pluginId';
// import { DEFAULT_ACTION } from './constants';
// const getRequestUrl = path => `/${pluginId}/${path}`;
function* defaultSaga() {}
export default defaultSaga;

View File

@ -0,0 +1,28 @@
import { createSelector } from 'reselect';
import pluginId from '../../pluginId';
import { initialState } from './reducer';
/**
* Direct selector to the main state domain
*/
const selectMainDomain = () => state =>
state.get(`${pluginId}_main`) || initialState;
/**
* Other specific selectors
*/
/**
* Default selector used by Main
*/
const makeSelectMain = () =>
createSelector(
selectMainDomain(),
substate => {
return substate.toJS();
}
);
export default makeSelectMain;
export { selectMainDomain };

View File

@ -0,0 +1,16 @@
import { GET_DATA, GET_DATA_SUCCEEDED } from './constants';
export function getData() {
return {
type: GET_DATA,
};
}
export function getDataSucceeded(generalSettings, groups, models) {
return {
type: GET_DATA_SUCCEEDED,
generalSettings,
groups,
models,
};
}

View File

@ -0,0 +1,3 @@
export const GET_DATA = 'ContentManager/SettingsView/GET_DATA';
export const GET_DATA_SUCCEEDED =
'ContentManager/SettingsView/GET_DATA_SUCCEEDED';

View File

@ -0,0 +1,53 @@
import React, { memo, useEffect } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { bindActionCreators, compose } from 'redux';
import { LoadingIndicatorPage } from 'strapi-helper-plugin';
import pluginId from '../../pluginId';
import { getData } from './actions';
import reducer from './reducer';
import saga from './saga';
import makeSelectSettingView from './selectors';
function SettingsView({ getData, isLoading }) {
strapi.useInjectReducer({ key: 'settingsView', reducer, pluginId });
strapi.useInjectSaga({ key: 'settingsView', saga, pluginId });
useEffect(() => {
getData();
}, []);
if (isLoading) {
return <LoadingIndicatorPage />;
}
return <div>SettingsView</div>;
}
SettingsView.propTypes = {
getData: PropTypes.func.isRequired,
isLoading: PropTypes.bool.isRequired,
};
const mapStateToProps = makeSelectSettingView();
export function mapDispatchToProps(dispatch) {
return bindActionCreators(
{
getData,
},
dispatch
);
}
const withConnect = connect(
mapStateToProps,
mapDispatchToProps
);
export default compose(
withConnect,
memo
)(SettingsView);

View File

@ -0,0 +1,29 @@
/**
*
* settingsView reducer
*/
import { fromJS, List, Map } from 'immutable';
import { GET_DATA_SUCCEEDED } from './constants';
export const initialState = fromJS({
generalSettings: Map({}),
groups: List([]),
models: List([]),
isLoading: true,
});
function settingsViewReducer(state = initialState, action) {
switch (action.type) {
case GET_DATA_SUCCEEDED:
return state
.update('generalSettings', () => Map(action.generalSettings))
.update('groups', () => List(action.groups))
.update('models', () => List(action.models))
.update('isLoading', () => false);
default:
return state;
}
}
export default settingsViewReducer;

View File

@ -0,0 +1,33 @@
import { all, fork, put, call, takeLatest } from 'redux-saga/effects';
import { request } from 'strapi-helper-plugin';
import pluginId from '../../pluginId';
import { getDataSucceeded } from './actions';
import { GET_DATA } from './constants';
const getRequestUrl = path => `/${pluginId}/${path}`;
export function* getData() {
try {
const [{ generalSettings }, { groups }, { models }] = yield all(
['fixtures/general-settings', 'fixtures/groups', 'fixtures/models'].map(
endPoint => call(request, getRequestUrl(endPoint), { method: 'GET' })
)
);
yield put(getDataSucceeded(generalSettings, groups, models));
} catch (err) {
console.log(err);
}
}
function* defaultSaga() {
try {
yield all([fork(takeLatest, GET_DATA, getData)]);
} catch (err) {
// Do nothing
}
}
export default defaultSaga;

View File

@ -0,0 +1,28 @@
import { createSelector } from 'reselect';
import pluginId from '../../pluginId';
import { initialState } from './reducer';
/**
* Direct selector to the settingView state domain
*/
const settingViewDomain = () => state =>
state.get(`${pluginId}_settingsView`) || initialState;
/**
* Other specific selectors
*/
/**
* Default selector used by Main
*/
const makeSelectSettingView = () =>
createSelector(
settingViewDomain(),
substate => {
return substate.toJS();
}
);
export default makeSelectSettingView;
export { settingViewDomain };

View File

@ -1,7 +1,7 @@
import React from 'react';
import pluginPkg from '../../package.json';
import pluginId from './pluginId';
import App from './containers/App';
import App from './containers/Main';
import Initializer from './containers/Initializer';
import lifecycles from './lifecycles';
import trads from './translations';
@ -28,7 +28,7 @@ const plugin = {
mainComponent: Comp,
name: pluginPkg.strapi.name,
preventComponentRendering: false,
suffixUrl: '/ctm-configurations',
suffixUrl: '/ctm-configurations/models',
trads,
};

View File

@ -1,7 +1,3 @@
// const { map, omit } = require('lodash');
// const { request } = require('strapi-helper-plugin');
// const pluginId = require('../pluginId');
import { map, omit } from 'lodash';
import { request } from 'strapi-helper-plugin';
import pluginId from '../pluginId';
@ -9,19 +5,18 @@ import pluginId from '../pluginId';
async function didGetSecuredData() {
const { updatePlugin } = this.props;
const requestURL = `/${pluginId}/models`;
const requestURL = `/${pluginId}/fixtures/models`;
try {
const {
models: { models },
} = await request(requestURL, { method: 'GET' });
const { models } = await request(requestURL, { method: 'GET' });
const menu = [
{
name: 'Content Types',
links: map(omit(models, 'plugins'), (model, key) => ({
label: model.labelPlural || model.label || key,
destination: key,
})),
links: models,
// links: map(omit(models, 'plugins'), (model, key) => ({
// label: model.labelPlural || model.label || key,
// destination: key,
// })),
},
];
@ -31,29 +26,4 @@ async function didGetSecuredData() {
}
}
// module.exports = async function didGetSecuredData() {
// const { updatePlugin } = this.props;
// const requestURL = `/${pluginId}/models`;
// try {
// const {
// models: { models },
// } = await request(requestURL, { method: 'GET' });
// const menu = [
// {
// name: 'Content Types',
// links: map(omit(models, 'plugins'), (model, key) => ({
// label: model.labelPlural || model.label || key,
// destination: key,
// })),
// },
// ];
// updatePlugin(pluginId, 'leftMenuSections', menu);
// } catch (err) {
// strapi.notification.error('content-manager.error.model.fetch');
// }
// };
// module.exports = didGetSecuredData;
export default didGetSecuredData;

View File

@ -8,6 +8,30 @@
"policies": []
}
},
{
"method": "GET",
"path": "/fixtures/general-settings",
"handler": "ContentManagerFixtures.getGeneralSettings",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/fixtures/groups",
"handler": "ContentManagerFixtures.getGroups",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/fixtures/models",
"handler": "ContentManagerFixtures.getModels",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/explorer/:model",

View File

@ -0,0 +1,50 @@
module.exports = {
getGeneralSettings: ctx => {
const generalSettings = {
bulkActions: true,
filters: true,
pageEntries: 10,
search: true,
};
ctx.body = { generalSettings };
},
getGroups: ctx => {
const groups = [
{
name: 'ingredient',
},
{
name: 'car',
},
];
ctx.body = { groups };
},
getModels: ctx => {
const models = [
{
name: 'article',
label: 'Article',
destination: 'article',
},
{
name: 'administrator',
label: 'Administrator',
destination: 'administrator',
source: 'admin', // this should be removed at some point
isDisplayed: false,
},
{
name: 'user',
label: 'Users',
destination: 'user',
source: 'users-permissions', // this should be removed at some point
isDisplayed: true,
},
];
ctx.body = { models };
},
};

View File

@ -24,7 +24,7 @@ function lifecycles() {
// Set hooks for the AdminPage container.
// Note: we don't need to specify the first argument because we already know what "willSecure" refers to.
this.setHooks({
didGetSecuredData,
// didGetSecuredData,
willSecure,
});
// Set hooks for the App container of the Content Manager.