Skip to content

Conversation

@FussuChalice
Copy link
Contributor

Description

Added a filter for groups and periods to the statistics on the publisher records page.
Thanks to Igor Selin, from whom I took a few lines of code.
These are the fixes for draft #4193.

Fixes # (issue)

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

@FussuChalice FussuChalice marked this pull request as ready for review October 23, 2025 12:30
@vercel
Copy link

vercel bot commented Oct 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
staging-organized-app Ready Ready Preview Dec 4, 2025 0:01am
test-organized-app Ready Ready Preview Dec 4, 2025 0:01am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2025

Walkthrough

Adds optional group-based filtering to core person/report hooks and threads a new publishersGroup prop through publisher report components; replaces month toggle UI with SelectPublishers and SelectPeriod controls and updates YearDetails state/handlers accordingly.

Changes

Cohort / File(s) Summary
Core hook grouping support
src/features/persons/hooks/usePersons.tsx, src/features/reports/hooks/useReportMonthly.tsx, src/features/reports/hooks/useReportYearly.tsx
Introduced optional group/publishersGroup parameter and memoized filtering of persons using fieldWithLanguageGroupsState; hooks now return persons scoped to the selected group (or all when omitted/'all').
Report component type definitions
src/features/reports/publisher_records/years_stats/auxiliary_pioneers/index.types.ts, src/features/reports/publisher_records/years_stats/fulltime_servants/index.types.ts, src/features/reports/publisher_records/years_stats/publishers/index.types.ts, src/features/reports/publisher_records/years_stats/total_statistics/index.types.ts
Added required publishersGroup: string property to public props types consumed by reporting components.
Report component hook implementations
src/features/reports/publisher_records/years_stats/auxiliary_pioneers/useAuxiliaryPioneers.tsx, src/features/reports/publisher_records/years_stats/fulltime_servants/useFulltimeServants.tsx, src/features/reports/publisher_records/years_stats/publishers/usePublishers.tsx, src/features/reports/publisher_records/years_stats/total_statistics/useTotalStatistics.tsx
Propagate publishersGroup into internal hooks: usePersons(publishersGroup), useReportYearly(publishersGroup), useReportMonthly(publishersGroup); adjust memo deps and downstream computations to use filtered persons.
Year details UI refactor
src/features/reports/publisher_records/years_stats/year_details/index.tsx, src/features/reports/publisher_records/years_stats/year_details/useYearDetails.tsx
Replaced MonthSelector/tooltip-based UI with SelectPublishers and SelectPeriod; introduced selectedPublishers/selectedMonth state and handlers (handleChangeSelectedPublishers, handleChangeSelectedMonth); compute wholeYear from selection and pass publishersGroup to children.
Publishers selector (new)
src/features/reports/publisher_records/years_stats/year_details/select_publishers/index.tsx, .../select_publishers/index.types.ts, .../select_publishers/useSelectPublishers.tsx
New SelectPublishers component and useSelectPublishers hook that reads fieldWithLanguageGroupsState and exposes groups (id/name), plus SelectPublishersProps type.
Period selector (new)
src/features/reports/publisher_records/years_stats/year_details/select_period/index.tsx, .../select_period/index.types.ts, .../select_period/useSelectPeriod.tsx
New SelectPeriod component and useSelectPeriod hook to list "service-year" and months for a given year; adds SelectPeriodProps type.

Sequence Diagram

sequenceDiagram
    participant User
    participant YearDetails
    participant SelectPublishers
    participant SelectPeriod
    participant useYearDetails
    participant ReportHooks as usePublishers/useAuxiliaryPioneers/...
    participant PersonHooks as usePersons/useReportYearly/useReportMonthly
    User->>SelectPublishers: choose group
    SelectPublishers->>YearDetails: onChange(selectedPublishers)
    YearDetails->>useYearDetails: handleChangeSelectedPublishers
    useYearDetails->>YearDetails: selectedPublishers

    User->>SelectPeriod: choose month/service-year
    SelectPeriod->>YearDetails: onChange(selectedMonth)
    YearDetails->>useYearDetails: handleChangeSelectedMonth
    useYearDetails->>YearDetails: selectedMonth, wholeYear

    YearDetails->>ReportHooks: call with publishersGroup + month/year/wholeYear
    ReportHooks->>PersonHooks: call usePersons(publishersGroup)
    PersonHooks->>PersonHooks: filter persons by fieldGroups membership
    PersonHooks-->>ReportHooks: return filtered persons
    ReportHooks-->>YearDetails: computed reports using filtered persons
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify correct threading of publishersGroup through all hooks and components.
  • Confirm memoization dependency arrays (useMemo) include fieldGroups/allPersons/group correctly.
  • Check SelectPublishers/SelectPeriod integration and useYearDetails state transitions.

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding filters for statistics on the publisher records page, which is clearly reflected across all modified hook files and UI components.
Description check ✅ Passed The description is directly related to the changeset, explaining that it adds filters for groups and periods to publisher records statistics, which aligns with the comprehensive changes across multiple hooks and UI components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 8

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/features/reports/publisher_records/years_stats/year_details/index.tsx (1)

40-63: Remove commented-out code.

Commented-out code should not be committed to version control. Git history preserves the old implementation if needed. Keeping dead code reduces maintainability and creates confusion.

Apply this diff to remove the commented block:

-        {/* <Tooltip
-          title={t('tr_wholeYearIsSelected')}
-          delaySpeed={'fast'}
-          show={wholeYear}
-          followCursor
-          sx={{ flex: 1 }}
-        >
-          <MonthSelector
-            year={year}
-            value={month}
-            onChange={handleMonthChange}
-            readOnly={wholeYear}
-            sx={{
-              flex: 1,
-            }}
-          />
-        </Tooltip>
-        <Box>
-          <SwitchWithLabel
-            label={t('tr_wholeYearSetting')}
-            checked={wholeYear}
-            onChange={handleToggleWholeYear}
-          /> 
-        </Box> */}
         <SelectPublishers
🧹 Nitpick comments (3)
src/features/reports/publisher_records/years_stats/year_details/useYearDetails.tsx (1)

1-2: Remove unused imports.

Line 2 imports useEffect and useState, but only useState is used. The useEffect import is unused, triggering the eslint-disable comment on line 1. Line 4 also redundantly imports useCallback which is already available from the React import.

Apply this diff:

-/* eslint-disable @typescript-eslint/no-unused-vars */
-import { useEffect, useState } from 'react';
+import { useState, useCallback } from 'react';
 import { YearDetailsProps } from './index.types';
-import { useCallback } from 'react';
src/features/reports/publisher_records/years_stats/year_details/select_period/index.types.ts (1)

1-5: Strengthen type definitions for better type safety.

The unknown types for onChange and value are too loose. Based on the component implementation in index.tsx, these should be more specific:

  • value should be string (holds either 'service-year' or a month in 'YYYY/MM' format)
  • onChange should accept SelectChangeEvent<string> from MUI

Apply this diff to improve type safety:

+import { SelectChangeEvent } from '@mui/material';
+
 export type SelectPeriodProps = {
-  onChange: (e: unknown) => void;
-  value: unknown;
+  onChange: (e: SelectChangeEvent<string>) => void;
+  value: string;
   year: string;
 };
src/features/reports/publisher_records/years_stats/year_details/select_period/useSelectPeriod.tsx (1)

3-11: Add proper return type and consider error handling.

The return type uses any[] which bypasses type safety. Based on the buildServiceYearsList implementation, months should be typed as { value: string; label: string }[].

Additionally, when the year is not found, an empty array is silently returned. Consider whether this is the desired behavior or if a warning/fallback would be more appropriate.

Apply this diff to add proper typing:

-const useSelectPeriod = ({ year }: { year: string }) => {
+const useSelectPeriod = ({ year }: { year: string }): { months: { value: string; label: string }[] } => {
   const serviceYears = buildServiceYearsList();
   const yearObj = serviceYears.find((y) => y.year === year);
   const months = yearObj ? yearObj.months : [];

   return {
     months,
   };
 };
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f963a0 and 1d7b297.

⛔ Files ignored due to path filters (1)
  • src/locales/en/general.json is excluded by !**/*.json
📒 Files selected for processing (19)
  • src/features/persons/hooks/usePersons.tsx (2 hunks)
  • src/features/reports/hooks/useReportMonthly.tsx (1 hunks)
  • src/features/reports/hooks/useReportYearly.tsx (1 hunks)
  • src/features/reports/publisher_records/years_stats/auxiliary_pioneers/index.types.ts (1 hunks)
  • src/features/reports/publisher_records/years_stats/auxiliary_pioneers/useAuxiliaryPioneers.tsx (1 hunks)
  • src/features/reports/publisher_records/years_stats/fulltime_servants/index.types.ts (1 hunks)
  • src/features/reports/publisher_records/years_stats/fulltime_servants/useFulltimeServants.tsx (1 hunks)
  • src/features/reports/publisher_records/years_stats/publishers/index.types.ts (1 hunks)
  • src/features/reports/publisher_records/years_stats/publishers/usePublishers.tsx (3 hunks)
  • src/features/reports/publisher_records/years_stats/total_statistics/index.types.ts (1 hunks)
  • src/features/reports/publisher_records/years_stats/total_statistics/useTotalStatistics.tsx (2 hunks)
  • src/features/reports/publisher_records/years_stats/year_details/index.tsx (3 hunks)
  • src/features/reports/publisher_records/years_stats/year_details/select_period/index.tsx (1 hunks)
  • src/features/reports/publisher_records/years_stats/year_details/select_period/index.types.ts (1 hunks)
  • src/features/reports/publisher_records/years_stats/year_details/select_period/useSelectPeriod.tsx (1 hunks)
  • src/features/reports/publisher_records/years_stats/year_details/select_publishers/index.tsx (1 hunks)
  • src/features/reports/publisher_records/years_stats/year_details/select_publishers/index.types.ts (1 hunks)
  • src/features/reports/publisher_records/years_stats/year_details/select_publishers/useSelectPublishers.tsx (1 hunks)
  • src/features/reports/publisher_records/years_stats/year_details/useYearDetails.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (11)
src/features/reports/publisher_records/years_stats/publishers/usePublishers.tsx (1)
src/features/reports/publisher_records/years_stats/publishers/index.types.ts (1)
  • PublishersProps (1-6)
src/features/reports/publisher_records/years_stats/fulltime_servants/useFulltimeServants.tsx (1)
src/features/reports/publisher_records/years_stats/fulltime_servants/index.types.ts (1)
  • FulltimeServantsProps (1-6)
src/features/persons/hooks/usePersons.tsx (2)
src/states/field_service_groups.ts (1)
  • fieldWithLanguageGroupsState (24-62)
src/states/persons.ts (1)
  • personsActiveState (25-34)
src/features/reports/hooks/useReportMonthly.tsx (3)
src/states/field_service_groups.ts (1)
  • fieldWithLanguageGroupsState (24-62)
src/states/field_service_reports.ts (1)
  • congFieldServiceReportsState (14-22)
src/states/persons.ts (1)
  • personsState (17-17)
src/features/reports/publisher_records/years_stats/year_details/select_period/useSelectPeriod.tsx (1)
src/utils/date.ts (1)
  • buildServiceYearsList (233-292)
src/features/reports/publisher_records/years_stats/total_statistics/useTotalStatistics.tsx (1)
src/features/reports/publisher_records/years_stats/total_statistics/index.types.ts (1)
  • TotalStatisticsProps (1-4)
src/features/reports/publisher_records/years_stats/year_details/select_publishers/useSelectPublishers.tsx (1)
src/states/field_service_groups.ts (1)
  • fieldWithLanguageGroupsState (24-62)
src/features/reports/publisher_records/years_stats/auxiliary_pioneers/useAuxiliaryPioneers.tsx (1)
src/features/reports/publisher_records/years_stats/auxiliary_pioneers/index.types.ts (1)
  • AuxiliaryPioneersProps (1-6)
src/features/reports/publisher_records/years_stats/year_details/select_period/index.tsx (1)
src/features/reports/publisher_records/years_stats/year_details/select_period/index.types.ts (1)
  • SelectPeriodProps (1-5)
src/features/reports/hooks/useReportYearly.tsx (3)
src/states/field_service_groups.ts (1)
  • fieldWithLanguageGroupsState (24-62)
src/states/field_service_reports.ts (1)
  • congFieldServiceReportsState (14-22)
src/states/persons.ts (1)
  • personsState (17-17)
src/features/reports/publisher_records/years_stats/year_details/select_publishers/index.tsx (1)
src/features/reports/publisher_records/years_stats/year_details/select_publishers/index.types.ts (1)
  • SelectPublishersProps (1-4)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: SonarCloud
  • GitHub Check: Code QL
  • GitHub Check: Summary
🔇 Additional comments (12)
src/features/reports/publisher_records/years_stats/fulltime_servants/index.types.ts (1)

5-5: LGTM!

The addition of publishersGroup is consistent with the group-filtering feature and follows the same pattern applied to other Props types in this PR.

src/features/reports/publisher_records/years_stats/publishers/index.types.ts (1)

5-5: LGTM!

Consistent addition of publishersGroup property to support group-based filtering.

src/features/reports/publisher_records/years_stats/auxiliary_pioneers/index.types.ts (1)

5-5: LGTM!

Consistent with the group-filtering pattern applied throughout this PR.

src/features/reports/publisher_records/years_stats/fulltime_servants/useFulltimeServants.tsx (1)

14-22: LGTM!

The publishersGroup parameter is correctly destructured and passed to the dependent hooks (usePersons, useReportYearly, useReportMonthly), enabling group-scoped data retrieval.

src/features/reports/publisher_records/years_stats/total_statistics/index.types.ts (1)

3-3: LGTM!

Addition of publishersGroup aligns with the group-filtering feature being introduced.

src/features/reports/publisher_records/years_stats/total_statistics/useTotalStatistics.tsx (1)

11-18: LGTM! Clean parameter threading.

The addition of publishersGroup parameter and its propagation to usePersons is implemented correctly, enabling group-based filtering for statistics.

src/features/reports/publisher_records/years_stats/year_details/select_period/index.tsx (1)

9-38: LGTM! Well-structured component.

The component properly integrates the custom hook, translation, and MUI components to render period selection UI. The static "service-year" option followed by dynamic month options provides clear structure.

src/features/reports/publisher_records/years_stats/year_details/select_publishers/index.tsx (1)

9-38: LGTM! Consistent and clean implementation.

The component follows the same well-structured pattern as SelectPeriod, with proper hook integration, translations, and rendering of both "all" and group-specific options.

src/features/reports/publisher_records/years_stats/year_details/select_publishers/useSelectPublishers.tsx (1)

5-21: LGTM! Clean data transformation.

The hook properly transforms field service groups into a simple structure for the UI, with appropriate fallback naming using translation keys and 1-based indexing.

src/features/reports/publisher_records/years_stats/publishers/usePublishers.tsx (1)

10-22: Clean implementation of group-based filtering.

The addition of publishersGroup parameter and its propagation to all dependent hooks (usePersons, useReportYearly, useReportMonthly) is consistent and correctly implemented.

src/features/reports/publisher_records/years_stats/auxiliary_pioneers/useAuxiliaryPioneers.tsx (1)

10-22: LGTM!

The implementation follows the same clean pattern as usePublishers.tsx, correctly propagating publishersGroup to all dependent hooks.

src/features/reports/publisher_records/years_stats/year_details/index.tsx (1)

75-96: Correct propagation of group-based filtering.

The updated component props correctly pass selectedMonth, selectedPublishers, and the derived publishersGroup to all child statistics components.

Comment on lines 1 to 4
export type SelectPublishersProps = {
onChange: (e: unknown) => void;
value: unknown;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Replace unknown types with specific types for better type safety.

Both onChange and value are typed as unknown, which bypasses TypeScript's type checking. Based on the context, value should be string (matching publishersGroup across other components), and onChange should accept a React change event.

Apply this diff:

 export type SelectPublishersProps = {
-  onChange: (e: unknown) => void;
-  value: unknown;
+  onChange: (e: React.ChangeEvent<HTMLSelectElement>) => void;
+  value: string;
 };
🤖 Prompt for AI Agents
In
src/features/reports/publisher_records/years_stats/year_details/select_publishers/index.types.ts
lines 1-4, replace the loose unknown types: change value to string and type
onChange as a React change event handler (e.g. (e:
React.ChangeEvent<HTMLSelectElement>) => void). Add the necessary React import
(or import { ChangeEvent } from 'react') if not already present so the file
compiles.

justifyContent="space-between"
>
<Tooltip
{/* <Tooltip
Copy link
Member

Choose a reason for hiding this comment

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

@FussuChalice: if no longer needed, this can be removed too.

@rhahao
Copy link
Member

rhahao commented Nov 11, 2025

@FussuChalice: does this replace the #4193 entirely?

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 4, 2025

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/features/reports/publisher_records/years_stats/year_details/useYearDetails.tsx (2)

1-3: Combine React imports to satisfy static analysis and simplify the module header

You can merge the two react imports into one to address the Sonar warning and keep the file header cleaner:

-import { useState } from 'react';
+import { useState, useCallback } from 'react';
 import { YearDetailsProps } from './index.types';
-import { useCallback } from 'react';

9-15: Consider typing the change handlers’ event parameter

e is currently implicitly typed, which can weaken TypeScript checks (especially with noImplicitAny enabled). Consider annotating it (or lifting the type from SelectPublishers/SelectPeriod) so the handler signatures stay aligned with the underlying components’ onChange contract.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1d7b297 and 88217e0.

📒 Files selected for processing (6)
  • src/features/persons/hooks/usePersons.tsx (2 hunks)
  • src/features/reports/hooks/useReportMonthly.tsx (1 hunks)
  • src/features/reports/hooks/useReportYearly.tsx (1 hunks)
  • src/features/reports/publisher_records/years_stats/year_details/index.tsx (1 hunks)
  • src/features/reports/publisher_records/years_stats/year_details/select_publishers/index.types.ts (1 hunks)
  • src/features/reports/publisher_records/years_stats/year_details/useYearDetails.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/features/reports/hooks/useReportMonthly.tsx
  • src/features/reports/publisher_records/years_stats/year_details/select_publishers/index.types.ts
  • src/features/persons/hooks/usePersons.tsx
  • src/features/reports/hooks/useReportYearly.tsx
🧰 Additional context used
🪛 GitHub Check: SonarCloud Code Analysis
src/features/reports/publisher_records/years_stats/year_details/useYearDetails.tsx

[warning] 1-1: 'react' imported multiple times.

See more on https://sonarcloud.io/project/issues?id=sws2apps_organized&issues=AZrpOi556HDDrD8R71j2&open=AZrpOi556HDDrD8R71j2&pullRequest=4660


[warning] 3-3: 'react' imported multiple times.

See more on https://sonarcloud.io/project/issues?id=sws2apps_organized&issues=AZrpOi556HDDrD8R71j3&open=AZrpOi556HDDrD8R71j3&pullRequest=4660

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Summary
🔇 Additional comments (1)
src/features/reports/publisher_records/years_stats/year_details/index.tsx (1)

1-65: Wiring of year details, filters, and publishersGroup looks consistent

YearDetails cleanly consumes useYearDetails and threads selectedMonth, wholeYear, and selectedPublishers into the selects and downstream sections (FulltimeServants, AuxiliaryPioneers, Publishers, TotalStatistics) in a consistent way; imports are minimal and relevant.

@FussuChalice
Copy link
Contributor Author

@FussuChalice: does this replace the #4193 entirely?

Yes.

@FussuChalice FussuChalice requested a review from rhahao December 4, 2025 12:06
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.

2 participants