1
0
Fork 0

run linter / formatter

This commit is contained in:
ChaotiCryptidz 2022-01-16 14:29:55 +00:00
parent bfbc3dad9c
commit d66cae805e
5 changed files with 38 additions and 155 deletions

View file

@ -44,7 +44,6 @@ import { UserPassUserEdit } from "./ui/pages/Access/Auth/userpass/UserPassUserEd
import { UserPassUserNew } from "./ui/pages/Access/Auth/userpass/UserPassUserNew"; import { UserPassUserNew } from "./ui/pages/Access/Auth/userpass/UserPassUserNew";
import { UserPassUserView } from "./ui/pages/Access/Auth/userpass/UserPassUserView"; import { UserPassUserView } from "./ui/pages/Access/Auth/userpass/UserPassUserView";
import { UserPassUsersList } from "./ui/pages/Access/Auth/userpass/UserPassUsersList"; import { UserPassUsersList } from "./ui/pages/Access/Auth/userpass/UserPassUsersList";
import { InternalTranslateTool } from "./ui/pages/InternalTranslateTool";
export const Main = () => ( export const Main = () => (
<Router> <Router>
@ -55,7 +54,6 @@ export const Main = () => (
<SetVaultURL path="/set_vault_url" settings={settings} api={api} /> <SetVaultURL path="/set_vault_url" settings={settings} api={api} />
<Unseal path="/unseal" settings={settings} api={api} /> <Unseal path="/unseal" settings={settings} api={api} />
<SetLanguage path="/set_language" settings={settings} api={api} /> <SetLanguage path="/set_language" settings={settings} api={api} />
<InternalTranslateTool path="/internal_translate_tool" />
<Secrets path="/secrets" settings={settings} api={api} /> <Secrets path="/secrets" settings={settings} api={api} />
<DeleteSecretsEngine path="/secrets/delete_engine/:mount" settings={settings} api={api} /> <DeleteSecretsEngine path="/secrets/delete_engine/:mount" settings={settings} api={api} />

View file

@ -1,4 +1,4 @@
module.exports = { module.exports = {
// The localised name for the language // The localised name for the language
language_name: "English", language_name: "English",
// Internal: The direction of text (ltr or rtl) // Internal: The direction of text (ltr or rtl)

View file

@ -182,7 +182,7 @@ module.exports = {
totp_new_generated: "Новый сгенерированный ключ", totp_new_generated: "Новый сгенерированный ключ",
totp_new_generated_suffix: "(новый сген.)", totp_new_generated_suffix: "(новый сген.)",
totp_new_generated_warning: totp_new_generated_warning:
'Не забудьте записать эту информацию в безопасном месте, так как снова её увидеть можно только при помощи "сырого" API Vault.', 'Не забудьте записать эту информацию в безопасном месте, так как снова её увидеть можно только при помощи "сырого" API Vault.',
totp_new_generated_issuer: "Издатель", totp_new_generated_issuer: "Издатель",
totp_new_generated_account_name: "Имя учётной записи", totp_new_generated_account_name: "Имя учётной записи",
totp_new_generated_algorithm: "Алгоритм", totp_new_generated_algorithm: "Алгоритм",

View file

@ -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 (
<div style="flex: 0 200px;">
{props.children}
</div>
)
}
const languageIDs = Object.getOwnPropertyNames(translations);
class LanguageSelector extends Component<{ onLanguageChange: (id: string) => void }> {
selectRef = createRef<HTMLSelectElement>()
render() {
return (
<select ref={this.selectRef} class="uk-select uk-form-width-large" name="language" onChange={() => {
this.props.onLanguageChange(this.selectRef.current.value)
}}>
{languageIDs.map((languageID) => (
<option value={languageID} selected={languageID == "en"}>
{i18next.getFixedT(languageID, null)("language_name")}
</option>
))}
</select>
)
}
}
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<string, unknown>
}
export class InternalTranslateTool extends Component<unknown, InternalTranslateToolState> {
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 (
<>
<h3>Internal Translation Tool</h3>
<InputWithTitle title="Source Language">
<LanguageSelector onLanguageChange={(id) => { this.setState({ sourceLangID: id }) }} />
</InputWithTitle>
<InputWithTitle title="Target Language">
<LanguageSelector onLanguageChange={(id) => {
this.setState({
targetLangID: id,
targetTranslationData: translations[id]
})
}} />
</InputWithTitle>
<br />
<h4>Source Language</h4>
<CodeEditor
tabSize={4}
language="json"
code={JSON.stringify(translations[this.state.sourceLangID], null, 2)}
onUpdate={() => { }}
/>
<h4>Target Language</h4>
<h4>Missing from target language:</h4>
<ul>
{diff.missing.map((value) => <li>- {value}</li>)}
</ul>
<h4>Extra Keys (maybe deprecated, renamed or no longer exists, check git log)</h4>
<ul>
{diff.extra.map((value) => <li>- {value}</li>)}
</ul>
<CodeEditor
tabSize={4}
language="json"
code={JSON.stringify(translations[this.state.targetLangID], null, 2)}
onUpdate={(code) => {
this.setState({
targetTranslationData: JSON.parse(code)
})
}}
/>
</>
)
}
}

View file

@ -1,31 +1,35 @@
import { CodeEditor } from "../../../elements/CodeEditor"; import { CodeEditor } from "../../../elements/CodeEditor";
import { Component, createRef, JSX } from "preact"; import { Component, JSX, createRef } from "preact";
import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { DefaultPageProps } from "../../../../types/DefaultPageProps";
import { InputWithTitle } from "../../../elements/InputWithTitle";
import { SecretTitleElement } from "../SecretTitleElement"; import { SecretTitleElement } from "../SecretTitleElement";
import { setErrorText } from "../../../../pageUtils"; import { setErrorText } from "../../../../pageUtils";
import { sortedObjectMap } from "../../../../utils"; import { sortedObjectMap } from "../../../../utils";
import { InputWithTitle } from "../../../elements/InputWithTitle";
import Hjson from "hjson"; import Hjson from "hjson";
import JSON5 from "json5"; import JSON5 from "json5";
import yaml from "js-yaml";
import i18next from "i18next"; import i18next from "i18next";
import yaml from "js-yaml";
// todo: put this in settings // todo: put this in settings
const defaultIndent = 2; const defaultIndent = 2;
function parseData(data: string, syntax: string = "json"): Record<string, unknown> { function parseData(data: string, syntax = "json"): Record<string, unknown> {
if (syntax == "json") { if (syntax == "json") {
return JSON.parse(data); return JSON.parse(data) as Record<string, unknown>;
} else if (syntax == "json5") { } else if (syntax == "json5") {
return JSON5.parse(data); return JSON5.parse(data);
} else if (syntax == "hjson") { } else if (syntax == "hjson") {
return Hjson.parse(data); return Hjson.parse(data) as Record<string, unknown>;
} else if (syntax == "yaml") { } else if (syntax == "yaml") {
return yaml.load(data) as Record<string, unknown>; return yaml.load(data) as Record<string, unknown>;
} }
} }
function dumpData(data: Record<string, unknown>, space: number = defaultIndent, syntax: string = "json"): string { function dumpData(
data: Record<string, unknown>,
space: number = defaultIndent,
syntax = "json",
): string {
if (syntax == "json") { if (syntax == "json") {
return JSON.stringify(data, null, space); return JSON.stringify(data, null, space);
} else if (syntax == "json5") { } else if (syntax == "json5") {
@ -37,7 +41,7 @@ function dumpData(data: Record<string, unknown>, space: number = defaultIndent,
} }
} }
export function validateData(str: string, syntax: string = "json"): boolean { export function validateData(str: string, syntax = "json"): boolean {
try { try {
parseData(str, syntax); parseData(str, syntax);
} catch (e) { } catch (e) {
@ -55,15 +59,15 @@ export type KVEditProps = DefaultPageProps & {
type KVEditState = type KVEditState =
| { | {
dataLoaded: false; dataLoaded: false;
syntax: string; syntax: string;
} }
| { | {
dataLoaded: true; dataLoaded: true;
kvData: Record<string, unknown>; kvData: Record<string, unknown>;
code: string; code: string;
syntax: string; syntax: string;
}; };
export class KVEditor extends Component<KVEditProps, KVEditState> { export class KVEditor extends Component<KVEditProps, KVEditState> {
constructor() { constructor() {
@ -100,15 +104,15 @@ export class KVEditor extends Component<KVEditProps, KVEditState> {
} }
async loadData() { async loadData() {
let kvData = await this.props.api.getSecret( const kvData = await this.props.api.getSecret(
this.props.baseMount, this.props.baseMount,
this.props.secretPath.map((e) => e + "/"), this.props.secretPath.map((e) => e + "/"),
this.props.secretItem, this.props.secretItem,
) );
this.setState({ this.setState({
dataLoaded: true, dataLoaded: true,
kvData: kvData, kvData: kvData,
code: this.getStringKVData(kvData) code: this.getStringKVData(kvData),
}); });
} }
@ -122,7 +126,7 @@ export class KVEditor extends Component<KVEditProps, KVEditState> {
return dumpData(Object.fromEntries(sortedObjectMap(data)), defaultIndent, this.state.syntax); return dumpData(Object.fromEntries(sortedObjectMap(data)), defaultIndent, this.state.syntax);
} }
syntaxSelectRef = createRef<HTMLSelectElement>() syntaxSelectRef = createRef<HTMLSelectElement>();
render(): JSX.Element { render(): JSX.Element {
if (!this.state.dataLoaded) { if (!this.state.dataLoaded) {
@ -132,22 +136,25 @@ export class KVEditor extends Component<KVEditProps, KVEditState> {
let codeEditorLanguage: string; let codeEditorLanguage: string;
if (this.state.syntax == "json") { if (this.state.syntax == "json") {
codeEditorLanguage = "json" codeEditorLanguage = "json";
} else if (this.state.syntax == "json5") { } else if (this.state.syntax == "json5") {
codeEditorLanguage = "json5" codeEditorLanguage = "json5";
}else if (this.state.syntax == "hjson") { } else if (this.state.syntax == "hjson") {
codeEditorLanguage = "js" codeEditorLanguage = "js";
} else if (this.state.syntax == "yaml") { } else if (this.state.syntax == "yaml") {
codeEditorLanguage = "yaml" codeEditorLanguage = "yaml";
} }
return ( return (
<div> <div>
<InputWithTitle title={i18next.t("kv_sec_edit_syntax")}> <InputWithTitle title={i18next.t("kv_sec_edit_syntax")}>
<select ref={this.syntaxSelectRef} class="uk-select uk-form-width-medium" onChange={() => { <select
this.setState({ syntax: this.syntaxSelectRef.current.value }) ref={this.syntaxSelectRef}
class="uk-select uk-form-width-medium"
}}> onChange={() => {
this.setState({ syntax: this.syntaxSelectRef.current.value });
}}
>
<option label="JSON" value="json" /> <option label="JSON" value="json" />
<option label="JSON5" value="json5" /> <option label="JSON5" value="json5" />
<option label="Hjson" value="hjson" /> <option label="Hjson" value="hjson" />