fix issue where new lines are not persisted to url params correctly (#1229)

If I try to create a multi-line where statement in the UI, it does not persist the new line character, which leads to errors as well.

Fixes HDX-2527
This commit is contained in:
Brandon Pereira 2025-10-06 09:18:32 -06:00 committed by GitHub
parent b68a4c9b16
commit 1ed32e432e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
"@hyperdx/app": patch
---
fix issue where new lines are not persisted to url params correctly

View file

@ -66,6 +66,7 @@ import OnboardingModal from './components/OnboardingModal';
import { Tags } from './components/Tags';
import useDashboardFilters from './hooks/useDashboardFilters';
import { useDashboardRefresh } from './hooks/useDashboardRefresh';
import { parseAsStringWithNewLines } from './utils/queryParsers';
import api from './api';
import { DEFAULT_CHART_CONFIG } from './ChartUtils';
import { IS_LOCAL_MODE } from './config';
@ -557,7 +558,7 @@ function DBDashboardPage({ presetConfig }: { presetConfig?: Dashboard }) {
) as [SQLInterval | undefined, (value: SQLInterval | undefined) => void];
const [where, setWhere] = useQueryState(
'where',
parseAsString.withDefault(''),
parseAsStringWithNewLines.withDefault(''),
);
const [whereLanguage, setWhereLanguage] = useQueryState(
'whereLanguage',

View file

@ -104,6 +104,7 @@ import PatternTable from './components/PatternTable';
import SourceSchemaPreview from './components/SourceSchemaPreview';
import { useTableMetadata } from './hooks/useMetadata';
import { useSqlSuggestions } from './hooks/useSqlSuggestions';
import { parseAsStringWithNewLines } from './utils/queryParsers';
import api from './api';
import { LOCAL_STORE_CONNECTIONS_KEY } from './connection';
import { DBSearchPageAlertModal } from './DBSearchPageAlertModal';
@ -590,11 +591,11 @@ export function useDefaultOrderBy(sourceID: string | undefined | null) {
// This is outside as it needs to be a stable reference
const queryStateMap = {
source: parseAsString,
where: parseAsString,
select: parseAsString,
where: parseAsStringWithNewLines,
select: parseAsStringWithNewLines,
whereLanguage: parseAsStringEnum<'sql' | 'lucene'>(['sql', 'lucene']),
filters: parseAsJson<Filter[]>(),
orderBy: parseAsString,
orderBy: parseAsStringWithNewLines,
};
function DBSearchPage() {

View file

@ -0,0 +1,8 @@
import { createParser } from 'nuqs';
// Note: this can be deleted once we upgrade to nuqs v2.2.3
// https://github.com/47ng/nuqs/pull/783
export const parseAsStringWithNewLines = createParser<string>({
parse: value => value.replace(/%0A/g, '\n'),
serialize: value => value.replace(/\n/g, '%0A'),
});