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

[charts] Improve dataset typing #11372

Merged
merged 2 commits into from
Dec 18, 2023
Merged

Conversation

alexfauquette
Copy link
Member

When working on mui/material-ui#40107 I noticed null was not accepted as a data set value. This PR fixes this issue by allowing null and undefined.

On a larger topic, I think devs tend to put various things in the dataset. The result of their data fetching without preprocessing to enable rich tooltip for example. I'm wondering if the default type should be unknown such that they can put whatever they want in the dataset, and do stricter type-checking into formatters

@alexfauquette alexfauquette added the component: charts This is the name of the generic UI component, not the React module! label Dec 11, 2023
@mui-bot
Copy link

mui-bot commented Dec 11, 2023

Deploy preview: https://deploy-preview-11372--material-ui-x.netlify.app/

Generated by 🚫 dangerJS against 8dbaac7

Copy link
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

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

It's a nice improvement! 🙌

<...> I'm wondering if the default type should be unknown such that they can put whatever they want in the dataset, and do stricter type-checking into formatters

That's a very valid proposition. 👍
However, do you feel it is a problem now?
Because if it's not, then maybe we can wait for community confirmation (request for it) on this regard?
It should be too hard making the types more loose—possibly not a breaking change. 😃

import defaultizeValueFormatter from '../internals/defaultizeValueFormatter';
import { DefaultizedProps } from '../models/helpers';

let warnOnce = false;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let warnOnce = false;
let warnedOnce = false;

if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
warnOnce = true;
console.error([
`MUI-X charts: your dataset key "${dataKey}" is used for plotting line, but contains non number elements.`,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`MUI-X charts: your dataset key "${dataKey}" is used for plotting line, but contains non number elements.`,
`MUI-X charts: your dataset key "${dataKey}" is used for plotting line, but contains nonnumerical elements.`,

if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
warnOnce = true;
console.error([
`MUI-X charts: your dataset key "${dataKey}" is used for plotting bars, but contains non number elements.`,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`MUI-X charts: your dataset key "${dataKey}" is used for plotting bars, but contains non number elements.`,
`MUI-X charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`,

Copy link

@Hugoo Hugoo left a comment

Choose a reason for hiding this comment

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

lgtm 😅😇

@alexfauquette alexfauquette merged commit a3c5bf6 into mui:next Dec 18, 2023
17 checks passed
@alexfauquette alexfauquette deleted the fix-ts-dataset branch December 18, 2023 08:22
alexfauquette added a commit to alexfauquette/mui-x that referenced this pull request Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: charts This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants