strapi-plugin-comments 2.0.0-rc.2 → 2.0.0

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.
Files changed (36) hide show
  1. package/.circleci/config.yml +1 -1
  2. package/README.md +20 -4
  3. package/__mocks__/initSetup.js +53 -0
  4. package/admin/src/components/ActionButton/styles.js +10 -0
  5. package/admin/src/components/DiscussionThread/index.js +2 -6
  6. package/admin/src/components/DiscussionThreadItem/index.js +25 -68
  7. package/admin/src/components/DiscussionThreadItem/styles.js +4 -79
  8. package/admin/src/components/DiscussionThreadItemActions/index.js +82 -40
  9. package/admin/src/components/DiscussionThreadItemActions/styles.js +1 -12
  10. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +2 -3
  11. package/admin/src/components/DiscussionThreadItemFooter/index.js +47 -0
  12. package/admin/src/components/DiscussionThreadItemFooter/styles.js +13 -0
  13. package/admin/src/components/DiscussionThreadItemReviewAction/index.js +131 -0
  14. package/admin/src/components/IconButton/styles.js +14 -0
  15. package/admin/src/components/ReportsReviewModal/index.js +1 -1
  16. package/admin/src/components/ReportsReviewTable/index.js +12 -6
  17. package/admin/src/components/StatusBadge/index.js +17 -0
  18. package/admin/src/components/StatusBadge/styles.js +17 -0
  19. package/admin/src/pages/Details/components/DetailsEntity/index.js +40 -24
  20. package/admin/src/pages/Details/components/DetailsFilters/index.js +8 -10
  21. package/admin/src/pages/Details/index.js +9 -15
  22. package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +28 -65
  23. package/admin/src/translations/en.json +13 -15
  24. package/admin/src/utils/resolveCommentStatus.js +4 -4
  25. package/package.json +7 -5
  26. package/server/controllers/utils/__tests__/functions.test.js +2 -2
  27. package/server/graphql/types/comment-nested.js +1 -0
  28. package/server/services/__tests__/common.test.js +165 -0
  29. package/server/services/client.js +2 -3
  30. package/server/services/common.js +19 -2
  31. package/server/services/utils/__tests__/functions.test.js +9 -73
  32. package/server/services/utils/functions.js +1 -17
  33. package/server/utils/__tests__/functions.test.js +17 -0
  34. package/admin/src/components/DiscussionThreadItemMeta/index.js +0 -42
  35. package/admin/src/components/DiscussionThreadItemWarnings/index.js +0 -147
  36. package/admin/src/components/DiscussionThreadItemWarnings/styles.js +0 -7
@@ -1,147 +0,0 @@
1
- /**
2
- *
3
- * Entity Details
4
- *
5
- */
6
-
7
- import React, { useState } from 'react';
8
- import PropTypes from 'prop-types';
9
- import { useMutation, useQueryClient } from 'react-query';
10
- import { isEmpty, orderBy } from 'lodash';
11
- import { Badge } from '@strapi/design-system/Badge';
12
- import { Box } from '@strapi/design-system/Box';
13
- import { Button } from '@strapi/design-system/Button';
14
- import { Divider } from '@strapi/design-system/Divider';
15
- import { Flex } from '@strapi/design-system/Flex';
16
- import { Typography } from '@strapi/design-system/Typography';
17
- import { useNotification, useOverlayBlocker } from '@strapi/helper-plugin';
18
- import { getMessage, handleAPIError } from '../../utils';
19
- import { blockItem, blockItemThread, resolveReport } from '../../pages/utils/api';
20
- import { DiscussionThreadItemWarningsWrapper } from './styles';
21
- import ReportsReviewModal from '../ReportsReviewModal';
22
- import ReportsReviewTable from '../ReportsReviewTable';
23
- import pluginId from '../../pluginId';
24
- import { LockIcon, ReviewIcon } from '../icons';
25
-
26
- const DiscussionThreadItemWarnings = (item) => {
27
- const { id, reports, gotThread, allowedActions: { canModerate, canAccessReports, canReviewReports }} = item;
28
-
29
- const [reportsReviewVisible, setReportsReviewVisible] = useState(false);
30
- const [blockButtonsDisabled, setBlockButtonsDisabled] = useState(false);
31
-
32
- const toggleNotification = useNotification();
33
- const queryClient = useQueryClient();
34
- const { lockApp, unlockApp } = useOverlayBlocker();
35
-
36
- const onSuccess = (message, stateAction = () => {}, indalidate = true) => async () => {
37
- if (indalidate) {
38
- await queryClient.invalidateQueries('get-details-data');
39
- }
40
- toggleNotification({
41
- type: 'success',
42
- message: `${pluginId}.${message}`,
43
- });
44
- stateAction(false);
45
- unlockApp();
46
- };
47
-
48
- const onError = err => { handleAPIError(err, toggleNotification); };
49
-
50
- const resolveReportMutation = useMutation(resolveReport, {
51
- onSuccess: onSuccess('page.details.panel.discussion.warnings.reports.dialog.confirmation.success', () => {}, false),
52
- onError,
53
- refetchActive: false,
54
- });
55
-
56
- const blockItemMutation = useMutation(blockItem, {
57
- onSuccess: onSuccess(
58
- 'page.details.actions.comment.block.confirmation.success',
59
- setReportsReviewVisible
60
- ),
61
- onError,
62
- refetchActive: false,
63
- });
64
- const blockItemThreadMutation = useMutation(blockItemThread, {
65
- onSuccess: onSuccess(
66
- 'page.details.actions.thread.block.confirmation.success',
67
- setReportsReviewVisible
68
- ),
69
- onError,
70
- refetchActive: false,
71
- });
72
-
73
- const handleReportsReviewClick = () => setReportsReviewVisible(true);
74
- const handleBlockItemClick = async () => {
75
- lockApp();
76
- blockItemMutation.mutate(id);
77
- };
78
- const handleBlockItemThreadClick = async () => {
79
- lockApp();
80
- blockItemThreadMutation.mutate(id);
81
- };
82
- const handleReportsReviewClose = async () => {
83
- await queryClient.invalidateQueries('get-details-data')
84
- setReportsReviewVisible(false);
85
- };
86
-
87
- const handleBlockButtonsStateChange = disabled => setBlockButtonsDisabled(disabled);
88
-
89
- const isLoading = blockItemMutation.isLoading || blockItemThreadMutation.isLoading || resolveReportMutation.isLoading;
90
- const openReports = reports?.filter(_ => !_.resolved);
91
-
92
- if (isEmpty(reports) || isEmpty(openReports)) {
93
- return null;
94
- }
95
-
96
- return (<>
97
- { canAccessReports && (<DiscussionThreadItemWarningsWrapper as={Flex} direction="row" padding={2} background="danger100" borderColor="danger200" border={1} hasRadius>
98
- <Box as={Flex} paddingRight={2} direction="row" grow={1}>
99
- <Badge textColor="neutral0" backgroundColor="warning600">{ openReports.length }</Badge>
100
- <Box paddingLeft={2}>
101
- <Typography textColor="warning600" fontWeight="bold">{getMessage(`page.details.panel.discussion.warnings.reports.description`, 'abuse reports')}</Typography>
102
- </Box>
103
- </Box>
104
- <Button onClick={handleReportsReviewClick} variant="ghost" endIcon={<ReviewIcon />}>
105
- { getMessage(`page.details.actions.comment.report.review`, 'review') }
106
- </Button>
107
- </DiscussionThreadItemWarningsWrapper>) }
108
- { (canAccessReports || canReviewReports) && (<ReportsReviewModal
109
- isVisible={reportsReviewVisible}
110
- isActionAsync={isLoading}
111
- onClose={handleReportsReviewClose}
112
- startActions={canModerate && (<>
113
- <Button onClick={handleBlockItemClick} variant="danger-light" startIcon={<LockIcon />} disabled={blockButtonsDisabled}>
114
- { getMessage(`page.details.actions.comment.block`, 'Block comment') }
115
- </Button>
116
- { gotThread && (<Button onClick={handleBlockItemThreadClick} variant="danger" startIcon={<LockIcon />} disabled={blockButtonsDisabled}>
117
- { getMessage(`page.details.actions.thread.block`, 'Block thread') }
118
- </Button>) }
119
- </>)}
120
- item={item}>
121
- <Typography variant="sigma" textColor="neutral600" id="reports-list">
122
- { getMessage('page.details.panel.discussion.warnings.reports.list', 'List') }
123
- </Typography>
124
- <Box paddingTop={2} paddingBottom={6}>
125
- <Divider />
126
- </Box>
127
- <ReportsReviewTable
128
- commentId={id}
129
- items={orderBy(reports, ['resolved', 'createdAt'], ['DESC', 'DESC'])}
130
- mutation={resolveReportMutation}
131
- allowedActions={{ canAccessReports, canReviewReports }}
132
- onBlockButtonsStateChange={handleBlockButtonsStateChange}
133
- />
134
- </ReportsReviewModal>) }
135
- </>);
136
- };
137
-
138
- DiscussionThreadItemWarnings.propTypes = {
139
- allowedActions: PropTypes.shape({
140
- canModerate: PropTypes.bool,
141
- canAccessReports: PropTypes.bool,
142
- canReviewReports: PropTypes.bool,
143
- }),
144
- };
145
-
146
- export default DiscussionThreadItemWarnings;
147
-
@@ -1,7 +0,0 @@
1
- import styled from 'styled-components';
2
- import { Box } from '@strapi/design-system/Box';
3
-
4
- export const DiscussionThreadItemWarningsWrapper = styled(Box)`
5
- width: 100%;
6
- margin-top: .5rem;
7
- `;