Skip to content

Commit 0e84764

Browse files
committed
Fix to eliminate the use of the wrong draft state
1 parent 79bd843 commit 0e84764

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

ui/packages/shared/profile/src/ProfileSelector/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const ProfileSelector = ({
132132
profileSelection,
133133
setProfileSelection,
134134
sumByLoading,
135+
draftParsedQuery,
135136
} = useQueryState({suffix});
136137

137138
// Use draft state for local state instead of committed state
@@ -208,6 +209,7 @@ const ProfileSelector = ({
208209
const currentTo = timeRangeSelection.getToMs(true);
209210
const currentRangeKey = timeRangeSelection.getRangeKey();
210211
// Commit with refreshed time range
212+
console.log('[draftExpression] setQueryExpression: committing with refreshed time range:', draftSelection.expression);
211213
commitDraft({
212214
from: currentFrom,
213215
to: currentTo,
@@ -303,6 +305,9 @@ const ProfileSelector = ({
303305
profileType={profileType}
304306
profileTypesError={error}
305307
viewComponent={viewComponent}
308+
draftSelection={draftSelection}
309+
setDraftMatchers={setDraftMatchers}
310+
draftParsedQuery={draftParsedQuery}
306311
/>
307312
</LabelsSource>
308313
</LabelsQueryProvider>

ui/packages/shared/profile/src/QueryControls/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {SelectWithRefresh} from '../SelectWithRefresh';
2828
import SimpleMatchers from '../SimpleMatchers/';
2929
import ViewMatchers from '../ViewMatchers';
3030
import {useLabelNames} from '../hooks/useLabels';
31+
import { QuerySelection } from '../ProfileSelector';
3132

3233
interface SelectOption {
3334
label: string;
@@ -67,6 +68,9 @@ interface QueryControlsProps {
6768
sumBySelectionLoading?: boolean;
6869
setUserSumBySelection?: (sumBy: string[]) => void;
6970
sumByRef?: React.RefObject<SelectInstance>;
71+
draftSelection: QuerySelection;
72+
setDraftMatchers: (selection: string) => void;
73+
draftParsedQuery?: Query | null;
7074
}
7175

7276
export function QueryControls({
@@ -94,6 +98,9 @@ export function QueryControls({
9498
setUserSumBySelection,
9599
sumByRef,
96100
queryClient,
101+
draftSelection,
102+
setDraftMatchers,
103+
draftParsedQuery,
97104
}: QueryControlsProps): JSX.Element {
98105
const {timezone} = useParcaContext();
99106
const defaultQueryBrowserRef = useRef<HTMLDivElement>(null);
@@ -178,6 +185,9 @@ export function QueryControls({
178185
<SimpleMatchers
179186
queryBrowserRef={actualQueryBrowserRef}
180187
searchExecutedTimestamp={searchExecutedTimestamp}
188+
draftSelection={draftSelection}
189+
setDraftMatchers={setDraftMatchers}
190+
draftParsedQuery={draftParsedQuery}
181191
/>
182192
)}
183193
</div>

ui/packages/shared/profile/src/SimpleMatchers/index.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ import {TEST_IDS, testId} from '@parca/test-utils';
2222
import {millisToProtoTimestamp, sanitizeLabelValue} from '@parca/utilities';
2323

2424
import {useUnifiedLabels} from '../contexts/UnifiedLabelsContext';
25-
import {transformLabelName} from '../contexts/utils';
26-
import {useQueryState} from '../hooks/useQueryState';
25+
import { transformLabelName } from '../contexts/utils';
2726
import Select, {type SelectItem} from './Select';
27+
import { QuerySelection } from 'ProfileSelector';
28+
import { Query } from '@parca/parser';
2829

2930
interface Props {
3031
queryBrowserRef: React.RefObject<HTMLDivElement>;
3132
searchExecutedTimestamp?: number;
33+
draftSelection: QuerySelection;
34+
setDraftMatchers: (selection: string) => void;
35+
draftParsedQuery?: Query | null;
3236
}
3337

3438
interface QueryRow {
@@ -98,8 +102,10 @@ const operatorOptions = [
98102

99103
const SimpleMatchers = ({
100104
queryBrowserRef,
101-
102105
searchExecutedTimestamp,
106+
draftSelection,
107+
setDraftMatchers,
108+
draftParsedQuery,
103109
}: Props): JSX.Element => {
104110
const [queryRows, setQueryRows] = useState<QueryRow[]>([
105111
{labelName: '', operator: '=', labelValue: '', labelValues: [], isLoading: false},
@@ -115,13 +121,8 @@ const SimpleMatchers = ({
115121
labelNameMappingsForSimpleMatchers: labelNameOptions,
116122
isLabelNamesLoading: labelNamesLoading,
117123
refetchLabelNames,
118-
suffix,
119124
} = useUnifiedLabels();
120125

121-
const {draftSelection, setDraftMatchers, draftParsedQuery} = useQueryState({
122-
suffix,
123-
});
124-
125126
// Reset editing mode when search is executed
126127
useEffect(() => {
127128
if (searchExecutedTimestamp !== undefined && searchExecutedTimestamp > 0) {

ui/packages/shared/profile/src/hooks/useQueryState.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -337,20 +337,6 @@ export const useQueryState = (options: UseQueryStateOptions = {}): UseQueryState
337337
]
338338
);
339339

340-
// Draft setters (update local state only, or commit directly if specified)
341-
const setDraftExpressionCallback = useCallback(
342-
(newExpression: string, commit = false) => {
343-
if (commit) {
344-
// Commit with the new expression, which will also update merge params and selection
345-
commitDraft(undefined, newExpression);
346-
} else {
347-
// Only update draft state
348-
setDraftExpression(newExpression);
349-
}
350-
},
351-
[commitDraft]
352-
);
353-
354340
const setDraftTimeRange = useCallback(
355341
(newFrom: number, newTo: number, newTimeSelection: string) => {
356342
setDraftFrom(newFrom.toString());
@@ -420,7 +406,7 @@ export const useQueryState = (options: UseQueryStateOptions = {}): UseQueryState
420406
draftSelection,
421407

422408
// Draft setters
423-
setDraftExpression: setDraftExpressionCallback,
409+
setDraftExpression,
424410
setDraftTimeRange,
425411
setDraftSumBy: setDraftSumByCallback,
426412
setDraftProfileName,

0 commit comments

Comments
 (0)