diff --git a/.changeset/wet-buckets-eat.md b/.changeset/wet-buckets-eat.md new file mode 100644 index 000000000..5c7919f15 --- /dev/null +++ b/.changeset/wet-buckets-eat.md @@ -0,0 +1,6 @@ +--- +'@hyperdx/api': patch +'@hyperdx/app': patch +--- + +Persist display columns to db diff --git a/packages/api/src/models/logView.ts b/packages/api/src/models/logView.ts index 54ce528b7..2bec0c8f4 100644 --- a/packages/api/src/models/logView.ts +++ b/packages/api/src/models/logView.ts @@ -9,6 +9,7 @@ export interface ILogView { query: string; team: ObjectId; tags: string[]; + columns: string[]; } const LogViewSchema = new Schema( @@ -27,6 +28,10 @@ const LogViewSchema = new Schema( type: [String], default: [], }, + columns: { + type: [String], + default: [], + }, }, { timestamps: true, diff --git a/packages/api/src/routers/api/logViews.ts b/packages/api/src/routers/api/logViews.ts index 2daa0b8fd..529baa398 100644 --- a/packages/api/src/routers/api/logViews.ts +++ b/packages/api/src/routers/api/logViews.ts @@ -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( @@ -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) => { @@ -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, @@ -105,6 +107,7 @@ router.patch( ...(name && { name }), ...(query && { query }), tags: tags && uniq(tags), + columns: columns, }, { new: true }, ); diff --git a/packages/app/src/LogTable.tsx b/packages/app/src/LogTable.tsx index bd4f0242c..31e395602 100644 --- a/packages/app/src/LogTable.tsx +++ b/packages/app/src/LogTable.tsx @@ -410,7 +410,7 @@ export const RawLogTable = memo( size: columnSizeStorage[column] ?? 150, })) as ColumnDef[]), { - accessorKey: 'body', + accessorKey: 'show-pattern', header: () => ( Message{' '} diff --git a/packages/app/src/SearchPage.tsx b/packages/app/src/SearchPage.tsx index 346679e08..19cecf3a6 100644 --- a/packages/app/src/SearchPage.tsx +++ b/packages/app/src/SearchPage.tsx @@ -275,6 +275,9 @@ const LogViewerContainer = memo(function LogViewerContainer({ isUTC, setIsUTC, onShowPatternsClick, + displayedColumns, + setDisplayedColumns, + toggleColumn, }: { config: { where: string; @@ -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( { @@ -329,9 +335,6 @@ const LogViewerContainer = memo(function LogViewerContainer({ [openedLog, setOpenedLogQuery], ); - const { displayedColumns, setDisplayedColumns, toggleColumn } = - useDisplayedColumns(); - return ( <> setDisplayedColumns(columns)} /> ); @@ -435,6 +438,9 @@ function SearchPage() { const [displayedSearchQuery, setDisplayedSearchQuery] = useState(''); + const { displayedColumns, setDisplayedColumns, toggleColumn } = + useDisplayedColumns(); + const doSearch = useCallback( (query: string, timeQuery: string) => { onSearch(timeQuery); @@ -484,6 +490,10 @@ function SearchPage() { } }, [selectedSavedSearch, setSearchedQuery, _searchedQuery]); + useEffect(() => { + setDisplayedColumns(selectedSavedSearch?.columns ?? []); + }, [selectedSavedSearch?.columns]); + const isArcBrowser = typeof window !== 'undefined' && window @@ -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({ @@ -1010,6 +1024,9 @@ function SearchPage() { setIsLive={setIsLive} isUTC={isUTC} setIsUTC={setIsUTC} + displayedColumns={displayedColumns} + setDisplayedColumns={setDisplayedColumns} + toggleColumn={toggleColumn} onShowPatternsClick={() => { setIsLive(false); setResultsMode('patterns'); diff --git a/packages/app/src/api.ts b/packages/app/src/api.ts index f77a498a3..fca1cbf23 100644 --- a/packages/app/src/api.ts +++ b/packages/app/src/api.ts @@ -549,7 +549,8 @@ const api = { { name: string; query: string; - tags?: string; + tags?: string[]; + columns?: string[]; } >(`log-views`, async ({ name, query, tags }) => hdxServer('log-views', { @@ -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(), ); diff --git a/packages/app/src/types.ts b/packages/app/src/types.ts index 94e1fe1e4..ce53e830c 100644 --- a/packages/app/src/types.ts +++ b/packages/app/src/types.ts @@ -42,6 +42,7 @@ export type LogView = { query: string; alerts?: Alert[]; tags?: string[]; + columns?: string[]; }; export type Dashboard = {