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
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ describe('Model Catalog Details Tabs', () => {
modelCatalog.findHardwareConfigurationTableHeaders().should('not.contain.text', 'ITL');
});

it('should reset to default latency filter (TTFT P90) when filter is reset', () => {
it('should reset to applied values when changes were made in the dropdown', () => {
modelCatalog.findModelCatalogDetailLink().first().click();
modelCatalog.clickPerformanceInsightsTab();

Expand All @@ -391,24 +391,18 @@ describe('Model Catalog Details Tabs', () => {
.should('contain.text', `E2E${NBSP}Latency Mean`);
modelCatalog.findHardwareConfigurationTableHeaders().should('not.contain.text', 'TTFT');

// Open filter and reset - this should apply the default (TTFT P90), not clear completely
modelCatalog.openLatencyFilter();
modelCatalog.clickResetFilter();
modelCatalog.selectLatencyMetric('TTFT');
modelCatalog.selectLatencyPercentile('P90');

// Close the dropdown by clicking outside
// Click reset - should restore to applied values (E2E Mean), not apply filter
modelCatalog.clickResetFilter();
cy.get('body').click(0, 0);

// Default latency filter (TTFT P90) should be applied
// Only TTFT and TPS P90 columns should be visible
modelCatalog
.findHardwareConfigurationTableHeaders()
.should('contain.text', `TTFT${NBSP}Latency P90`);
modelCatalog
.findHardwareConfigurationTableHeaders()
.should('contain.text', `TPS${NBSP}P90`);
// E2E and ITL should NOT be visible (filter is applied, not cleared)
modelCatalog.findHardwareConfigurationTableHeaders().should('not.contain.text', 'E2E');
modelCatalog.findHardwareConfigurationTableHeaders().should('not.contain.text', 'ITL');
.should('contain.text', `E2E${NBSP}Latency Mean`);
modelCatalog.findHardwareConfigurationTableHeaders().should('not.contain.text', 'TTFT');
});

it('should keep non-latency columns visible when latency filter is applied', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ const LatencyFilter: React.FC = () => {
return defaultFilterState;
});

const appliedFilterStateRef = React.useRef<LatencyFilterState | null>(null);

// Update local filter when active filter changes
React.useEffect(() => {
if (currentActiveFilter) {
Expand All @@ -113,6 +115,23 @@ const LatencyFilter: React.FC = () => {
}
}, [currentActiveFilter]);

// Capture the applied filter state when menu opens
React.useEffect(() => {
if (isOpen) {
// Capture the current filter state when menu opens
if (currentActiveFilter) {
appliedFilterStateRef.current = {
metric: currentActiveFilter.metric,
percentile: currentActiveFilter.percentile,
value: currentActiveFilter.value,
};
} else {
appliedFilterStateRef.current = defaultFilterState;
}
setLocalFilter(appliedFilterStateRef.current);
}
}, [isOpen, currentActiveFilter, defaultFilterState]);

const { minValue, maxValue, isSliderDisabled } = React.useMemo((): SliderRange => {
const filterKey = getLatencyFilterKey(localFilter.metric, localFilter.percentile);

Expand Down Expand Up @@ -173,21 +192,15 @@ const LatencyFilter: React.FC = () => {
};

const handleReset = () => {
// Reset to default latency filter (performance filters should reset to defaults, not clear)
// First clear any existing latency filter
if (currentActiveFilter) {
setFilterData(currentActiveFilter.fieldName, undefined);
// Reset to the filter state that was active when menu opened (not the original default)
if (appliedFilterStateRef.current) {
const resetState = appliedFilterStateRef.current;
setLocalFilter(resetState);
// Update the refs so the useEffect doesn't think metric/percentile changed
// This prevents the value from being reset to maxValue
prevMetricRef.current = resetState.metric;
prevPercentileRef.current = resetState.percentile;
}

// Apply the default latency filter
const defaultFilterKey = getLatencyFilterKey(
defaultFilterState.metric,
defaultFilterState.percentile,
);
setFilterData(defaultFilterKey, defaultFilterState.value);

// Reset local filter to default
setLocalFilter(defaultFilterState);
};

const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,29 @@ import {
import { ModelCatalogNumberFilterKey } from '~/concepts/modelCatalog/const';
import { useCatalogNumberFilterState } from '~/app/pages/modelCatalog/utils/modelCatalogUtils';
import { MAX_RPS_RANGE } from '~/app/pages/modelCatalog/utils/performanceMetricsUtils';
import { ModelCatalogContext } from '~/app/context/modelCatalog/ModelCatalogContext';
import SliderWithInput from './SliderWithInput';

const filterKey = ModelCatalogNumberFilterKey.MAX_RPS;

const MaxRpsFilter: React.FC = () => {
const { value: rpsFilterValue, setValue: setRpsFilterValue } =
useCatalogNumberFilterState(filterKey);
const { getPerformanceFilterDefaultValue } = React.useContext(ModelCatalogContext);
const [isOpen, setIsOpen] = React.useState(false);

const { minValue, maxValue, isSliderDisabled } = MAX_RPS_RANGE;

const [localValue, setLocalValue] = React.useState<number>(() => rpsFilterValue ?? maxValue);

const appliedValueRef = React.useRef<number | undefined>(undefined);

const clampedValue = React.useMemo(
() => Math.min(Math.max(localValue, minValue), maxValue),
[localValue, minValue, maxValue],
);

React.useEffect(() => {
if (isOpen) {
appliedValueRef.current = rpsFilterValue;
setLocalValue(rpsFilterValue ?? maxValue);
}
}, [isOpen, rpsFilterValue, maxValue]);
Expand All @@ -55,11 +56,7 @@ const MaxRpsFilter: React.FC = () => {
};

const handleReset = () => {
// Get default value from namedQueries, fallback to maxValue
const defaultValue = getPerformanceFilterDefaultValue(filterKey);
const value = typeof defaultValue === 'number' ? defaultValue : maxValue;
setRpsFilterValue(value);
setLocalValue(value);
setLocalValue(appliedValueRef.current ?? maxValue);
};

const toggle = (toggleRef: React.Ref<MenuToggleElement>) => (
Expand Down
Loading