Skip to content

Wireup Department History Timeline API#147

Merged
ChanukaUOJ merged 3 commits intoLDFLK:mainfrom
sehansi-9:department-history-timeline
Mar 20, 2026
Merged

Wireup Department History Timeline API#147
ChanukaUOJ merged 3 commits intoLDFLK:mainfrom
sehansi-9:department-history-timeline

Conversation

@sehansi-9
Copy link
Copy Markdown
Member

Wireup the new api, introduce useDepartmentHistory hook and remove history enriching logic from DepartmentHistoryTimeline component

closes #66

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the architecture for displaying department history by centralizing data fetching and processing. It introduces a dedicated API endpoint and a custom React hook, useDepartmentHistory, to handle the retrieval and initial structuring of historical department data. This change streamlines the DepartmentHistoryTimeline component, making it leaner, more focused on presentation, and easier to maintain by offloading data management responsibilities to the new hook.

Highlights

  • New API Endpoint: Introduced a new API endpoint /department-history/{departmentId} to fetch historical data for departments.
  • New React Hook: Created a useDepartmentHistory React Query hook to abstract and manage the fetching of department history data.
  • Component Refactoring: Refactored the DepartmentHistoryTimeline component to consume data from the new useDepartmentHistory hook, removing complex data fetching and enrichment logic directly from the component.
Changelog
  • src/hooks/useDepartmentHistory.js
    • Created a new React Query hook useDepartmentHistory to fetch department history data.
    • Configured the hook with queryKey, queryFn, enabled status, staleTime, and gcTime for efficient data management.
  • src/pages/DepartmentPage/components/DepartmentHistoryTimeline.jsx
    • Removed extensive useEffect logic responsible for fetching and enriching department history data.
    • Replaced manual data fetching and state management with the useDepartmentHistory hook.
    • Simplified the rendering logic to directly consume data from the new hook.
    • Removed imports related to redux, utils, and api that are no longer needed for data enrichment.
  • src/services/services.jsx
    • Added a new asynchronous function getDepartmentHistory to make API calls to the /department-history/{departmentId} endpoint.
Activity
  • The pull request was created by sehansi-9.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a great improvement, refactoring the DepartmentHistoryTimeline component to use a new useDepartmentHistory hook and a dedicated API endpoint. This change significantly simplifies the frontend by moving complex data processing to the backend. My feedback focuses on making the timeline component more robust by ensuring data is always sorted correctly and by using more stable keys for list rendering.

Comment thread src/pages/DepartmentPage/components/DepartmentHistoryTimeline.jsx
{departmentHistory.map((entry, idx) => {
return (
<VerticalTimelineElement
key={idx}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using the array index as a key is not recommended, as it can lead to incorrect behavior and performance issues when the list is sorted or items are added/removed. It's best to use a unique and stable identifier from the data. Since a simple unique ID doesn't seem to be available on the entry object, you can create a composite key from its properties.

Suggested change
key={idx}
key={`${entry.ministry_name}-${entry.period}`}

@sehansi-9 sehansi-9 requested a review from ChanukaUOJ March 17, 2026 10:35
}, [selectedDepartment]);
const {
data: departmentHistory,
isLoading,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

catch the error state as well in case the request breaks we need it to fallback

Suggested change
isLoading,
isLoading,
error

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

noted!

<div className="flex justify-center items-center h-20">
<ClipLoader color={colors.textPrimary} loading={loading} size={25} />
<ClipLoader color={colors.textPrimary} loading={isLoading} size={25} />
</div>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a fallback component here in case the api throws an error.

Suggested change
</div>
</div>
) : error ? (
<p className="text-primary mt-5">Error loading department history.</p>

this is just an idea for you to look at, implement a fallback ui for the DepartmentHistoryTimeline.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

added!

Copy link
Copy Markdown
Member

@ChanukaUOJ ChanukaUOJ left a comment

Choose a reason for hiding this comment

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

Initial Comments!

Comment thread src/services/services.jsx
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Make sure all the unused functions are removed from this file

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

will be addressed here #114

Comment on lines +30 to +32
<h2 className="text-md font-semibold text-gray-900 dark:text-white mb-2">
Department History Not Available
</h2>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need this one

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

noted

Copy link
Copy Markdown
Member

@ChanukaUOJ ChanukaUOJ left a comment

Choose a reason for hiding this comment

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

LGTM!

@ChanukaUOJ ChanukaUOJ merged commit 1e232db into LDFLK:main Mar 20, 2026
1 check passed
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.

Department History API wireup

3 participants