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

Remove "context" prop from visualizations #4789

Merged
merged 2 commits into from
Apr 13, 2020

Conversation

gabrieldutra
Copy link
Member

What type of PR is this? (check all applicable)

  • Refactor

Description

Use a Table visualization option instead (it was the only lib that used that prop)

Related Tickets & Documents

--

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

--

@gabrieldutra gabrieldutra self-assigned this Apr 8, 2020
@@ -120,7 +120,7 @@ export default function Renderer({ options, data, context }) {
columns={tableColumns}
dataSource={preparedRows}
pagination={{
size: context === "widget" ? "small" : "",
size: get(options, "paginationSize", ""),
Copy link
Collaborator

Choose a reason for hiding this comment

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

@gabrieldutra That's definitely a right direction, but let's improve it even more. Let's not extent visualization's options, but instead pass a new prop (customOptions, rendererOptions, whatever) of type object. It will contain additional settings like paginationSize. VisualizationRenderer should also take this prop and just pass it to the Renderer.

And usage in widget component: <VisualizationRenderer ...(existing props) customOptions={{ paginationSize: "small" }}>

Copy link
Member Author

Choose a reason for hiding this comment

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

@kravets-levko I thought about that too, but somehow that's still a layout option for the Table visualization, although we don't offer it as a setting. So why not keep it it simple and leave it in the unified place for options instead of creating a new prop?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have some concerns about this solution.

First of all, visualization options object should contain only options that could be edited by user (not necessarily right now, we might have some "hidden" options that aren't available in UI, but they behave like other ones). That's not good if we introduce some "magic" option that comes from somewhere else than corresponding "getOptions" function. Furthermore, it's 2x bad when that option (which in fact depends on state of app that uses library) comes from a wrapper component where it's hard-coded and depends on visualization type. Therefore I suggested a new prop.

Regarding

which in fact depends on state of app that uses library

Pagination size depends on where visualization is used in the app, so in fact we still keep that "context" concept, but call it in a different way (we directly map context to paginationSize).

That's what my idea solves: if app needs to change pagination size, then app should tell about it. No any magic and hardcode in the library. Also, some of other visualizations have pagination as well (e.g. Details), so that custom option may be used there (BTW - good chance to implement it now 🙂). And the app is the only right place to decide when we need small pagination - library should just do what the app says.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll give some more time to think about that, but first I'll give you more details on why I went that way.

When thinking in isolated Renderer and Editor, there's not much of an "could be edited by user" concept. I was thinking of the Renderer by being a "you give the Type, the Data and the Options and it renders your component" (so in here the "options" seemed to just be the right place for it). Also there shouldn't be a problem on having this option on getOptions (and it probably should be there, it's just that I forgot to add it).

The way I was trying to think about it was: In an isolated, non-Redash app, what would be the way to provide the paginationSize as a setting. The "static" part of it is a Redash thing, thus there's the "hack" of making it a static option over the renderer options.

I see your point though, I'll give it some time to think, if it's really necessary I'll introduce a renderOptions or staticOptions in there too. I just don't want to give complexity on the Library use as I see it can be confusing since there's no clear difference between that new option and the "options" itself when you forget about the Redash use for it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you, now I see your point. I think we could end up with something between: for me it looks more or less fine to pass paginationSize among visualization options, BUT:

  1. it should be mentioned (with default value) in getOptions;
  2. there should be no special handling for it (I mean that IF in VisualizationRenderer). Let's move this logic upper, to Widget component - let widget extends visualization options with that new value and then passes it to VisualizationRenderer.

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. Done;
  2. It does seem to make sense, the problem is how things are structured now. VisualizationRenderer is the first component that is on the Redash app side, currently it takes a visualization object (not a data and options separately), so to extend it in there wee need to change the visualization object or refactor component props.

Currently EditVisualizationDialog and VisualizationRenderer are the ones on the Redash side that are abstracting visualizations for Redash use. I hope those become clearer once the separating process is done (and so we can rethink about how to structure such abstractions).

Copy link
Collaborator

@kravets-levko kravets-levko left a comment

Choose a reason for hiding this comment

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

Considering your last comment, I approve this PR. But let's keep in mind that we should revisit this thing after visualizations will be finally decoupled from Redash app

@gabrieldutra gabrieldutra merged commit c698359 into master Apr 13, 2020
@gabrieldutra gabrieldutra deleted the remove-context-from-visualizations branch April 13, 2020 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants