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

Add move action #340

Merged
merged 3 commits into from
May 7, 2024
Merged

Add move action #340

merged 3 commits into from
May 7, 2024

Conversation

3mcd
Copy link
Member

@3mcd 3mcd commented May 6, 2024

This PR adds a simple move action that moves pubs between stages.

The moves are immedately reflected (when run manually) in the UI. This was accomplished by adding a revalidateTag call in the actions framework code.

This PR also adds a fourth stageId parameter to the action run functions. This will allow actions to do work in the context of their stage. In this case, the stageId parameter is used to remove the pub from the stage where the action was run.

Issue(s) Resolved

Resolves #339

Test Plan

  • Open the stage editor page
  • Add the move action to a stage. Configure the action instance with the stage id of the stage you plan to move pubs into.
  • Create a pub or two in the stage.
  • Run the action manually on pub(s) you created. The pub should move into the new stage and the change should be immediately visible without a refresh.

@3mcd 3mcd requested review from tefkah, kalilsn and qweliant May 7, 2024 14:12
@3mcd 3mcd marked this pull request as ready for review May 7, 2024 14:12
@3mcd 3mcd force-pushed the em/move-action branch from ff7c759 to ee4c985 Compare May 7, 2024 14:12
config: z.object({
stage: z.string().describe("Destination stage"),
}),
description: "Move a pub to a different stage",
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding some indication its the id here would be nice

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call. I think I'll skip updating the description for now because we'll need to provide a custom dropdown that populates with the community's stages. But I can add a comment.

pubId: pub.id as PubsId,
stageId: config.stage as StagesId,
})
.execute();
Copy link
Member

Choose a reason for hiding this comment

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

I think this is movePub query is a good candidate for being extracted to a kysely helpers module (or just an existing lib/server module) since there are so many ways to do it, and one of them (updating rather than insert+delete) breaks our event listener.

Separately, do you know how doing these queries in a transaction compares to doing them in a CTE? Is it still a single request/response if you use a transaction?

Copy link
Member Author

@3mcd 3mcd May 7, 2024

Choose a reason for hiding this comment

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

I doubt it treats two operations any differently other than rolling them back in the event of an error, so its probably opening two "connections". I'm actually not sure if a CTE would be rolled back within a transaction. And furthermore I'm not sure if doing a destructive operation within a CTE is a good pattern or not just to save a round trip. It was my understanding that CTEs are mostly used for generating read-only views (e.g. in the case of a recursive query) used by the outer/primary portion of a query.

I'll pull the query out into a kysely helper.

Copy link
Member

@kalilsn kalilsn left a comment

Choose a reason for hiding this comment

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

Just added the cte change per our slack convo! Feel free to extract it but we can also do that later.

I also tested it out and it works well! I do think we should change the stage selection from a string to a list of stages by name, but there's a lot of ways we could do that so I can see why you'd want to wait on that. just saw your comment lol

@3mcd 3mcd merged commit fca322c into main May 7, 2024
7 checks passed
@3mcd 3mcd deleted the em/move-action branch May 7, 2024 23:21
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.

PubMover action
3 participants