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

Coding Dojo : Create custom hooks for presentation logic, modularise large functions <DO NOT MERGE> #245

Open
wants to merge 3 commits into
base: development
Choose a base branch
from

Conversation

9sneha-n
Copy link
Contributor

@9sneha-n 9sneha-n commented Apr 5, 2024

📌 References

📝 Implementation

  1. Create custom hooks for presentation logic
  2. Modularise large functions
  3. Created Import Options type

📹 Screenshots/Screen capture

🔥 Testing

@9sneha-n 9sneha-n requested review from tokland and removed request for tokland April 5, 2024 09:41
@9sneha-n 9sneha-n requested a review from tokland April 12, 2024 07:43
@9sneha-n 9sneha-n marked this pull request as ready for review April 12, 2024 07:43
@@ -31,3 +33,15 @@ export type NonBlockingError = {
type: "non-blocking";
error: ConsistencyError;
};

export interface ImportOptions {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

move to usecase

orgUnitName: string;
countryCode: string;
dryRun: boolean;
eventListId: string | undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

use Id wherever applicable. use Maybe<>

dryRun: boolean,
eventListId: string | undefined
): FutureData<ImportSummary> {
public execute(inputFile: File, options: ImportOptions): FutureData<ImportSummary> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for future projects : do not pass file to domain, as it is not a domain entity

orgUnitName: currentOrgUnitAccess.orgUnitName,
countryCode: currentOrgUnitAccess.orgUnitCode,
dryRun: false,
eventListId: "",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so not pass empty string

};
const secondaryUploadId = localStorage.getItem("secondaryUploadId");
const params = {
primaryUploadId: "",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ideally we should not pass empty strings

}
}, [batchId, isPrimaryFileValid, isSecondaryFileValid, moduleName]);

const changeBatchId = async (event: React.ChangeEvent<{ value: unknown }>) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

useCallback

}
);
}, [compositionRoot.fileSubmission, snackbar, orgUnitId, moduleName, orgUnitCode, uploadFileType, setLoading]);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

usecallbackeffect

const primaryUploadId = localStorage.getItem("primaryUploadId");
const secondaryUploadId = localStorage.getItem("secondaryUploadId");
if (secondaryUploadId && primaryUploadId)
compositionRoot.glassDocuments.updateSecondaryFileWithPrimaryId(secondaryUploadId, primaryUploadId).run(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

usecallbackeffect in all functions

if (secondaryFile) {
validate(true);
} else {
validate(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

validate(Boolean(secondaryFile))


export function useSecondaryFile(
secondaryFile: File | null,
setSecondaryFile: React.Dispatch<React.SetStateAction<File | null>>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

chaneg null to undefined

@9sneha-n 9sneha-n removed the request for review from tokland April 12, 2024 11:16
@9sneha-n 9sneha-n changed the title Refactor: Create custom hooks for presentation logic, modularise large functions, Coding Dojo : Create custom hooks for presentation logic, modularise large functions <DO NOT MERGE> Apr 24, 2024
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.

1 participant