Skip to content
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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,13 @@
"default": "usage",
"enum": [
"usage",
"name"
"name",
"config"
],
"enumDescriptions": [
"Sort actions by most recently used",
"Sort actions alphabetically by name"
"Sort actions alphabetically by name",
"Sort actions in the order they are defined in the configuration, regardless of their origin"
],
"description": "Determine how actions should be sorted in the action selection menu"
},
Expand Down
33 changes: 17 additions & 16 deletions src/ui/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,25 +670,26 @@ export async function getAllAvailableActions(targets: ActionTarget[], scheme: st
});

// Get the sort preference from settings
const sortBy = IBMi.connectionManager.get<string>(`sortActionsBy`) || `usage`;
const sortBy = IBMi.connectionManager.get<'name'|'usage'|'config'>(`sortActionsBy`) || `usage`;

// Then we get all the available Actions for the current context
const availableActions: AvailableAction[] = allActions.filter(action => action.type === scheme)
const contextActions = allActions.filter(action => action.type === scheme)
.filter(action => !action.extensions || action.extensions.every(e => !e) || targets.every(t => action.extensions!.includes(t.extension) || action.extensions!.includes(t.fragment)) || action.extensions.includes(`GLOBAL`))
.filter(action => action.runOnProtected || !targets.some(t => t.protected))
.sort((a, b) => {
if (sortBy === `name`) {
// Sort alphabetically by name
return a.name.localeCompare(b.name);
} else {
// Sort by most recently used (default behavior)
return (actionUsed.get(b.name) || 0) - (actionUsed.get(a.name) || 0);
}
})
.map(action => ({
label: action.name,
action
}));
.filter(action => action.runOnProtected || !targets.some(t => t.protected));

if (sortBy === `name`) {
// Sort alphabetically by name
contextActions.sort((a, b) => a.name.localeCompare(b.name));
} else if (sortBy === `usage`) {
// Sort by most recently used (default behavior).
// `config` keeps actions in the order they are defined, regardless of their origin.
contextActions.sort((a, b) => (actionUsed.get(b.name) || 0) - (actionUsed.get(a.name) || 0));
}

const availableActions: AvailableAction[] = contextActions.map(action => ({
label: action.name,
action
}));

return availableActions;
}
Expand Down