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

Persist display columns #406

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions .changeset/wet-buckets-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@hyperdx/api': patch
'@hyperdx/app': patch
---

Persist display columns to db
5 changes: 5 additions & 0 deletions packages/api/src/models/logView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface ILogView {
query: string;
team: ObjectId;
tags: string[];
columns: string[];
}

const LogViewSchema = new Schema<ILogView>(
Expand All @@ -27,6 +28,10 @@ const LogViewSchema = new Schema<ILogView>(
type: [String],
default: [],
},
columns: {
type: [String],
default: [],
},
},
{
timestamps: true,
Expand Down
5 changes: 4 additions & 1 deletion packages/api/src/routers/api/logViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ router.get('/', async (req, res, next) => {
tags: 1,
createdAt: 1,
updatedAt: 1,
columns: 1,
},
).sort({ createdAt: -1 });
const allAlerts = await Promise.all(
Expand All @@ -85,6 +86,7 @@ router.patch(
name: z.string().max(1024).min(1).optional(),
query: z.string().max(2048).optional(),
tags: tagsSchema,
columns: z.array(z.string()),
}),
}),
async (req, res, next) => {
Expand All @@ -95,7 +97,7 @@ router.patch(
return res.sendStatus(403);
}

const { query, tags, name } = req.body;
const { query, tags, name, columns } = req.body;
const logView = await LogView.findOneAndUpdate(
{
_id: logViewId,
Expand All @@ -105,6 +107,7 @@ router.patch(
...(name && { name }),
...(query && { query }),
tags: tags && uniq(tags),
columns: columns,
},
{ new: true },
);
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/LogTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export const RawLogTable = memo(
size: columnSizeStorage[column] ?? 150,
})) as ColumnDef<any>[]),
{
accessorKey: 'body',
accessorKey: 'show-pattern',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MikeShi42 Changed accessorKey from 'body' to 'show-pattern' as it was conflicting with 'body' custom column

Copy link
Contributor

Choose a reason for hiding this comment

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

accessorKey should stay body as it renders log's body property, could you provide more context on why it conflicts with custom columns?

Screenshot 2024-05-28 at 4 45 48 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When custom column 'body' is added it conflicts with the 'message' column which has the same accessorKey
image

This causes duplicate of body when switching to other search views in this instance:
image

Not sure if there is a different way to resolve this

header: () => (
<span>
Message{' '}
Expand Down
27 changes: 22 additions & 5 deletions packages/app/src/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ const LogViewerContainer = memo(function LogViewerContainer({
isUTC,
setIsUTC,
onShowPatternsClick,
displayedColumns,
setDisplayedColumns,
toggleColumn,
}: {
config: {
where: string;
Expand All @@ -296,6 +299,9 @@ const LogViewerContainer = memo(function LogViewerContainer({
isUTC: boolean;
setIsUTC: (isUTC: boolean) => void;
onShowPatternsClick: () => void;
displayedColumns: string[];
setDisplayedColumns: (columns: string[]) => void;
toggleColumn: (column: string) => void;
}) {
const [openedLogQuery, setOpenedLogQuery] = useQueryParams(
{
Expand Down Expand Up @@ -329,9 +335,6 @@ const LogViewerContainer = memo(function LogViewerContainer({
[openedLog, setOpenedLogQuery],
);

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

return (
<>
<ErrorBoundary
Expand Down Expand Up @@ -385,7 +388,7 @@ const LogViewerContainer = memo(function LogViewerContainer({
)}
onShowPatternsClick={onShowPatternsClick}
displayedColumns={displayedColumns}
setDisplayedColumns={setDisplayedColumns}
setDisplayedColumns={columns => setDisplayedColumns(columns)}
/>
</>
);
Expand Down Expand Up @@ -435,6 +438,9 @@ function SearchPage() {

const [displayedSearchQuery, setDisplayedSearchQuery] = useState('');

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

const doSearch = useCallback(
(query: string, timeQuery: string) => {
onSearch(timeQuery);
Expand Down Expand Up @@ -484,6 +490,10 @@ function SearchPage() {
}
}, [selectedSavedSearch, setSearchedQuery, _searchedQuery]);

useEffect(() => {
setDisplayedColumns(selectedSavedSearch?.columns ?? []);
}, [selectedSavedSearch?.columns]);

const isArcBrowser =
typeof window !== 'undefined' &&
window
Expand Down Expand Up @@ -528,7 +538,11 @@ function SearchPage() {
const onClickUpdateLogView = () => {
if (selectedSavedSearch?._id && displayedSearchQuery) {
updateLogView.mutate(
{ id: selectedSavedSearch._id, query: displayedSearchQuery },
{
id: selectedSavedSearch._id,
query: displayedSearchQuery,
columns: displayedColumns,
},
{
onSuccess: () => {
notifications.show({
Expand Down Expand Up @@ -1010,6 +1024,9 @@ function SearchPage() {
setIsLive={setIsLive}
isUTC={isUTC}
setIsUTC={setIsUTC}
displayedColumns={displayedColumns}
setDisplayedColumns={setDisplayedColumns}
toggleColumn={toggleColumn}
onShowPatternsClick={() => {
setIsLive(false);
setResultsMode('patterns');
Expand Down
7 changes: 5 additions & 2 deletions packages/app/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ const api = {
{
name: string;
query: string;
tags?: string;
tags?: string[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MikeShi42 Changed tag type from string to string[], not sure if that is accurate. Please correct if wrong

columns?: string[];
}
>(`log-views`, async ({ name, query, tags }) =>
hdxServer('log-views', {
Expand All @@ -571,14 +572,16 @@ const api = {
name?: string;
query?: string;
tags?: string[];
columns?: string[];
}
>(`log-views`, async ({ id, name, query, tags }) =>
>(`log-views`, async ({ id, name, query, tags, columns }) =>
hdxServer(`log-views/${id}`, {
method: 'PATCH',
json: {
name,
query,
tags,
columns,
},
}).json(),
);
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type LogView = {
query: string;
alerts?: Alert[];
tags?: string[];
columns?: string[];
};

export type Dashboard = {
Expand Down
Loading