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

feat: Dynamic most recent date filter #1291

Merged
merged 4 commits into from
Dec 8, 2023

Conversation

bprusinowski
Copy link
Collaborator

@bprusinowski bprusinowski commented Dec 4, 2023

This PR:

  • changes the configurator temporal filters to use date pickers instead of select elements (to be consistent with interactive filters where this is already the case),
  • introduces a "pin to most recent date" feature to configurator temporal filters, to make a published chart always show the maximum available date as default.

TODO

  • 🎨 UI of the feature will need to be adjusted once we have design ready

Context

For the description of the technical approach see this Notion document.

How to test

⚠️ Part of testing is only possible if you have a control over a test cube in Cube Creator!

  1. Start making a chart using the cube you own that contains a temporal dimension. Use deployment preview link.
  2. See that the application now uses date picker instead of select element to select the filter value.
  3. See that it's possible to pin the temporal dimension filter to most recent value.
Screenshot 2023-12-05 at 11 23 44
  1. Publish the chart.
  2. Update the cube to contain more recent date.
  3. See that the published chart updated to this date.

Copy link

vercel bot commented Dec 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
visualization-tool ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 8, 2023 3:48pm

@bprusinowski bprusinowski force-pushed the feat/most-recent-date-filter branch from 95d31ec to 058f82d Compare December 5, 2023 10:02
@bprusinowski bprusinowski force-pushed the feat/most-recent-date-filter branch from 058f82d to 323ce96 Compare December 5, 2023 10:05
@bprusinowski bprusinowski merged commit 610a170 into main Dec 8, 2023
4 of 5 checks passed
@bprusinowski bprusinowski deleted the feat/most-recent-date-filter branch December 8, 2023 15:49
@KerstinFaye
Copy link

@bprusinowski Could we adjust a little bit on the margins and paddings: https://www.figma.com/file/Hn9wvuEYLUmdJtg4KwZYUx/visualize.admin.ch---design?type=design&node-id=2151-136045&mode=design&t=eufhsDZ6QmDsMILm-4

@bprusinowski
Copy link
Collaborator Author

Sure, will do! :)

value: `${value.value}`,
};
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure I understand this 😓 Can you give me an example, or add a test 😁 ?

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'll add a test, but just to explain: possible filters coming from the backend do not return VISUALIZE_MAX_VALUE, but rather an actual date (e.g. 2023), so if we didn't replace it back with VISUALIZE_MAX_VALUE, we would potentially trigger an update that shouldn't happen (as in fact, the pinned date didn't change, but is still equal to VISUALIZE_MAX_VALUE). Maybe it would make sense to already do this replacement on the backend side? 🤔

Copy link
Collaborator

@ptbrowne ptbrowne left a comment

Choose a reason for hiding this comment

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

LGTM 👏 One unit test on buildFilters could be good ?

<MUISwitch
checked={usesMostRecentDate}
onChange={() =>
fieldProps.onChange({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Instead of relying on the state usesMOstRecentDate, I think it is preferrable to rely on the checked value coming in the 2nd argument of the callback. This way the function could be stable, and I think it'd be clearer since here you have to think "ok usesMostRecentDate is true, so when it is clicked it shuold be false, and the max date should be used". IN the callback, the checked parameter is already right, so I think it's clearer.

sparqlClient.query,
{ operation: "postUrlencoded" }
);
const maxValue = maxValueRaw?.[0]?.value?.value as string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Function could be extracted for clarity ? It could aso be memoized ?

It made me think that if we'd use react-query, we could cache the sparql client results. Then I remember that we are using urql for it's graphql abilities 🤷

Copy link
Collaborator Author

@bprusinowski bprusinowski Dec 14, 2023

Choose a reason for hiding this comment

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

Yup, it can be extracted 👍 But for memoization I am not sure how would you memoize it, I guess when it's extracted it's already "memoized"? (as we are not in the useMemo world here in the backend 😅)

@bprusinowski
Copy link
Collaborator Author

Thanks for the review @ptbrowne 🙇‍♂️ I'll try to tackle the changes this week, otherwise I'll make a note to myself to do it in the new year 😅

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