Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UISACQCOMP-166: view list of donors #724

Merged
merged 17 commits into from
Nov 3, 2023
Merged

UISACQCOMP-166: view list of donors #724

merged 17 commits into from
Nov 3, 2023

Conversation

alisher-epam
Copy link
Contributor

Purpose

UISACQCOMP-166 - View the list of donors associated with a given record
so that accurately track donors and donations

Approach

Screen.Recording.2023-10-31.at.1.49.35.PM.mov

Pre-Merge Checklist

Before merging this PR, please go through the following list and take appropriate actions.

  • I've added appropriate record to the CHANGELOG.md
  • Does this PR meet or exceed the expected quality standards?
    • Code coverage on new code is 80% or greater
    • Duplications on new code is 3% or less
    • There are no major code smells or security issues
  • Does this introduce breaking changes?
    • If any API-related changes - okapi interfaces and permissions are reviewed/changed correspondingly
    • There are no breaking changes in this PR.

If there are breaking changes, please STOP and consider the following:

  • What other modules will these changes impact?
  • Do JIRAs exist to update the impacted modules?
    • If not, please create them
    • Do they contain the appropriate level of detail? Which endpoints/schemas changed, etc.
    • Do they have all they appropriate links to blocked/related issues?
  • Are the JIRAs under active development?
    • If not, contact the project's PO and make sure they're aware of the urgency.
  • Do PRs exist for these changes?
    • If so, have they been approved?

Ideally all of the PRs involved in breaking changes would be merged in the same day to avoid breaking the folio-testing environment. Communication is paramount if that is to be achieved, especially as the number of intermodule and inter-team dependencies increase.

While it's helpful for reviewers to help identify potential problems, ensuring that it's safe to merge is ultimately the responsibility of the PR assignee.

@github-actions
Copy link

github-actions bot commented Oct 31, 2023

Jest Unit Test Statistics

    1 files  ±0  143 suites  +4   3m 56s ⏱️ + 1m 5s
377 tests +7  376 ✔️ +7  1 💤 ±0  0 ±0 
379 runs  +8  378 ✔️ +8  1 💤 ±0  0 ±0 

Results for commit a989e49. ± Comparison against base commit fc2f33d.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Oct 31, 2023

BigTest Unit Test Statistics

0 tests  ±0   0 ✔️ ±0   0s ⏱️ ±0s
0 suites ±0   0 💤 ±0 
0 files   ±0   0 ±0 

Results for commit a989e49. ± Comparison against base commit fc2f33d.

♻️ This comment has been updated with latest results.

@alisher-epam alisher-epam requested review from usavkov-epam, BogdanDenis and a team October 31, 2023 15:30
export const useFetchDonors = () => {
const ky = useOkapiKy();

const { isLoading, mutateAsync } = useMutation(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you use useQuery for fetching by ids?

Copy link
Contributor Author

@alisher-epam alisher-epam Nov 1, 2023

Choose a reason for hiding this comment

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

The mutation will be passed as a prop inside the other components and it will call the mutation on the demand.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, but you have the query key to invalidate the fn and you can use ids of donors for that purpose. I know, that there are examples of using useMutation to fetch the data, but probably useQuery will bring more benefits, like caching.


import { acqRowFormatter } from '../utils';
import AddDonorButton from './AddDonorButton';
import { alignRowProps, columnMapping, columnWidths, visibleColumns } from './constants';
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, break imports into separate lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How could I miss this step again =(

}) => ({
name: donor => donor.name,
code: donor => donor.code,
unassignDonor: (donor) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep consistency in code style: two args in the callbacks before not wrapped in the (..)

align="end"
aria-label={intl.formatMessage({ id: 'stripes-acq-components.donors.button.unassign' })}
buttonStyle="fieldControl"
data-test-unassign-donor
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you use this attr. anywhere?

lib/DonorsList/DonorsList.js Show resolved Hide resolved
export const useFetchDonors = () => {
const ky = useOkapiKy();

const { isLoading, mutateAsync } = useMutation(
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, but you have the query key to invalidate the fn and you can use ids of donors for that purpose. I know, that there are examples of using useMutation to fetch the data, but probably useQuery will bring more benefits, like caching.


useEffect(() => {
if (donorOrganizationIds.length) {
handleFetchDonors(donorOrganizationIds);
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems you don't need extra function handleFetchDonors to update ids now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, sorry the implementation was for mutation. I will remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I meant handleFetchDonors callback: it is redundant, because it does the same as a setDonorIds, so you can use it directly, and the useEffect was fine 🙂

_index,
};
});
const contentData = sortBy(donors, [({ lastName }) => lastName?.toLowerCase()]);
Copy link
Contributor

Choose a reason for hiding this comment

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

probably makes sense to wrap in useMemo, because sorting is quite an expensive operation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

);

return ({
donors: data || [],
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please create a constant for default data (like DEFAULT_DATA) outside the hook to always return the same reference on each rerender.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@alisher-epam alisher-epam requested review from usavkov-epam and removed request for BogdanDenis November 2, 2023 19:16
name={name}
id={name}
component={DonorsList}
fetchDonors={handleFetchDonors}
Copy link
Contributor

Choose a reason for hiding this comment

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

should be called like setDonorIds and accept setDonorIds, because now the callback does not fetch anything

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

const newDonorsIds = map(donors.filter(({ id }) => !addedDonorIds.has(id)), 'id');

if (newDonorsIds.length) {
fetchDonors([...addedDonorIds, ...newDonorsIds]);
Copy link
Contributor

Choose a reason for hiding this comment

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

the fetchDonors should be called smth like onAddDonor, btn doesn't fetch anything

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

.json()
.then(({ organizations }) => organizations),
donorOrganizationIds,
buildQueryByIds,
Copy link
Contributor

Choose a reason for hiding this comment

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

redundant as batchRequest build query by provided ids by default

export const batchRequest = (requestFn, items, buildQuery = buildQueryByIds, _params = {}, filterParamName = 'query') => {

import { useFetchDonors } from './hooks';

function DonorsContainer({ name, donorOrganizationIds }) {
const [donorIds, setDonorIds] = useState(() => donorOrganizationIds);

Choose a reason for hiding this comment

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

Why is lazy initialization needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. We can remove it. Initial implementation I had a function to get the ids.

visibleFilters,
} from './constants';

const AddDonorButton = ({ onAddDonors, fields, stripes, name }) => {

Choose a reason for hiding this comment

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

Please add a test file for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

Copy link

sonarqubecloud bot commented Nov 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

91.5% 91.5% Coverage
0.0% 0.0% Duplication

@alisher-epam alisher-epam merged commit 5bbcf17 into master Nov 3, 2023
5 checks passed
@alisher-epam alisher-epam deleted the UISACQCOMP-166 branch November 3, 2023 13:55
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