Skip to content

Commit

Permalink
Improve selection handling when editing workflows
Browse files Browse the repository at this point in the history
- Improve the logic behind the selection when workflows are updated,
  moved or deleted.
  • Loading branch information
zenangst committed Jan 11, 2021
1 parent 918df8c commit 6d33313
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
29 changes: 26 additions & 3 deletions App/Sources/Features/GroupsFeatureController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ final class GroupsFeatureController: ActionController,

// MARK: Private methods

private func setSelectionToWorkflow(_ workflow: Workflow) {
workflowSelection = workflow.id
workflowSelections = workflowSelection
}

private func reload(_ groups: [ModelKit.Group]) {
groupsController.reloadGroups(groups)
subject.send(groups)
Expand Down Expand Up @@ -130,8 +135,8 @@ final class GroupsFeatureController: ActionController,
group.workflows.add(workflow)
try groups.replace(group)
reload(groups)
workflowSelection = group.workflows.last?.id
workflowSelections = workflowSelection
controller.workflowController.perform(.set(workflow: workflow))
setSelectionToWorkflow(workflow)
}

func workflowsFeatureController(_ controller: WorkflowsFeatureController,
Expand All @@ -149,6 +154,13 @@ final class GroupsFeatureController: ActionController,
didDeleteWorkflow workflow: Workflow) throws {
var group = try findGroup(for: workflow)
var groups = self.groupsController.groups
var newOffset: Int = 0

if let index = group.workflows.firstIndex(of: workflow),
group.workflows.count > 1 {
newOffset = max(index - 1, 0)
}

try group.workflows.remove(workflow)
try groups.replace(group)
reload(groups)
Expand All @@ -158,6 +170,12 @@ final class GroupsFeatureController: ActionController,
array.remove(at: index)
self.workflowSelections = array.joined(separator: ",")
}

if !group.workflows.isEmpty {
let workflow = group.workflows[newOffset]
controller.workflowController.perform(.set(workflow: workflow))
setSelectionToWorkflow(workflow)
}
}

func workflowsFeatureController(_ controller: WorkflowsFeatureController,
Expand All @@ -180,9 +198,14 @@ final class GroupsFeatureController: ActionController,
group.workflows.add(workflow)
try groups.replace(group)
reload(groups)

controller.workflowController.perform(.set(workflow: workflow))
setSelectionToWorkflow(workflow)
}

func workflowsFeatureController(_ controller: WorkflowsFeatureController, didTransferWorkflowIds workflowIds: Set<String>, toGroup group: ModelKit.Group) throws {
func workflowsFeatureController(_ controller: WorkflowsFeatureController,
didTransferWorkflowIds workflowIds: Set<String>,
toGroup group: ModelKit.Group) throws {
var newGroup = group
guard let groupId = groupSelection,
var currentGroup = groupsController.groups.first(where: { $0.id == groupId }) else {
Expand Down
4 changes: 2 additions & 2 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ targets:
base:
ASSETCATALOG_COMPILER_APPICON_NAME: "AppIcon"
CODE_SIGN_IDENTITY: "-"
CURRENT_PROJECT_VERSION: 24
CURRENT_PROJECT_VERSION: 25
INFOPLIST_FILE: "App/Resources/Info.plist"
MARKETING_VERSION: 0.7.1
MARKETING_VERSION: 0.7.2
PRODUCT_BUNDLE_IDENTIFIER: "com.zenangst.Keyboard-Cowboy"
PRODUCT_NAME: "Keyboard Cowboy"
ENABLE_HARDENED_RUNTIME: true
Expand Down

0 comments on commit 6d33313

Please sign in to comment.