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

Use @osd/std to prettify objects for display #8232

Merged
merged 2 commits into from
Sep 19, 2024
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
2 changes: 2 additions & 0 deletions changelogs/fragments/8232.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Use @osd/std to prettify objects for display ([#8232](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8232))
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ describe('asPrettyString', () => {
});

test('Converts objects values into presentable strings', () => {
expect(asPrettyString({ key: 'value' })).toBe('{\n "key": "value"\n}');
const longPositive = BigInt(Number.MAX_SAFE_INTEGER) * 2n;
const longNegative = BigInt(Number.MIN_SAFE_INTEGER) * 2n;
expect(asPrettyString({ key: 'value', longPositive, longNegative })).toBe(
`{\n "key": "value",\n "longPositive": ${longPositive.toString()},\n "longNegative": ${longNegative.toString()}\n}`
);
});

test('Converts other non-string values into strings', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* under the License.
*/

import { stringify } from '@osd/std';

/**
* Convert a value to a presentable string
*/
Expand All @@ -37,7 +39,7 @@
case 'string':
return val;
case 'object':
return JSON.stringify(val, null, ' ');
return stringify(val, null, ' ');

Check warning on line 42 in src/plugins/data/common/field_formats/utils/as_pretty_string.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/field_formats/utils/as_pretty_string.ts#L42

Added line #L42 was not covered by tests
default:
return '' + val;
}
Expand Down
Loading