Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor logo usage #4702

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Console] Migrate `/lib/autocomplete/` module to TypeScript ([#4148](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4148))
- [Console] Migrate `/lib/!autocomplete/` module to TypeScript ([#4150](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4150))
- [Dashboard] Restructure the `Dashboard` plugin folder to be more cohesive with the project ([#4575](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4575))
- Refactor logo usage to centralize and optimize assets and improve tests ([#4702](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4702))

### 🔩 Tests

Expand Down
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)) {
BSFishy marked this conversation as resolved.
Show resolved Hide resolved
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'),
};
1 change: 1 addition & 0 deletions packages/osd-dev-utils/src/serializers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ export * from './recursive_serializer';
export * from './any_instance_serizlizer';
export * from './replace_serializer';
export * from './strip_promises_serizlizer';
export * from './flat_object_serializer';
7 changes: 7 additions & 0 deletions src/core/common/index.ts
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';
Loading
Loading