Skip to content

Commit

Permalink
fix: update the count
Browse files Browse the repository at this point in the history
  • Loading branch information
mortada-codes committed Apr 19, 2023
1 parent a993662 commit 0fa0cc7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
17 changes: 5 additions & 12 deletions src/components/organisms/NavigatorPane/NavigatorDescription.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {intersection, size} from 'lodash';

import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {setLeftMenuSelection} from '@redux/reducers/ui';
import {filteredResourcesIdsSelector, navigatorResourcesCountSelector} from '@redux/selectors/resourceSelectors';
import {navigatorResourcesCountSelector} from '@redux/selectors/resourceSelectors';
import {
errorsResourceIdsSelector,
errorsByResourcesFilterCountSelector,
useValidationSelector,
warningsResourcesIdsSelector,
warningsByResourcesFilterCountSelector,
} from '@redux/validation/validation.selectors';
import {setValidationFilters} from '@redux/validation/validation.slice';

Expand All @@ -19,13 +17,8 @@ import * as S from './NavigatorDescription.styled';
const NavigatorDescription: React.FC = () => {
const dispatch = useAppDispatch();

const errorsResourcesIds = useValidationSelector(errorsResourceIdsSelector);
const warningsResourcesIds = useValidationSelector(warningsResourcesIdsSelector);

const filteredResources = useAppSelector(filteredResourcesIdsSelector);

const errorsCount = size(intersection(errorsResourcesIds, filteredResources));
const warningsCount = size(intersection(warningsResourcesIds, filteredResources));
const errorsCount = useValidationSelector(errorsByResourcesFilterCountSelector);
const warningsCount = useValidationSelector(warningsByResourcesFilterCountSelector);

const navigatorResourcesCount = useAppSelector(navigatorResourcesCountSelector);

Expand Down
20 changes: 15 additions & 5 deletions src/redux/validation/validation.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {TypedUseSelectorHook} from 'react-redux';
import {createSelector} from 'reselect';

import {useAppSelector} from '@redux/hooks';
import {filteredResourcesIdsSelector} from '@redux/selectors/resourceSelectors';
import {createDeepEqualSelector} from '@redux/selectors/utils';

import {
Expand Down Expand Up @@ -69,11 +70,6 @@ export const problemsByResourcesSelector = createDeepEqualSelector(
export const errorsByResourcesSelector = (state: ValidationState) => problemsByResourcesSelector(state, 'error');
export const warningsByResourcesSelector = (state: ValidationState) => problemsByResourcesSelector(state, 'warning');

export const errorsResourceIdsSelector = createSelector(errorsByResourcesSelector, errors => Object.keys(errors));
export const warningsResourcesIdsSelector = createSelector(warningsByResourcesSelector, warnings =>
Object.keys(warnings)
);

export const problemsByResourceSelector = createDeepEqualSelector(
[
(state: ValidationState, _resource?: string, level?: RuleLevel) => {
Expand All @@ -91,6 +87,20 @@ export const warningsByResourceSelector = (state: ValidationState, resource?: st
return problemsByResourceSelector(state, resource, 'warning');
};

export const errorsByResourcesFilterCountSelector = createSelector(
[filteredResourcesIdsSelector, errorsByResourcesSelector],
(filteredResources, errorsByResourceMap) => {
return filteredResources.map(id => errorsByResourceMap[id]?.length || 0).reduce((a, b) => a + b, 0);
}
);

export const warningsByResourcesFilterCountSelector = createSelector(
[filteredResourcesIdsSelector, warningsByResourcesSelector],
(filteredResources, warningsByResourceMap) => {
return filteredResources.map(id => warningsByResourceMap[id]?.length || 0).reduce((a, b) => a + b, 0);
}
);

/* * * * * * * * * * * * * * * * * *
* Problems by file path
* * * * * * * * * * * * * * * * * */
Expand Down

0 comments on commit 0fa0cc7

Please sign in to comment.