1
0
Fork 0
VaultUI/src/ui/pages/Policies/PolicyView.tsx

58 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-05-26 12:38:40 +01:00
import { CodeBlock } from "../../elements/CodeBlock";
2022-01-07 13:14:25 +00:00
import { Component } from "preact";
import { DefaultPageProps } from "../../../types/DefaultPageProps";
2022-01-07 15:55:15 +00:00
import { Margin } from "../../elements/Margin";
2022-01-07 13:14:25 +00:00
import { PageTitle } from "../../elements/PageTitle";
import { policyDeleteURL, policyEditURL } from "../pageLinks";
2022-01-07 15:55:15 +00:00
import { route } from "preact-router";
import i18next from "i18next";
2021-05-26 12:38:40 +01:00
2022-01-07 14:11:14 +00:00
export class PolicyView extends Component<
DefaultPageProps,
{ policy: string; policyName: string }
> {
2022-01-07 13:14:25 +00:00
async componentDidMount() {
const policyName = this.props.matches["policyName"];
const policy = await this.props.api.getPolicy(policyName);
2022-01-07 13:14:25 +00:00
this.setState({
2022-01-07 14:11:14 +00:00
policy,
policyName,
});
2021-05-26 12:38:40 +01:00
}
2022-01-07 13:14:25 +00:00
render() {
if (!this.state.policy) return;
return (
<>
2022-01-07 14:11:14 +00:00
<PageTitle title={i18next.t("policy_view_title", { policy: this.state.policyName })} />
<div>
<p>
2021-05-26 12:52:45 +01:00
<button
2022-01-07 14:11:14 +00:00
class="uk-button uk-button-primary"
2021-05-26 12:52:45 +01:00
onClick={async () => {
2022-01-07 14:11:14 +00:00
route(policyEditURL(this.state.policyName));
2021-05-26 12:52:45 +01:00
}}
>
{i18next.t("common_edit")}
2021-05-26 12:38:40 +01:00
</button>
2022-01-07 14:11:14 +00:00
{this.state.policyName !== "default" && (
<button
class="uk-button uk-button-danger"
onClick={async () => {
route(policyDeleteURL(this.state.policyName));
}}
>
{i18next.t("common_delete")}
2022-01-07 14:11:14 +00:00
</button>
)}
</p>
2021-05-26 12:38:40 +01:00
2022-01-07 14:11:14 +00:00
<Margin>
<CodeBlock language="hcl" code={this.state.policy} />
</Margin>
</div>
2022-01-07 13:14:25 +00:00
</>
2021-05-26 12:38:40 +01:00
);
}
}