Skip to content

Commit

Permalink
Merge branch 'main' into ei/mantine-upd
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Apr 19, 2024
2 parents 664be0f + 14ae58b commit a48bfe4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-tools-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/app': patch
---

LogViewer: better JSON parsing and other tweaks
4 changes: 2 additions & 2 deletions packages/app/src/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const Tile = forwardRef(

return (
<div
className={`bg-hdx-dark p-3 ${className} d-flex flex-column ${
className={`bg-hdx-dark p-3 ${className} d-flex flex-column dashboard-chart ${
isHighlighed && 'dashboard-chart-highlighted'
}`}
id={`chart-${chart.id}`}
Expand Down Expand Up @@ -320,7 +320,7 @@ const Tile = forwardRef(
</div>
) : (
<div
className="fs-7 text-muted flex-grow-1 overflow-hidden"
className="fs-7 text-muted flex-grow-1"
onMouseDown={e => e.stopPropagation()}
>
<ErrorBoundary
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/HDXMultiSeriesTimeChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const HDXLineChartTooltip = withErrorBoundary(
.sort((a: any, b: any) => b.value - a.value)
.map((p: any) => (
<div key={p.dataKey} style={{ color: p.color }}>
{truncateMiddle(p.name ?? p.dataKey, 70)}:{' '}
{truncateMiddle(p.name ?? p.dataKey, 70)}:&nbsp;
{numberFormat ? formatNumber(p.value, numberFormat) : p.value}
</div>
))}
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/LogSidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ function PropertySubpanel({
{
normallyExpanded: true,
tabulate: true,
lineWrap: true,
lineWrap: false,
useLegacyViewer: false,
},
);
Expand Down Expand Up @@ -1623,7 +1623,7 @@ function PropertySubpanel({
}}
/>
)}
<Menu width={240}>
<Menu width={240} withinPortal={false}>
<Menu.Target>
<ActionIcon size="md" variant="filled" color="gray">
<i className="bi bi-gear" />
Expand Down
37 changes: 22 additions & 15 deletions packages/app/src/components/HyperJson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,28 +124,35 @@ const Line = React.memo(
// mounting it for potentially hundreds of lines
const { ref, hovered } = useHover<HTMLDivElement>();

const isStringValueJsonLike = React.useMemo(() => {
const isStringValueValidJson = React.useMemo(() => {
if (!isString(value)) return false;
return (
(value.startsWith('{') && value.endsWith('}')) ||
(value.startsWith('[') && value.endsWith(']'))
);
try {
if (
(value.startsWith('{') && value.endsWith('}')) ||
(value.startsWith('[') && value.endsWith(']'))
) {
const parsed = JSON.parse(value);
return !!parsed;
}
} catch (e) {
return false;
}
}, [value]);

const [isExpanded, setIsExpanded] = React.useState(
normallyExpanded && !isStringValueJsonLike,
normallyExpanded && !isStringValueValidJson,
);

React.useEffect(() => {
setIsExpanded(normallyExpanded && !isStringValueJsonLike);
}, [isStringValueJsonLike, normallyExpanded]);
setIsExpanded(normallyExpanded && !isStringValueValidJson);
}, [isStringValueValidJson, normallyExpanded]);

const isExpandable = React.useMemo(
() =>
(isPlainObject(value) && Object.keys(value).length > 0) ||
(isArray(value) && value.length > 0) ||
isStringValueJsonLike,
[isStringValueJsonLike, value],
isStringValueValidJson,
[isStringValueValidJson, value],
);

const handleToggle = React.useCallback(() => {
Expand All @@ -154,15 +161,15 @@ const Line = React.memo(
}, [isExpandable]);

const expandedData = React.useMemo(() => {
if (isStringValueJsonLike) {
if (isStringValueValidJson) {
try {
return JSON.parse(value);
} catch (e) {
return null;
}
}
return value;
}, [isStringValueJsonLike, value]);
}, [isStringValueValidJson, value]);

const nestedLevel = parentKeyPath.length;
const keyPath = React.useMemo(
Expand Down Expand Up @@ -198,13 +205,13 @@ const Line = React.memo(
</div>
</div>
<div className={styles.valueContainer}>
{isStringValueJsonLike ? (
{isStringValueValidJson ? (
isExpanded ? (
<div className={styles.object}>{'{}'} Parsed JSON</div>
) : (
<>
<ValueRenderer value={value} />
<div className={styles.jsonBtn}>Looks like JSON. Parse?</div>
<div className={styles.jsonBtn}>Expand JSON</div>
</>
)
) : (
Expand All @@ -219,7 +226,7 @@ const Line = React.memo(
<TreeNode
data={expandedData}
keyPath={keyPath}
disableMenu={isStringValueJsonLike}
disableMenu={isStringValueValidJson}
/>
)}
</>
Expand Down
14 changes: 10 additions & 4 deletions packages/app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,16 @@ div.react-datepicker {
border: 1px solid rgba(255, 166, 0, 0.5);
}

.dashboard-chart:hover {
z-index: 10000;
}

.recharts-tooltip-wrapper {
&:focus-visible {
outline: none;
}
}

@keyframes highlightedChart {
0% {
background-color: rgba(255, 166, 0, 0.5);
Expand All @@ -797,7 +807,3 @@ div.react-datepicker {
color: white;
}
}

// html {
// filter: invert(1) hue-rotate(180deg);
// }

0 comments on commit a48bfe4

Please sign in to comment.