Skip to content

chore(island-ui): Refactor InputFileUpload component #18801

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

Merged
merged 55 commits into from
Apr 25, 2025

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Apr 15, 2025

Refactor InputFileUpload component

Asana

What

This is a re-write of the InputFileUpload component. What this re-write accomplishes is

  • Remove duplicate code. We had f.x. both UploadFileStatus and FileUploadStatus which contained the same values.
  • Simplify props. We used to f.x. accept a doneIcon prop and this pr accepts a icons prop where consumers can control each individual icon, if they want.
  • Implements better truncateMiddle and formatFileSize functions. truncateMiddle now no longer relies on a useMeasure hook and formatFileSize displays B, KB, MB, GB as appropriate.

Why

The old component was becoming bloated and in need of a rewrite.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • Refactor

    • Replaced all usages of current file upload components and types with their deprecated counterparts across multiple applications and libraries for consistency.
    • Updated file upload component props: renamed fileList to files, header to title, and added name props where applicable.
    • Standardized file upload status handling by replacing string literals with enum values for improved type safety.
    • Removed showFileSize prop in some file upload components.
    • Split style objects for file upload status indicators into separate exports.
  • Chores

    • Added exports for deprecated file upload components and types to the main UI library entry point.
    • Updated storybook and documentation to use deprecated file upload components where relevant.

Copy link
Contributor

coderabbitai bot commented Apr 15, 2025

Walkthrough

This change introduces a new deprecated file upload component (InputFileUploadDeprecated) and associated types, and systematically replaces usages of the current file upload component and types with their deprecated counterparts across multiple applications and libraries. The update also standardizes file upload status handling by replacing string literals with a strongly typed enum (FileUploadStatus) in the current implementation. Additionally, the main InputFileUpload component is refactored for improved type safety, clearer prop usage, and enhanced UI behavior. Various prop names are updated for consistency, and new exports are added to the UI core library to expose the deprecated components and types.

Changes

Files/Paths (grouped) Change Summary
libs/island-ui/core/src/lib/InputFileUpload/InputFileUpload.tsx
libs/island-ui/core/src/lib/InputFileUpload/InputFileUploadDeprecated.tsx
Refactored main file upload component for type safety, prop renaming, enum-based status, improved UI, and introduced a new deprecated version with supporting types and components.
libs/island-ui/core/src/index.ts Added named exports for deprecated file upload components and types.
libs/island-ui/core/src/lib/InputFileUpload/InputFileUpload.stories.tsx Updated story to use deprecated component and types.
Multiple files in apps/consultation-portal, apps/financial-aid, apps/judicial-system, apps/web, libs/application, libs/portals, etc. Replaced usages of current file upload components/types with deprecated versions (InputFileUploadDeprecated, UploadFileDeprecated, etc.). Updated prop names (fileListfiles, headertitle, etc.) and status handling to enums where needed.
apps/judicial-system/web/src/components/EditableCaseFile/EditableCaseFile.css.ts Refactored CSS styles from a variants object to separate style objects for each file status.
apps/judicial-system/web/src/components/EditableCaseFile/EditableCaseFile.tsx Updated status handling to use enums, adjusted type declarations, and conditional logic for styling and actions.
libs/portals/admin/form-system/src/hooks/fileUploadReducer.ts Updated reducer and actions to use deprecated file upload types.
libs/application/templates/financial-aid/src/fields/Files/Files.tsx
apps/financial-aid/web-osk/src/components/Files/Files.tsx
Updated prop and parameter types to use deprecated file upload types.
libs/application/templates/financial-aid/src/fields/Summary/Files.tsx
libs/financial-aid/shared/src/components/FileList/FileList.tsx
Updated prop types to use deprecated file upload types.
libs/application/templates/financial-aid/src/fields/MissingFiles/FileList/FileList.tsx Updated prop type for files to use deprecated file upload type.
libs/application/templates/financial-aid/src/fields/Summary/SummaryForm.tsx Updated function parameter type to use deprecated file upload type.
libs/application/templates/financial-aid/src/lib/hooks/useFileUpload.ts
apps/financial-aid/web-osk/src/utils/hooks/useFileUpload.ts
Updated hook signatures and internal usage to deprecated file upload types.
libs/application/templates/financial-aid/src/lib/utils.ts
libs/application/ui-components/src/utilities/FileUploadController/utils.ts
Updated function parameter types to use deprecated file upload types.
libs/portals/admin/signature-collection/src/lib/utils.ts Updated utility function to use deprecated file upload types and utility.
libs/application/templates/official-journal-of-iceland/src/hooks/useFileUpload.ts Updated hook to use deprecated file upload types throughout.
libs/application/ui-components/src/utilities/FileUploadController/index.tsx Updated to use deprecated file upload types and components; minor formatting changes.
libs/application/ui-fields/src/lib/FileUploadFormField/FileUploadFormField.tsx Updated type annotations to use deprecated file upload type.
apps/judicial-system/web/src/utils/hooks/useS3Upload/useS3Upload.ts Replaced string status literals with FileUploadStatus enum.
apps/judicial-system/web/src/components/AccordionItems/IndictmentsCaseFilesAccordionItem/...
apps/judicial-system/web/src/routes/...
Standardized status handling to use FileUploadStatus enum and updated file upload component prop names.
libs/portals/admin/regulations-admin/src/components/EditSignature.tsx
libs/portals/admin/signature-collection/src/screens-presidential/List/components/paperUpload/index.tsx
libs/portals/admin/signature-collection/src/shared-components/compareLists/index.tsx
Switched file upload component usage to deprecated version.
libs/application/templates/aosh/seminars/src/fields/Participants/index.tsx
libs/application/templates/official-journal-of-iceland/src/fields/Attachments.tsx
libs/application/templates/official-journal-of-iceland/src/fields/Original.tsx
Updated to use deprecated file upload component and types.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FileUploadComponent
    participant AppState

    User->>FileUploadComponent: Selects or drags file(s)
    FileUploadComponent->>AppState: Calls onChange with file list (deprecated or current type)
    AppState->>FileUploadComponent: Renders files with status (enum or string)
    User->>FileUploadComponent: Clicks remove/retry/open
    FileUploadComponent->>AppState: Calls onRemove/onRetry/onOpenFile callbacks
Loading

Suggested labels

deprecated:automerge

Suggested reviewers

  • albinagu
  • thorhildurt

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9824f48 and de9000e.

📒 Files selected for processing (1)
  • apps/judicial-system/web/src/routes/Shared/AddFiles/AddFiles.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/judicial-system/web/src/routes/Shared/AddFiles/AddFiles.tsx
⏰ Context from checks skipped due to timeout of 90000ms (48)
  • GitHub Check: build (application-system-form)
  • GitHub Check: build (consultation-portal)
  • GitHub Check: build (island-ui-storybook)
  • GitHub Check: build (api)
  • GitHub Check: build (services-auth-personal-representative)
  • GitHub Check: build (portals-admin)
  • GitHub Check: build (system-e2e)
  • GitHub Check: build (reference-next-app)
  • GitHub Check: build (financial-aid-api,financial-aid-backend,financial-aid-open-api,financial-aid-web-osk,finan...
  • GitHub Check: build (skilavottord-web)
  • GitHub Check: build (web)
  • GitHub Check: tests (web)
  • GitHub Check: build (contentful-apps,contentful-role-permissions)
  • GitHub Check: build (service-portal)
  • GitHub Check: build (payments)
  • GitHub Check: build (services-payments)
  • GitHub Check: build (application-system-api)
  • GitHub Check: tests (skilavottord-web)
  • GitHub Check: build (judicial-system-web)
  • GitHub Check: tests (service-portal)
  • GitHub Check: build (air-discount-scheme-web)
  • GitHub Check: tests (shared-components,shared-connected,shared-form-fields)
  • GitHub Check: tests (react-components,react-feature-flags,react-spa-bff,react-spa-shared)
  • GitHub Check: tests (form-system-graphql)
  • GitHub Check: tests (reference-next-app)
  • GitHub Check: tests (island-ui-contentful,island-ui-core)
  • GitHub Check: tests (portals-admin,portals-admin-air-discount-scheme,portals-admin-application-system,portals-a...
  • GitHub Check: tests (services-payments)
  • GitHub Check: tests (delegation-admin)
  • GitHub Check: tests (judicial-system-web)
  • GitHub Check: tests (fiancial-statement-individual-election)
  • GitHub Check: tests (native-app)
  • GitHub Check: tests (api,api-domains-application,api-domains-municipalities-financial-aid,api-domains-payment,a...
  • GitHub Check: tests (services-auth-personal-representative)
  • GitHub Check: tests (air-discount-scheme-web)
  • GitHub Check: tests (financial-aid-api,financial-aid-backend,financial-aid-open-api,financial-aid-shared,financ...
  • GitHub Check: tests (application-api-core,application-api-files,application-api-history,application-api-payment...
  • GitHub Check: tests (contentful-apps,contentful-role-permissions)
  • GitHub Check: tests (clients-charge-fjs-v2,clients-municipalities-financial-aid,clients-payments)
  • GitHub Check: tests (payments)
  • GitHub Check: tests (my-pages-air-discount)
  • GitHub Check: tests (example-common-actions,example-inputs,example-no-inputs,example-payment,example-state-tran...
  • GitHub Check: tests (application-system-api)
  • GitHub Check: tests (consultation-portal)
  • GitHub Check: e2e (financial-aid-web-osk)
  • GitHub Check: linting-workspace
  • GitHub Check: linting (consultation-portal,financial-aid-web-osk,financial-aid-web-osk-e2e,judicial-system-web,...
  • GitHub Check: formatting

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

nx-cloud bot commented Apr 15, 2025

View your CI Pipeline Execution ↗ for commit de9000e.

Command Status Duration Result
nx run-many --projects application-api-core,app... ✅ Succeeded 12m 36s View ↗
nx run-many --target=build --projects=web --par... ✅ Succeeded 10m 16s View ↗
nx run-many --target=build --projects=judicial-... ✅ Succeeded 4m 43s View ↗
nx run-many --projects judicial-system-web --ta... ✅ Succeeded 3m 50s View ↗
nx run-many --projects react-components,react-f... ✅ Succeeded 2s View ↗
nx run-many --projects portals-admin,portals-ad... ✅ Succeeded 14s View ↗
nx run-many --projects shared-components,shared... ✅ Succeeded 1s View ↗
nx run-many --projects delegation-admin --targe... ✅ Succeeded 1s View ↗
Additional runs (42) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-04-23 13:55:37 UTC

@datadog-island-is
Copy link

datadog-island-is bot commented Apr 15, 2025

Datadog Report

All test runs ef9b431 🔗

10 Total Test Services: 0 Failed, 9 Passed

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Test Service View
application-api-files 0 0 0 2 0 11.25s Link
application-core 0 0 0 97 0 22.44s Link
application-template-api-modules 0 0 0 30 0 5m 3.14s Link
application-templates-accident-notification 0 0 0 140 0 24.99s Link
application-templates-criminal-record 0 0 0 2 0 16.66s Link
application-templates-driving-license 0 0 0 13 0 17.87s Link
application-templates-financial-aid 0 0 0 11 0 20.07s Link
application-templates-general-petition 0 0 0 5 0 17.23s Link
application-templates-health-insurance 0 0 0 0 0 2.5s Link
application-templates-mortgage-certificate 0 0 0 3 0 19.61s Link

@oddsson oddsson changed the title UI/refactor input file upload chore(island-ui): Refactor InputFileUpload component Apr 16, 2025
@oddsson oddsson marked this pull request as ready for review April 16, 2025 09:42
@oddsson oddsson requested review from a team as code owners April 16, 2025 09:42
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 (1)
libs/island-ui/core/src/lib/InputFileUpload/InputFileUpload.tsx (1)

101-111: Improved truncateMiddle function no longer depends on external hooks

This implementation is more efficient as it no longer relies on the useMeasure hook as mentioned in the PR objectives. However, the maxLength is hardcoded which might not be ideal for all scenarios.

Consider making the maxLength configurable through props to handle different UI contexts:

-  const truncateMiddle = (fileName: string) => {
+  const truncateMiddle = (fileName: string, maxLength = 40) => {
-    const maxLength = 40
    if (fileName.length <= maxLength) return fileName
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4867de0 and b1962c8.

📒 Files selected for processing (2)
  • apps/judicial-system/web/src/components/AccordionItems/IndictmentsCaseFilesAccordionItem/IndictmentsCaseFilesAccordionItem.spec.tsx (4 hunks)
  • libs/island-ui/core/src/lib/InputFileUpload/InputFileUpload.tsx (8 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/judicial-system/web/src/components/AccordionItems/IndictmentsCaseFilesAccordionItem/IndictmentsCaseFilesAccordionItem.spec.tsx
🧰 Additional context used
📓 Path-based instructions (1)
`libs/**/*`: "Confirm that the code adheres to the following: - Reusability of components and hooks across different NextJS apps. - TypeScript usage for defining props and exportin...

libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
  • libs/island-ui/core/src/lib/InputFileUpload/InputFileUpload.tsx
🔇 Additional comments (9)
libs/island-ui/core/src/lib/InputFileUpload/InputFileUpload.tsx (9)

59-64: Improved icon management with a dedicated interface

This new Icons interface provides a centralized way to manage and customize icons, making the component more flexible and maintainable. This is a good replacement for the previous doneIcon prop mentioned in the PR objectives.


76-90: Good use of default values for icons

The component now provides sensible defaults for icons while allowing consumers to override any individual icon if needed. This implementation aligns well with the PR objective of making the component more flexible.


92-99: Well-designed event handler abstraction

This handleClick function effectively reduces code duplication by centralizing event handling logic. It properly handles event propagation and conditionally calls the appropriate handler.


113-127: Enhanced file size formatting with appropriate units

The new formatFileSize function is a significant improvement as stated in the PR objectives. It now correctly handles different size units (B, KB, MB, GB) with appropriate precision.


184-186: Improved file name and size display

Good implementation of the truncated file name and size formatting. The condition properly checks that file.size is a number before attempting to format it.


190-190: Space between icon and text

This intentional space between the icon and text improves readability, as confirmed in the previous review comments.


229-248: Improved props interface with better naming and organization

The props interface has been significantly improved:

  • Added required name prop for better accessibility
  • Renamed fileList to files and header to title for clarity
  • Added comments clarifying the units for maxSize
  • Included the new hideIcons prop for more flexibility

These changes align with the PR objective of simplifying the component's props.


316-316: Fixed style prop usage

The style is now correctly passed to getRootProps, addressing the issue identified in previous review comments.


344-344: Improved accessibility with proper input attributes

Using the name prop for both id and name attributes on the input element improves form handling and accessibility, as it ensures the input can be properly associated with its label.

@oddsson oddsson requested a review from jonnigs April 22, 2025 12:32
Copy link
Member

@thorkellmani thorkellmani left a comment

Choose a reason for hiding this comment

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

LGTM

@oddsson oddsson force-pushed the ui/refactor-input-file-upload branch from cbcbc05 to b1962c8 Compare April 22, 2025 12:43
…or-input-file-upload

	# Please enter a commit message to explain why this merge is necessary,
	# especially if it merges an updated upstream into a topic branch.
	#
	# Lines starting with '#' will be ignored, and an empty message aborts
	# the commit.
Copy link
Member

@magnearun magnearun left a comment

Choose a reason for hiding this comment

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

Core files lgtm

@oddsson oddsson removed request for snaerth and jonnigs April 22, 2025 14:45
@unakb unakb added this pull request to the merge queue Apr 25, 2025
Merged via the queue into main with commit 16c13df Apr 25, 2025
73 checks passed
@unakb unakb deleted the ui/refactor-input-file-upload branch April 25, 2025 16:25
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.