Skip to content

Commit

Permalink
Refactor logo usage (opensearch-project#4702)
Browse files Browse the repository at this point in the history
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
AMoo-Miki authored Aug 22, 2023
1 parent 061e476 commit d7c5577
Show file tree
Hide file tree
Showing 105 changed files with 4,730 additions and 8,029 deletions.
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
93 changes: 93 additions & 0 deletions packages/osd-dev-utils/src/serializers/flat_object_serializer.ts
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'),
};
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

0 comments on commit d7c5577

Please sign in to comment.