diff --git a/src/translations/en.js b/src/translations/en.js index 3c29f9b..a01ba23 100644 --- a/src/translations/en.js +++ b/src/translations/en.js @@ -148,6 +148,7 @@ module.exports = { kv_view_new_btn: "New", kv_view_delete_btn: "Delete", kv_view_none_here_text: "You seem to have no secrets here, would you like to create one?", + kv_view_search_input_text: "Search", // TOTP View Page totp_view_title: "TOTP", diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx index f8c947e..3abe8a2 100644 --- a/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx +++ b/src/ui/pages/Secrets/KeyValue/KeyValueView.tsx @@ -1,4 +1,4 @@ -import { Component, JSX, render } from "preact"; +import { Component, createRef, JSX, render } from "preact"; import { DoesNotExistError } from "../../../../types/internalErrors"; import { Page } from "../../../../types/Page"; import { SecretTitleElement } from "../SecretTitleElement"; @@ -17,14 +17,36 @@ export type KVKeysListProps = { type KVKeysListState = { dataLoaded: boolean; keys: string[]; + searchQuery: string; }; +function SecretsList(secrets: string[], page: Page): JSX.Element[] { + return secrets.map((secret) => ( +
  • + { + if (secret.endsWith("/")) { + page.state.pushSecretPath(secret); + await page.router.changePage("KEY_VALUE_VIEW"); + } else { + page.state.secretItem = secret; + await page.router.changePage("KEY_VALUE_SECRET"); + } + }} + > + {secret} + +
  • + )); +} + export class KVKeysList extends Component { constructor() { super(); this.state = { dataLoaded: false, keys: [], + searchQuery: "", }; } @@ -76,6 +98,8 @@ export class KVKeysList extends Component { void this.loadData(); } + searchBarRef = createRef(); + render(): JSX.Element { if (!this.state.dataLoaded) { return

    {i18next.t("content_loading")}

    ; @@ -86,27 +110,31 @@ export class KVKeysList extends Component { } return ( - +
      + {...((): JSX.Element[] => { + let secrets: string[] = this.state.keys; + if (this.state.searchQuery.length > 0) { + secrets = secrets.filter((secret) => secret.includes(this.state.searchQuery)); + } + return SecretsList(secrets, this.props.page); + })()} +
    + ); } } @@ -173,4 +201,4 @@ export class KeyValueViewPage extends Page { get name(): string { return i18next.t("kv_view_title"); } -} +} \ No newline at end of file