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

[Maintenance] Migrating util.js and chartTheme.js to typescript #2009

Merged
merged 31 commits into from
Dec 6, 2023

Conversation

ghosetuhin
Copy link
Contributor

@ghosetuhin ghosetuhin commented Dec 2, 2023

Link to issue: #1483

Replaced util.js with util.ts

  • Added data types when easily inferrable to the functions in the file
  • Fixed lint errors which were created during changes

Replaced chart-theme.js with chart-theme.ts

  • Created types for all the different styles being used
  • Assigned data types to all the variables in the file

@trafico-bot trafico-bot bot added the 🚧 WIP label Dec 2, 2023
Copy link

netlify bot commented Dec 2, 2023

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 6930cf4
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/656fab8027315e000824f899
😎 Deploy Preview https://deploy-preview-2009.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 Dec 2, 2023

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
16 3.08 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
static/js/main.js 1.26 MB 0%
static/js/665.chunk.js 824.28 kB 0%
static/media/Inter-italic.var.woff2 239.29 kB 0%
static/media/Inter-roman.var.woff2 221.86 kB 0%
static/js/444.chunk.js 156.11 kB 0%
static/js/231.chunk.js 117.38 kB 0%
static/js/wide-components.chunk.js 114.8 kB 0%
static/js/reports.chunk.js 75.09 kB 0%
static/js/narrow-components.chunk.js 51.17 kB 0%
static/js/226.chunk.js 28.94 kB 0%
static/js/473.chunk.js 13 kB 0%
static/js/resize-observer-polyfill.chunk.js 8.88 kB 0%
static/css/main.css 7.41 kB 0%
asset-manifest.json 2.07 kB 0%
index.html 1.66 kB 0%
static/media/browser-server.js 911 B 0%

Copy link
Contributor

github-actions bot commented Dec 2, 2023

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
2 2.22 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.23 MB 0%
xfo.xfo.kcab.worker.js 1014.46 kB 0%

@ghosetuhin ghosetuhin changed the title [WIP][Maintenance] Migrating util.js and chartTheme.js to typescript [Maintenance] Migrating util.js and chartTheme.js to typescript Dec 4, 2023
Copy link
Member

@MatissJanis MatissJanis left a comment

Choose a reason for hiding this comment

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

👋 Hi @ghosetuhin ! Thanks for your first contribution! I left a couple of comments that I hope won't be too tricky for you to solve. And once they are solved I'll be happy to merge this PR :)

redFadeEnd: string;
};

let colorFades: ColorFades = {
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏this type is automatically inferred. There's no point in manually recreating it if we're not re-using it in multiple places.

Suggested change
let colorFades: ColorFades = {
let colorFades = {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! Made the changes!

stroke: string;
};

const baseLabelStyles: LabelStyles = {
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏same issue here

Suggested change
const baseLabelStyles: LabelStyles = {
const baseLabelStyles = {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it

tickLabels: LabelStyles;
};

const axisBaseStyles: AxisBaseStyles = {
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏and here

Suggested change
const axisBaseStyles: AxisBaseStyles = {
const axisBaseStyles = {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it

};
};

export const chartTheme: ChartTheme = {
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏and here

Suggested change
export const chartTheme: ChartTheme = {
export const chartTheme = {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it

};

export function getColorScale(name: string): string[] {
const scales: ColorScales = {
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏would be better to use an inline style here if we want to be super-strict. Although personally I wouldn't add a manual type to it. Up to you.

Suggested change
const scales: ColorScales = {
const scales: Record<string, string[]> = {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented it inline. Thanks for the suggestion!

@@ -13,23 +17,23 @@ export async function runAll(queries, cb) {
cb(data);
}

export function index(data, field, mapper) {
export function index(data, field: string, mapper?: (input) => unknown) {
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏could be improved with generics

Suggested change
export function index(data, field: string, mapper?: (input) => unknown) {
export function index<T, K extends keyof T>(data: T[], field: K, mapper?: (input: T[K]) => string) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please take a look at this. I implemented it using generics this time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the generics I implemented using the way you suggested were failing the type checks for some reason with the error Argument of type 'string' is not assignable to parameter of type 'never'. I tried playing around with it but couldn't fix it. Had to finally resort to using string as the type for some fields

const result = {};
data.forEach(item => {
result[mapper ? mapper(item[field]) : item[field]] = item;
});
return result;
}

export function indexStack(data, fieldName, field) {
export function indexStack(data, fieldName: string, field: string) {
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏this one and also indexCashFlow (below) could be improved with generics too.

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 tried implementing it for indexCashFlow but it is not taking generic types quite well

@trafico-bot trafico-bot bot added ⚠️ Changes requested Pull Request needs changes before it can be reviewed again and removed 🔍 Ready for Review labels Dec 4, 2023
@trafico-bot trafico-bot bot removed the ⚠️ Changes requested Pull Request needs changes before it can be reviewed again label Dec 4, 2023
@@ -13,23 +17,24 @@ export async function runAll(queries, cb) {
cb(data);
}

export function index(data, field, mapper) {
const result = {};
export function index<T>(data: T[], field: string, mapper?: (input) => string) {
Copy link
Member

Choose a reason for hiding this comment

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

Was a pretty fun problem to solve. Here you go: https://gist.github.com/MatissJanis/307e49bbeec34f2975709e0ec3bc3100 :)

Copy link
Contributor Author

@ghosetuhin ghosetuhin Dec 5, 2023

Choose a reason for hiding this comment

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

Ah, I see. Thanks for this! I implemented these changes!!

Copy link
Member

@MatissJanis MatissJanis left a comment

Choose a reason for hiding this comment

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

Thanks!

@MatissJanis MatissJanis merged commit cde4551 into actualbudget:master Dec 6, 2023
19 checks passed
@trafico-bot trafico-bot bot added ✨ Merged Pull Request has been merged successfully and removed ✅ Approved labels Dec 6, 2023
FlorianLang06 pushed a commit to FlorianLang06/actual that referenced this pull request Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Merged Pull Request has been merged successfully
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants