Merge branch 'report-rule-types' into 'develop'
Account for different 'rule_type' on rules See merge request soapbox-pub/soapbox-fe!1350
This commit is contained in:
commit
fe77a22da2
4 changed files with 37 additions and 14 deletions
|
@ -208,7 +208,12 @@ class ModalRoot extends React.PureComponent {
|
||||||
})}
|
})}
|
||||||
style={{ opacity: revealed ? 1 : 0 }}
|
style={{ opacity: revealed ? 1 : 0 }}
|
||||||
>
|
>
|
||||||
<div role='presentation' id='modal-overlay' className='fixed inset-0 bg-gray-600 bg-opacity-90' onClick={this.handleOnClose} />
|
<div
|
||||||
|
role='presentation'
|
||||||
|
id='modal-overlay'
|
||||||
|
className='fixed inset-0 bg-gray-600 bg-opacity-90'
|
||||||
|
onClick={this.handleOnClose}
|
||||||
|
/>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
role='dialog'
|
role='dialog'
|
||||||
|
|
|
@ -4,7 +4,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||||
|
|
||||||
import { blockAccount } from 'soapbox/actions/accounts';
|
import { blockAccount } from 'soapbox/actions/accounts';
|
||||||
import { submitReport, cancelReport, submitReportSuccess, submitReportFail } from 'soapbox/actions/reports';
|
import { submitReport, submitReportSuccess, submitReportFail } from 'soapbox/actions/reports';
|
||||||
import { expandAccountTimeline } from 'soapbox/actions/timelines';
|
import { expandAccountTimeline } from 'soapbox/actions/timelines';
|
||||||
import AttachmentThumbs from 'soapbox/components/attachment_thumbs';
|
import AttachmentThumbs from 'soapbox/components/attachment_thumbs';
|
||||||
import StatusContent from 'soapbox/components/status_content';
|
import StatusContent from 'soapbox/components/status_content';
|
||||||
|
@ -87,6 +87,7 @@ const ReportModal = ({ onClose }: IReportModal) => {
|
||||||
const ruleIds = useAppSelector((state) => state.reports.getIn(['new', 'rule_ids']) as ImmutableSet<string>);
|
const ruleIds = useAppSelector((state) => state.reports.getIn(['new', 'rule_ids']) as ImmutableSet<string>);
|
||||||
const selectedStatusIds = useAppSelector((state) => state.reports.getIn(['new', 'status_ids']) as ImmutableSet<string>);
|
const selectedStatusIds = useAppSelector((state) => state.reports.getIn(['new', 'status_ids']) as ImmutableSet<string>);
|
||||||
|
|
||||||
|
const isReportingAccount = useMemo(() => selectedStatusIds.size === 0, []);
|
||||||
const shouldRequireRule = rules.length > 0;
|
const shouldRequireRule = rules.length > 0;
|
||||||
|
|
||||||
const [currentStep, setCurrentStep] = useState<Steps>(Steps.ONE);
|
const [currentStep, setCurrentStep] = useState<Steps>(Steps.ONE);
|
||||||
|
@ -101,11 +102,6 @@ const ReportModal = ({ onClose }: IReportModal) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
|
||||||
dispatch(cancelReport());
|
|
||||||
onClose();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleNextStep = () => {
|
const handleNextStep = () => {
|
||||||
switch (currentStep) {
|
switch (currentStep) {
|
||||||
case Steps.ONE:
|
case Steps.ONE:
|
||||||
|
@ -152,8 +148,8 @@ const ReportModal = ({ onClose }: IReportModal) => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return isSubmitting || (shouldRequireRule && ruleIds.isEmpty()) || selectedStatusIds.size === 0;
|
return isSubmitting || (shouldRequireRule && ruleIds.isEmpty()) || (!isReportingAccount && selectedStatusIds.size === 0);
|
||||||
}, [currentStep, isSubmitting, shouldRequireRule, ruleIds, selectedStatusIds.size]);
|
}, [currentStep, isSubmitting, shouldRequireRule, ruleIds, selectedStatusIds.size, isReportingAccount]);
|
||||||
|
|
||||||
const calculateProgress = useCallback(() => {
|
const calculateProgress = useCallback(() => {
|
||||||
switch (currentStep) {
|
switch (currentStep) {
|
||||||
|
@ -183,7 +179,7 @@ const ReportModal = ({ onClose }: IReportModal) => {
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title={<FormattedMessage id='report.target' defaultMessage='Reporting {target}' values={{ target: <strong>@{account.acct}</strong> }} />}
|
title={<FormattedMessage id='report.target' defaultMessage='Reporting {target}' values={{ target: <strong>@{account.acct}</strong> }} />}
|
||||||
onClose={handleClose}
|
onClose={onClose}
|
||||||
cancelAction={currentStep === Steps.THREE ? undefined : onClose}
|
cancelAction={currentStep === Steps.THREE ? undefined : onClose}
|
||||||
confirmationAction={handleNextStep}
|
confirmationAction={handleNextStep}
|
||||||
confirmationText={confirmationText}
|
confirmationText={confirmationText}
|
||||||
|
@ -193,7 +189,7 @@ const ReportModal = ({ onClose }: IReportModal) => {
|
||||||
<Stack space={4}>
|
<Stack space={4}>
|
||||||
<ProgressBar progress={calculateProgress()} />
|
<ProgressBar progress={calculateProgress()} />
|
||||||
|
|
||||||
{currentStep !== Steps.THREE && renderSelectedStatuses()}
|
{(currentStep !== Steps.THREE && !isReportingAccount) && renderSelectedStatuses()}
|
||||||
|
|
||||||
<StepToRender account={account} />
|
<StepToRender account={account} />
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import React, { useEffect, useRef, useState } from 'react';
|
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { defineMessages, useIntl } from 'react-intl';
|
import { defineMessages, useIntl } from 'react-intl';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
|
|
||||||
|
@ -36,6 +36,9 @@ const ReasonStep = (_props: IReasonStep) => {
|
||||||
const ruleIds = useAppSelector((state) => state.reports.getIn(['new', 'rule_ids']) as ImmutableSet<string>);
|
const ruleIds = useAppSelector((state) => state.reports.getIn(['new', 'rule_ids']) as ImmutableSet<string>);
|
||||||
const shouldRequireRule = rules.length > 0;
|
const shouldRequireRule = rules.length > 0;
|
||||||
|
|
||||||
|
const selectedStatusIds = useAppSelector((state) => state.reports.getIn(['new', 'status_ids']) as ImmutableSet<string>);
|
||||||
|
const isReportingAccount = useMemo(() => selectedStatusIds.size === 0, []);
|
||||||
|
|
||||||
const handleCommentChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
|
const handleCommentChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||||
dispatch(changeReportComment(event.target.value));
|
dispatch(changeReportComment(event.target.value));
|
||||||
};
|
};
|
||||||
|
@ -58,6 +61,16 @@ const ReasonStep = (_props: IReasonStep) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const filterRuleType = (rule: any) => {
|
||||||
|
const ruleTypeToFilter = isReportingAccount ? 'account' : 'content';
|
||||||
|
|
||||||
|
if (rule.rule_type) {
|
||||||
|
return rule.rule_type === ruleTypeToFilter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(fetchRules());
|
dispatch(fetchRules());
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -87,7 +100,7 @@ const ReasonStep = (_props: IReasonStep) => {
|
||||||
onScroll={handleRulesScrolling}
|
onScroll={handleRulesScrolling}
|
||||||
ref={rulesListRef}
|
ref={rulesListRef}
|
||||||
>
|
>
|
||||||
{rules.map((rule, idx) => {
|
{rules.filter(filterRuleType).map((rule, idx) => {
|
||||||
const isSelected = ruleIds.includes(String(rule.id));
|
const isSelected = ruleIds.includes(String(rule.id));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
|
import { cancelReport } from 'soapbox/actions/reports';
|
||||||
|
|
||||||
import { cancelReplyCompose } from '../../../actions/compose';
|
import { cancelReplyCompose } from '../../../actions/compose';
|
||||||
import { closeModal } from '../../../actions/modals';
|
import { closeModal } from '../../../actions/modals';
|
||||||
import ModalRoot from '../components/modal_root';
|
import ModalRoot from '../components/modal_root';
|
||||||
|
@ -18,8 +20,15 @@ const mapStateToProps = state => {
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
onClose(type) {
|
onClose(type) {
|
||||||
if (type === 'COMPOSE') {
|
switch (type) {
|
||||||
|
case 'COMPOSE':
|
||||||
dispatch(cancelReplyCompose());
|
dispatch(cancelReplyCompose());
|
||||||
|
break;
|
||||||
|
case 'REPORT':
|
||||||
|
dispatch(cancelReport());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(closeModal(type));
|
dispatch(closeModal(type));
|
||||||
|
|
Loading…
Reference in a new issue