Skip to content

FIX: position was being incorrectly allocated to new step #5

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

Merged
merged 1 commit into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create
if WorkflowStep.count == 0 || WorkflowStep.where(workflow_id: workflow_step.workflow_id).count == 0
workflow_step.position = 1
else
workflow_step.position = WorkflowStep.maximum(:position) + 1
workflow_step.position = WorkflowStep.where(workflow_id: workflow_step.workflow_id).maximum(:position).to_i + 1
end
end
if workflow_step.save
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ export default class WorkflowStepEditor extends Component {
});
this.router.transitionTo(
"adminPlugins.show.discourse-workflow-workflows.edit",
this.args.currentWorkflowStep.workflow_id
this.args.currentWorkflowStep.workflow_id,
{ queryParams: { refresh: true } }
);
} catch (e) {
this.args.currentWorkflowStep.setProperties(backupModel);
Expand Down Expand Up @@ -88,7 +89,8 @@ export default class WorkflowStepEditor extends Component {
// this.args.currentWorkflowSteps.removeObject(this.args.currentWorkflowStep);
this.router.transitionTo(
"adminPlugins.show.discourse-workflow-workflows.edit",
this.args.currentWorkflowStep.workflow_id
this.args.currentWorkflowStep.workflow_id,
{ queryParams: { refresh: true } }
);
});
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import DiscourseRoute from "discourse/routes/discourse";

export default class AdminPluginsShowDiscourseWorkflowWorkflowEdit extends DiscourseRoute {
queryParams = {
refresh: { refreshModel: true },
};

async model(params) {
const allWorkflows = await this.modelFor(
"adminPlugins.show.discourse-workflow-workflows"
).content;
const id = parseInt(params.workflow_id, 10);
// return allWorkflows.find((workflow) => workflow.id === id);
return allWorkflows.findBy("id", id);
return this.store.find("workflow", id, { reload: true });
}

setupController(controller, model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ export default class AdminPluginsShowDiscourseWorkflowWorkflowStepsNew extends D
const workflow = this.modelFor(
"adminPlugins.show.discourse-workflow-workflows-steps"
);

const sortedSteps = [...workflow.workflow_steps].sort(
(a, b) => a.position - b.position
);

// Create a new workflow step record
// Asign a default position to be the last existing step + 1
const record = this.store.createRecord("workflow-step", {
workflow_id: workflow.id,
position:
workflow.workflow_steps.length > 0
? workflow.workflow_steps[workflow.workflow_steps.length - 1]
.position + 1
sortedSteps.length > 0
? sortedSteps[workflow.workflow_steps.length - 1].position + 1
: 1,
});

Expand Down
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ en:
next: "Next"
back: "Back"
finish: "Finish"
close: "Close"
reopen: "Reopen"
back: "Back"
save: "Save"
Expand Down
2 changes: 1 addition & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# name: discourse-workflow
# about: A topic-based workflow engine for Discourse
# version: 0.0.12
# version: 0.0.13
# authors: Robert Barrow
# contact_emails: robert@pavilion.tech
# url: https://github.com/merefield/discourse-workflow
Expand Down