Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ui/packages/shared/components/src/ParcaContext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ interface Props {
disableProfileTypesDropdown?: boolean;
labelnames?: string[];
disableExplorativeQuerying?: boolean;
profileFilterDefaults?: unknown[];
};
profileViewExternalMainActions?: ReactNode;
profileViewExternalSubActions?: ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {ReactNode} from 'react';
import {ReactNode, act} from 'react';

// eslint-disable-next-line import/named
import {act, renderHook, waitFor} from '@testing-library/react';
import {renderHook, waitFor} from '@testing-library/react';
import {beforeEach, describe, expect, it, vi} from 'vitest';

import {
Expand Down
15 changes: 14 additions & 1 deletion ui/packages/shared/profile/src/ProfileSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import {TEST_IDS, testId} from '@parca/test-utils';
import {millisToProtoTimestamp, type NavigateFunction} from '@parca/utilities';

import {useMetricsGraphDimensions} from '../MetricsGraph/useMetricsGraphDimensions';
import {
ProfileFilter,
useProfileFilters,
} from '../ProfileView/components/ProfileFilters/useProfileFilters';
import {QueryControls} from '../QueryControls';
import {LabelsQueryProvider, useLabelsQueryProvider} from '../contexts/LabelsQueryProvider';
import {UnifiedLabelsProvider} from '../contexts/UnifiedLabelsContext';
Expand Down Expand Up @@ -119,6 +123,15 @@ const ProfileSelector = ({
const [queryBrowserMode, setQueryBrowserMode] = useURLState('query_browser_mode');
const batchUpdates = useURLStateBatch();

const profileFilterDefaults = viewComponent?.profileFilterDefaults as ProfileFilter[] | undefined;
const {forceApplyFilters} = useProfileFilters();

const handleProfileTypeChange = useCallback(() => {
if (profileFilterDefaults != null && profileFilterDefaults.length > 0) {
forceApplyFilters(profileFilterDefaults);
}
}, [forceApplyFilters, profileFilterDefaults]);

// Use the new useQueryState hook - reads directly from URL params
const {
querySelection,
Expand All @@ -133,7 +146,7 @@ const ProfileSelector = ({
setProfileSelection,
sumByLoading,
draftParsedQuery,
} = useQueryState({suffix});
} = useQueryState({suffix, onProfileTypeChange: handleProfileTypeChange});

// Use draft state for local state instead of committed state
const [timeRangeSelection, setTimeRangeSelection] = useState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export const useAutoQuerySelector = ({
}
dispatch(setAutoQuery('true'));
let profileType = profileTypesData.types.find(
type => type.name === 'parca_agent' && type.delta
type => type.name === 'parca_agent' && type.sampleType === 'samples' && type.delta
);
if (profileType == null) {
profileType = profileTypesData.types.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ export const useProfileFilters = (): {
removeFilter: (id: string) => void;
updateFilter: (id: string, updates: Partial<ProfileFilter>) => void;
resetFilters: () => void;
setAppliedFilters: (filters: ProfileFilter[]) => void;
forceApplyFilters: (filters: ProfileFilter[]) => void;
} => {
const {appliedFilters, setAppliedFilters} = useProfileFiltersUrlState();
const {appliedFilters, setAppliedFilters, forceApplyFilters} = useProfileFiltersUrlState();
const resetFlameGraphState = useResetFlameGraphState();

const [localFilters, setLocalFilters] = useState<ProfileFilter[]>(appliedFilters ?? []);
Expand Down Expand Up @@ -422,5 +424,7 @@ export const useProfileFilters = (): {
removeFilter,
updateFilter,
resetFilters,
setAppliedFilters,
forceApplyFilters,
};
};
Loading
Loading