Change SecretTitleElement props.
This commit is contained in:
parent
7e4d168429
commit
4c4a69464f
|
@ -43,7 +43,7 @@ export class KeyValueDeletePage extends Page {
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(
|
render(
|
||||||
<SecretTitleElement router={this.router} suffix={i18next.t("kv_delete_suffix")} />,
|
<SecretTitleElement page={this} suffix={i18next.t("kv_delete_suffix")} />,
|
||||||
this.router.pageTitleElement,
|
this.router.pageTitleElement,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ export class KeyValueNewPage extends Page {
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(
|
render(
|
||||||
<SecretTitleElement router={this.router} suffix={i18next.t("kv_new_suffix")} />,
|
<SecretTitleElement page={this} suffix={i18next.t("kv_new_suffix")} />,
|
||||||
this.router.pageTitleElement,
|
this.router.pageTitleElement,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@ export class KeyValueSecretPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(<SecretTitleElement router={this.router} />, this.router.pageTitleElement);
|
render(<SecretTitleElement page={this} />, this.router.pageTitleElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -117,7 +117,7 @@ export class KeyValueSecretEditPage extends Page {
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(
|
render(
|
||||||
<SecretTitleElement router={this.router} suffix={i18next.t("kv_sec_edit_suffix")} />,
|
<SecretTitleElement page={this} suffix={i18next.t("kv_sec_edit_suffix")} />,
|
||||||
this.router.pageTitleElement,
|
this.router.pageTitleElement,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ export class KeyValueVersionsPage extends Page {
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(
|
render(
|
||||||
<SecretTitleElement router={this.router} suffix={i18next.t("kv_sec_versions_suffix")} />,
|
<SecretTitleElement page={this} suffix={i18next.t("kv_sec_versions_suffix")} />,
|
||||||
this.router.pageTitleElement,
|
this.router.pageTitleElement,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,7 +149,7 @@ export class KeyValueViewPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(<SecretTitleElement router={this.router} />, this.router.pageTitleElement);
|
render(<SecretTitleElement page={this} />, this.router.pageTitleElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -1,28 +1,26 @@
|
||||||
import { JSX } from "preact/jsx-runtime";
|
import { JSX } from "preact/jsx-runtime";
|
||||||
import { PageRouter } from "z-pagerouter";
|
import { Page } from "../../types/Page";
|
||||||
import { PageState } from "../../state/PageState";
|
|
||||||
|
|
||||||
function currentTitleSecretText(state: PageState): string {
|
function currentTitleSecretText(page: Page): string {
|
||||||
let secretItemText = state.secretItem;
|
let secretItemText = page.state.secretItem;
|
||||||
if (state.secretVersion !== null) secretItemText += ` (v${state.secretVersion})`;
|
if (page.state.secretVersion !== null) secretItemText += ` (v${page.state.secretVersion})`;
|
||||||
return secretItemText;
|
return secretItemText;
|
||||||
}
|
}
|
||||||
|
|
||||||
type SecretTitleElementProps = {
|
type SecretTitleElementProps = {
|
||||||
router: PageRouter;
|
page: Page;
|
||||||
suffix?: string;
|
suffix?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function SecretTitleElement(props: SecretTitleElementProps): JSX.Element {
|
export function SecretTitleElement(props: SecretTitleElementProps): JSX.Element {
|
||||||
const router = props.router;
|
const page = props.page;
|
||||||
const suffix = props.suffix || "";
|
const suffix = props.suffix || "";
|
||||||
const state = router.state as PageState;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<a
|
<a
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
await router.changePage("SECRETS_HOME");
|
await page.router.changePage("SECRETS_HOME");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{"/ "}
|
{"/ "}
|
||||||
|
@ -30,35 +28,38 @@ export function SecretTitleElement(props: SecretTitleElementProps): JSX.Element
|
||||||
|
|
||||||
<a
|
<a
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
state.secretPath = [];
|
page.state.secretPath = [];
|
||||||
state.secretItem = "";
|
page.state.secretItem = "";
|
||||||
state.secretVersion = null;
|
page.state.secretVersion = null;
|
||||||
|
|
||||||
if (state.secretMountType.startsWith("kv") || state.secretMountType == "cubbyhole") {
|
if (
|
||||||
await router.changePage("KEY_VALUE_VIEW");
|
page.state.secretMountType.startsWith("kv") ||
|
||||||
} else if (state.secretMountType == "totp") {
|
page.state.secretMountType == "cubbyhole"
|
||||||
await router.changePage("TOTP_VIEW");
|
) {
|
||||||
} else if (state.secretMountType == "transit") {
|
await page.router.changePage("KEY_VALUE_VIEW");
|
||||||
await router.changePage("TRANSIT_VIEW");
|
} else if (page.state.secretMountType == "totp") {
|
||||||
|
await page.router.changePage("TOTP_VIEW");
|
||||||
|
} else if (page.state.secretMountType == "transit") {
|
||||||
|
await page.router.changePage("TRANSIT_VIEW");
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{state.baseMount + " "}
|
{page.state.baseMount + " "}
|
||||||
</a>
|
</a>
|
||||||
{...state.secretPath.map((secretPath, index, secretPaths) => (
|
{...page.state.secretPath.map((secretPath, index, secretPaths) => (
|
||||||
<a
|
<a
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
state.secretVersion = null;
|
page.state.secretVersion = null;
|
||||||
if (state.secretMountType.startsWith("kv")) {
|
if (page.state.secretMountType.startsWith("kv")) {
|
||||||
state.secretPath = secretPaths.slice(0, index + 1);
|
page.state.secretPath = secretPaths.slice(0, index + 1);
|
||||||
await router.changePage("KEY_VALUE_VIEW");
|
await page.router.changePage("KEY_VALUE_VIEW");
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{secretPath + " "}
|
{secretPath + " "}
|
||||||
</a>
|
</a>
|
||||||
))}
|
))}
|
||||||
{state.secretItem.length != 0 && <span>{currentTitleSecretText(state)}</span>}
|
{page.state.secretItem.length != 0 && <span>{currentTitleSecretText(page)}</span>}
|
||||||
{suffix.length != 0 && <span>{suffix}</span>}
|
{suffix.length != 0 && <span>{suffix}</span>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -37,7 +37,7 @@ export class TOTPDeletePage extends Page {
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(
|
render(
|
||||||
<SecretTitleElement router={this.router} suffix={i18next.t("totp_delete_suffix")} />,
|
<SecretTitleElement page={this} suffix={i18next.t("totp_delete_suffix")} />,
|
||||||
this.router.pageTitleElement,
|
this.router.pageTitleElement,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ export class TOTPNewPage extends Page {
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(
|
render(
|
||||||
<SecretTitleElement router={this.router} suffix={i18next.t("totp_new_suffix")} />,
|
<SecretTitleElement page={this} suffix={i18next.t("totp_new_suffix")} />,
|
||||||
this.router.pageTitleElement,
|
this.router.pageTitleElement,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ export class TOTPViewPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(<SecretTitleElement router={this.router} />, this.router.pageTitleElement);
|
render(<SecretTitleElement page={this} />, this.router.pageTitleElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -78,7 +78,7 @@ export class NewTransitKeyPage extends Page {
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(
|
render(
|
||||||
<SecretTitleElement router={this.router} suffix={i18next.t("transit_new_key_suffix")} />,
|
<SecretTitleElement page={this} suffix={i18next.t("transit_new_key_suffix")} />,
|
||||||
this.router.pageTitleElement,
|
this.router.pageTitleElement,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ export class TransitDecryptPage extends Page {
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(
|
render(
|
||||||
<SecretTitleElement router={this.router} suffix={i18next.t("transit_decrypt_suffix")} />,
|
<SecretTitleElement page={this} suffix={i18next.t("transit_decrypt_suffix")} />,
|
||||||
this.router.pageTitleElement,
|
this.router.pageTitleElement,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ export class TransitEncryptPage extends Page {
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(
|
render(
|
||||||
<SecretTitleElement router={this.router} suffix={i18next.t("transit_encrypt_suffix")} />,
|
<SecretTitleElement page={this} suffix={i18next.t("transit_encrypt_suffix")} />,
|
||||||
this.router.pageTitleElement,
|
this.router.pageTitleElement,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ export class TransitRewrapPage extends Page {
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(
|
render(
|
||||||
<SecretTitleElement router={this.router} suffix={i18next.t("transit_rewrap_suffix")} />,
|
<SecretTitleElement page={this} suffix={i18next.t("transit_rewrap_suffix")} />,
|
||||||
this.router.pageTitleElement,
|
this.router.pageTitleElement,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ export class TransitViewPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(<SecretTitleElement router={this.router} />, this.router.pageTitleElement);
|
render(<SecretTitleElement page={this} />, this.router.pageTitleElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -53,7 +53,7 @@ export class TransitViewSecretPage extends Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderPageTitle(): Promise<void> {
|
async renderPageTitle(): Promise<void> {
|
||||||
render(<SecretTitleElement router={this.router} />, this.router.pageTitleElement);
|
render(<SecretTitleElement page={this} />, this.router.pageTitleElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
get name(): string {
|
get name(): string {
|
||||||
|
|
|
@ -2,4 +2,4 @@ export interface StorageType {
|
||||||
clear(): void;
|
clear(): void;
|
||||||
getItem(key: string): string;
|
getItem(key: string): string;
|
||||||
setItem(key: string, value: string);
|
setItem(key: string, value: string);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue