Skip to content

Commit 30eed18

Browse files
author
andypalmi
committed
feat: add automation/add-tab action
Closes #200
1 parent bf79995 commit 30eed18

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

resources/expertAutomations.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ const GET_NODES = 'automation/get-nodes'
66
const EDIT_NODE = 'automation/open-node-edit'
77
const SEARCH = 'automation/search'
88
const ADD_FLOW_TAB = 'automation/add-flow-tab'
9+
const ADD_TAB = 'automation/add-tab'
910

1011
/**
11-
* @typedef {SELECT_NODES|GET_NODES|EDIT_NODE|SEARCH|ADD_FLOW_TAB} ExpertAutomationsActionsEnum
12+
* @typedef {SELECT_NODES|GET_NODES|EDIT_NODE|SEARCH|ADD_FLOW_TAB|ADD_TAB} ExpertAutomationsActionsEnum
1213
*/
1314

1415
export class ExpertAutomations extends ExpertActionsInterface {
@@ -98,6 +99,20 @@ export class ExpertAutomations extends ExpertActionsInterface {
9899
}
99100
}
100101
}
102+
,
103+
[ADD_TAB]: {
104+
params: {
105+
type: 'object',
106+
properties: {
107+
id: { type: 'string', description: 'Tab ID — auto-generated if omitted' },
108+
label: { type: 'string', description: 'Tab label' },
109+
disabled: { type: 'boolean', description: 'Create as disabled' },
110+
info: { type: 'string', description: 'Tab notes' },
111+
env: { type: 'array', description: 'Environment variables' }
112+
},
113+
required: ['label']
114+
}
115+
}
101116
})
102117

103118
/**
@@ -229,6 +244,24 @@ export class ExpertAutomations extends ExpertActionsInterface {
229244
return newTab
230245
}
231246

247+
/**
248+
* Add a new flow tab with an explicit ID and configuration.
249+
* @param {Object} tab - tab definition with id, label, disabled, info, env
250+
*/
251+
addTab (tab) {
252+
const ws = {
253+
type: 'tab',
254+
id: tab.id || this.RED.nodes.id(),
255+
label: tab.label,
256+
disabled: tab.disabled || false,
257+
info: tab.info || '',
258+
env: tab.env || []
259+
}
260+
this.RED.nodes.addWorkspace(ws)
261+
this.RED.workspaces.add(ws)
262+
this.RED.workspaces.show(ws.id)
263+
}
264+
232265
get supportedActions () {
233266
return this.actions
234267
}
@@ -300,6 +333,10 @@ export class ExpertAutomations extends ExpertActionsInterface {
300333
}
301334
break
302335

336+
case ADD_TAB:
337+
this.addTab(params)
338+
result.success = true
339+
break
303340
default:
304341
result.handled = false
305342
result.success = false

test/unit/resources/expertAutomations.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describeMain('expertAutomations', () => {
6565
it('should have supported actions', () => {
6666
const supportedActions = expertAutomations.supportedActions
6767
supportedActions.should.be.an.Object()
68-
supportedActions.should.only.have.keys('automation/get-nodes', 'automation/select-nodes', 'automation/open-node-edit', 'automation/search', 'automation/add-flow-tab')
68+
supportedActions.should.only.have.keys('automation/get-nodes', 'automation/select-nodes', 'automation/open-node-edit', 'automation/search', 'automation/add-flow-tab', 'automation/add-tab')
6969
})
7070
it('should have hasAction method', () => {
7171
expertAutomations.should.have.property('hasAction').which.is.a.Function()
@@ -323,5 +323,21 @@ describeMain('expertAutomations', () => {
323323
result.should.have.property('success', true)
324324
})
325325
})
326+
describe('addTab action', () => {
327+
it('should create a new tab', async () => {
328+
mockRED.nodes.addWorkspace = sinon.stub()
329+
mockRED.nodes.id = sinon.stub().returns('gen-id')
330+
mockRED.workspaces = { add: sinon.stub(), show: sinon.stub() }
331+
const result = {}
332+
await expertAutomations.invokeAction('automation/add-tab', {
333+
params: { label: 'My Tab' }
334+
}, result)
335+
mockRED.nodes.addWorkspace.calledOnce.should.be.true()
336+
const ws = mockRED.nodes.addWorkspace.firstCall.args[0]
337+
ws.should.have.property('label', 'My Tab')
338+
ws.should.have.property('type', 'tab')
339+
result.should.have.property('success', true)
340+
})
341+
})
326342
})
327343
})

0 commit comments

Comments
 (0)