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

feat: Toggle columns from LogSidePanel #82

Merged
merged 5 commits into from
Nov 7, 2023
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
5 changes: 5 additions & 0 deletions .changeset/famous-files-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/app': minor
---

feat: Toggle columns from LogSidePanel
38 changes: 38 additions & 0 deletions packages/app/src/LogSidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ function TraceSubpanel({
onPropertyAddClick,
generateChartUrl,
generateSearchUrl,
displayedColumns,
toggleColumn,
}: {
logData: any;
onClose: () => void;
Expand All @@ -493,6 +495,8 @@ function TraceSubpanel({
}) => string;

onPropertyAddClick?: (name: string, value: string) => void;
displayedColumns?: string[];
toggleColumn?: (column: string) => void;
}) {
const date = new Date(logData.timestamp);
const start = add(date, { minutes: -240 });
Expand Down Expand Up @@ -681,6 +685,8 @@ function TraceSubpanel({
generateSearchUrl={generateSearchUrl}
onClose={onClose}
generateChartUrl={generateChartUrl}
displayedColumns={displayedColumns}
toggleColumn={toggleColumn}
/>
</ErrorBoundary>
</>
Expand Down Expand Up @@ -1300,6 +1306,8 @@ function PropertySubpanel({
generateSearchUrl,
onClose,
generateChartUrl,
displayedColumns,
toggleColumn,
}: {
logData: any;
generateSearchUrl: (query?: string, timeRange?: [Date, Date]) => string;
Expand All @@ -1312,6 +1320,8 @@ function PropertySubpanel({
}) => string;

onPropertyAddClick?: (key: string, value: string) => void;
displayedColumns?: string[];
toggleColumn?: (column: string) => void;
}) {
const [propertySearchValue, setPropertySearchValue] = useState('');
const [isNestedView, setIsNestedView] = useLocalStorage(
Expand Down Expand Up @@ -1582,6 +1592,8 @@ function PropertySubpanel({
}}
valueRenderer={(raw, value, ...rawKeyPath) => {
const keyPath = rawKeyPath.slice().reverse();
const keyPathString = keyPath.join('.');

return (
<div className="parent-hover-trigger d-inline-block px-2">
<pre
Expand Down Expand Up @@ -1648,6 +1660,24 @@ function PropertySubpanel({
</Button>
</Link>
) : null}

{!!toggleColumn && keyPath.length === 1 ? (
<Button
className="fs-8 text-muted-hover child-hover-trigger p-0"
variant="link"
as="a"
title={
displayedColumns?.includes(keyPathString)
? `Remove ${keyPathString} column from results table`
: `Add ${keyPathString} column to results table`
}
style={{ width: 20 }}
onClick={() => toggleColumn(keyPathString)}
>
<i className="bi bi-table" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if I should use a different icon :D

</Button>
) : null}

<CopyToClipboard
text={value}
onCopy={() => {
Expand Down Expand Up @@ -2032,6 +2062,8 @@ export default function LogSidePanel({
generateChartUrl,
sortKey,
isNestedPanel = false,
displayedColumns,
toggleColumn,
}: {
logId: string | undefined;
onClose: () => void;
Expand All @@ -2048,6 +2080,8 @@ export default function LogSidePanel({
}) => string;
sortKey: string | undefined;
isNestedPanel?: boolean;
displayedColumns?: string[];
toggleColumn?: (column: string) => void;
}) {
const contextZIndex = useZIndex();

Expand Down Expand Up @@ -2222,6 +2256,8 @@ export default function LogSidePanel({
generateSearchUrl={generateSearchUrl}
generateChartUrl={generateChartUrl}
onClose={_onClose}
displayedColumns={displayedColumns}
toggleColumn={toggleColumn}
/>
<EventTagSubpanel
logData={logData}
Expand Down Expand Up @@ -2251,6 +2287,8 @@ export default function LogSidePanel({
generateSearchUrl={generateSearchUrl}
generateChartUrl={generateChartUrl}
onClose={_onClose}
displayedColumns={displayedColumns}
toggleColumn={toggleColumn}
/>
</div>
) : null}
Expand Down
5 changes: 4 additions & 1 deletion packages/app/src/LogTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,8 @@ export default function LogTable({
onEnd,
onShowPatternsClick,
tableId,
displayedColumns,
setDisplayedColumns,
}: {
config: {
where: string;
Expand All @@ -802,10 +804,11 @@ export default function LogTable({
onEnd?: () => void;
onShowPatternsClick?: () => void;
tableId?: string;
displayedColumns: string[];
setDisplayedColumns: (columns: string[]) => void;
}) {
const [instructionsOpen, setInstructionsOpen] = useState(false);
const [settingsOpen, setSettingsOpen] = useState(false);
const [displayedColumns, setDisplayedColumns] = useState<string[]>([]);
const [wrapLines, setWrapLines] = useState(false);

const prevQueryConfig = usePrevious({ searchedQuery, isLive });
Expand Down
8 changes: 8 additions & 0 deletions packages/app/src/LogTableWithSidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import usePortal from 'react-useportal';
import type { LogView } from './types';
import LogSidePanel from './LogSidePanel';
import LogTable from './LogTable';
import { useDisplayedColumns } from './useDisplayedColumns';

export function LogTableWithSidePanel({
config,
Expand Down Expand Up @@ -82,6 +83,9 @@ export function LogTableWithSidePanel({

const voidFn = useCallback(() => {}, []);

const { displayedColumns, setDisplayedColumns, toggleColumn } =
useDisplayedColumns();

return (
<>
{openedLog != null ? (
Expand All @@ -95,6 +99,8 @@ export function LogTableWithSidePanel({
onPropertyAddClick={onPropertyAddClick}
generateSearchUrl={generateSearchUrl}
generateChartUrl={generateChartUrl}
displayedColumns={displayedColumns}
toggleColumn={toggleColumn}
/>
</Portal>
) : null}
Expand All @@ -114,6 +120,8 @@ export function LogTableWithSidePanel({
[setOpenedLog, onRowExpandClick],
)}
onEnd={onSettled}
displayedColumns={displayedColumns}
setDisplayedColumns={setDisplayedColumns}
/>
</>
);
Expand Down
8 changes: 8 additions & 0 deletions packages/app/src/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import SearchPageActionBar from './SearchPageActionBar';
import { useTimeQuery } from './timeQuery';
import { MemoPatternTableWithSidePanel } from './PatternTableWithSidePanel';
import { ErrorBoundary } from 'react-error-boundary';
import { useDisplayedColumns } from './useDisplayedColumns';

const formatDate = (
date: Date,
Expand Down Expand Up @@ -323,6 +324,9 @@ const LogViewerContainer = memo(function LogViewerContainer({
[setOpenedLogQuery],
);

const { displayedColumns, setDisplayedColumns, toggleColumn } =
useDisplayedColumns();

return (
<>
<ErrorBoundary
Expand All @@ -346,6 +350,8 @@ const LogViewerContainer = memo(function LogViewerContainer({
onPropertyAddClick={onPropertyAddClick}
generateSearchUrl={generateSearchUrl}
generateChartUrl={generateChartUrl}
displayedColumns={displayedColumns}
toggleColumn={toggleColumn}
/>
</ErrorBoundary>
<LogTable
Expand Down Expand Up @@ -373,6 +379,8 @@ const LogViewerContainer = memo(function LogViewerContainer({
[setOpenedLog, setIsLive],
)}
onShowPatternsClick={onShowPatternsClick}
displayedColumns={displayedColumns}
setDisplayedColumns={setDisplayedColumns}
/>
</>
);
Expand Down
16 changes: 16 additions & 0 deletions packages/app/src/useDisplayedColumns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useState } from 'react';

// TODO: Instead of prop drilling additional columns, we can consider using React.Context or Jotai
export const useDisplayedColumns = () => {
const [displayedColumns, setDisplayedColumns] = useState<string[]>([]);

const toggleColumn = (column: string) => {
if (displayedColumns.includes(column)) {
setDisplayedColumns(displayedColumns.filter(c => c !== column));
} else {
setDisplayedColumns([...displayedColumns, column]);
}
};

return { displayedColumns, setDisplayedColumns, toggleColumn };
};
Loading