diff --git a/res/css/_components.scss b/res/css/_components.scss index 8aa2d709542..fe09ea499b2 100644 --- a/res/css/_components.scss +++ b/res/css/_components.scss @@ -133,7 +133,6 @@ @import "./views/dialogs/_UploadConfirmDialog.scss"; @import "./views/dialogs/_UserSettingsDialog.scss"; @import "./views/dialogs/_WidgetCapabilitiesPromptDialog.scss"; -@import "./views/dialogs/_WidgetOpenIDPermissionsDialog.scss"; @import "./views/dialogs/security/_AccessSecretStorageDialog.scss"; @import "./views/dialogs/security/_CreateCrossSigningDialog.scss"; @import "./views/dialogs/security/_CreateKeyBackupDialog.scss"; @@ -161,6 +160,7 @@ @import "./views/elements/_InlineSpinner.scss"; @import "./views/elements/_InteractiveTooltip.scss"; @import "./views/elements/_InviteReason.scss"; +@import "./views/elements/_LabelledCheckbox.scss"; @import "./views/elements/_ManageIntegsButton.scss"; @import "./views/elements/_MiniAvatarUploader.scss"; @import "./views/elements/_Pill.scss"; diff --git a/res/css/views/dialogs/_WidgetCapabilitiesPromptDialog.scss b/res/css/views/dialogs/_WidgetCapabilitiesPromptDialog.scss index 8786defed38..c559467c9de 100644 --- a/res/css/views/dialogs/_WidgetCapabilitiesPromptDialog.scss +++ b/res/css/views/dialogs/_WidgetCapabilitiesPromptDialog.scss @@ -46,10 +46,6 @@ limitations under the License. font-size: $font-12px; .mx_ToggleSwitch { - display: inline-block; - vertical-align: middle; - margin-right: 8px; - // downsize the switch + ball width: $font-32px; height: $font-15px; @@ -64,10 +60,5 @@ limitations under the License. border-radius: $font-15px; } } - - .mx_SettingsFlag_label { - display: inline-block; - vertical-align: middle; - } } } diff --git a/res/css/views/dialogs/_WidgetOpenIDPermissionsDialog.scss b/res/css/views/elements/_LabelledCheckbox.scss similarity index 51% rename from res/css/views/dialogs/_WidgetOpenIDPermissionsDialog.scss rename to res/css/views/elements/_LabelledCheckbox.scss index a419c105a9a..c97b1b341a1 100644 --- a/res/css/views/dialogs/_WidgetOpenIDPermissionsDialog.scss +++ b/res/css/views/elements/_LabelledCheckbox.scss @@ -1,5 +1,5 @@ /* -Copyright 2019 Travis Ralston +Copyright 2022 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,15 +14,26 @@ See the License for the specific language governing permissions and limitations under the License. */ -.mx_WidgetOpenIDPermissionsDialog .mx_SettingsFlag { - .mx_ToggleSwitch { - display: inline-block; - vertical-align: middle; - margin-right: 8px; +.mx_LabelledCheckbox { + display: flex; + flex-direction: row; + + .mx_Checkbox { + margin-top: 3px; // visually align with label text } - .mx_SettingsFlag_label { - display: inline-block; - vertical-align: middle; + .mx_LabelledCheckbox_labels { + flex: 1; + + .mx_LabelledCheckbox_label { + vertical-align: middle; + } + + .mx_LabelledCheckbox_byline { + display: block; + padding-top: $spacing-4; + color: $muted-fg-color; + font-size: $font-11px; + } } } diff --git a/res/css/views/elements/_SettingsFlag.scss b/res/css/views/elements/_SettingsFlag.scss index c6f4cf6ec5c..6d941e94eb5 100644 --- a/res/css/views/elements/_SettingsFlag.scss +++ b/res/css/views/elements/_SettingsFlag.scss @@ -24,6 +24,19 @@ limitations under the License. .mx_ToggleSwitch { flex: 0 0 auto; } + + &.mx_SettingsFlag_toggleInFront { + .mx_ToggleSwitch { + display: inline-block; + vertical-align: middle; + margin-right: 8px; + } + + .mx_SettingsFlag_label { + display: inline-block; + vertical-align: middle; + } + } } .mx_SettingsFlag_label { diff --git a/src/components/views/dialogs/ReportEventDialog.tsx b/src/components/views/dialogs/ReportEventDialog.tsx index 7a2d51889f8..929c33b128e 100644 --- a/src/components/views/dialogs/ReportEventDialog.tsx +++ b/src/components/views/dialogs/ReportEventDialog.tsx @@ -1,5 +1,6 @@ /* Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> +Copyright 2022 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -30,6 +31,7 @@ import BaseDialog from "./BaseDialog"; import DialogButtons from "../elements/DialogButtons"; import Field from "../elements/Field"; import Spinner from "../elements/Spinner"; +import LabelledCheckbox from "../elements/LabelledCheckbox"; interface IProps extends IDialogProps { mxEvent: MatrixEvent; @@ -42,6 +44,7 @@ interface IState { err?: string; // If we know it, the nature of the abuse, as specified by MSC3215. nature?: ExtendedNature; + ignoreUserToo: boolean; // if true, user will be ignored/blocked on submit } const MODERATED_BY_STATE_EVENT_TYPE = [ @@ -160,9 +163,14 @@ export default class ReportEventDialog extends React.Component { err: null, // If specified, the nature of the abuse, as specified by MSC3215. nature: null, + ignoreUserToo: false, // default false, for now. Could easily be argued as default true }; } + private onIgnoreUserTooChanged = (newVal: boolean): void => { + this.setState({ ignoreUserToo: newVal }); + }; + // The user has written down a freeform description of the abuse. private onReasonChange = ({ target: { value: reason } }): void => { this.setState({ reason }); @@ -232,6 +240,15 @@ export default class ReportEventDialog extends React.Component { // Report to homeserver admin through the dedicated Matrix API. await client.reportEvent(ev.getRoomId(), ev.getId(), -100, this.state.reason.trim()); } + + // if the user should also be ignored, do that + if (this.state.ignoreUserToo) { + await client.setIgnoredUsers([ + ...client.getIgnoredUsers(), + ev.getSender(), + ]); + } + this.props.onFinished(true); } catch (e) { logger.error(e); @@ -242,7 +259,7 @@ export default class ReportEventDialog extends React.Component { } }; - render() { + public render() { let error = null; if (this.state.err) { error =
@@ -259,6 +276,14 @@ export default class ReportEventDialog extends React.Component { ); } + const ignoreUserCheckbox = ; + const adminMessageMD = SdkConfig .getObject("report_event")?.get("admin_message_md", "adminMessageMD"); let adminMessage; @@ -387,6 +412,7 @@ export default class ReportEventDialog extends React.Component { /> { progress } { error } + { ignoreUserCheckbox }
{ /> { progress } { error } + { ignoreUserCheckbox } = ({ value, label, byline, disabled, onChange }) => { + return ; +}; + +export default LabelledCheckbox; diff --git a/src/components/views/elements/LabelledToggleSwitch.tsx b/src/components/views/elements/LabelledToggleSwitch.tsx index 952c92ac427..6df972440a9 100644 --- a/src/components/views/elements/LabelledToggleSwitch.tsx +++ b/src/components/views/elements/LabelledToggleSwitch.tsx @@ -1,5 +1,5 @@ /* -Copyright 2019 - 2021 The Matrix.org Foundation C.I.C. +Copyright 2019 - 2022 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ limitations under the License. */ import React from "react"; +import classNames from "classnames"; import ToggleSwitch from "./ToggleSwitch"; @@ -35,7 +36,7 @@ interface IProps { } export default class LabelledToggleSwitch extends React.PureComponent { - render() { + public render() { // This is a minimal version of a SettingsFlag let firstPart = { this.props.label }; @@ -52,7 +53,9 @@ export default class LabelledToggleSwitch extends React.PureComponent { secondPart = temp; } - const classes = `mx_SettingsFlag ${this.props.className || ""}`; + const classes = classNames("mx_SettingsFlag", this.props.className, { + "mx_SettingsFlag_toggleInFront": this.props.toggleInFront, + }); return (
{ firstPart } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index ede1176ef68..c7e7b9793d8 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2677,6 +2677,8 @@ "Just a heads up, if you don't add an email and forget your password, you could permanently lose access to your account.": "Just a heads up, if you don't add an email and forget your password, you could permanently lose access to your account.", "Email (optional)": "Email (optional)", "Please fill why you're reporting.": "Please fill why you're reporting.", + "Ignore user": "Ignore user", + "Check if you want to hide all current and future messages from this user.": "Check if you want to hide all current and future messages from this user.", "What this user is writing is wrong.\nThis will be reported to the room moderators.": "What this user is writing is wrong.\nThis will be reported to the room moderators.", "This user is displaying toxic behaviour, for instance by insulting other users or sharing adult-only content in a family-friendly room or otherwise violating the rules of this room.\nThis will be reported to the room moderators.": "This user is displaying toxic behaviour, for instance by insulting other users or sharing adult-only content in a family-friendly room or otherwise violating the rules of this room.\nThis will be reported to the room moderators.", "This user is displaying illegal behaviour, for instance by doxing people or threatening violence.\nThis will be reported to the room moderators who may escalate this to legal authorities.": "This user is displaying illegal behaviour, for instance by doxing people or threatening violence.\nThis will be reported to the room moderators who may escalate this to legal authorities.", diff --git a/test/components/views/elements/LabelledCheckbox-test.tsx b/test/components/views/elements/LabelledCheckbox-test.tsx new file mode 100644 index 00000000000..b03ee0c1f18 --- /dev/null +++ b/test/components/views/elements/LabelledCheckbox-test.tsx @@ -0,0 +1,124 @@ +/* +Copyright 2022 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import React from 'react'; +import { mount } from 'enzyme'; +import { act } from "react-dom/test-utils"; + +import LabelledCheckbox from "../../../../src/components/views/elements/LabelledCheckbox"; + +// Fake random strings to give a predictable snapshot for checkbox IDs +jest.mock( + 'matrix-js-sdk/src/randomstring', + () => { + return { + randomString: () => "abdefghi", + }; + }, +); + +describe('', () => { + type CompProps = React.ComponentProps; + const getComponent = (props: CompProps) => mount(); + type CompClass = ReturnType; + + const getCheckbox = (component: CompClass) => component.find(`input[type="checkbox"]`); + const getLabel = (component: CompClass) => component.find(`.mx_LabelledCheckbox_label`); + const getByline = (component: CompClass) => component.find(`.mx_LabelledCheckbox_byline`); + + const isChecked = (checkbox: ReturnType) => checkbox.is(`[checked=true]`); + const isDisabled = (checkbox: ReturnType) => checkbox.is(`[disabled=true]`); + const getText = (span: ReturnType) => span.length > 0 ? span.at(0).text() : null; + + test.each([null, "this is a byline"])( + "should render with byline of %p", + (byline) => { + const props: CompProps = { + label: "Hello world", + value: true, + byline: byline, + onChange: jest.fn(), + }; + const component = getComponent(props); + const checkbox = getCheckbox(component); + + expect(component).toMatchSnapshot(); + expect(isChecked(checkbox)).toBe(true); + expect(isDisabled(checkbox)).toBe(false); + expect(getText(getLabel(component))).toBe(props.label); + expect(getText(getByline(component))).toBe(byline); + }, + ); + + it('should support unchecked by default', () => { + const props: CompProps = { + label: "Hello world", + value: false, + onChange: jest.fn(), + }; + const component = getComponent(props); + + expect(isChecked(getCheckbox(component))).toBe(false); + }); + + it('should be possible to disable the checkbox', () => { + const props: CompProps = { + label: "Hello world", + value: false, + disabled: true, + onChange: jest.fn(), + }; + const component = getComponent(props); + + expect(isDisabled(getCheckbox(component))).toBe(true); + }); + + it('should emit onChange calls', () => { + const props: CompProps = { + label: "Hello world", + value: false, + onChange: jest.fn(), + }; + const component = getComponent(props); + + expect(props.onChange).not.toHaveBeenCalled(); + + act(() => { + getCheckbox(component).simulate('change'); + }); + + expect(props.onChange).toHaveBeenCalledTimes(1); + }); + + it('should react to value and disabled prop changes', () => { + const props: CompProps = { + label: "Hello world", + value: false, + onChange: jest.fn(), + }; + const component = getComponent(props); + let checkbox = getCheckbox(component); + + expect(isChecked(checkbox)).toBe(false); + expect(isDisabled(checkbox)).toBe(false); + + component.setProps({ value: true, disabled: true }); + checkbox = getCheckbox(component); // refresh reference to checkbox + + expect(isChecked(checkbox)).toBe(true); + expect(isDisabled(checkbox)).toBe(true); + }); +}); diff --git a/test/components/views/elements/__snapshots__/LabelledCheckbox-test.tsx.snap b/test/components/views/elements/__snapshots__/LabelledCheckbox-test.tsx.snap new file mode 100644 index 00000000000..34cdbe59be9 --- /dev/null +++ b/test/components/views/elements/__snapshots__/LabelledCheckbox-test.tsx.snap @@ -0,0 +1,108 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` should render with byline of "this is a byline" 1`] = ` + +