Skip to content

Commit 2c26826

Browse files
authored
Refactor query expression commit logic in profile selector (#6074)
Updated MetricsGraphSection and ProfileSelector to use the commitDraft function for applying label matcher filters from the metrics graph.
1 parent 8b05cd5 commit 2c26826

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ interface MetricsGraphSectionProps {
3737
selectQuery: (query: QuerySelection) => void;
3838
setProfileSelection: (mergeFrom: bigint, mergeTo: bigint, query: Query) => void;
3939
query: Query;
40-
setNewQueryExpression: (queryExpression: string, commit?: boolean) => void;
40+
setNewQueryExpression: (queryExpression: string) => void;
4141
setQueryExpression: (updateTs?: boolean) => void;
42+
commitDraft: (
43+
refreshedTimeRange?: {from: number; to: number; timeSelection: string},
44+
expression?: string
45+
) => void;
4246
}
4347

4448
export function MetricsGraphSection({
@@ -57,6 +61,7 @@ export function MetricsGraphSection({
5761
setProfileSelection,
5862
query,
5963
setNewQueryExpression,
64+
commitDraft,
6065
}: MetricsGraphSectionProps): JSX.Element {
6166
const resetStateOnSeriesChange = useResetStateOnSeriesChange();
6267
const batchUpdates = useURLStateBatch();
@@ -106,9 +111,11 @@ export function MetricsGraphSection({
106111
}
107112

108113
if (hasChanged) {
109-
// TODO: Change this to store the query object
110-
// Pass commit: true to immediately apply the filter when clicking on metrics graph labels
111-
setNewQueryExpression(newQuery.toString(), true);
114+
// Immediately apply the filter when adding label matchers from the graph
115+
batchUpdates(() => {
116+
setNewQueryExpression(newQuery.toString());
117+
commitDraft(undefined, newQuery.toString());
118+
});
112119
}
113120
};
114121

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ const ProfileSelector = ({
341341
query={query}
342342
setQueryExpression={setQueryExpression}
343343
setNewQueryExpression={setDraftExpression}
344+
commitDraft={commitDraft}
344345
/>
345346
</>
346347
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface UseQueryStateReturn {
3838
draftSelection: QuerySelection;
3939

4040
// Draft setters (update local state only)
41-
setDraftExpression: (expression: string, commit?: boolean) => void;
41+
setDraftExpression: (expression: string) => void;
4242
setDraftTimeRange: (from: number, to: number, timeSelection: string) => void;
4343
setDraftSumBy: (sumBy: string[] | undefined) => void;
4444
setDraftProfileName: (profileName: string) => void;

0 commit comments

Comments
 (0)