-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also: * Move logos to a central location * Make the loading spinner color-scheme-aware * Recreate `OverviewPageHeader`, `HomeIcon`, `HeaderLogo`, `SolutionTitle`, `Welcome`, `Overview` tests * Enhance `ExitFullScreenButton`, `Header` tests * Tinified favicon assets Signed-off-by: Miki <[email protected]>
- Loading branch information
Showing
105 changed files
with
12,928 additions
and
8,034 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
packages/osd-dev-utils/src/serializers/flat_object_serializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
const walk = (value: any, path: string[] = [], collector: string[] = []) => { | ||
let objValue; | ||
switch (Object.prototype.toString.call(value)) { | ||
case '[object Map]': | ||
case '[object WeakMap]': | ||
// Turn into an Object so it can be iterated | ||
objValue = Object.fromEntries(value); | ||
break; | ||
|
||
case '[object Set]': | ||
case '[object WeakSet]': | ||
// Turn into an Array so it can be iterated | ||
objValue = Array.from(value); | ||
break; | ||
|
||
case '[object Object]': | ||
case '[object Array]': | ||
objValue = value; | ||
break; | ||
|
||
case '[object RegExp]': | ||
case '[object Function]': | ||
case '[object Date]': | ||
case '[object Boolean]': | ||
case '[object Number]': | ||
case '[object Symbol]': | ||
case '[object Error]': | ||
collector.push(`${path.join('.')} = ${value.toString()}`); | ||
break; | ||
|
||
case '[object Null]': | ||
collector.push(`${path.join('.')} = null`); | ||
break; | ||
|
||
case '[object Undefined]': | ||
collector.push(`${path.join('.')} = undefined`); | ||
break; | ||
|
||
case '[object String]': | ||
collector.push(`${path.join('.')} = ${JSON.stringify(value)}`); | ||
break; | ||
|
||
case '[object BigInt]': | ||
collector.push(`${path.join('.')} = ${value.toString()}n`); | ||
break; | ||
|
||
default: | ||
// if it is a TypedArray, turn it into an array | ||
if (value instanceof Object.getPrototypeOf(Uint8Array)) { | ||
objValue = Array.from(value); | ||
} | ||
} | ||
|
||
// If objValue is set, it is an Array or Object that can be iterated; else bail. | ||
if (!objValue) return collector; | ||
|
||
if (Array.isArray(objValue)) { | ||
objValue.forEach((v, i) => { | ||
walk(v, [...path, i.toString()], collector); | ||
}); | ||
} else { | ||
// eslint-disable-next-line guard-for-in | ||
for (const key in objValue) { | ||
walk(objValue[key], [...path, key], collector); | ||
} | ||
} | ||
|
||
return collector; | ||
}; | ||
|
||
/** | ||
* The serializer flattens objects into dotified key-value pairs, each on a line, and | ||
* sorts them to aid in diff-ing. | ||
* | ||
* Example: | ||
* { K: ["a", "b", { X: 1n }], Y: 1} | ||
* | ||
* Serialized: | ||
* K.0 = "a" | ||
* K.1 = "b" | ||
* K.2.X = 1n | ||
* Y = 1 | ||
*/ | ||
export const flatObjectSerializer = { | ||
test: (value: any) => | ||
['[object Object]', '[object Array]'].includes(Object.prototype.toString.call(value)), | ||
serialize: (value: any) => walk(value).sort().join('\n'), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { ImageType, ColorScheme, getLogos } from './logos'; | ||
export type { Logos } from './types'; |
Oops, something went wrong.