Skip to content

Commit 1ed32e4

Browse files
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
1 parent b68a4c9 commit 1ed32e4

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

.changeset/cuddly-days-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/app": patch
3+
---
4+
5+
fix issue where new lines are not persisted to url params correctly

packages/app/src/DBDashboardPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import OnboardingModal from './components/OnboardingModal';
6666
import { Tags } from './components/Tags';
6767
import useDashboardFilters from './hooks/useDashboardFilters';
6868
import { useDashboardRefresh } from './hooks/useDashboardRefresh';
69+
import { parseAsStringWithNewLines } from './utils/queryParsers';
6970
import api from './api';
7071
import { DEFAULT_CHART_CONFIG } from './ChartUtils';
7172
import { IS_LOCAL_MODE } from './config';
@@ -557,7 +558,7 @@ function DBDashboardPage({ presetConfig }: { presetConfig?: Dashboard }) {
557558
) as [SQLInterval | undefined, (value: SQLInterval | undefined) => void];
558559
const [where, setWhere] = useQueryState(
559560
'where',
560-
parseAsString.withDefault(''),
561+
parseAsStringWithNewLines.withDefault(''),
561562
);
562563
const [whereLanguage, setWhereLanguage] = useQueryState(
563564
'whereLanguage',

packages/app/src/DBSearchPage.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ import PatternTable from './components/PatternTable';
104104
import SourceSchemaPreview from './components/SourceSchemaPreview';
105105
import { useTableMetadata } from './hooks/useMetadata';
106106
import { useSqlSuggestions } from './hooks/useSqlSuggestions';
107+
import { parseAsStringWithNewLines } from './utils/queryParsers';
107108
import api from './api';
108109
import { LOCAL_STORE_CONNECTIONS_KEY } from './connection';
109110
import { DBSearchPageAlertModal } from './DBSearchPageAlertModal';
@@ -590,11 +591,11 @@ export function useDefaultOrderBy(sourceID: string | undefined | null) {
590591
// This is outside as it needs to be a stable reference
591592
const queryStateMap = {
592593
source: parseAsString,
593-
where: parseAsString,
594-
select: parseAsString,
594+
where: parseAsStringWithNewLines,
595+
select: parseAsStringWithNewLines,
595596
whereLanguage: parseAsStringEnum<'sql' | 'lucene'>(['sql', 'lucene']),
596597
filters: parseAsJson<Filter[]>(),
597-
orderBy: parseAsString,
598+
orderBy: parseAsStringWithNewLines,
598599
};
599600

600601
function DBSearchPage() {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { createParser } from 'nuqs';
2+
3+
// Note: this can be deleted once we upgrade to nuqs v2.2.3
4+
// https://github.com/47ng/nuqs/pull/783
5+
export const parseAsStringWithNewLines = createParser<string>({
6+
parse: value => value.replace(/%0A/g, '\n'),
7+
serialize: value => value.replace(/\n/g, '%0A'),
8+
});

0 commit comments

Comments
 (0)