Skip to content

Commit

Permalink
Improve rendering of long/multiline strings in dataview changes preview
Browse files Browse the repository at this point in the history
  • Loading branch information
jaclarke committed Feb 26, 2024
1 parent 7ac063a commit a3c2c1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 9 additions & 4 deletions shared/inspector/buildScalar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function renderValue(
showTypeTag: boolean = true,
overrideStyles: {[key: string]: string} = {},
implicitLength?: number,
noMultiline: boolean = false
singleLineLimit?: boolean | number
): {body: JSX.Element; height?: number} {
if (value == null) {
return {body: <span className={styles.scalar_empty}>{"{}"}</span>};
Expand Down Expand Up @@ -155,17 +155,22 @@ export function renderValue(

// @ts-ignore - Intentional fallthrough
case "std::json":
value = noMultiline ? value : prettyPrintJSON(value);
value = singleLineLimit ? value : prettyPrintJSON(value);
case "std::str": {
const str = noMultiline ? toSingleLineStr(value) : strToString(value);
const str = singleLineLimit
? toSingleLineStr(
value,
singleLineLimit === true ? undefined : singleLineLimit
)
: strToString(value);
return {
body: (
<span className={styles.scalar_string}>
{str}
{implicitLength && value.length === implicitLength ? "…" : ""}
</span>
),
height: noMultiline ? 1 : (str as string).split("\n").length,
height: singleLineLimit ? 1 : (str as string).split("\n").length,
};
}
}
Expand Down
5 changes: 4 additions & 1 deletion shared/studio/tabs/dataview/reviewEditsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ function renderParam({
type.schemaType === "Range" || type.schemaType === "Multirange"
? type.elementType.name
: undefined,
false
false,
undefined,
undefined,
50
).body;
}
}

0 comments on commit a3c2c1b

Please sign in to comment.