1
0
Fork 0
VaultUI/src/elements/SecretTitleElement.ts

56 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-05-16 10:27:21 +01:00
import { PageRouter } from "z-pagerouter";
2021-05-16 09:42:43 +01:00
import { PageState } from "../PageState";
2021-05-16 10:35:35 +01:00
import { makeElement } from "../htmlUtils";
2021-05-16 09:42:43 +01:00
function currentTitleSecretText(state: PageState, suffix = ""): string {
let currentSecretText = state.currentSecret;
currentSecretText += suffix;
2021-05-16 10:35:35 +01:00
if (state.currentSecretVersion !== null) currentSecretText += ` (v${state.currentSecretVersion})`;
return currentSecretText;
}
export async function SecretTitleElement(router: PageRouter, suffix = ""): Promise<HTMLElement> {
2021-05-16 10:35:35 +01:00
const state = router.state as PageState;
const titleElement = makeElement({
tag: "div",
children: [
makeElement({
tag: "a",
2021-05-16 09:42:43 +01:00
text: state.currentBaseMount + " ",
onclick: async () => {
2021-05-16 09:42:43 +01:00
state.currentSecretPath = [];
state.currentSecret = "";
state.currentSecretVersion = null;
2021-05-16 10:35:35 +01:00
if (state.currentMountType.startsWith("kv") || state.currentMountType == "cubbyhole") {
await router.changePage("KEY_VALUE_VIEW");
2021-05-16 09:42:43 +01:00
} else if (state.currentMountType == "totp") {
await router.changePage("TOTP");
2021-05-16 09:42:43 +01:00
} else if (state.currentMountType == "transit") {
await router.changePage("TRANSIT_VIEW");
}
},
}),
2021-05-16 09:42:43 +01:00
...state.currentSecretPath.map((secretPath, index, secretPaths) => {
return makeElement({
tag: "a",
text: secretPath + " ",
onclick: async () => {
2021-05-16 09:42:43 +01:00
state.currentSecretVersion = null;
if (state.currentMountType.startsWith("kv")) {
state.currentSecretPath = secretPaths.slice(0, index + 1);
await router.changePage("KEY_VALUE_VIEW");
}
},
});
}),
makeElement({
tag: "span",
2021-05-16 09:42:43 +01:00
condition: state.currentSecret.length != 0,
text: currentTitleSecretText(state, suffix),
}),
],
});
return titleElement;
}