run linter / formatter
This commit is contained in:
parent
bfbc3dad9c
commit
d66cae805e
|
@ -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 = () => (
|
||||
<Router>
|
||||
|
@ -55,7 +54,6 @@ export const Main = () => (
|
|||
<SetVaultURL path="/set_vault_url" settings={settings} api={api} />
|
||||
<Unseal path="/unseal" settings={settings} api={api} />
|
||||
<SetLanguage path="/set_language" settings={settings} api={api} />
|
||||
<InternalTranslateTool path="/internal_translate_tool" />
|
||||
|
||||
<Secrets path="/secrets" settings={settings} api={api} />
|
||||
<DeleteSecretsEngine path="/secrets/delete_engine/:mount" settings={settings} api={api} />
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
|
@ -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<string, unknown> {
|
||||
function parseData(data: string, syntax = "json"): Record<string, unknown> {
|
||||
if (syntax == "json") {
|
||||
return JSON.parse(data);
|
||||
return JSON.parse(data) as Record<string, unknown>;
|
||||
} else if (syntax == "json5") {
|
||||
return JSON5.parse(data);
|
||||
} else if (syntax == "hjson") {
|
||||
return Hjson.parse(data);
|
||||
return Hjson.parse(data) as Record<string, unknown>;
|
||||
} else if (syntax == "yaml") {
|
||||
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") {
|
||||
return JSON.stringify(data, null, space);
|
||||
} 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 {
|
||||
parseData(str, syntax);
|
||||
} catch (e) {
|
||||
|
@ -100,15 +104,15 @@ export class KVEditor extends Component<KVEditProps, KVEditState> {
|
|||
}
|
||||
|
||||
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<KVEditProps, KVEditState> {
|
|||
return dumpData(Object.fromEntries(sortedObjectMap(data)), defaultIndent, this.state.syntax);
|
||||
}
|
||||
|
||||
syntaxSelectRef = createRef<HTMLSelectElement>()
|
||||
syntaxSelectRef = createRef<HTMLSelectElement>();
|
||||
|
||||
render(): JSX.Element {
|
||||
if (!this.state.dataLoaded) {
|
||||
|
@ -132,22 +136,25 @@ export class KVEditor extends Component<KVEditProps, KVEditState> {
|
|||
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 (
|
||||
<div>
|
||||
<InputWithTitle title={i18next.t("kv_sec_edit_syntax")}>
|
||||
<select ref={this.syntaxSelectRef} class="uk-select uk-form-width-medium" onChange={() => {
|
||||
this.setState({ syntax: this.syntaxSelectRef.current.value })
|
||||
|
||||
}}>
|
||||
<select
|
||||
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="JSON5" value="json5" />
|
||||
<option label="Hjson" value="hjson" />
|
||||
|
|
Loading…
Reference in a new issue