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

Support type-checking on spreadsheet fields (part 1) #3093

Merged

Conversation

jfdoming
Copy link
Contributor

@jfdoming jfdoming commented Jul 18, 2024

This PR (along with the subsequent ones, see follow-up PRs for parts 2 and 3) adds stricter types to the "spreadsheet" utilities used in the app. The ultimate goal is to convert src/components/accounts/Account.jsx to Typescript (see previous attempt here along with comments). In terms of types being added, the approach taken is to add types field-by-field, and require field names to be present in a type map (see the SpreadsheetFieldTypes type added in this PR).

Since this is a large change, the approach taken for rollout is to add generic types in this PR, initially default them to any, and finally remove the defaults in the last PR. Please see this link for a collapsed version of all the PRs.

Feedback on the approach (rollout or typing) welcome!

Copy link

netlify bot commented Jul 18, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 0d6297b
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/66aad34181623700083ab116
😎 Deploy Preview https://deploy-preview-3093.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Jul 18, 2024

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
9 4.8 MB → 4.8 MB (+217 B) +0.00%
Changeset
File Δ Size
src/components/spreadsheet/index.ts 🆕 +68 B 0 B → 68 B
home/runner/work/actual/actual/packages/loot-core/src/client/queries.ts 📈 +126 B (+1.84%) 6.68 kB → 6.8 kB
src/components/table.tsx 📈 +23 B (+0.09%) 24.25 kB → 24.28 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 3.04 MB → 3.04 MB (+217 B) +0.01%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/resize-observer.js 18.37 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/narrow.js 78.3 kB 0%
static/js/usePreviewTransactions.js 790 B 0%
static/js/AppliedFilters.js 27.61 kB 0%
static/js/wide.js 277.31 kB 0%
static/js/ReportRouter.js 1.23 MB 0%

Copy link
Contributor

github-actions bot commented Jul 18, 2024

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.14 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.14 MB 0%

@jfdoming jfdoming force-pushed the jfdoming/strict-binding-types-part-1 branch from 5b1ccd9 to 4831db2 Compare July 18, 2024 06:46
Comment on lines 25 to 28
// eslint-disable-next-line @typescript-eslint/no-explicit-any
SheetName extends SheetNames = any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
FieldName extends SheetFields<SheetName> = any,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See PR description; the approach is to use any for a slow rollout and revert the use of any after the last PR in the stack is merged (3 PRs, can all be merged around the same time).

Copy link
Contributor

@joel-jeremy joel-jeremy left a comment

Choose a reason for hiding this comment

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

This is nice!

@@ -722,7 +745,7 @@ export function SheetCell({
}
textAlign={textAlign}
{...props}
value={sheetValue}
value={(sheetValue ?? '').toString()}
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this work here?

Suggested change
value={(sheetValue ?? '').toString()}
value={String(sheetValue)}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think for null this would return 'null' instead of '', I think we probably want '' here?

packages/loot-core/src/client/queries.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@joel-jeremy joel-jeremy left a comment

Choose a reason for hiding this comment

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

LGTM!

@jfdoming jfdoming merged commit e0d7233 into actualbudget:master Aug 3, 2024
19 checks passed
@jfdoming jfdoming deleted the jfdoming/strict-binding-types-part-1 branch August 3, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants