diff --git a/src/pages/Home.js b/src/pages/Home.js index 6c12401..3b1c292 100644 --- a/src/pages/Home.js +++ b/src/pages/Home.js @@ -4,6 +4,7 @@ import { getMounts } from "../api/getMounts"; import { lookupSelf } from "../api/lookupSelf"; import { makeElement } from "../htmlUtils.js"; import { pageState } from "../globalPageState.js"; +import { sortedObjectMap } from "../utils.js"; import i18next from 'i18next'; export class HomePage extends Page { @@ -63,7 +64,7 @@ export class HomePage extends Page { let mounts = await getMounts(); // sort it by secretPath so it's in alphabetical order consistantly. - const mountsMap = new Map(Object.entries(mounts).sort()); + const mountsMap = sortedObjectMap(mounts); mountsMap.forEach(function (mount, baseMount) { if (typeof mount != 'object') return; diff --git a/src/pages/KeyValue/KeyValueSecret.js b/src/pages/KeyValue/KeyValueSecret.js index d50d456..18dbcef 100644 --- a/src/pages/KeyValue/KeyValueSecret.js +++ b/src/pages/KeyValue/KeyValueSecret.js @@ -5,6 +5,7 @@ import { getCapabilities } from "../../api/getCapabilities"; import { getSecret } from "../../api/getSecret"; import { makeElement } from "../../htmlUtils.js"; import { pageState } from "../../globalPageState.js"; +import { sortedObjectMap } from "../../utils.js"; import { undeleteSecret } from "../../api/undeleteSecret"; import Prism from "prismjs"; import i18next from 'i18next'; @@ -125,7 +126,7 @@ export class KeyValueSecretPage extends Page { return; } - const secretsMap = new Map(Object.entries(secretInfo).sort()); + const secretsMap = sortedObjectMap(secretInfo); for (let value of secretsMap.values()) { if (typeof value == 'object') isSecretNestedJson = true; diff --git a/src/pages/KeyValue/KeyValueVersions.js b/src/pages/KeyValue/KeyValueVersions.js index 440237c..e3d5742 100644 --- a/src/pages/KeyValue/KeyValueVersions.js +++ b/src/pages/KeyValue/KeyValueVersions.js @@ -2,6 +2,7 @@ import { Page } from "../../types/Page.js"; import { changePage, setPageContent, setTitleElement } from "../../pageUtils.js"; import { getSecretMetadata } from "../../api/getSecretMetadata.js"; import { makeElement } from "../../htmlUtils.js"; +import { objectToMap } from "../../utils.js"; import { pageState } from "../../globalPageState.js"; import i18next from 'i18next'; @@ -32,7 +33,7 @@ export class KeyValueVersionsPage extends Page { pageState.currentSecret ); - new Map(Object.entries(metadata.versions)).forEach((_, ver) => { + objectToMap(metadata.versions).forEach((_, ver) => { versionsList.appendChild(makeElement({ tag: "li", children: makeElement({ diff --git a/src/utils.js b/src/utils.js index d4a0066..89eeee5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -4,6 +4,7 @@ export function removeDoubleSlash(str) { export const getObjectKeys = (obj) => Object.getOwnPropertyNames(obj); export const objectToMap = (obj) => new Map(Object.entries(obj)); +export const sortedObjectMap = (obj) => new Map(Object.entries(obj).sort()); export function getKeyByObjectPropertyValue(map, searchValue) { for (let key of getObjectKeys(map)) {