From a59dc855d94b332ca01b4a2477ef94ee68da9fe6 Mon Sep 17 00:00:00 2001 From: f0x52 Date: Fri, 3 Feb 2023 12:07:40 +0100 Subject: [PATCH] [feature/frogend] (Mastodon) domain block CSV import (#1390) * checkbox-list styling with taller

element * CSV import/export, UI/UX improvements to import-export interface * minor styling tweaks * csv export, clean up export type branching * abstract domain block entry validation * foundation for PSL check + suggestions * Squashed commit of the following: commit e3655ba4fbea1d55738b2f9e407d3378af26afe6 Author: f0x Date: Tue Jan 31 15:19:10 2023 +0100 let debug depend on env (prod/debug) again commit 79c792b832a2b59e472dcdff646bad6d71b42cc9 Author: f0x Date: Tue Jan 31 00:34:01 2023 +0100 update checklist components commit 4367960fe4be4e3978077af06e63a729d64e32fb Author: f0x Date: Mon Jan 30 23:46:20 2023 +0100 checklist performance improvements commit 204a4c02d16ffad189a6e8a6001d5bf4ff95fc4e Author: f0x Date: Mon Jan 30 20:05:34 2023 +0100 checklist field: use reducer for state * remove debug logging * show and use domain block suggestion * restructure import/export buttons * updating suggestions * suggestion overview * restructure check-list behavior, domain import/export --- web/source/css/base.css | 2 +- web/source/index.js | 7 +- web/source/package.json | 3 + .../admin/emoji/remote/parse-from-toot.js | 21 +- .../admin/federation/import-export.js | 307 ---------------- .../import-export/export-format-table.jsx | 64 ++++ .../admin/federation/import-export/form.jsx | 123 +++++++ .../admin/federation/import-export/index.jsx | 78 +++++ .../federation/import-export/process.jsx | 327 ++++++++++++++++++ web/source/settings/components/check-list.jsx | 82 +++-- .../settings/components/form/inputs.jsx | 3 +- web/source/settings/lib/domain-block.js | 50 +++ web/source/settings/lib/form/check-list.jsx | 245 +++++++------ web/source/settings/lib/form/text.jsx | 31 +- .../settings/lib/query/admin/import-export.js | 109 ++++-- web/source/settings/style.css | 94 ++++- web/source/yarn.lock | 15 + 17 files changed, 1077 insertions(+), 484 deletions(-) delete mode 100644 web/source/settings/admin/federation/import-export.js create mode 100644 web/source/settings/admin/federation/import-export/export-format-table.jsx create mode 100644 web/source/settings/admin/federation/import-export/form.jsx create mode 100644 web/source/settings/admin/federation/import-export/index.jsx create mode 100644 web/source/settings/admin/federation/import-export/process.jsx create mode 100644 web/source/settings/lib/domain-block.js diff --git a/web/source/css/base.css b/web/source/css/base.css index cd65a617e..06ce28ff6 100644 --- a/web/source/css/base.css +++ b/web/source/css/base.css @@ -315,7 +315,7 @@ input, select, textarea, .input { border-color: $input-focus-border; } - &:invalid { + &:invalid, .invalid & { border-color: $input-error-border; } diff --git a/web/source/index.js b/web/source/index.js index 0f80ef22c..26340ec19 100644 --- a/web/source/index.js +++ b/web/source/index.js @@ -66,10 +66,15 @@ skulk({ ], }, settings: { - debug: false, entryFile: "settings", outputFile: "settings.js", prodCfg: prodCfg, + transform: [ + ["babelify", { + global: true, + ignore: [/node_modules\/(?!nanoid)/] + }] + ], presets: [ "react", ["postcss", { diff --git a/web/source/package.json b/web/source/package.json index f9520baba..9e7951620 100644 --- a/web/source/package.json +++ b/web/source/package.json @@ -19,9 +19,12 @@ "langs": "^2.0.0", "match-sorter": "^6.3.1", "modern-normalize": "^1.1.0", + "nanoid": "^4.0.0", + "papaparse": "^5.3.2", "photoswipe": "^5.3.3", "photoswipe-dynamic-caption-plugin": "^1.2.7", "photoswipe-video-plugin": "^1.0.2", + "psl": "^1.9.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-error-boundary": "^3.1.4", diff --git a/web/source/settings/admin/emoji/remote/parse-from-toot.js b/web/source/settings/admin/emoji/remote/parse-from-toot.js index 309619ea4..84bbbdc92 100644 --- a/web/source/settings/admin/emoji/remote/parse-from-toot.js +++ b/web/source/settings/admin/emoji/remote/parse-from-toot.js @@ -129,14 +129,16 @@ function CopyEmojiForm({ localEmojiCodes, type, emojiList }) { title: "No emoji selected, cannot perform any actions" }; + const checkListExtraProps = React.useCallback(() => ({ localEmojiCodes }), [localEmojiCodes]); + return (

This {type == "statuses" ? "toot" : "account"} uses the following custom emoji, select the ones you want to copy/disable:
{ - onChange({ valid: shortcodeField.valid }); - /* eslint-disable-next-line react-hooks/exhaustive-deps */ - }, [shortcodeField.valid]); + if (emoji.valid != shortcodeField.valid) { + onChange({ valid: shortcodeField.valid }); + } + }, [onChange, emoji.valid, shortcodeField.valid]); + + React.useEffect(() => { + shortcodeField.validate(); + // only need this update if it's the emoji.checked that updated, not shortcodeField + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [emoji.checked]); return ( <> diff --git a/web/source/settings/admin/federation/import-export.js b/web/source/settings/admin/federation/import-export.js deleted file mode 100644 index a11174b1f..000000000 --- a/web/source/settings/admin/federation/import-export.js +++ /dev/null @@ -1,307 +0,0 @@ -/* - GoToSocial - Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -"use strict"; - -const React = require("react"); -const { Switch, Route, Redirect, useLocation } = require("wouter"); - -const query = require("../../lib/query"); - -const { - useTextInput, - useBoolInput, - useRadioInput, - useCheckListInput -} = require("../../lib/form"); - -const useFormSubmit = require("../../lib/form/submit"); - -const { - TextInput, - TextArea, - Checkbox, - Select, - RadioGroup -} = require("../../components/form/inputs"); - -const CheckList = require("../../components/check-list"); -const MutationButton = require("../../components/form/mutation-button"); -const isValidDomain = require("is-valid-domain"); -const FormWithData = require("../../lib/form/form-with-data"); -const { Error } = require("../../components/error"); - -const baseUrl = "/settings/admin/federation/import-export"; - -module.exports = function ImportExport() { - const [updateFromFile, setUpdateFromFile] = React.useState(false); - const form = { - domains: useTextInput("domains"), - exportType: useTextInput("exportType", { defaultValue: "plain", dontReset: true }) - }; - - const [submitParse, parseResult] = useFormSubmit(form, query.useProcessDomainListMutation()); - const [submitExport, exportResult] = useFormSubmit(form, query.useExportDomainListMutation()); - - function fileChanged(e) { - const reader = new FileReader(); - reader.onload = function (read) { - form.domains.setter(read.target.result); - setUpdateFromFile(true); - }; - reader.readAsText(e.target.files[0]); - } - - React.useEffect(() => { - if (exportResult.isSuccess) { - form.domains.setter(exportResult.data); - } - /* eslint-disable-next-line react-hooks/exhaustive-deps */ - }, [exportResult]); - - const [_location, setLocation] = useLocation(); - - if (updateFromFile) { - setUpdateFromFile(false); - submitParse(); - } - - return ( - - - {!parseResult.isSuccess && } - -

- { - parseResult.reset(); - setLocation(baseUrl); - }}> - < back - Confirm import: -

- -
- - - {parseResult.isSuccess && } -

Import / Export suspended domains

- -
- -