Skip to content

Conversation

@ghazwarhili
Copy link
Contributor

PR Summary

Manage all the calculation result filters with a single hook.

@ghazwarhili ghazwarhili changed the title create use computation result filters persist computation result filters Dec 2, 2025
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
11.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Copy link
Contributor

@flomillot flomillot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some renaming to do to be more acurate and understable

  • onFilter -> onFilterChange
  • api -> agGridApi


const { countriesFilter, voltageLevelsFilter, propertiesFilter } = useGlobalFilterOptions();
const { globalFilters, handleGlobalFilterChange } = useGlobalFilters();
const { handleGlobalFilterChange, globalFilters } = useGlobalFilters();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the setter at the end, keep original order?


const { persistFilters } = useComputationColumnsFilters(AgGridFilterType.Loadflow, mappingTabs(tabIndex));

const onFilter = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const onFilter = useCallback(
const onFilterChange = useCallback(

[dispatchGlobalFilters, studyUuid, config?.id]
);

return useMemo(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this useMemo ?

[studyUuid, computationResultFilterUuid, columnUuid]
);

return useMemo(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

);

const persistFilters = useCallback(
(colId: string, api: GridApi, filters: FilterConfig[]) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(colId: string, api: GridApi, filters: FilterConfig[]) => {
(colId: string, agGridApi: GridApi, filters: FilterConfig[]) => {

Comment on lines +71 to 76
useEffect(() => {
// Clear the globalfilter when tab changes
handleGlobalFilterChange([]);
}, [handleGlobalFilterChange]);

return (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this change because you just moved the use effect so we can keep the git history


const { persistFilters } = useComputationColumnsFilters(FilterType.PccMin, PCCMIN_RESULT);

const onFilter = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

);

const onFilter = useCallback(() => {
const memoizedSetPageCallback = useCallback(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not originally from you but I don't understand the name of this callback

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it's not goFirstPage or something like this ?

dataType: c.filterDataType,
tolerance: c.filterTolerance ?? undefined,
});
export function setComputationResultFiltersState(filtersInfos: ComputationResultFiltersInfos): ComputationFiltersState {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function setComputationResultFiltersState(filtersInfos: ComputationResultFiltersInfos): ComputationFiltersState {
export function getComputationResultFiltersState(filtersInfos: ComputationResultFiltersInfos): ComputationFiltersState {

or create / init but not set

resetTableDefinitions(collection);
});

const fetchComputationResultFiltersPromise = getComputationResultFilters(studyUuid).then(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const fetchComputationResultFiltersPromise = getComputationResultFilters(studyUuid).then(
const fetchComputationResultFilters = getComputationResultFilters(studyUuid).then(

no need to add promise when you already have fetch in the name function

import { updateFilters } from '../components/custom-aggrid/custom-aggrid-filters/utils/aggrid-filters-utils';
import { GridApi } from 'ag-grid-community';

export function useComputationColumnsFilters(filterType: FilterType, filterTab: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function useComputationColumnsFilters(filterType: FilterType, filterTab: string) {
export function useUpdateComputationColumnsFilters(filterType: FilterType, filterTab: string) {

as the only thing you return is persistFilters which update filters

(state: any) => state.computationFilters?.[filterType]?.columnsFilters?.[filterTab]?.id
);

const persistFilters = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const persistFilters = useCallback(
const updateColumnFilters = useCallback(

import { updateFilters } from '../components/custom-aggrid/custom-aggrid-filters/utils/aggrid-filters-utils';
import { GridApi } from 'ag-grid-community';

export function useComputationColumnsFilters(filterType: FilterType, filterTab: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not here If we are short in time, so maybe in the next pull request :

  • rename the hook into useColumnsFilters
  • include const { filters } = useFilterSelector and return filters like for global filters
  • remove const { filters } = useFilterSelector from other components

// @ts-expect-error TODO: found a better way to go into state
(state: AppState) => state[FILTER_PARAMS[filterType].filterType][filterTab]
);
const entry = FILTER_PARAMS[filterType];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to rename the variable and add a comment to explain the code ? personally I don't understand this part

};
});
});
builder.addCase(UPDATE_COLUMN_FILTERS, (state, action: UpdateColumnFiltersAction) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better indeed 👍 nice

subtypeSubstationProperties.push(filter.label);
} else {
substationProperties.set(filter.filterSubtype, [filter.label]);
value.forEach((filter) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

FilterType as AgGridFilterType,
textFilterParams,
numericFilterParams,
textFilterParams,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert for history

tab: mappingTabs(tabIndex),
updateFilterCallback: onFilter,
};
const createUpdateFilterCallback = (colId: string) => (api?: GridApi, filters?: FilterConfig[]) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated as say sonar.

filterValue: filter?.value,
filterTolerance: filter?.tolerance,
};
updateFilters(api, filters);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why it's here and not directly inside useCustomAggridFilter ?

import { updateFilters } from '../components/custom-aggrid/custom-aggrid-filters/utils/aggrid-filters-utils';
import { GridApi } from 'ag-grid-community';

export function useComputationColumnsFilters(filterType: FilterType, filterTab: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, did you really need this hook?
You could not put this code inside useCustomAggridFilter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants