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

[refactor] Update UI package to typescript #75

Merged
merged 14 commits into from
Oct 17, 2023

Conversation

2Steaks
Copy link
Collaborator

@2Steaks 2Steaks commented Oct 11, 2023

What?

This PR updates the UI package to use Typescript

Why?

Add type safety

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (go run mage.go lint) and all checks pass.
  • I have run tests locally (go run mage.go test) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

2Steaks and others added 5 commits October 10, 2023 11:24
- Create components directory
- Create store directory
- Add TS and config
- update model constructor types
- Refactored ui types
@2Steaks 2Steaks self-assigned this Oct 11, 2023
@CLAassistant
Copy link

CLAassistant commented Oct 11, 2023

CLA assistant check
All committers have signed the CLA.

@@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: 2023 Raintank, Inc. dba Grafana Labs
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would be interested to know if the class would allow generics so that we don't have to do this.

https://www.tutorialsteacher.com/typescript/typescript-generic-class


import { Section } from "@xk6-dashboard/view"

export interface Tab {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Could @xk6-dashboard/view export the Tab type?

Copy link
Collaborator

Choose a reason for hiding this comment

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

sure

Comment on lines -100 to -101
extra.push(color)
extra[name] = color
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I assume this was a mistake since extra is an array

Copy link
Collaborator

Choose a reason for hiding this comment

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

It was by intention, array may have properties as well, and in this way we can access colors by name. It is a bit hacky, but it started as JavaScript (not TS)... so feel free to refactor...

width: width,
height: 250,
title: panel.title,
cursor: { sync: { key: sync.key } },
legend: { live: false },
series: plot.series,
series: plot.series as Series[],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps we could find a way for SeriesPlot to return the correct type? Type 'object | undefined' is not assignable to type 'Series[]'

}

return (
<Grid ref={ref} className="chart panel" item md={12} lg={6}>
<UplotReact options={options} data={plot.data} onCreate={onCreate} />
<UplotReact options={options} data={plot.data as AlignedData} onCreate={onCreate} />
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps we could find a way for SeriesPlot to return the correct type? Type '(number | undefined)[][]' is not assignable to type 'AlignedData'.

width: width,
height: 32,
title: value,
series: plot.series,
series: plot.series as Series[],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps we could find a way for SeriesPlot to return the correct type? Type 'object | undefined' is not assignable to type 'Series[]'

@@ -59,12 +67,8 @@ export default function Stat({ panel }) {
{panel.title}
</Typography>
<div ref={ref}>
<UplotReact options={options} data={plot.data} />
<UplotReact options={options} data={plot.data as AlignedData} />
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Perhaps we could find a way for SeriesPlot to return the correct type? Type '(number | undefined)[][]' is not assignable to type 'AlignedData'.

@2Steaks 2Steaks requested a review from szkiba October 11, 2023 09:52
2Steaks and others added 9 commits October 11, 2023 13:09
@szkiba szkiba merged commit afb8e12 into master Oct 17, 2023
10 checks passed
@szkiba szkiba deleted the refactor/update-ui-to-typescript branch June 7, 2024 11:15
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