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

Unify charts #368

Merged
merged 25 commits into from Dec 14, 2020
Merged

Unify charts #368

merged 25 commits into from Dec 14, 2020

Conversation

tleraj
Copy link
Collaborator

@tleraj tleraj commented Nov 23, 2020

This PR is scheduled to fix #354.

@tleraj tleraj marked this pull request as ready for review November 23, 2020 16:07
@ericboucher ericboucher changed the base branch from master to local-time November 23, 2020 23:41
Copy link
Collaborator

@Ry-DS Ry-DS left a comment

Choose a reason for hiding this comment

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

Looks good overall 👍 Maybe these suggestions might help improve this PR a little...

chartPeriod,
classes,
}: CombinedChartsProps) => {
const [open, setOpen] = useState<boolean>(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Type could be implicit, but this is fine too.

<CircularProgress size="6rem" thickness={1} />
</Box>
) : (
(spotterData && spotterData.bottomTemperature.length > 1 && (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional chaining might work here?

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 thought so too, but spotterData?.bottomTemperature.length gives an Object is possibly 'undefined' error.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I see, its because you cant compare undefined which could be returned by an optional chain with a number according to TS. We could leave this then 👍

packages/website/src/common/CombinedCharts/index.tsx Outdated Show resolved Hide resolved
packages/website/src/common/CombinedCharts/index.tsx Outdated Show resolved Hide resolved
@Ry-DS
Copy link
Collaborator

Ry-DS commented Nov 24, 2020

Maybe this component could be moved to common/Charts?

Base automatically changed from local-time to master December 1, 2020 23:28
const [open, setOpen] = useState<boolean>(false);
const spotterDataLoading = useSelector(reefSpotterDataLoadingSelector);

const spotterComponent = useCallback(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

When I mentioned simplifying the logic here, I was moreso thinking of having 3 booleans with simple, expressive names, so we know the 3 states this conditional can be in just by reading them.
For example:
const doShowLoading=....
const doShowSpotterData=...
const doShow...=....
then when rendering:
{doShowLoading &&<.../>}
{doShow... && <.../>}
etc.

So we don't have to do the logic in our heads when we read this haha.

I'm not sure about this callback however, as when I see this hook I think its a utility function, not a component.
If you think a component is best, maybe moving it outside and making it a proper component with its own props and everything would be nice. However if you think this would be a mess (there are quite a lot of props you'd have to pass down) my approach might work well too, you'll just have to think of some good logic for the booleans.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For the boolean approach, since the components are mutually exclusive, you might need to add extra logic to those 3 booleans to make sure only one ever will be true. Otherwise, if thats too complicated, you could just use the logic you have right now for the 3 booleans then do:
doShow... ? <.../> : doShow... ? <.../> : <../> Its a nested ternary, but since the boolean names make it easy to read, I think it won't be an issue :) Eric can weigh in on this.

Copy link
Collaborator

@Ry-DS Ry-DS Dec 9, 2020

Choose a reason for hiding this comment

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

@tleraj After a second look, I think we can just remove the useCallback and just rename spotterComponent to something more descriptive and in PascalCase so we can wrap this PR up 👍

useCallback would be perfect here if we were passing this component as a dependancy, but in its current state useCallback would likely actually worsen performance than improve it.
Doing this, and adding comments for the 3 if statements inside would be perfect!

Copy link
Collaborator Author

@tleraj tleraj Dec 9, 2020

Choose a reason for hiding this comment

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

@SimplyBallistic So I decided to use the boolean logic you mentioned above. I used the names spotterDataLoading, spotterDataSuccess and spotterDataError. Let me know if they sound good 🙂

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good! I would just add a prefix to the boolean names like *is*SpotterDataLoading

Copy link
Collaborator

@Ry-DS Ry-DS left a comment

Choose a reason for hiding this comment

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

Looks great! I did a quick commit to rename the booleans and just pass setOpen without a new function. Let me know if that's good with you 👍

@ericboucher ericboucher merged commit 55a6b89 into master Dec 14, 2020
@ericboucher ericboucher deleted the unify-charts branch December 14, 2020 02: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.

Combine Survey View and Reef Details Chart Components to one component
3 participants