plugin-workflow-portainer 0.0.0-stage → 0.1.1

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 (98) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +31 -3
  3. package/client-v2.js +1 -0
  4. package/client.js +1 -0
  5. package/dist/client/127.5012da93825a6e5c.js +10 -0
  6. package/dist/client/57.ace9538136438718.js +10 -0
  7. package/dist/client/65.ec4a55173511c06d.js +10 -0
  8. package/dist/client/660.546c702d1ddf7eff.js +10 -0
  9. package/dist/client/index.js +10 -0
  10. package/dist/client-v2/127.0ec4dce7b13750e9.js +10 -0
  11. package/dist/client-v2/57.e7cfc50fb651ac14.js +10 -0
  12. package/dist/client-v2/65.9c745ea32ac96e98.js +10 -0
  13. package/dist/client-v2/660.29ae3c3b4040039d.js +10 -0
  14. package/dist/client-v2/index.js +10 -0
  15. package/dist/externalVersion.js +20 -0
  16. package/dist/index.js +48 -0
  17. package/dist/locale/en-US.json +151 -0
  18. package/dist/locale/vi-VN.json +151 -0
  19. package/dist/locale/zh-CN.json +151 -0
  20. package/dist/node_modules/joi/dist/joi-browser.min.js +1 -0
  21. package/dist/node_modules/joi/lib/annotate.js +175 -0
  22. package/dist/node_modules/joi/lib/base.js +1069 -0
  23. package/dist/node_modules/joi/lib/cache.js +143 -0
  24. package/dist/node_modules/joi/lib/common.js +216 -0
  25. package/dist/node_modules/joi/lib/compile.js +283 -0
  26. package/dist/node_modules/joi/lib/errors.js +271 -0
  27. package/dist/node_modules/joi/lib/extend.js +312 -0
  28. package/dist/node_modules/joi/lib/index.d.ts +2365 -0
  29. package/dist/node_modules/joi/lib/index.js +1 -0
  30. package/dist/node_modules/joi/lib/manifest.js +476 -0
  31. package/dist/node_modules/joi/lib/messages.js +207 -0
  32. package/dist/node_modules/joi/lib/modify.js +267 -0
  33. package/dist/node_modules/joi/lib/ref.js +414 -0
  34. package/dist/node_modules/joi/lib/schemas.js +302 -0
  35. package/dist/node_modules/joi/lib/state.js +166 -0
  36. package/dist/node_modules/joi/lib/template.js +463 -0
  37. package/dist/node_modules/joi/lib/trace.js +346 -0
  38. package/dist/node_modules/joi/lib/types/alternatives.js +364 -0
  39. package/dist/node_modules/joi/lib/types/any.js +174 -0
  40. package/dist/node_modules/joi/lib/types/array.js +809 -0
  41. package/dist/node_modules/joi/lib/types/binary.js +100 -0
  42. package/dist/node_modules/joi/lib/types/boolean.js +150 -0
  43. package/dist/node_modules/joi/lib/types/date.js +233 -0
  44. package/dist/node_modules/joi/lib/types/function.js +93 -0
  45. package/dist/node_modules/joi/lib/types/keys.js +1084 -0
  46. package/dist/node_modules/joi/lib/types/link.js +184 -0
  47. package/dist/node_modules/joi/lib/types/number.js +363 -0
  48. package/dist/node_modules/joi/lib/types/object.js +22 -0
  49. package/dist/node_modules/joi/lib/types/string.js +850 -0
  50. package/dist/node_modules/joi/lib/types/symbol.js +102 -0
  51. package/dist/node_modules/joi/lib/validator.js +750 -0
  52. package/dist/node_modules/joi/lib/values.js +263 -0
  53. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.d.ts +60 -0
  54. package/dist/node_modules/joi/node_modules/@hapi/topo/lib/index.js +225 -0
  55. package/dist/node_modules/joi/node_modules/@hapi/topo/package.json +30 -0
  56. package/dist/node_modules/joi/package.json +1 -0
  57. package/dist/server/actions/portainer.js +192 -0
  58. package/dist/server/collections/portainer-instances.js +54 -0
  59. package/dist/server/index.js +54 -0
  60. package/dist/server/instructions/PortainerStackControlInstruction.js +156 -0
  61. package/dist/server/instructions/PortainerStackRedeployInstruction.js +254 -0
  62. package/dist/server/instructions/helpers.js +211 -0
  63. package/dist/server/plugin.js +170 -0
  64. package/dist/server/services/PortainerClient.js +497 -0
  65. package/dist/shared/collection.js +57 -0
  66. package/dist/shared/constants.js +66 -0
  67. package/dist/shared/env.js +221 -0
  68. package/dist/shared/types.js +24 -0
  69. package/package.json +50 -4
  70. package/server.js +1 -0
  71. package/src/client/index.tsx +50 -0
  72. package/src/client/instructions.tsx +76 -0
  73. package/src/client-v2/__tests__/workflow-registration.test.tsx +132 -0
  74. package/src/client-v2/components/ControlFieldset.tsx +46 -0
  75. package/src/client-v2/components/PortainerEnvEditor.tsx +223 -0
  76. package/src/client-v2/components/PortainerSettingsPage.tsx +671 -0
  77. package/src/client-v2/components/PortainerTargetFields.tsx +317 -0
  78. package/src/client-v2/components/RedeployFieldset.tsx +123 -0
  79. package/src/client-v2/index.tsx +50 -0
  80. package/src/client-v2/instructions.tsx +162 -0
  81. package/src/client-v2/locale.ts +24 -0
  82. package/src/index.ts +11 -0
  83. package/src/locale/en-US.json +151 -0
  84. package/src/locale/vi-VN.json +151 -0
  85. package/src/locale/zh-CN.json +151 -0
  86. package/src/server/__tests__/portainer-workflow.test.ts +455 -0
  87. package/src/server/actions/portainer.ts +196 -0
  88. package/src/server/collections/portainer-instances.ts +34 -0
  89. package/src/server/index.ts +13 -0
  90. package/src/server/instructions/PortainerStackControlInstruction.ts +139 -0
  91. package/src/server/instructions/PortainerStackRedeployInstruction.ts +255 -0
  92. package/src/server/instructions/helpers.ts +237 -0
  93. package/src/server/plugin.ts +167 -0
  94. package/src/server/services/PortainerClient.ts +589 -0
  95. package/src/shared/collection.ts +32 -0
  96. package/src/shared/constants.ts +25 -0
  97. package/src/shared/env.ts +228 -0
  98. package/src/shared/types.ts +105 -0
@@ -0,0 +1,671 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import {
11
+ ApiOutlined,
12
+ AppstoreOutlined,
13
+ CheckCircleOutlined,
14
+ DeleteOutlined,
15
+ EditOutlined,
16
+ PlusOutlined,
17
+ ReloadOutlined,
18
+ } from '@ant-design/icons';
19
+ import { useApp } from '@nocobase/client-v2';
20
+ import {
21
+ Alert,
22
+ Button,
23
+ Card,
24
+ Checkbox,
25
+ Collapse,
26
+ Drawer,
27
+ Flex,
28
+ Form,
29
+ Input,
30
+ InputNumber,
31
+ Modal,
32
+ Popconfirm,
33
+ Select,
34
+ Space,
35
+ Switch,
36
+ Table,
37
+ Tag,
38
+ Typography,
39
+ message,
40
+ } from 'antd';
41
+ import type { ColumnsType } from 'antd/es/table';
42
+ import React, { useCallback, useEffect, useState } from 'react';
43
+ import {
44
+ DEFAULT_TIMEOUT_MS,
45
+ MAX_TIMEOUT_MS,
46
+ MIN_TIMEOUT_MS,
47
+ PORTAINER_INSTANCES_COLLECTION,
48
+ PORTAINER_RESOURCE,
49
+ SECRET_MASK,
50
+ } from '../../shared/constants';
51
+ import type { PortainerEndpointSummary, PortainerInstanceSummary, PortainerStackSummary } from '../../shared/types';
52
+ import { useT } from '../locale';
53
+
54
+ interface InstanceFormValues {
55
+ name: string;
56
+ baseUrl: string;
57
+ apiKey?: string;
58
+ gitCredentialId?: number | null;
59
+ gitUsername?: string;
60
+ gitAccessToken?: string;
61
+ allowInsecureTls?: boolean;
62
+ defaultTimeoutMs?: number;
63
+ isDefault?: boolean;
64
+ enabled?: boolean;
65
+ }
66
+
67
+ export function PortainerSettingsPage() {
68
+ const t = useT();
69
+ const api = useApp().apiClient;
70
+ const [form] = Form.useForm<InstanceFormValues>();
71
+
72
+ const [instances, setInstances] = useState<PortainerInstanceSummary[]>([]);
73
+ const [loading, setLoading] = useState(false);
74
+ const [modalOpen, setModalOpen] = useState(false);
75
+ const [editing, setEditing] = useState<PortainerInstanceSummary | null>(null);
76
+ const [saving, setSaving] = useState(false);
77
+ const [testingDraft, setTestingDraft] = useState(false);
78
+ const [testingId, setTestingId] = useState<number | null>(null);
79
+
80
+ const [explorerInstance, setExplorerInstance] = useState<PortainerInstanceSummary | null>(null);
81
+ const [endpoints, setEndpoints] = useState<PortainerEndpointSummary[]>([]);
82
+ const [selectedEndpointId, setSelectedEndpointId] = useState<number | undefined>(undefined);
83
+ const [stacks, setStacks] = useState<PortainerStackSummary[]>([]);
84
+ const [loadingStacks, setLoadingStacks] = useState(false);
85
+
86
+ const loadInstances = useCallback(async () => {
87
+ setLoading(true);
88
+ try {
89
+ const res = await api.request<{ data?: PortainerInstanceSummary[] }>({
90
+ url: `${PORTAINER_INSTANCES_COLLECTION}:list`,
91
+ method: 'get',
92
+ params: {
93
+ pageSize: 100,
94
+ sort: ['-isDefault', 'id'],
95
+ },
96
+ });
97
+ setInstances(Array.isArray(res?.data?.data) ? res.data.data : []);
98
+ } catch {
99
+ message.error(t('Failed to load Portainer instances'));
100
+ } finally {
101
+ setLoading(false);
102
+ }
103
+ }, [api, t]);
104
+
105
+ useEffect(() => {
106
+ loadInstances();
107
+ }, [loadInstances]);
108
+
109
+ const openCreateModal = () => {
110
+ setEditing(null);
111
+ form.resetFields();
112
+ form.setFieldsValue({
113
+ defaultTimeoutMs: DEFAULT_TIMEOUT_MS,
114
+ allowInsecureTls: false,
115
+ isDefault: instances.length === 0,
116
+ enabled: true,
117
+ });
118
+ setModalOpen(true);
119
+ };
120
+
121
+ const openEditModal = (record: PortainerInstanceSummary) => {
122
+ setEditing(record);
123
+ form.setFieldsValue({
124
+ name: record.name,
125
+ baseUrl: record.baseUrl,
126
+ apiKey: record.apiKey || SECRET_MASK,
127
+ gitCredentialId: record.gitCredentialId ?? undefined,
128
+ gitUsername: record.gitUsername ?? '',
129
+ gitAccessToken: record.gitAccessToken || '',
130
+ allowInsecureTls: Boolean(record.allowInsecureTls),
131
+ defaultTimeoutMs: record.defaultTimeoutMs ?? DEFAULT_TIMEOUT_MS,
132
+ isDefault: Boolean(record.isDefault),
133
+ enabled: record.enabled !== false,
134
+ });
135
+ setModalOpen(true);
136
+ };
137
+
138
+ const handleSave = async () => {
139
+ let values: InstanceFormValues;
140
+ try {
141
+ values = await form.validateFields();
142
+ } catch {
143
+ return;
144
+ }
145
+ setSaving(true);
146
+ try {
147
+ if (editing) {
148
+ await api.request({
149
+ url: `${PORTAINER_INSTANCES_COLLECTION}:update`,
150
+ method: 'post',
151
+ params: { filterByTk: editing.id },
152
+ data: values,
153
+ });
154
+ message.success(t('Portainer instance updated'));
155
+ } else {
156
+ await api.request({
157
+ url: `${PORTAINER_INSTANCES_COLLECTION}:create`,
158
+ method: 'post',
159
+ data: values,
160
+ });
161
+ message.success(t('Portainer instance created'));
162
+ }
163
+ setModalOpen(false);
164
+ await loadInstances();
165
+ } catch (err) {
166
+ const msg = err instanceof Error ? err.message : t('Failed to save Portainer instance');
167
+ message.error(msg);
168
+ } finally {
169
+ setSaving(false);
170
+ }
171
+ };
172
+
173
+ const handleTestDraft = async () => {
174
+ const values = form.getFieldsValue();
175
+ if (!values.baseUrl) {
176
+ message.warning(t('Please enter a Portainer base URL first'));
177
+ return;
178
+ }
179
+ setTestingDraft(true);
180
+ try {
181
+ const res = await api.request<{ data?: { version?: string; endpointCount?: number } }>({
182
+ url: `${PORTAINER_RESOURCE}:testConnectionDraft`,
183
+ method: 'post',
184
+ data: {
185
+ ...values,
186
+ id: editing?.id,
187
+ },
188
+ });
189
+ const info = res?.data?.data;
190
+ message.success(
191
+ t('Connected to Portainer v{{version}} ({{count}} environments found)', {
192
+ version: info?.version ?? 'unknown',
193
+ count: info?.endpointCount ?? 0,
194
+ }),
195
+ );
196
+ } catch {
197
+ message.error(t('Connection test failed. Check URL, API key, and TLS settings.'));
198
+ } finally {
199
+ setTestingDraft(false);
200
+ }
201
+ };
202
+
203
+ const handleTestSaved = async (record: PortainerInstanceSummary) => {
204
+ setTestingId(record.id);
205
+ try {
206
+ const res = await api.request<{ data?: { version?: string; endpointCount?: number } }>({
207
+ url: `${PORTAINER_RESOURCE}:testConnection`,
208
+ method: 'post',
209
+ params: { filterByTk: record.id },
210
+ });
211
+ const info = res?.data?.data;
212
+ message.success(
213
+ t('Connected to Portainer v{{version}} ({{count}} environments found)', {
214
+ version: info?.version ?? 'unknown',
215
+ count: info?.endpointCount ?? 0,
216
+ }),
217
+ );
218
+ await loadInstances();
219
+ } catch {
220
+ message.error(t('Connection test failed'));
221
+ await loadInstances();
222
+ } finally {
223
+ setTestingId(null);
224
+ }
225
+ };
226
+
227
+ const handleToggleEnabled = async (record: PortainerInstanceSummary, enabled: boolean) => {
228
+ try {
229
+ await api.request({
230
+ url: `${PORTAINER_INSTANCES_COLLECTION}:update`,
231
+ method: 'post',
232
+ params: { filterByTk: record.id },
233
+ data: { enabled },
234
+ });
235
+ await loadInstances();
236
+ } catch {
237
+ message.error(t('Failed to update status'));
238
+ }
239
+ };
240
+
241
+ const handleDelete = async (record: PortainerInstanceSummary) => {
242
+ try {
243
+ await api.request({
244
+ url: `${PORTAINER_INSTANCES_COLLECTION}:destroy`,
245
+ method: 'post',
246
+ params: { filterByTk: record.id },
247
+ });
248
+ message.success(t('Portainer instance deleted'));
249
+ await loadInstances();
250
+ } catch {
251
+ message.error(t('Failed to delete Portainer instance'));
252
+ }
253
+ };
254
+
255
+ const loadExplorerData = useCallback(
256
+ async (instanceId: number, endpointId?: number) => {
257
+ setLoadingStacks(true);
258
+ try {
259
+ const [epRes, stRes] = await Promise.all([
260
+ api.request<{ data?: PortainerEndpointSummary[] }>({
261
+ url: `${PORTAINER_RESOURCE}:listEndpoints`,
262
+ method: 'get',
263
+ params: { instanceId },
264
+ }),
265
+ api.request<{ data?: PortainerStackSummary[] }>({
266
+ url: `${PORTAINER_RESOURCE}:listStacks`,
267
+ method: 'get',
268
+ params: {
269
+ instanceId,
270
+ ...(endpointId ? { endpointId } : {}),
271
+ },
272
+ }),
273
+ ]);
274
+ setEndpoints(Array.isArray(epRes?.data?.data) ? epRes.data.data : []);
275
+ setStacks(Array.isArray(stRes?.data?.data) ? stRes.data.data : []);
276
+ } catch {
277
+ message.error(t('Failed to load environments and stacks from Portainer'));
278
+ } finally {
279
+ setLoadingStacks(false);
280
+ }
281
+ },
282
+ [api, t],
283
+ );
284
+
285
+ const openExplorer = (record: PortainerInstanceSummary) => {
286
+ setExplorerInstance(record);
287
+ setSelectedEndpointId(undefined);
288
+ loadExplorerData(record.id, undefined);
289
+ };
290
+
291
+ const columns: ColumnsType<PortainerInstanceSummary> = [
292
+ {
293
+ title: t('Name'),
294
+ dataIndex: 'name',
295
+ key: 'name',
296
+ render: (name: string, record) => (
297
+ <Space>
298
+ <Typography.Text strong>{name}</Typography.Text>
299
+ {record.isDefault ? <Tag color="blue">{t('Default')}</Tag> : null}
300
+ </Space>
301
+ ),
302
+ },
303
+ {
304
+ title: t('Base URL'),
305
+ dataIndex: 'baseUrl',
306
+ key: 'baseUrl',
307
+ render: (url: string) => <Typography.Text code>{url}</Typography.Text>,
308
+ },
309
+ {
310
+ title: t('Health & Version'),
311
+ key: 'health',
312
+ render: (_, record) => {
313
+ if (!record.lastHealthStatus) {
314
+ return <Tag>{t('Not tested')}</Tag>;
315
+ }
316
+ return record.lastHealthStatus === 'ok' ? (
317
+ <Space size="small">
318
+ <Tag color="success" icon={<CheckCircleOutlined />}>
319
+ {t('Connected')}
320
+ </Tag>
321
+ {record.lastVersion ? <Typography.Text type="secondary">v{record.lastVersion}</Typography.Text> : null}
322
+ </Space>
323
+ ) : (
324
+ <Tag color="error">{t('Unreachable')}</Tag>
325
+ );
326
+ },
327
+ },
328
+ {
329
+ title: t('Enabled'),
330
+ dataIndex: 'enabled',
331
+ key: 'enabled',
332
+ width: 100,
333
+ render: (enabled: boolean, record) => (
334
+ <Switch
335
+ checked={enabled !== false}
336
+ aria-label={`${t('Toggle Portainer instance')} ${record.name}`}
337
+ onChange={(checked) => {
338
+ handleToggleEnabled(record, checked);
339
+ }}
340
+ />
341
+ ),
342
+ },
343
+ {
344
+ title: t('Actions'),
345
+ key: 'actions',
346
+ width: 300,
347
+ render: (_, record) => (
348
+ <Space size="small" wrap>
349
+ <Button
350
+ size="small"
351
+ htmlType="button"
352
+ icon={<ApiOutlined />}
353
+ loading={testingId === record.id}
354
+ aria-label={`${t('Test connection')} ${record.name}`}
355
+ onClick={() => {
356
+ handleTestSaved(record);
357
+ }}
358
+ >
359
+ {t('Test')}
360
+ </Button>
361
+ <Button
362
+ size="small"
363
+ htmlType="button"
364
+ icon={<AppstoreOutlined />}
365
+ aria-label={`${t('Browse Stacks')} ${record.name}`}
366
+ onClick={() => openExplorer(record)}
367
+ >
368
+ {t('Stacks')}
369
+ </Button>
370
+ <Button
371
+ size="small"
372
+ htmlType="button"
373
+ icon={<EditOutlined />}
374
+ aria-label={`${t('Edit Portainer instance')} ${record.name}`}
375
+ onClick={() => openEditModal(record)}
376
+ />
377
+ <Popconfirm title={t('Delete this Portainer instance?')} onConfirm={() => handleDelete(record)}>
378
+ <Button
379
+ size="small"
380
+ danger
381
+ htmlType="button"
382
+ icon={<DeleteOutlined />}
383
+ aria-label={`${t('Delete Portainer instance')} ${record.name}`}
384
+ />
385
+ </Popconfirm>
386
+ </Space>
387
+ ),
388
+ },
389
+ ];
390
+
391
+ const stackColumns: ColumnsType<PortainerStackSummary> = [
392
+ {
393
+ title: t('ID'),
394
+ dataIndex: 'id',
395
+ key: 'id',
396
+ width: 72,
397
+ },
398
+ {
399
+ title: t('Stack Name'),
400
+ dataIndex: 'name',
401
+ key: 'name',
402
+ render: (name: string) => <Typography.Text strong>{name}</Typography.Text>,
403
+ },
404
+ {
405
+ title: t('Endpoint'),
406
+ dataIndex: 'endpointId',
407
+ key: 'endpointId',
408
+ width: 130,
409
+ render: (epId: number) => {
410
+ const ep = endpoints.find((item) => item.id === epId);
411
+ return ep ? `${ep.name} (#${epId})` : `#${epId}`;
412
+ },
413
+ },
414
+ {
415
+ title: t('Source'),
416
+ key: 'source',
417
+ render: (_, st) => (
418
+ <Space size="small" wrap>
419
+ <Tag color={st.isGitStack ? 'processing' : 'purple'}>{st.isGitStack ? t('Git Stack') : t('Compose')}</Tag>
420
+ {st.gitReference ? <Typography.Text code>{st.gitReference}</Typography.Text> : null}
421
+ </Space>
422
+ ),
423
+ },
424
+ {
425
+ title: t('Status'),
426
+ dataIndex: 'status',
427
+ key: 'status',
428
+ width: 110,
429
+ render: (status: number) => {
430
+ if (status === 3) {
431
+ return <Tag color="processing">{t('Deploying')}</Tag>;
432
+ }
433
+ if (status === 4) {
434
+ return <Tag color="error">{t('Error')}</Tag>;
435
+ }
436
+ return <Tag color={status === 1 ? 'success' : 'default'}>{status === 1 ? t('Active') : t('Inactive')}</Tag>;
437
+ },
438
+ },
439
+ {
440
+ title: t('Env Vars'),
441
+ dataIndex: 'envCount',
442
+ key: 'envCount',
443
+ width: 90,
444
+ },
445
+ ];
446
+
447
+ return (
448
+ <Card
449
+ title={t('Portainer Instances')}
450
+ extra={
451
+ <Space>
452
+ <Button
453
+ htmlType="button"
454
+ icon={<ReloadOutlined />}
455
+ loading={loading}
456
+ onClick={() => {
457
+ loadInstances();
458
+ }}
459
+ >
460
+ {t('Refresh')}
461
+ </Button>
462
+ <Button type="primary" htmlType="button" icon={<PlusOutlined />} onClick={openCreateModal}>
463
+ {t('Add Portainer instance')}
464
+ </Button>
465
+ </Space>
466
+ }
467
+ >
468
+ <Alert
469
+ type="info"
470
+ showIcon
471
+ style={{ marginBottom: 16 }}
472
+ message={t(
473
+ 'Configure Portainer servers with an Access Token (X-API-Key). Workflow nodes can select Environments and Stacks directly or receive dynamic IDs and Env variables from upstream build catalogs.',
474
+ )}
475
+ />
476
+
477
+ <Table<PortainerInstanceSummary>
478
+ rowKey="id"
479
+ loading={loading}
480
+ dataSource={instances}
481
+ columns={columns}
482
+ pagination={false}
483
+ />
484
+
485
+ <Modal
486
+ open={modalOpen}
487
+ title={editing ? t('Edit Portainer instance') : t('Add Portainer instance')}
488
+ onCancel={() => setModalOpen(false)}
489
+ destroyOnClose
490
+ width={620}
491
+ footer={
492
+ <Flex justify="space-between" align="center">
493
+ <Button
494
+ htmlType="button"
495
+ icon={<ApiOutlined />}
496
+ loading={testingDraft}
497
+ onClick={() => {
498
+ handleTestDraft();
499
+ }}
500
+ >
501
+ {t('Test connection')}
502
+ </Button>
503
+ <Space>
504
+ <Button htmlType="button" onClick={() => setModalOpen(false)}>
505
+ {t('Cancel')}
506
+ </Button>
507
+ <Button
508
+ type="primary"
509
+ htmlType="button"
510
+ loading={saving}
511
+ onClick={() => {
512
+ handleSave();
513
+ }}
514
+ >
515
+ {t('Save')}
516
+ </Button>
517
+ </Space>
518
+ </Flex>
519
+ }
520
+ >
521
+ <Form form={form} layout="vertical">
522
+ <Form.Item
523
+ name="name"
524
+ label={t('Instance name')}
525
+ rules={[{ required: true, message: t('Instance name is required') }]}
526
+ >
527
+ <Input placeholder="Portainer Production" />
528
+ </Form.Item>
529
+
530
+ <Form.Item
531
+ name="baseUrl"
532
+ label={t('Portainer base URL')}
533
+ rules={[{ required: true, message: t('Base URL is required') }]}
534
+ extra={t('Example: https://portainer.internal:9443')}
535
+ >
536
+ <Input
537
+ placeholder="https://portainer.example.com:9443"
538
+ autoCorrect="off"
539
+ autoCapitalize="none"
540
+ spellCheck={false}
541
+ />
542
+ </Form.Item>
543
+
544
+ <Form.Item
545
+ name="apiKey"
546
+ label={t('Portainer API key (X-API-Key)')}
547
+ rules={[{ required: !editing, message: t('API key is required') }]}
548
+ extra={t('Generated under Portainer -> My account -> Access tokens. Encrypted at rest.')}
549
+ >
550
+ <Input.Password
551
+ placeholder="ptr_..."
552
+ autoComplete="new-password"
553
+ autoCorrect="off"
554
+ autoCapitalize="none"
555
+ spellCheck={false}
556
+ />
557
+ </Form.Item>
558
+
559
+ <Flex gap="middle" wrap="wrap">
560
+ <Form.Item
561
+ name="defaultTimeoutMs"
562
+ label={t('Default build/redeploy timeout (ms)')}
563
+ style={{ flex: '1 1 240px' }}
564
+ >
565
+ <InputNumber min={MIN_TIMEOUT_MS} max={MAX_TIMEOUT_MS} step={5000} style={{ width: '100%' }} />
566
+ </Form.Item>
567
+ </Flex>
568
+
569
+ <Space size="large" wrap style={{ marginBottom: 16 }}>
570
+ <Form.Item name="isDefault" valuePropName="checked" style={{ marginBottom: 0 }}>
571
+ <Checkbox>{t('Set as default instance')}</Checkbox>
572
+ </Form.Item>
573
+ <Form.Item name="allowInsecureTls" valuePropName="checked" style={{ marginBottom: 0 }}>
574
+ <Checkbox>{t('Allow self-signed TLS certificate (:9443)')}</Checkbox>
575
+ </Form.Item>
576
+ <Form.Item name="enabled" valuePropName="checked" style={{ marginBottom: 0 }}>
577
+ <Checkbox>{t('Enabled')}</Checkbox>
578
+ </Form.Item>
579
+ </Space>
580
+
581
+ <Collapse
582
+ size="small"
583
+ items={[
584
+ {
585
+ key: 'git-fallback',
586
+ label: t('Optional Git authentication fallback (when Stack has no saved GitCredentialID)'),
587
+ children: (
588
+ <>
589
+ <Form.Item
590
+ name="gitCredentialId"
591
+ label={t('Portainer saved Git Credential ID (optional)')}
592
+ extra={t(
593
+ 'Automatically detected from each Git Stack when present; set here only to supply a default ID.',
594
+ )}
595
+ >
596
+ <InputNumber min={1} style={{ width: '100%' }} />
597
+ </Form.Item>
598
+ <Form.Item name="gitUsername" label={t('Fallback Git username (optional)')}>
599
+ <Input autoCorrect="off" autoCapitalize="none" spellCheck={false} placeholder="oauth2" />
600
+ </Form.Item>
601
+ <Form.Item
602
+ name="gitAccessToken"
603
+ label={t('Fallback Git Personal Access Token (optional)')}
604
+ style={{ marginBottom: 0 }}
605
+ >
606
+ <Input.Password
607
+ autoComplete="new-password"
608
+ autoCorrect="off"
609
+ autoCapitalize="none"
610
+ spellCheck={false}
611
+ />
612
+ </Form.Item>
613
+ </>
614
+ ),
615
+ },
616
+ ]}
617
+ />
618
+ </Form>
619
+ </Modal>
620
+
621
+ <Drawer
622
+ open={Boolean(explorerInstance)}
623
+ title={explorerInstance ? `${t('Portainer Stacks')} — ${explorerInstance.name}` : t('Portainer Stacks')}
624
+ onClose={() => setExplorerInstance(null)}
625
+ width={780}
626
+ >
627
+ <Flex gap="small" align="center" style={{ marginBottom: 16 }}>
628
+ <Select
629
+ allowClear
630
+ style={{ width: 280 }}
631
+ placeholder={t('All environments (Endpoints)')}
632
+ value={selectedEndpointId}
633
+ options={endpoints.map((ep) => ({
634
+ value: ep.id,
635
+ label: `${ep.name} (#${ep.id})`,
636
+ }))}
637
+ onChange={(epId) => {
638
+ setSelectedEndpointId(epId);
639
+ if (explorerInstance) {
640
+ loadExplorerData(explorerInstance.id, epId);
641
+ }
642
+ }}
643
+ />
644
+ <Button
645
+ htmlType="button"
646
+ icon={<ReloadOutlined />}
647
+ loading={loadingStacks}
648
+ onClick={() => {
649
+ if (explorerInstance) {
650
+ loadExplorerData(explorerInstance.id, selectedEndpointId);
651
+ }
652
+ }}
653
+ >
654
+ {t('Refresh')}
655
+ </Button>
656
+ </Flex>
657
+
658
+ <Table<PortainerStackSummary>
659
+ rowKey="id"
660
+ size="small"
661
+ loading={loadingStacks}
662
+ dataSource={stacks}
663
+ columns={stackColumns}
664
+ pagination={{ pageSize: 15 }}
665
+ />
666
+ </Drawer>
667
+ </Card>
668
+ );
669
+ }
670
+
671
+ export default PortainerSettingsPage;