-
Notifications
You must be signed in to change notification settings - Fork 117
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
feat(chart-provider): add component to wrap charts #4236
base: main
Are you sure you want to change the base?
Conversation
|
🦋 Changeset detectedLatest commit: d1ec0b5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
{ | ||
"name": "@twilio-paste/chart-provider", | ||
"version": "0.0.0", | ||
"category": "data display", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure exactly what category we want to use for these charting components. What do you all think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless we are adding a new category related to visualisation, data display looks good
View your CI Pipeline Execution ↗ for commit d1ec0b5.
☁️ Nx Cloud last updated this comment at |
View your CI Pipeline Execution ↗ for commit 6a90b9c.
☁️ Nx Cloud last updated this comment at |
highchartsOptions: Highcharts.Options; | ||
pasteOptions?: never; | ||
} | ||
|
||
export type ChartProviderProps = HighchartsOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit redundant at this point as there is only one type but sets the groundwork for union types that will only allow users to either set pasteOptions
or highchartsOptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good future thinking
// eslint-disable-next-line object-shorthand | ||
redraw: function (this) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using highcharts you have to use these verbose functions and this syntax. Tried it other ways but just doesn't work :/
Size Change: +513 B (0%) Total Size: 1.12 MB
ℹ️ View Unchanged
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit d1ec0b5:
|
Paste
|
Project |
Paste
|
Branch Review |
feat-chart-context-provider
|
Run status |
|
Run duration | 01m 55s |
Commit |
|
Committer | Kristian Antrobus |
View all properties for this run ↗︎ |
Test results | |
---|---|
|
0
|
|
0
|
|
0
|
|
0
|
|
67
|
View all changes introduced in this branch ↗︎ |
{ | ||
"name": "@twilio-paste/chart-provider", | ||
"version": "0.0.0", | ||
"category": "data display", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless we are adding a new category related to visualisation, data display looks good
* The current chart type. Used to trigger rerenders of other components inside ChartProvider. | ||
* | ||
* @type {string} | ||
* @memberof ChartContextProps | ||
*/ | ||
chartType?: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how will this string be used to trigger re-renders or other components?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When working on the sandbox I found that custom components that rendered based on nested elements could not pick up changes to re-render.
Specifically for this I had a legend that would look at the current series and see if there was a marker symbol used to show the correct marker in the legend. When switching between chart types it would no cause a re-render due to react only shallow comparing the chart context object. Picking up the change in the chart type options and listening for that fixed the issue.
It is not needed for this release so I'm happy to leave out and investigate further if there is a better way to capture this to avoid a breaking change in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can leave this in since its very internal thing and probably will only cause minor change even if changed in future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I'd push for removing it until it's necessary and we're more certain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove it for now, it's not being currently used. I will make the change in an upcoming commit.
highchartsOptions: Highcharts.Options; | ||
pasteOptions?: never; | ||
} | ||
|
||
export type ChartProviderProps = HighchartsOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good future thinking
it("should render", () => { | ||
const { getByText, getByTestId } = render(<TestChartProvider>test</TestChartProvider>); | ||
expect(getByText("test")).toBeDefined(); | ||
expect(getByTestId("chart-provider").getAttribute("data-paste-element")).toEqual("CHART_PROVIDER"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: is this assertion adding anything that's not already being tested on line 41?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just making sure the children show up. A little unnecessary
getByTestId("change-to-column-btn").click(); | ||
}); | ||
|
||
expect(getByTestId("chart-type-paragraph").textContent).toEqual("The chart type in the context is: column"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: in addition to these tests, maybe some tests to ensure that all the context values get correctly passed down?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently chartType and options are the only ones being set. The options part is currently being tested as the redraw updates the chart type so I am testing that the modified options callback is working correctly and that the chartType gets updated.
We should keep expanding these tests though once we start adding in more options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple small comments, but code and stories look great! Are we leaving it as beta for now until more charting components are exported?
Co-authored-by: Nora Krantz <[email protected]>
…paste into feat-chart-context-provider
Adds the new component
ChartProvider
used to manage state for the child chart implementations.Added additional typedocs to the context attributes so developer understand the usage correctly when creating their own context providers or when using them in the custom components.
Added some storybooks and unit tests to be sure the callbacks and hooks function correctly.
Storybooks I am implementing a chart to fully test the context functions but the chart component is not included with this provider.