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

RN-1130: Update types for dashboard item presentation options #5380

Merged
merged 25 commits into from
Feb 15, 2024

Conversation

alexd-bes
Copy link
Contributor

@alexd-bes alexd-bes commented Jan 25, 2024

Issue RN-1130: Update types for dashboard item presentation options

Changes:

  • Updated the types for dashboard item visualisations, mainly in presentationOptions. Cross referenced what we had in the database with what we had in the codebase
  • Updated ui-chart-components and tupaia-web to use the correct types

granularity?: ValueOf<typeof GRANULARITIES>;
startDate?: Moment | string;
endDate?: Moment | string;
granularity?: `${VizPeriodGranularity}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using a type like ${.....} makes the dev-x a little nicer because when you hover over the value it shows all the string values it could be

const { viewType } = config;
if (
viewType === 'multiValue' &&
'presentationOptions' in config &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a little annoying to have to type check for presentations every time they're used, and I did explore a util function but it ended up being not that useful since there are several different shapes of presentationOptions so I could never get the types exactly right in a generic function (mainly because if you have a union type and pass a key into a function as keyof the union type, it only gives you the common keys that apply to everything in that union type, not all the possible keys. Seemed more trouble than it was worth to make it work).

@@ -176,7 +180,8 @@ const MatrixVisual = () => {
return (
<>
<MatrixComponent
{...config}
// casting here because we know that the config is a MatrixConfig and it has a different shape than configs of other types, and while we know that this component only ever gets a MatrixConfig, the Matrix component doesn't know that as it all comes from the same context
{...(config as MatrixConfig)}
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 didn't really want to have to cast the type here, but I wasn't sure of a better way, since all the config is from a common context that has a union type for config

return {
...reportData,
...exportViewConfig,
} as ExportViewContent; // casting here to handle the different types of data that can be passed to the ExportViewContent component, which the union type doesn't cover well, and the fact that DashboardItemReport doesn't know when type is chart that it returns a ChartData type and not a ViewDataItem type etc
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not super stoked with having to cast here, but I was finding it really difficult when the data was different shapes, and the report type doesn't know that it is returning a chart report when type is chart, etc. Unsure if there is a better way?

Copy link
Collaborator

@rohan-bes rohan-bes left a comment

Choose a reason for hiding this comment

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

I promise I haven't forgotten this one!

I've been deep diving on it over the past couple days to try and make some changes. Gosh, this code is really complex to follow!

Wanna try tackle this together on Thursday?

@alexd-bes
Copy link
Contributor Author

I promise I haven't forgotten this one!

I've been deep diving on it over the past couple days to try and make some changes. Gosh, this code is really complex to follow!

Wanna try tackle this together on Thursday?

For sure! I know, it's complicated, took me almost a week to wade through it all and get everything building 😓

Copy link
Collaborator

@rohan-bes rohan-bes left a comment

Choose a reason for hiding this comment

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

Thanks for making these changes @alexd-bes 🙏
All looks good to me!

@alexd-bes alexd-bes merged commit 568bdfc into dev Feb 15, 2024
42 checks passed
@alexd-bes alexd-bes deleted the rn-1130-presentation-options branch February 15, 2024 01:45
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