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 <miki@amazon.com>

(cherry picked from commit d7c5577)
Signed-off-by: Miki <miki@amazon.com>
  • Loading branch information
AMoo-Miki committed Aug 22, 2023
1 parent 28bf38d commit dea0488
Show file tree
Hide file tree
Showing 103 changed files with 4,037 additions and 8,007 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Replace the use of `bluebird` in `saved_objects` plugin ([#4026](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4026))
- [Table Visualization] Remove custom styling for text-align:center in favor of OUI utility class. ([#4164](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4164))
- [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 dea0488

Please sign in to comment.