From d66cae805e30c4526246c5627f000ea1202ac7ee Mon Sep 17 00:00:00 2001 From: ChaotiCryptidz Date: Sun, 16 Jan 2022 14:29:55 +0000 Subject: [PATCH] run linter / formatter --- src/pages.tsx | 2 - src/translations/en.js | 2 +- src/translations/ru.js | 2 +- src/ui/pages/InternalTranslateTool.tsx | 122 ------------------ .../pages/Secrets/KeyValue/KeyValueEdit.tsx | 65 +++++----- 5 files changed, 38 insertions(+), 155 deletions(-) delete mode 100644 src/ui/pages/InternalTranslateTool.tsx diff --git a/src/pages.tsx b/src/pages.tsx index 1d26f56..fa6388c 100644 --- a/src/pages.tsx +++ b/src/pages.tsx @@ -44,7 +44,6 @@ import { UserPassUserEdit } from "./ui/pages/Access/Auth/userpass/UserPassUserEd import { UserPassUserNew } from "./ui/pages/Access/Auth/userpass/UserPassUserNew"; import { UserPassUserView } from "./ui/pages/Access/Auth/userpass/UserPassUserView"; import { UserPassUsersList } from "./ui/pages/Access/Auth/userpass/UserPassUsersList"; -import { InternalTranslateTool } from "./ui/pages/InternalTranslateTool"; export const Main = () => ( @@ -55,7 +54,6 @@ export const Main = () => ( - diff --git a/src/translations/en.js b/src/translations/en.js index ae14fff..320b688 100644 --- a/src/translations/en.js +++ b/src/translations/en.js @@ -1,4 +1,4 @@ -module.exports = { +module.exports = { // The localised name for the language language_name: "English", // Internal: The direction of text (ltr or rtl) diff --git a/src/translations/ru.js b/src/translations/ru.js index 9ddf841..c960c02 100644 --- a/src/translations/ru.js +++ b/src/translations/ru.js @@ -182,7 +182,7 @@ module.exports = { totp_new_generated: "Новый сгенерированный ключ", totp_new_generated_suffix: "(новый сген.)", totp_new_generated_warning: - 'Не забудьте записать эту информацию в безопасном месте, так как снова её увидеть можно только при помощи "сырого" API Vault.', + 'Не забудьте записать эту информацию в безопасном месте, так как снова её увидеть можно только при помощи "сырого" API Vault.', totp_new_generated_issuer: "Издатель", totp_new_generated_account_name: "Имя учётной записи", totp_new_generated_algorithm: "Алгоритм", diff --git a/src/ui/pages/InternalTranslateTool.tsx b/src/ui/pages/InternalTranslateTool.tsx deleted file mode 100644 index d144873..0000000 --- a/src/ui/pages/InternalTranslateTool.tsx +++ /dev/null @@ -1,122 +0,0 @@ -import { Component, JSX, createRef } from "preact"; -import i18next from "i18next"; - -import { InputWithTitle } from "../elements/InputWithTitle" - -// @ts-ignore -import translations from "../../translations/index.mjs"; -import { CodeEditor } from "../elements/CodeEditor"; -import { getObjectKeys } from "../../utils"; -// ts-unignore - -function SplitView(props: { children: JSX.Element | JSX.Element[] }) { - return ( -
- {props.children} -
- ) -} - - -const languageIDs = Object.getOwnPropertyNames(translations); - -class LanguageSelector extends Component<{ onLanguageChange: (id: string) => void }> { - selectRef = createRef() - render() { - return ( - - ) - } -} - -function arrayDiff(a: string[], b: string[]): {missing: string[], extra: string[]} { - return { - missing: a.filter(x => !b.includes(x)), - extra: b.filter(x => !a.includes(x)), - }; -} - - -type InternalTranslateToolState = { - sourceLangID: string; - targetLangID: string; - targetTranslationData: Record -} - -export class InternalTranslateTool extends Component { - constructor() { - super() - this.setState({ - sourceLangID: "en", - targetLangID: "en", - }) - } - - render() { - let diff = arrayDiff( - getObjectKeys(translations[this.state.sourceLangID]), - getObjectKeys(this.state.targetTranslationData || translations[this.state.targetLangID]) - ); - - return ( - <> -

Internal Translation Tool

- - - { this.setState({ sourceLangID: id }) }} /> - - - - { - this.setState({ - targetLangID: id, - targetTranslationData: translations[id] - }) - }} /> - - -
- -

Source Language

- - { }} - /> - -

Target Language

- -

Missing from target language:

-
    - {diff.missing.map((value) =>
  • - {value}
  • )} -
- -

Extra Keys (maybe deprecated, renamed or no longer exists, check git log)

-
    - {diff.extra.map((value) =>
  • - {value}
  • )} -
- - { - this.setState({ - targetTranslationData: JSON.parse(code) - }) - }} - /> - - ) - } -} \ No newline at end of file diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueEdit.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueEdit.tsx index 6a8bd08..07f0b17 100644 --- a/src/ui/pages/Secrets/KeyValue/KeyValueEdit.tsx +++ b/src/ui/pages/Secrets/KeyValue/KeyValueEdit.tsx @@ -1,31 +1,35 @@ import { CodeEditor } from "../../../elements/CodeEditor"; -import { Component, createRef, JSX } from "preact"; +import { Component, JSX, createRef } from "preact"; import { DefaultPageProps } from "../../../../types/DefaultPageProps"; +import { InputWithTitle } from "../../../elements/InputWithTitle"; import { SecretTitleElement } from "../SecretTitleElement"; import { setErrorText } from "../../../../pageUtils"; import { sortedObjectMap } from "../../../../utils"; -import { InputWithTitle } from "../../../elements/InputWithTitle"; import Hjson from "hjson"; import JSON5 from "json5"; -import yaml from "js-yaml"; import i18next from "i18next"; +import yaml from "js-yaml"; // todo: put this in settings const defaultIndent = 2; -function parseData(data: string, syntax: string = "json"): Record { +function parseData(data: string, syntax = "json"): Record { if (syntax == "json") { - return JSON.parse(data); + return JSON.parse(data) as Record; } else if (syntax == "json5") { return JSON5.parse(data); } else if (syntax == "hjson") { - return Hjson.parse(data); + return Hjson.parse(data) as Record; } else if (syntax == "yaml") { return yaml.load(data) as Record; } } -function dumpData(data: Record, space: number = defaultIndent, syntax: string = "json"): string { +function dumpData( + data: Record, + space: number = defaultIndent, + syntax = "json", +): string { if (syntax == "json") { return JSON.stringify(data, null, space); } else if (syntax == "json5") { @@ -37,7 +41,7 @@ function dumpData(data: Record, space: number = defaultIndent, } } -export function validateData(str: string, syntax: string = "json"): boolean { +export function validateData(str: string, syntax = "json"): boolean { try { parseData(str, syntax); } catch (e) { @@ -55,15 +59,15 @@ export type KVEditProps = DefaultPageProps & { type KVEditState = | { - dataLoaded: false; - syntax: string; - } + dataLoaded: false; + syntax: string; + } | { - dataLoaded: true; - kvData: Record; - code: string; - syntax: string; - }; + dataLoaded: true; + kvData: Record; + code: string; + syntax: string; + }; export class KVEditor extends Component { constructor() { @@ -100,15 +104,15 @@ export class KVEditor extends Component { } async loadData() { - let kvData = await this.props.api.getSecret( + const kvData = await this.props.api.getSecret( this.props.baseMount, this.props.secretPath.map((e) => e + "/"), this.props.secretItem, - ) + ); this.setState({ dataLoaded: true, kvData: kvData, - code: this.getStringKVData(kvData) + code: this.getStringKVData(kvData), }); } @@ -122,7 +126,7 @@ export class KVEditor extends Component { return dumpData(Object.fromEntries(sortedObjectMap(data)), defaultIndent, this.state.syntax); } - syntaxSelectRef = createRef() + syntaxSelectRef = createRef(); render(): JSX.Element { if (!this.state.dataLoaded) { @@ -132,22 +136,25 @@ export class KVEditor extends Component { let codeEditorLanguage: string; if (this.state.syntax == "json") { - codeEditorLanguage = "json" + codeEditorLanguage = "json"; } else if (this.state.syntax == "json5") { - codeEditorLanguage = "json5" - }else if (this.state.syntax == "hjson") { - codeEditorLanguage = "js" + codeEditorLanguage = "json5"; + } else if (this.state.syntax == "hjson") { + codeEditorLanguage = "js"; } else if (this.state.syntax == "yaml") { - codeEditorLanguage = "yaml" + codeEditorLanguage = "yaml"; } return (
- { + this.setState({ syntax: this.syntaxSelectRef.current.value }); + }} + >