Add some more handy Object/Map utils.
This commit is contained in:
parent
ccf420d107
commit
3dadc99580
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in a new issue