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

Plugin order #3100

Merged
merged 26 commits into from
Jan 27, 2021
Merged

Plugin order #3100

merged 26 commits into from
Jan 27, 2021

Conversation

mariusandra
Copy link
Collaborator

@mariusandra mariusandra commented Jan 27, 2021

Changes

Checklist

  • All querysets/queries filter by Organization, by Team, and by User
  • Django backend tests
  • Jest frontend tests
  • Cypress end-to-end tests

@timgl timgl temporarily deployed to posthog-plugin-order-fkfcb5veq January 27, 2021 06:55 Inactive
@mariusandra mariusandra temporarily deployed to posthog-plugin-order-fkfcb5veq January 27, 2021 08:21 Inactive
@mariusandra mariusandra temporarily deployed to posthog-plugin-order-fkfcb5veq January 27, 2021 09:06 Inactive
@mariusandra mariusandra temporarily deployed to posthog-plugin-order-fkfcb5veq January 27, 2021 09:38 Inactive
@mariusandra
Copy link
Collaborator Author

This is ready for a first look (some test to fix still?)! Please definitely give feedback on the design and UX. The main bit that changed in this PR is the ordering:

2021-01-27 10 38 58

Some comments (and replies to PostHog/plugin-server#102):

  • I did in the end split this to two sections: enabled and installed plugins. Playing with it, it seems to work quite well. I think that in situations where you have a lot of installed plugins (e.g. the cloud?), splitting enabled/installed still makes some sense and also makes the ordering logic easier to explain.
  • You must confirm the order after rearranging. This is mostly to prevent mistakes, as the accidentally dragging and rearranging the plugins could have consequences
  • All newly enabled plugins start out at the end of the list. It's quite easy to move them up.

Other flyby changes with this PR:

  • Renamed the tab "Custom" to "Advanced"
  • Moved the "opt out of plugins" button into a "danger zone" on the "advanced" tab from the top-right of the page (this prompted the rename of the tab)
  • Added an empty state for the installed page with a link to the repository

@mariusandra mariusandra marked this pull request as ready for review January 27, 2021 09:47
@mariusandra mariusandra temporarily deployed to posthog-plugin-order-fkfcb5veq January 27, 2021 09:47 Inactive
@yakkomajuri
Copy link
Contributor

Immediate thought is that the plugins page is getting a little too crowded - not that massive of a problem at this stage though

Copy link
Collaborator

@Twixes Twixes left a comment

Choose a reason for hiding this comment

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

This looks really good, just a few nitpicks.

These arrows are kind of confusing, why are some above and some below?

Screen Shot 2021-01-27 at 11 05 16

As a side note, will this reliably order processing now or is there something to do in the plugin server too?

posthog/api/plugin.py Outdated Show resolved Hide resolved
posthog/api/plugin.py Outdated Show resolved Hide resolved
posthog/api/plugin.py Outdated Show resolved Hide resolved
frontend/src/scenes/plugins/utils.ts Outdated Show resolved Hide resolved

const move = (arr: PluginTypeWithConfig[], from: number, to: number): { id: number; order: number }[] => {
const clone = [...arr]
Array.prototype.splice.call(clone, to, 0, Array.prototype.splice.call(clone, from, 1)[0])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why on Array.prototype.splice instead of just clone?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, not sure I fully understand the question here :).

We need to clone, since .splice alters the array. The splice code itself is from a react-sortable-hoc demo and it's the shortest accurate reordering code I've found some far.

@mariusandra mariusandra temporarily deployed to posthog-plugin-order-fkfcb5veq January 27, 2021 11:26 Inactive
@mariusandra
Copy link
Collaborator Author

I fixed the nits as well as I could. Not sure about the clone/splice question though.

Regarding the arrows, The last 3 icon has an arrow above it to show that it's the last one in the queue. Without it there, the "v" below all the other numbers will just look a bit out of place and not leave the impression that it's a queue. Please feel free to suggest something nicer looking! I have two left hands for these things.

I also added one more flyby. Now when updates are available, clicking on the tag for Github and Gitlab plugins will open a diff comparing what exactly changed in the code:
image

@mariusandra
Copy link
Collaborator Author

And yes, we need a PR for plugin-server as well to use the new order. To be addressed separately...

Copy link
Collaborator

@Twixes Twixes left a comment

Choose a reason for hiding this comment

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

👍
A few nitpicks too, but do as you wish about them.

frontend/src/scenes/plugins/plugin/PluginCard.tsx Outdated Show resolved Hide resolved
@@ -310,18 +310,21 @@ def global_plugins(self, request: request.Request, **kwargs):
@action(methods=["PATCH"], detail=False)
def rearrange(self, request: request.Request, **kwargs):
if not can_configure_plugins_via_api(self.team.organization_id):
return Response([])
return Response(status=403)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I may totally be in the wrong, but if we're not returning anything here, raise PermissionDenied may work better (error message and all).

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 added a raise ValidationError("Plugin configuration via the web is disabled!"). Not sure if that's the right error, but this same line was used a few lines higher in the code, and all errors dispatched here are those. Maybe something to check another time. I'll merge it now though if/when the tests pass.

@mariusandra mariusandra temporarily deployed to posthog-plugin-order-fkfcb5veq January 27, 2021 16:24 Inactive
@mariusandra mariusandra merged commit 9cfd196 into master Jan 27, 2021
@mariusandra mariusandra deleted the plugin-order branch January 27, 2021 16:43
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.

None yet

4 participants