Skip to content

Commit c500739

Browse files
authored
Move ASCII constants to module (#1251)
1 parent 8e8c1eb commit c500739

File tree

5 files changed

+29
-25
lines changed

5 files changed

+29
-25
lines changed

packages/graph-explorer/src/components/EdgeRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DisplayEdge, DisplayVertex } from "@/core";
22
import { ComponentPropsWithoutRef } from "react";
33
import { EdgeSymbol } from "./EdgeSymbol";
4-
import { cn, NBSP, RSAQUO } from "@/utils";
4+
import { ASCII, cn } from "@/utils";
55
import { SearchResultSubtitle, SearchResultTitle } from "./SearchResult";
66

77
/**
@@ -26,7 +26,7 @@ export function EdgeRow({
2626
const nameIsSameAsTypes = edge.displayTypes === edge.displayName;
2727
const displayName = nameIsSameAsTypes
2828
? edge.displayName
29-
: `${edge.displayTypes}${NBSP}${RSAQUO} ${edge.displayName}`;
29+
: `${edge.displayTypes}${ASCII.NBSP}${ASCII.RSAQUO} ${edge.displayName}`;
3030
const title = `${resultName}${displayName}`;
3131

3232
return (

packages/graph-explorer/src/components/VertexRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DisplayVertex } from "@/core";
22
import { SearchResultSubtitle, SearchResultTitle, VertexSymbol } from ".";
33
import { ComponentPropsWithoutRef } from "react";
4-
import { cn, NBSP, RSAQUO } from "@/utils";
4+
import { ASCII, cn } from "@/utils";
55

66
export function VertexRow({
77
name,
@@ -16,7 +16,7 @@ export function VertexRow({
1616
const nameIsSameAsTypes = vertex.displayTypes === vertex.displayName;
1717
const displayName = nameIsSameAsTypes
1818
? vertex.displayName
19-
: `${vertex.displayTypes}${NBSP}${RSAQUO} ${vertex.displayName}`;
19+
: `${vertex.displayTypes}${ASCII.NBSP}${ASCII.RSAQUO} ${vertex.displayName}`;
2020
const title = `${resultName}${displayName}`;
2121

2222
return (

packages/graph-explorer/src/connector/entities/bundle.test.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, it, expect } from "vitest";
22
import { createPatchedResultBundle, getDisplayValueForBundle } from "./bundle";
33
import { createResultScalar } from "./scalar";
4-
import { MISSING_DISPLAY_VALUE, NBSP } from "@/utils/constants";
4+
import { MISSING_DISPLAY_VALUE, ASCII } from "@/utils/constants";
55
import { createTestableEdge, createTestableVertex } from "@/utils/testing";
66

77
describe("getDisplayValueForBundle", () => {
@@ -17,7 +17,9 @@ describe("getDisplayValueForBundle", () => {
1717

1818
const result = getDisplayValueForBundle(bundle);
1919

20-
expect(result).toBe(`Name: John${NBSP}• Age: 25${NBSP}• Active: true`);
20+
expect(result).toBe(
21+
`Name: John${ASCII.NBSP}• Age: 25${ASCII.NBSP}• Active: true`
22+
);
2123
});
2224

2325
it("should format scalar values without names", () => {
@@ -31,7 +33,7 @@ describe("getDisplayValueForBundle", () => {
3133

3234
const result = getDisplayValueForBundle(bundle);
3335

34-
expect(result).toBe(`John${NBSP}• 25${NBSP}• false`);
36+
expect(result).toBe(`John${ASCII.NBSP}• 25${ASCII.NBSP}• false`);
3537
});
3638

3739
it("should format null scalar values", () => {
@@ -45,7 +47,7 @@ describe("getDisplayValueForBundle", () => {
4547
const result = getDisplayValueForBundle(bundle);
4648

4749
expect(result).toBe(
48-
`EmptyField: ${MISSING_DISPLAY_VALUE}${NBSP}${MISSING_DISPLAY_VALUE}`
50+
`EmptyField: ${MISSING_DISPLAY_VALUE}${ASCII.NBSP}${MISSING_DISPLAY_VALUE}`
4951
);
5052
});
5153

@@ -62,7 +64,7 @@ describe("getDisplayValueForBundle", () => {
6264
const expectedDateFormat = "Dec 25 2023, 10:30 AM";
6365

6466
expect(result).toBe(
65-
`CreatedAt: ${expectedDateFormat}${NBSP}${expectedDateFormat}`
67+
`CreatedAt: ${expectedDateFormat}${ASCII.NBSP}${expectedDateFormat}`
6668
);
6769
});
6870

@@ -168,7 +170,7 @@ describe("getDisplayValueForBundle", () => {
168170
const result = getDisplayValueForBundle(bundle);
169171

170172
expect(result).toBe(
171-
`Name: John${NBSP}• Profile: v(v123)${NBSP}• Connection: e(e456)${NBSP}• SubBundle: [...]`
173+
`Name: John${ASCII.NBSP}• Profile: v(v123)${ASCII.NBSP}• Connection: e(e456)${ASCII.NBSP}• SubBundle: [...]`
172174
);
173175
});
174176

@@ -195,7 +197,7 @@ describe("getDisplayValueForBundle", () => {
195197
const expectedPopulation = new Intl.NumberFormat().format(1000000);
196198

197199
expect(result).toBe(
198-
`Price: ${expectedPrice}${NBSP}• Population: ${expectedPopulation}`
200+
`Price: ${expectedPrice}${ASCII.NBSP}• Population: ${expectedPopulation}`
199201
);
200202
});
201203

@@ -211,7 +213,7 @@ describe("getDisplayValueForBundle", () => {
211213
const upperCaseTransformer = (text: string) => text.toUpperCase();
212214
const result = getDisplayValueForBundle(bundle, upperCaseTransformer);
213215

214-
expect(result).toBe(`USER_NAME: JOHN DOE${NBSP}• STATUS: ACTIVE`);
216+
expect(result).toBe(`USER_NAME: JOHN DOE${ASCII.NBSP}• STATUS: ACTIVE`);
215217
});
216218

217219
it("should apply text transformer to scalar values without names", () => {
@@ -225,7 +227,7 @@ describe("getDisplayValueForBundle", () => {
225227
const upperCaseTransformer = (text: string) => text.toUpperCase();
226228
const result = getDisplayValueForBundle(bundle, upperCaseTransformer);
227229

228-
expect(result).toBe(`HELLO WORLD${NBSP}• TEST VALUE`);
230+
expect(result).toBe(`HELLO WORLD${ASCII.NBSP}• TEST VALUE`);
229231
});
230232

231233
it("should apply text transformer to bundle names", () => {
@@ -258,7 +260,7 @@ describe("getDisplayValueForBundle", () => {
258260
const result = getDisplayValueForBundle(bundle, upperCaseTransformer);
259261

260262
expect(result).toBe(
261-
`user_profile: v(v123)${NBSP}• connection_edge: e(e456)`
263+
`user_profile: v(v123)${ASCII.NBSP}• connection_edge: e(e456)`
262264
);
263265
});
264266

@@ -274,7 +276,7 @@ describe("getDisplayValueForBundle", () => {
274276
const result = getDisplayValueForBundle(bundle, upperCaseTransformer);
275277

276278
expect(result).toBe(
277-
`EMPTY_FIELD: ${MISSING_DISPLAY_VALUE}${NBSP}${MISSING_DISPLAY_VALUE}`
279+
`EMPTY_FIELD: ${MISSING_DISPLAY_VALUE}${ASCII.NBSP}${MISSING_DISPLAY_VALUE}`
278280
);
279281
});
280282

@@ -295,7 +297,7 @@ describe("getDisplayValueForBundle", () => {
295297
const result = getDisplayValueForBundle(bundle, upperCaseTransformer);
296298

297299
expect(result).toBe(
298-
`NAME: JOHN${NBSP}• profile: v(v123)${NBSP}• SUB_BUNDLE: [...]`
300+
`NAME: JOHN${ASCII.NBSP}• profile: v(v123)${ASCII.NBSP}• SUB_BUNDLE: [...]`
299301
);
300302
});
301303

@@ -310,7 +312,7 @@ describe("getDisplayValueForBundle", () => {
310312
const identityTransformer = (text: string) => text;
311313
const result = getDisplayValueForBundle(bundle, identityTransformer);
312314

313-
expect(result).toBe(`Name: John${NBSP}• Age: 25`);
315+
expect(result).toBe(`Name: John${ASCII.NBSP}• Age: 25`);
314316
});
315317

316318
it("should handle complex transformations", () => {
@@ -325,7 +327,7 @@ describe("getDisplayValueForBundle", () => {
325327
text.replace(/_/g, "-").toLowerCase();
326328
const result = getDisplayValueForBundle(bundle, kebabCaseTransformer);
327329

328-
expect(result).toBe(`field-name: user-name${NBSP}• some value`);
330+
expect(result).toBe(`field-name: user-name${ASCII.NBSP}• some value`);
329331
});
330332
});
331333
});

packages/graph-explorer/src/connector/entities/bundle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getDisplayValueForScalar } from "./scalar";
22
import { PatchedResultEntity, ResultEntity } from "./entities";
3-
import { NBSP } from "@/utils";
3+
import { ASCII } from "@/utils";
44
import { TextTransformer } from "@/hooks";
55

66
/**
@@ -129,5 +129,5 @@ export function getDisplayValueForBundle(
129129
: `[...]`;
130130
}
131131
})
132-
.join(`${NBSP}• `);
132+
.join(`${ASCII.NBSP}• `);
133133
}

packages/graph-explorer/src/utils/constants.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ export const MISSING_DISPLAY_TYPE = "---";
2828
/** Used as the label for the ID of a blank node in the node details or query results. */
2929
export const LABEL_FOR_BLANK_NODE_ID = "Blank Node Id";
3030

31-
/** Non breaking space */
32-
export const NBSP = "\u00A0";
33-
34-
/** Small arrow character */
35-
export const RSAQUO = "\u203A";
31+
/** ASCII characters used in strings */
32+
export const ASCII = {
33+
/** Non breaking space */
34+
NBSP: "\u00A0",
35+
/** Small arrow character */
36+
RSAQUO: "\u203A",
37+
} as const;

0 commit comments

Comments
 (0)