plugin-workflow-portainer 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/client/127.09e6675863ac8138.js +10 -0
  2. package/dist/client/57.67f04a547ead06b8.js +10 -0
  3. package/dist/client/981.e38099c59bf992f0.js +10 -0
  4. package/dist/client/index.js +1 -1
  5. package/dist/client-v2/127.9f65dc2e3d0df10a.js +10 -0
  6. package/dist/client-v2/57.a60e16e4b4e4fa28.js +10 -0
  7. package/dist/client-v2/981.8627062881ad83d1.js +10 -0
  8. package/dist/client-v2/index.js +1 -1
  9. package/dist/locale/en-US.json +43 -1
  10. package/dist/locale/vi-VN.json +43 -1
  11. package/dist/locale/zh-CN.json +43 -1
  12. package/dist/node_modules/joi/package.json +1 -1
  13. package/dist/server/actions/portainer.js +125 -0
  14. package/dist/server/plugin.js +8 -1
  15. package/dist/server/services/PortainerClient.js +177 -5
  16. package/dist/shared/env.js +19 -2
  17. package/package.json +2 -2
  18. package/src/client-v2/__tests__/workflow-registration.test.tsx +111 -1
  19. package/src/client-v2/components/PortainerSettingsPage.tsx +38 -2
  20. package/src/client-v2/components/PortainerTargetFields.tsx +10 -18
  21. package/src/client-v2/components/RedeployFieldset.tsx +2 -1
  22. package/src/client-v2/components/StackDetailDrawer.tsx +790 -0
  23. package/src/locale/en-US.json +43 -1
  24. package/src/locale/vi-VN.json +43 -1
  25. package/src/locale/zh-CN.json +43 -1
  26. package/src/server/__tests__/portainer-workflow.test.ts +105 -1
  27. package/src/server/actions/portainer.ts +167 -2
  28. package/src/server/plugin.ts +8 -1
  29. package/src/server/services/PortainerClient.ts +259 -2
  30. package/src/shared/env.ts +15 -0
  31. package/src/shared/types.ts +59 -0
  32. package/dist/client/127.5012da93825a6e5c.js +0 -10
  33. package/dist/client/57.ace9538136438718.js +0 -10
  34. package/dist/client/65.ec4a55173511c06d.js +0 -10
  35. package/dist/client-v2/127.0ec4dce7b13750e9.js +0 -10
  36. package/dist/client-v2/57.e7cfc50fb651ac14.js +0 -10
  37. package/dist/client-v2/65.9c745ea32ac96e98.js +0 -10
@@ -7,9 +7,14 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
+ import { Form } from 'antd';
11
+ import React from 'react';
12
+ import { renderToStaticMarkup } from 'react-dom/server';
10
13
  import PluginWorkflowPortainerClient from '../../client';
14
+ import { formatBytes } from '../components/StackDetailDrawer';
11
15
  import PluginWorkflowPortainerClientV2 from '../index';
12
16
  import { INSTRUCTION_GROUP_KEY, INSTRUCTION_TYPES } from '../../shared/constants';
17
+ import { isWorkflowVariableValue } from '../../shared/env';
13
18
 
14
19
  const runtimes = vi.hoisted(() => {
15
20
  class V1Instruction {}
@@ -22,18 +27,51 @@ vi.mock('@nocobase/client', () => ({ Plugin: class Plugin {} }));
22
27
  vi.mock('@nocobase/client-v2', () => ({
23
28
  Plugin: class Plugin {},
24
29
  ExtendCollectionsProvider: runtimes.ExtendCollectionsProvider,
25
- useApp: () => ({ i18n: { t: (key: string) => key } }),
30
+ useApp: () => ({
31
+ i18n: { t: (key: string) => key },
32
+ apiClient: { request: vi.fn(async () => ({ data: { data: [] } })) },
33
+ }),
26
34
  }));
27
35
  vi.mock('@nocobase/plugin-workflow/client', () => ({
28
36
  Instruction: runtimes.V1Instruction,
29
37
  }));
38
+ // Intentionally omit `isWorkflowVariableValue` to match NocoBase 2.2.49 runtime exports.
30
39
  vi.mock('@nocobase/plugin-workflow/client-v2', () => ({
31
40
  Instruction: runtimes.V2Instruction,
32
41
  defaultFieldNames: { value: 'value', label: 'label', children: 'children' },
42
+ WorkflowVariableInput: ({ placeholder }: { placeholder?: string }) => (
43
+ <input data-placeholder={placeholder ?? ''} readOnly />
44
+ ),
45
+ WorkflowVariableTextArea: ({ placeholder }: { placeholder?: string }) => (
46
+ <textarea data-placeholder={placeholder ?? ''} readOnly />
47
+ ),
48
+ WorkflowVariableJsonTextArea: ({ placeholder }: { placeholder?: string }) => (
49
+ <textarea data-placeholder={placeholder ?? ''} readOnly />
50
+ ),
51
+ WorkflowVariableWrapper: ({
52
+ value,
53
+ onChange,
54
+ render,
55
+ }: {
56
+ value?: unknown;
57
+ onChange?: (val: unknown) => void;
58
+ render: (props: { value?: unknown; onChange?: (val: unknown) => void }) => React.ReactNode;
59
+ }) => <>{render({ value, onChange })}</>,
33
60
  }));
34
61
  vi.mock('@ant-design/icons', () => ({
35
62
  CloudUploadOutlined: () => null,
36
63
  ClusterOutlined: () => null,
64
+ ReloadOutlined: () => null,
65
+ CloudDownloadOutlined: () => null,
66
+ DeleteOutlined: () => null,
67
+ PlusOutlined: () => null,
68
+ CheckCircleOutlined: () => null,
69
+ CloseCircleOutlined: () => null,
70
+ CodeOutlined: () => null,
71
+ FileTextOutlined: () => null,
72
+ PauseCircleOutlined: () => null,
73
+ PlayCircleOutlined: () => null,
74
+ EyeOutlined: () => null,
37
75
  }));
38
76
 
39
77
  function createStrictWorkflow(baseClass: new (...args: never[]) => object) {
@@ -129,4 +167,76 @@ describe('Portainer workflow dual-runtime client registration', () => {
129
167
  expect(addMenuItem).toHaveBeenCalledTimes(1);
130
168
  expect(addPageTabItem).toHaveBeenCalledTimes(1);
131
169
  });
170
+
171
+ it('loads and renders RedeployFieldset and ControlFieldset without relying on upstream isWorkflowVariableValue', async () => {
172
+ expect(isWorkflowVariableValue('{{$context.data.stackId}}')).toBe(true);
173
+ expect(isWorkflowVariableValue(' {{ $jobsMapByNodeKey.n1.endpointId }} ')).toBe(true);
174
+ expect(isWorkflowVariableValue(42)).toBe(false);
175
+ expect(isWorkflowVariableValue('plain-text')).toBe(false);
176
+
177
+ const workflow = createStrictWorkflow(runtimes.V2Instruction);
178
+ const pluginCtx = {
179
+ app: {
180
+ pm: { get: vi.fn(() => workflow) },
181
+ addProvider: vi.fn(),
182
+ },
183
+ pluginSettingsManager: {
184
+ addMenuItem: vi.fn(),
185
+ addPageTabItem: vi.fn(),
186
+ },
187
+ t: (key: string) => key,
188
+ };
189
+
190
+ await PluginWorkflowPortainerClientV2.prototype.load.call(pluginCtx as unknown as PluginWorkflowPortainerClientV2);
191
+
192
+ const redeployInst = workflow.instructions.get(INSTRUCTION_TYPES.redeploy) as {
193
+ FieldsetLoader: () => Promise<{ default: React.ComponentType }>;
194
+ };
195
+ const controlInst = workflow.instructions.get(INSTRUCTION_TYPES.control) as {
196
+ FieldsetLoader: () => Promise<{ default: React.ComponentType }>;
197
+ };
198
+
199
+ const { default: RedeployFieldset } = await redeployInst.FieldsetLoader();
200
+ const { default: ControlFieldset } = await controlInst.FieldsetLoader();
201
+
202
+ const redeployHtml = renderToStaticMarkup(
203
+ <Form
204
+ initialValues={{
205
+ config: {
206
+ mode: 'stack',
207
+ instanceId: 3,
208
+ endpointId: '{{$context.data.endpointId}}',
209
+ stackId: '{{$context.data.gitStackId}}',
210
+ envStrategy: 'merge',
211
+ envPairs: [{ name: 'IMAGE_TAG', value: '{{$context.data.imageTag}}', secret: false }],
212
+ },
213
+ }}
214
+ >
215
+ <RedeployFieldset />
216
+ </Form>,
217
+ );
218
+ expect(redeployHtml).toContain('Execution mode');
219
+ expect(redeployHtml).toContain('Target Stack');
220
+ expect(redeployHtml).toContain('Environment merge strategy');
221
+
222
+ const controlHtml = renderToStaticMarkup(
223
+ <Form
224
+ initialValues={{
225
+ config: {
226
+ action: 'inspect',
227
+ instanceId: 3,
228
+ endpointId: 1,
229
+ stackId: 2,
230
+ },
231
+ }}
232
+ >
233
+ <ControlFieldset />
234
+ </Form>,
235
+ );
236
+ expect(controlHtml).toContain('Stack operation');
237
+ expect(controlHtml).toContain('Target Stack');
238
+ expect(formatBytes(0)).toBe('0 B');
239
+ expect(formatBytes(1536)).toBe('1.5 KB');
240
+ expect(formatBytes(104857600)).toBe('100 MB');
241
+ });
132
242
  });
@@ -13,6 +13,7 @@ import {
13
13
  CheckCircleOutlined,
14
14
  DeleteOutlined,
15
15
  EditOutlined,
16
+ EyeOutlined,
16
17
  PlusOutlined,
17
18
  ReloadOutlined,
18
19
  } from '@ant-design/icons';
@@ -50,6 +51,7 @@ import {
50
51
  } from '../../shared/constants';
51
52
  import type { PortainerEndpointSummary, PortainerInstanceSummary, PortainerStackSummary } from '../../shared/types';
52
53
  import { useT } from '../locale';
54
+ import { StackDetailDrawer } from './StackDetailDrawer';
53
55
 
54
56
  interface InstanceFormValues {
55
57
  name: string;
@@ -82,6 +84,7 @@ export function PortainerSettingsPage() {
82
84
  const [selectedEndpointId, setSelectedEndpointId] = useState<number | undefined>(undefined);
83
85
  const [stacks, setStacks] = useState<PortainerStackSummary[]>([]);
84
86
  const [loadingStacks, setLoadingStacks] = useState(false);
87
+ const [selectedStack, setSelectedStack] = useState<PortainerStackSummary | null>(null);
85
88
 
86
89
  const loadInstances = useCallback(async () => {
87
90
  setLoading(true);
@@ -284,6 +287,7 @@ export function PortainerSettingsPage() {
284
287
 
285
288
  const openExplorer = (record: PortainerInstanceSummary) => {
286
289
  setExplorerInstance(record);
290
+ setSelectedStack(null);
287
291
  setSelectedEndpointId(undefined);
288
292
  loadExplorerData(record.id, undefined);
289
293
  };
@@ -442,6 +446,22 @@ export function PortainerSettingsPage() {
442
446
  key: 'envCount',
443
447
  width: 90,
444
448
  },
449
+ {
450
+ title: t('Actions'),
451
+ key: 'actions',
452
+ width: 105,
453
+ render: (_, st) => (
454
+ <Button
455
+ size="small"
456
+ htmlType="button"
457
+ icon={<EyeOutlined />}
458
+ aria-label={`${t('Detail')} ${st.name}`}
459
+ onClick={() => setSelectedStack(st)}
460
+ >
461
+ {t('Detail')}
462
+ </Button>
463
+ ),
464
+ },
445
465
  ];
446
466
 
447
467
  return (
@@ -621,8 +641,11 @@ export function PortainerSettingsPage() {
621
641
  <Drawer
622
642
  open={Boolean(explorerInstance)}
623
643
  title={explorerInstance ? `${t('Portainer Stacks')} — ${explorerInstance.name}` : t('Portainer Stacks')}
624
- onClose={() => setExplorerInstance(null)}
625
- width={780}
644
+ onClose={() => {
645
+ setSelectedStack(null);
646
+ setExplorerInstance(null);
647
+ }}
648
+ width={820}
626
649
  >
627
650
  <Flex gap="small" align="center" style={{ marginBottom: 16 }}>
628
651
  <Select
@@ -663,6 +686,19 @@ export function PortainerSettingsPage() {
663
686
  columns={stackColumns}
664
687
  pagination={{ pageSize: 15 }}
665
688
  />
689
+
690
+ <StackDetailDrawer
691
+ open={Boolean(selectedStack)}
692
+ instance={explorerInstance}
693
+ stack={selectedStack}
694
+ endpoints={endpoints}
695
+ onClose={() => setSelectedStack(null)}
696
+ onStackChanged={() => {
697
+ if (explorerInstance) {
698
+ loadExplorerData(explorerInstance.id, selectedEndpointId);
699
+ }
700
+ }}
701
+ />
666
702
  </Drawer>
667
703
  </Card>
668
704
  );
@@ -9,10 +9,11 @@
9
9
 
10
10
  import { ReloadOutlined } from '@ant-design/icons';
11
11
  import { useApp } from '@nocobase/client-v2';
12
- import { isWorkflowVariableValue, WorkflowVariableWrapper } from '@nocobase/plugin-workflow/client-v2';
12
+ import { WorkflowVariableWrapper } from '@nocobase/plugin-workflow/client-v2';
13
13
  import { Button, Flex, Form, InputNumber, Select, Tag } from 'antd';
14
14
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
15
15
  import { PORTAINER_RESOURCE } from '../../shared/constants';
16
+ import { isWorkflowVariableValue, toFiniteNumber } from '../../shared/env';
16
17
  import type { PortainerEndpointSummary, PortainerInstanceSummary, PortainerStackSummary } from '../../shared/types';
17
18
  import { useT } from '../locale';
18
19
 
@@ -66,7 +67,7 @@ export function PortainerInstanceField() {
66
67
  <Select
67
68
  allowClear
68
69
  loading={loading}
69
- value={typeof value === 'number' ? value : value ? Number(value) : undefined}
70
+ value={toFiniteNumber(value)}
70
71
  onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
71
72
  options={options}
72
73
  placeholder={t('Default Portainer instance')}
@@ -95,18 +96,9 @@ export function PortainerTargetFields({
95
96
  const endpointIsVar = isWorkflowVariableValue(watchedEndpointId);
96
97
  const stackIsVar = isWorkflowVariableValue(watchedStackId);
97
98
 
98
- const numericInstanceId =
99
- !instanceIsVar && watchedInstanceId !== null && typeof watchedInstanceId !== 'undefined' && watchedInstanceId !== ''
100
- ? Number(watchedInstanceId)
101
- : undefined;
102
- const numericEndpointId =
103
- !endpointIsVar && watchedEndpointId !== null && typeof watchedEndpointId !== 'undefined' && watchedEndpointId !== ''
104
- ? Number(watchedEndpointId)
105
- : undefined;
106
- const numericStackId =
107
- !stackIsVar && watchedStackId !== null && typeof watchedStackId !== 'undefined' && watchedStackId !== ''
108
- ? Number(watchedStackId)
109
- : undefined;
99
+ const numericInstanceId = toFiniteNumber(watchedInstanceId);
100
+ const numericEndpointId = toFiniteNumber(watchedEndpointId);
101
+ const numericStackId = toFiniteNumber(watchedStackId);
110
102
 
111
103
  const [endpoints, setEndpoints] = useState<PortainerEndpointSummary[]>([]);
112
104
  const [stacks, setStacks] = useState<PortainerStackSummary[]>([]);
@@ -231,7 +223,7 @@ export function PortainerTargetFields({
231
223
  instanceIsVar ? (
232
224
  <InputNumber
233
225
  min={1}
234
- value={typeof value === 'number' ? value : value ? Number(value) : undefined}
226
+ value={toFiniteNumber(value)}
235
227
  onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
236
228
  placeholder={t('Endpoint ID (e.g. 1)')}
237
229
  style={{ width: '100%' }}
@@ -243,7 +235,7 @@ export function PortainerTargetFields({
243
235
  showSearch
244
236
  optionFilterProp="searchLabel"
245
237
  loading={loadingEndpoints}
246
- value={typeof value === 'number' ? value : value ? Number(value) : undefined}
238
+ value={toFiniteNumber(value)}
247
239
  onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
248
240
  options={endpointOptions}
249
241
  placeholder={t('Auto-resolve from Stack or select environment')}
@@ -282,7 +274,7 @@ export function PortainerTargetFields({
282
274
  instanceIsVar || endpointIsVar ? (
283
275
  <InputNumber
284
276
  min={1}
285
- value={typeof value === 'number' ? value : value ? Number(value) : undefined}
277
+ value={toFiniteNumber(value)}
286
278
  onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
287
279
  placeholder={t('Stack ID (e.g. 12)')}
288
280
  style={{ width: '100%' }}
@@ -293,7 +285,7 @@ export function PortainerTargetFields({
293
285
  showSearch
294
286
  optionFilterProp="searchLabel"
295
287
  loading={loadingStacks}
296
- value={typeof value === 'number' ? value : value ? Number(value) : undefined}
288
+ value={toFiniteNumber(value)}
297
289
  onChange={(nextVal) => {
298
290
  const numVal = typeof nextVal === 'number' ? nextVal : null;
299
291
  onChange?.(numVal);
@@ -11,6 +11,7 @@ import { WorkflowVariableInput, WorkflowVariableWrapper } from '@nocobase/plugin
11
11
  import { Checkbox, Form, InputNumber, Radio } from 'antd';
12
12
  import React, { useState } from 'react';
13
13
  import { DEFAULT_TIMEOUT_MS, MAX_TIMEOUT_MS, MIN_TIMEOUT_MS } from '../../shared/constants';
14
+ import { toFiniteNumber } from '../../shared/env';
14
15
  import type { RedeployTargetMode } from '../../shared/types';
15
16
  import { useT } from '../locale';
16
17
  import { PortainerEnvEditor } from './PortainerEnvEditor';
@@ -105,7 +106,7 @@ export function RedeployFieldset() {
105
106
  max={MAX_TIMEOUT_MS}
106
107
  step={5000}
107
108
  addonAfter={t('ms')}
108
- value={typeof value === 'number' ? value : value ? Number(value) : DEFAULT_TIMEOUT_MS}
109
+ value={toFiniteNumber(value) ?? DEFAULT_TIMEOUT_MS}
109
110
  onChange={(nextVal) => onChange?.(typeof nextVal === 'number' ? nextVal : null)}
110
111
  style={{ width: '100%' }}
111
112
  />