strapi-plugin-comments 2.0.0-beta.1 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/admin/src/index.js +6 -4
- package/admin/src/pages/App/index.js +31 -3
- package/admin/src/pages/App/reducer/actions.js +8 -0
- package/admin/src/pages/App/reducer/constants.js +4 -0
- package/admin/src/pages/App/reducer/index.js +27 -0
- package/admin/src/pages/App/reducer/init.js +7 -0
- package/admin/src/pages/App/reducer/selectors.js +35 -0
- package/admin/src/pages/App/utils/api.js +20 -0
- package/admin/src/pages/Discover/index.js +20 -2
- package/admin/src/pages/Discover/utils/api.js +0 -3
- package/admin/src/reducers.js +8 -0
- package/package.json +1 -1
- package/server/config/index.js +5 -1
- package/server/controllers/admin.js +5 -21
- package/server/services/admin.js +8 -2
- package/server/services/common.js +1 -1
package/admin/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import pluginId from './pluginId';
|
|
|
4
4
|
import Initializer from './components/Initializer';
|
|
5
5
|
import PluginIcon from './components/PluginIcon';
|
|
6
6
|
import pluginPermissions from './permissions';
|
|
7
|
+
import reducers from './reducers';
|
|
7
8
|
|
|
8
9
|
const name = pluginPkg.strapi.name;
|
|
9
10
|
|
|
@@ -24,6 +25,7 @@ export default {
|
|
|
24
25
|
},
|
|
25
26
|
permissions: pluginPermissions,
|
|
26
27
|
});
|
|
28
|
+
app.addReducers(reducers);
|
|
27
29
|
app.registerPlugin({
|
|
28
30
|
id: pluginId,
|
|
29
31
|
initializer: Initializer,
|
|
@@ -33,10 +35,10 @@ export default {
|
|
|
33
35
|
},
|
|
34
36
|
|
|
35
37
|
bootstrap(app) {
|
|
36
|
-
app.injectContentManagerComponent('editView', 'informations', {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
38
|
+
// app.injectContentManagerComponent('editView', 'informations', {
|
|
39
|
+
// name: 'comments-link',
|
|
40
|
+
// Component: () => 'TODO: Comments count',
|
|
41
|
+
// });
|
|
40
42
|
},
|
|
41
43
|
|
|
42
44
|
async registerTrads({ locales }) {
|
|
@@ -5,16 +5,44 @@
|
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React from 'react';
|
|
8
|
+
import React, { useReducer } from 'react';
|
|
9
9
|
import { Switch, Route } from 'react-router-dom';
|
|
10
|
-
import {
|
|
10
|
+
import { useQuery } from 'react-query';
|
|
11
|
+
import {
|
|
12
|
+
NotFound,
|
|
13
|
+
LoadingIndicatorPage,
|
|
14
|
+
useNotification } from '@strapi/helper-plugin';
|
|
15
|
+
|
|
11
16
|
import ComingSoonPage from '../ComingSoonPage';
|
|
12
17
|
import getUrl from '../../utils/getUrl';
|
|
13
18
|
import Discover from '../Discover';
|
|
14
19
|
import Details from '../Details';
|
|
15
|
-
|
|
20
|
+
import { fetchConfig } from './utils/api';
|
|
21
|
+
import initReducer from './reducer/init';
|
|
22
|
+
import reducer, { initialState } from './reducer';
|
|
23
|
+
import { setConfig } from './reducer/actions';
|
|
16
24
|
|
|
17
25
|
const App = () => {
|
|
26
|
+
|
|
27
|
+
const toggleNotification = useNotification();
|
|
28
|
+
const [reducerState, dispatch] = useReducer(reducer, initialState, () =>
|
|
29
|
+
initReducer(initialState)
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const { isLoading, isFetching } = useQuery(
|
|
33
|
+
'get-config', () => fetchConfig(toggleNotification),
|
|
34
|
+
{
|
|
35
|
+
initialData: { },
|
|
36
|
+
onSuccess: (response) => {
|
|
37
|
+
dispatch(setConfig(response));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (isLoading || isFetching) {
|
|
43
|
+
return (<LoadingIndicatorPage />)
|
|
44
|
+
}
|
|
45
|
+
|
|
18
46
|
return (
|
|
19
47
|
<div>
|
|
20
48
|
<Switch>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import produce from 'immer'; // current
|
|
2
|
+
import { set } from 'lodash';
|
|
3
|
+
import { GET_CONFIG, SET_CONFIG } from './constants';
|
|
4
|
+
|
|
5
|
+
const initialState = {
|
|
6
|
+
config: {},
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const reducer = (state = initialState, action) =>
|
|
10
|
+
// eslint-disable-next-line consistent-return
|
|
11
|
+
produce(state, draftState => {
|
|
12
|
+
switch (action.type) {
|
|
13
|
+
case SET_CONFIG: {
|
|
14
|
+
set(draftState, 'config', action.data);
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
case GET_CONFIG: {
|
|
18
|
+
return draftState?.config;
|
|
19
|
+
}
|
|
20
|
+
default:
|
|
21
|
+
console.log('draftState', draftState);
|
|
22
|
+
return draftState;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export default reducer;
|
|
27
|
+
export { initialState };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { createSelector } from 'reselect';
|
|
4
|
+
import { initialState } from './';
|
|
5
|
+
import { REDUCER_NAME } from './constants';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Direct selector to the listView state domain
|
|
9
|
+
*/
|
|
10
|
+
const appView = () => state => state[REDUCER_NAME] || initialState;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Other specific selectors
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Default selector used by listView
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const makeAppView = () =>
|
|
21
|
+
createSelector(
|
|
22
|
+
appView(),
|
|
23
|
+
substate => {
|
|
24
|
+
return substate;
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const selectConfig = state => {
|
|
29
|
+
const { config } = state[REDUCER_NAME];
|
|
30
|
+
|
|
31
|
+
return config;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default makeAppView;
|
|
35
|
+
export { appView, selectConfig };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { stringify } from 'qs';
|
|
2
|
+
import { isEmpty } from 'lodash';
|
|
3
|
+
|
|
4
|
+
import { getApiURL, axiosInstance } from '../../../utils';
|
|
5
|
+
|
|
6
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
7
|
+
export const fetchConfig = async (toggleNotification) => {
|
|
8
|
+
try {
|
|
9
|
+
const { data } = await axiosInstance.get(getApiURL(`moderate/config`));
|
|
10
|
+
|
|
11
|
+
return data;
|
|
12
|
+
} catch (err) {
|
|
13
|
+
toggleNotification({
|
|
14
|
+
type: 'warning',
|
|
15
|
+
message: { id: 'notification.error' },
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
throw new Error('error');
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import React, { memo, useRef, useMemo } from 'react';
|
|
8
|
+
import { connect } from 'react-redux';
|
|
9
|
+
import { bindActionCreators, compose } from 'redux';
|
|
10
|
+
import isEqual from 'react-fast-compare';
|
|
8
11
|
import { useIntl } from 'react-intl';
|
|
9
12
|
import { useQuery } from 'react-query';
|
|
10
13
|
import { useHistory } from 'react-router-dom';
|
|
@@ -41,8 +44,10 @@ import { COMMENT_STATUS } from '../../utils/constants';
|
|
|
41
44
|
import TablePagination from '../../components/TablePagination';
|
|
42
45
|
import filtersSchema from './utils/filtersSchema';
|
|
43
46
|
import TableFilters from '../../components/TableFilters';
|
|
47
|
+
import appReducer from '../App/reducer';
|
|
48
|
+
import makeAppView, { selectConfig } from '../App/reducer/selectors';
|
|
44
49
|
|
|
45
|
-
const Discover = () => {
|
|
50
|
+
const Discover = ({ config }) => {
|
|
46
51
|
useFocusWhenNavigate();
|
|
47
52
|
|
|
48
53
|
const { push } = useHistory();
|
|
@@ -182,4 +187,17 @@ const Discover = () => {
|
|
|
182
187
|
</Box>;
|
|
183
188
|
}
|
|
184
189
|
|
|
185
|
-
|
|
190
|
+
const mapStateToProps = makeAppView();
|
|
191
|
+
|
|
192
|
+
export function mapDispatchToProps(dispatch) {
|
|
193
|
+
return bindActionCreators(
|
|
194
|
+
{ },
|
|
195
|
+
dispatch
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
const withConnect = connect(
|
|
199
|
+
mapStateToProps,
|
|
200
|
+
mapDispatchToProps
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
export default compose(withConnect)(memo(Discover, isEqual));
|
|
@@ -6,9 +6,6 @@ import { getApiURL, axiosInstance } from '../../../utils';
|
|
|
6
6
|
// eslint-disable-next-line import/prefer-default-export
|
|
7
7
|
export const fetchData = async (queryParams, toggleNotification) => {
|
|
8
8
|
try {
|
|
9
|
-
console.log('api');
|
|
10
|
-
console.log(queryParams);
|
|
11
|
-
console.log(getApiURL(`moderate/all${!isEmpty(queryParams) ? `?${stringify(queryParams, { encode: false })}` : ''}`));
|
|
12
9
|
const { data } = await axiosInstance.get(getApiURL(`moderate/all${queryParams ? `?${stringify(queryParams, { encode: false })}` : ''}`));
|
|
13
10
|
|
|
14
11
|
return data;
|
package/package.json
CHANGED
package/server/config/index.js
CHANGED
|
@@ -102,27 +102,11 @@ module.exports = {
|
|
|
102
102
|
},
|
|
103
103
|
|
|
104
104
|
async config() {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const current = configRelatedContentTypes[currentKey];
|
|
111
|
-
const { key } = contentsTypes.find(content => content.value === currentKey) || {};
|
|
112
|
-
return {
|
|
113
|
-
...acc,
|
|
114
|
-
[currentKey]: {
|
|
115
|
-
...current,
|
|
116
|
-
globalName: _.snakeCase(key),
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
},
|
|
120
|
-
{},
|
|
121
|
-
);
|
|
122
|
-
return {
|
|
123
|
-
relatedContentTypes,
|
|
124
|
-
contentsTypes,
|
|
125
|
-
};
|
|
105
|
+
try {
|
|
106
|
+
return await this.getService().config();
|
|
107
|
+
} catch (e) {
|
|
108
|
+
throwError(ctx, e);
|
|
109
|
+
}
|
|
126
110
|
},
|
|
127
111
|
|
|
128
112
|
getContentsTypes() {
|
package/server/services/admin.js
CHANGED
|
@@ -22,6 +22,14 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
|
22
22
|
return getPluginService('common');
|
|
23
23
|
},
|
|
24
24
|
|
|
25
|
+
// Config
|
|
26
|
+
async config() {
|
|
27
|
+
const entryLabel = this.getCommonService().getConfig('entryLabel');
|
|
28
|
+
return {
|
|
29
|
+
entryLabel,
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
|
|
25
33
|
// Find all comments
|
|
26
34
|
async findAll({ related, entity, ...query }) {
|
|
27
35
|
const { _q, orderBy, pageSize = 10, page = 1, filters, ...rest } = parseParams(query);
|
|
@@ -57,8 +65,6 @@ const { APPROVAL_STATUS, REGEX } = require('./../utils/constants')
|
|
|
57
65
|
.map(_ => filterOurResolvedReports(this.getCommonService().sanitizeCommentEntity(_)))
|
|
58
66
|
.map(_ => this.getCommonService().mergeRelatedEntityTo(_, relatedEntities));
|
|
59
67
|
|
|
60
|
-
console.log(relatedEntities);
|
|
61
|
-
|
|
62
68
|
return {
|
|
63
69
|
result,
|
|
64
70
|
pagination: {
|
|
@@ -93,7 +93,7 @@ module.exports = ({ strapi }) => ({
|
|
|
93
93
|
return { id: _.id, itemsInTread: count, firstThreadItemId: first(nestedEntries)?.id }
|
|
94
94
|
}));
|
|
95
95
|
|
|
96
|
-
const relatedEntities = relatedEntity !== null ? [relatedEntity] : await this.findRelatedEntitiesFor([...
|
|
96
|
+
const relatedEntities = relatedEntity !== null ? [relatedEntity] : await this.findRelatedEntitiesFor([...entries]);
|
|
97
97
|
const result = entries
|
|
98
98
|
.map(_ => {
|
|
99
99
|
const threadedItem = entriesWithThreads.find(item => item.id === _.id);
|