UI: Use Client Count export API (#27455)

This commit is contained in:
Chelsea Shaw
2024-08-01 11:03:31 -05:00
committed by GitHub
parent c23ebb173f
commit 10068ffb0a
19 changed files with 748 additions and 408 deletions

View File

@@ -0,0 +1,31 @@
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { isEmptyValue } from 'core/helpers/is-empty-value';
/**
* queryParamString converts an object to a query param string with URL encoded keys and values.
* It does not include values that are falsey.
* @param {object} queryObject with key-value pairs of desired URL params
* @returns string like ?key=val1&key2=val2
*/
export default function queryParamString(queryObject) {
if (
!queryObject ||
isEmptyValue(queryObject) ||
typeof queryObject !== 'object' ||
Array.isArray(queryObject)
)
return '';
return Object.keys(queryObject).reduce((prev, key) => {
const value = queryObject[key];
if (!value) return prev;
const keyval = `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
if (prev === '?') {
return `${prev}${keyval}`;
}
return `${prev}&${keyval}`;
}, '?');
}