mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
Load doc
This commit is contained in:
parent
c7b7fddaba
commit
d6e8ff0807
@ -11,14 +11,14 @@ import { Switch, Route } from 'react-router-dom';
|
||||
import pluginId from '../../pluginId';
|
||||
// Containers
|
||||
import HomePage from '../HomePage';
|
||||
import NotFoundPage from '../NotFoundPage';
|
||||
import { NotFound } from 'strapi-helper-plugin';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className={pluginId}>
|
||||
<Switch>
|
||||
<Route path={`/plugins/${pluginId}`} component={HomePage} exact />
|
||||
<Route component={NotFoundPage} />
|
||||
<Route component={NotFound} />
|
||||
</Switch>
|
||||
</div>
|
||||
);
|
||||
|
@ -1,14 +1,24 @@
|
||||
// import { LOCATION_CHANGE } from 'react-router-redux';
|
||||
import { cloneDeep, isArray } from 'lodash';
|
||||
import { all, takeLatest, put, fork, call, select } from 'redux-saga/effects';
|
||||
import request from 'utils/request';
|
||||
import { GET_DOC_INFOS, ON_CONFIRM_DELETE_DOC, ON_UPDATE_DOC, ON_SUBMIT } from './constants';
|
||||
import { request } from 'strapi-helper-plugin';
|
||||
import {
|
||||
GET_DOC_INFOS,
|
||||
ON_CONFIRM_DELETE_DOC,
|
||||
ON_UPDATE_DOC,
|
||||
ON_SUBMIT,
|
||||
} from './constants';
|
||||
import { getDocInfosSucceeded, setFormErrors } from './actions';
|
||||
import { makeSelectVersionToDelete, makeSelectPrefix, makeSelectForm } from './selectors';
|
||||
import {
|
||||
makeSelectVersionToDelete,
|
||||
makeSelectPrefix,
|
||||
makeSelectForm,
|
||||
} from './selectors';
|
||||
|
||||
function* getData() {
|
||||
try {
|
||||
const response = yield call(request, '/documentation/getInfos', { method: 'GET' });
|
||||
const response = yield call(request, '/documentation/getInfos', {
|
||||
method: 'GET',
|
||||
});
|
||||
yield put(getDocInfosSucceeded(response));
|
||||
} catch (err) {
|
||||
strapi.notification.error('An error occurred');
|
||||
@ -50,7 +60,9 @@ function* submit() {
|
||||
|
||||
if (body.restrictedAccess && body.password === '') {
|
||||
return yield put(
|
||||
setFormErrors({ password: [{ id: 'components.Input.error.validation.required' }] }),
|
||||
setFormErrors({
|
||||
password: [{ id: 'components.Input.error.validation.required' }],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@ -67,7 +79,10 @@ function* updateDoc(action) {
|
||||
try {
|
||||
const body = { version: action.version };
|
||||
const prefix = yield select(makeSelectPrefix());
|
||||
const response = yield call(request, `${prefix}/regenerateDoc`, { method: 'POST', body });
|
||||
const response = yield call(request, `${prefix}/regenerateDoc`, {
|
||||
method: 'POST',
|
||||
body,
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
yield call(getData);
|
||||
|
@ -1,20 +0,0 @@
|
||||
/**
|
||||
* NotFoundPage
|
||||
*
|
||||
* This is the page we show when the user visits a url that doesn't have a route
|
||||
*
|
||||
* NOTE: while this component should technically be a stateless functional
|
||||
* component (SFC), hot reloading does not currently support SFCs. If hot
|
||||
* reloading is not a neccessity for you then you can refactor it and remove
|
||||
* the linting exception.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import NotFound from 'components/NotFound';
|
||||
|
||||
export default class NotFoundPage extends React.Component {
|
||||
render() {
|
||||
return <NotFound {...this.props} />;
|
||||
}
|
||||
}
|
93
packages/strapi-plugin-documentation/admin/src/index.js
Normal file
93
packages/strapi-plugin-documentation/admin/src/index.js
Normal file
@ -0,0 +1,93 @@
|
||||
import React from 'react';
|
||||
import { reduce } from 'lodash';
|
||||
import pluginPkg from '../../package.json';
|
||||
import pluginId from './pluginId';
|
||||
|
||||
import App from './containers/App';
|
||||
|
||||
const pluginDescription = pluginPkg.strapi.description || pluginPkg.description;
|
||||
|
||||
const formatMessages = messages =>
|
||||
reduce(
|
||||
messages,
|
||||
(result, value, key) => {
|
||||
result[`${pluginId}.${key}`] = value;
|
||||
|
||||
return result;
|
||||
},
|
||||
{},
|
||||
);
|
||||
const requireTranslations = language => {
|
||||
try {
|
||||
return require(`./translations/${language}.json`); // eslint-disable-line global-require
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Unable to load "${language}" translation for the plugin ${pluginId}. Please make sure "${language}.json" file exists in "pluginPath/admin/src/translations" folder.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
const translationMessages = reduce(
|
||||
strapi.languages,
|
||||
(result, language) => {
|
||||
result[language] = formatMessages(requireTranslations(language));
|
||||
return result;
|
||||
},
|
||||
{},
|
||||
);
|
||||
// const layout = (() => {
|
||||
// try {
|
||||
// return require('../../config/layout.js'); // eslint-disable-line import/no-unresolved
|
||||
// } catch (err) {
|
||||
// return null;
|
||||
// }
|
||||
// })();
|
||||
|
||||
const injectedComponents = (() => {
|
||||
try {
|
||||
return require('./injectedComponents').default; // eslint-disable-line import/no-unresolved
|
||||
} catch (err) {
|
||||
return [];
|
||||
}
|
||||
})();
|
||||
|
||||
const initializer = (() => {
|
||||
try {
|
||||
return require('./initializer');
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
|
||||
const lifecycles = (() => {
|
||||
try {
|
||||
return require('./lifecycles');
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
|
||||
function Comp(props) {
|
||||
return <App {...props} />;
|
||||
}
|
||||
|
||||
const plugin = {
|
||||
blockerComponent: null,
|
||||
blockerComponentProps: {},
|
||||
description: pluginDescription,
|
||||
icon: pluginPkg.strapi.icon,
|
||||
id: pluginId,
|
||||
initializer,
|
||||
injectedComponents,
|
||||
layout: null,
|
||||
lifecycles,
|
||||
leftMenuLinks: [],
|
||||
leftMenuSections: [],
|
||||
mainComponent: Comp,
|
||||
name: pluginPkg.strapi.name,
|
||||
preventComponentRendering: false,
|
||||
translationMessages,
|
||||
};
|
||||
|
||||
export default plugin;
|
Loading…
x
Reference in New Issue
Block a user