@n8n/frontend-module-self-healing 0.0.0-stage → 0.1.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.
- package/LICENSE.md +88 -0
- package/README.md +5 -2
- package/biome.jsonc +4 -0
- package/eslint.config.mjs +4 -0
- package/package.json +55 -3
- package/src/__tests__/design-system-icons.test.ts +24 -0
- package/src/__tests__/setup.ts +4 -0
- package/src/components/ProjectSelfHealingSection.test.ts +119 -0
- package/src/components/ProjectSelfHealingSection.vue +298 -0
- package/src/index.ts +2 -0
- package/src/self-healing.api.ts +48 -0
- package/src/self-healing.store.test.ts +130 -0
- package/src/self-healing.store.ts +75 -0
- package/src/views/SelfHealingConfigView.test.ts +436 -0
- package/src/views/SelfHealingConfigView.vue +490 -0
- package/stylelint.config.mjs +9 -0
- package/vite.config.ts +50 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# License
|
|
2
|
+
|
|
3
|
+
Portions of this software are licensed as follows:
|
|
4
|
+
|
|
5
|
+
- Content of branches other than the main branch (i.e. "master") are not licensed.
|
|
6
|
+
- Source code files that contain ".ee." in their filename or ".ee" in their dirname are NOT licensed under
|
|
7
|
+
the Sustainable Use License.
|
|
8
|
+
To use source code files that contain ".ee." in their filename or ".ee" in their dirname you must hold a
|
|
9
|
+
valid n8n Enterprise License specifically allowing you access to such source code files and as defined
|
|
10
|
+
in "LICENSE_EE.md".
|
|
11
|
+
- All third party components incorporated into the n8n Software are licensed under the original license
|
|
12
|
+
provided by the owner of the applicable component.
|
|
13
|
+
- Content outside of the above mentioned files or restrictions is available under the "Sustainable Use
|
|
14
|
+
License" as defined below.
|
|
15
|
+
|
|
16
|
+
## Sustainable Use License
|
|
17
|
+
|
|
18
|
+
Version 1.0
|
|
19
|
+
|
|
20
|
+
### Acceptance
|
|
21
|
+
|
|
22
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
23
|
+
|
|
24
|
+
### Copyright License
|
|
25
|
+
|
|
26
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license
|
|
27
|
+
to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject
|
|
28
|
+
to the limitations below.
|
|
29
|
+
|
|
30
|
+
### Limitations
|
|
31
|
+
|
|
32
|
+
You may use or modify the software only for your own internal business purposes or for non-commercial or
|
|
33
|
+
personal use. You may distribute the software or provide it to others only if you do so free of charge for
|
|
34
|
+
non-commercial purposes. You may not alter, remove, or obscure any licensing, copyright, or other notices of
|
|
35
|
+
the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
36
|
+
|
|
37
|
+
### Patents
|
|
38
|
+
|
|
39
|
+
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to
|
|
40
|
+
license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case
|
|
41
|
+
subject to the limitations and conditions in this license. This license does not cover any patent claims that
|
|
42
|
+
you cause to be infringed by modifications or additions to the software. If you or your company make any
|
|
43
|
+
written claim that the software infringes or contributes to infringement of any patent, your patent license
|
|
44
|
+
for the software granted under these terms ends immediately. If your company makes such a claim, your patent
|
|
45
|
+
license ends immediately for work on behalf of your company.
|
|
46
|
+
|
|
47
|
+
### Notices
|
|
48
|
+
|
|
49
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these
|
|
50
|
+
terms. If you modify the software, you must include in any modified copies of the software a prominent notice
|
|
51
|
+
stating that you have modified the software.
|
|
52
|
+
|
|
53
|
+
### No Other Rights
|
|
54
|
+
|
|
55
|
+
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
56
|
+
|
|
57
|
+
### Termination
|
|
58
|
+
|
|
59
|
+
If you use the software in violation of these terms, such use is not licensed, and your license will
|
|
60
|
+
automatically terminate. If the licensor provides you with a notice of your violation, and you cease all
|
|
61
|
+
violation of this license no later than 30 days after you receive that notice, your license will be reinstated
|
|
62
|
+
retroactively. However, if you violate these terms after such reinstatement, any additional violation of these
|
|
63
|
+
terms will cause your license to terminate automatically and permanently.
|
|
64
|
+
|
|
65
|
+
### No Liability
|
|
66
|
+
|
|
67
|
+
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will
|
|
68
|
+
not be liable to you for any damages arising out of these terms or the use or nature of the software, under
|
|
69
|
+
any kind of legal claim.
|
|
70
|
+
|
|
71
|
+
### Definitions
|
|
72
|
+
|
|
73
|
+
The “licensor” is the entity offering these terms.
|
|
74
|
+
|
|
75
|
+
The “software” is the software the licensor makes available under these terms, including any portion of it.
|
|
76
|
+
|
|
77
|
+
“You” refers to the individual or entity agreeing to these terms.
|
|
78
|
+
|
|
79
|
+
“Your company” is any legal entity, sole proprietorship, or other kind of organization that you work for, plus
|
|
80
|
+
all organizations that have control over, are under the control of, or are under common control with that
|
|
81
|
+
organization. Control means ownership of substantially all the assets of an entity, or the power to direct its
|
|
82
|
+
management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
83
|
+
|
|
84
|
+
“Your license” is the license granted to you for the software under these terms.
|
|
85
|
+
|
|
86
|
+
“Use” means anything you do with the software requiring your license.
|
|
87
|
+
|
|
88
|
+
“Trademark” means trademarks, service marks, and similar rights.
|
package/README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Self-healing settings
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This package owns the configuration list and form in Project Settings.
|
|
4
|
+
The editor shell registers the route through the existing Instance AI module.
|
|
5
|
+
Configuration management requires `project:update` and the existing workflow suggestions flag.
|
|
6
|
+
The backend API owns selection conflicts, reviewer eligibility, and lifecycle changes.
|
package/biome.jsonc
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n8n/frontend-module-self-healing",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@n8n/api-types": "1.45.0",
|
|
11
|
+
"@n8n/composables": "1.35.0",
|
|
12
|
+
"@n8n/design-system": "2.44.0",
|
|
13
|
+
"@n8n/frontend-constants": "0.11.0",
|
|
14
|
+
"@n8n/i18n": "2.45.0",
|
|
15
|
+
"@n8n/rest-api-client": "2.45.0",
|
|
16
|
+
"@n8n/stores": "2.45.0",
|
|
17
|
+
"pinia": "^2.2.4",
|
|
18
|
+
"vue": "^3.5.13",
|
|
19
|
+
"vue-router": "^4.5.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@iconify/json": "^2.2.488",
|
|
23
|
+
"@n8n/eslint-config": "0.0.1",
|
|
24
|
+
"@n8n/frontend-test-utils": "0.1.0",
|
|
25
|
+
"@n8n/frontend-vite-config": "0.1.0",
|
|
26
|
+
"@n8n/playwright-janitor": "0.1.0",
|
|
27
|
+
"@n8n/stylelint-config": "0.0.1",
|
|
28
|
+
"@n8n/typescript-config": "1.12.0",
|
|
29
|
+
"@n8n/vitest-config": "1.24.0",
|
|
30
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
31
|
+
"@testing-library/vue": "^8.1.0",
|
|
32
|
+
"@vitejs/plugin-vue": "^6.0.8",
|
|
33
|
+
"@vitest/coverage-v8": "5.0.1",
|
|
34
|
+
"eslint": "9.29.0",
|
|
35
|
+
"jsdom": "23.0.1",
|
|
36
|
+
"stylelint": "^16.23.0",
|
|
37
|
+
"typescript": "6.0.2",
|
|
38
|
+
"unplugin-icons": "^23.0.1",
|
|
39
|
+
"vite": "^8.1.6",
|
|
40
|
+
"vite-svg-loader": "5.1.0",
|
|
41
|
+
"vitest": "5.0.1",
|
|
42
|
+
"vue-tsc": "^2.2.8"
|
|
43
|
+
},
|
|
44
|
+
"license": "LicenseRef-n8n-sustainable-use",
|
|
45
|
+
"scripts": {
|
|
46
|
+
"clean": "rimraf .turbo",
|
|
47
|
+
"typecheck": "vue-tsc --noEmit",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"test:changed": "janitor test-scoped",
|
|
50
|
+
"test:dev": "vitest",
|
|
51
|
+
"lint": "eslint src --quiet",
|
|
52
|
+
"lint:fix": "eslint src --fix",
|
|
53
|
+
"lint:styles": "stylelint \"src/**/*.{scss,sass,vue}\" --cache --allow-empty-input",
|
|
54
|
+
"lint:styles:fix": "stylelint \"src/**/*.{scss,sass,vue}\" --fix --cache --allow-empty-input",
|
|
55
|
+
"format": "biome format --write . && prettier --write . --ignore-path ../../../../.prettierignore",
|
|
56
|
+
"format:check": "biome ci . && prettier --check . --ignore-path ../../../../.prettierignore"
|
|
57
|
+
}
|
|
6
58
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { N8nIcon } from '@n8n/design-system';
|
|
2
|
+
import { render } from '@testing-library/vue';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A build-config test, not a feature test. `@n8n/design-system` is consumed from source, so its
|
|
6
|
+
* two icon mechanisms are this package's problem, and each package carries its own
|
|
7
|
+
* `vite.config.ts`. Both cases fail loudly when a plugin goes missing from that file:
|
|
8
|
+
*
|
|
9
|
+
* - `inbox` comes from `~icons/lucide/inbox`, which only `unplugin-icons` resolves.
|
|
10
|
+
* - `webhook` comes from `custom/webhook.svg`, which only `svgLoader` turns into a component.
|
|
11
|
+
* Without it the import is a data-URI string, which Vue renders as a tag name.
|
|
12
|
+
*
|
|
13
|
+
* Keep this test while the module renders any design-system component.
|
|
14
|
+
*/
|
|
15
|
+
describe('design-system icons', () => {
|
|
16
|
+
it.each([
|
|
17
|
+
['a lucide icon', 'inbox'],
|
|
18
|
+
['a custom svg icon', 'webhook'],
|
|
19
|
+
])('renders %s', (_case, icon) => {
|
|
20
|
+
const { container } = render(N8nIcon, { props: { icon } });
|
|
21
|
+
|
|
22
|
+
expect(container.querySelector('svg')).not.toBeNull();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// The shared frontend test harness: the jsdom environment, english messages, and a fresh pinia
|
|
2
|
+
// per test. It lives in `@n8n/frontend-test-utils` rather than in `@n8n/vitest-config`, because
|
|
3
|
+
// `@n8n/i18n` devDepends on the latter and importing i18n there closes a cycle in the turbo graph.
|
|
4
|
+
import '@n8n/frontend-test-utils/setup';
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { SelfHealingConfigurationDto } from '@n8n/api-types';
|
|
2
|
+
import { SELF_HEALING_CONFIGURATION_VIEW } from '@n8n/frontend-constants/self-healing';
|
|
3
|
+
import { fireEvent, render, waitFor } from '@testing-library/vue';
|
|
4
|
+
import { createMemoryHistory, createRouter } from 'vue-router';
|
|
5
|
+
|
|
6
|
+
import { useSelfHealingStore } from '../self-healing.store';
|
|
7
|
+
import ProjectSelfHealingSection from './ProjectSelfHealingSection.vue';
|
|
8
|
+
|
|
9
|
+
const { confirm } = vi.hoisted(() => ({ confirm: vi.fn() }));
|
|
10
|
+
vi.mock('@n8n/design-system', async (importOriginal) => ({
|
|
11
|
+
...(await importOriginal<typeof import('@n8n/design-system')>()),
|
|
12
|
+
useMessage: () => ({ confirm }),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
const configuration: SelfHealingConfigurationDto = {
|
|
16
|
+
id: 1,
|
|
17
|
+
projectId: 'project',
|
|
18
|
+
scope: 'all',
|
|
19
|
+
workflowIds: [],
|
|
20
|
+
reviewerIds: ['reviewer'],
|
|
21
|
+
enabled: false,
|
|
22
|
+
enabledById: null,
|
|
23
|
+
lastActivity: null,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
async function renderSection() {
|
|
27
|
+
const store = useSelfHealingStore();
|
|
28
|
+
store.configurations.project = [{ ...configuration }];
|
|
29
|
+
store.options.project = {
|
|
30
|
+
workflows: [],
|
|
31
|
+
reviewers: [
|
|
32
|
+
{ id: 'reviewer', firstName: 'Test', lastName: 'Reviewer', email: 'reviewer@example.com' },
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
vi.spyOn(store, 'load').mockResolvedValue();
|
|
36
|
+
const router = createRouter({
|
|
37
|
+
history: createMemoryHistory(),
|
|
38
|
+
routes: [
|
|
39
|
+
{ path: '/projects/:projectId/settings', component: { render: () => null } },
|
|
40
|
+
{
|
|
41
|
+
path: '/projects/:projectId/settings/self-healing/:configurationId',
|
|
42
|
+
name: SELF_HEALING_CONFIGURATION_VIEW,
|
|
43
|
+
component: { render: () => null },
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
await router.push('/projects/project/settings');
|
|
48
|
+
const view = render(ProjectSelfHealingSection, {
|
|
49
|
+
props: { projectId: 'project' },
|
|
50
|
+
global: { plugins: [router] },
|
|
51
|
+
});
|
|
52
|
+
await view.findByText('All workflows');
|
|
53
|
+
return { view, store, router };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
beforeEach(() => vi.clearAllMocks());
|
|
57
|
+
|
|
58
|
+
it('keeps the active switch unchanged when saving fails and allows another attempt', async () => {
|
|
59
|
+
const { view, store } = await renderSection();
|
|
60
|
+
const pending = Promise.withResolvers<undefined>();
|
|
61
|
+
const setEnabled = vi.spyOn(store, 'setEnabled').mockReturnValueOnce(pending.promise);
|
|
62
|
+
const toggle = view.getByRole('switch', { name: 'Enable self-healing' });
|
|
63
|
+
await fireEvent.click(toggle);
|
|
64
|
+
expect(toggle).toBeDisabled();
|
|
65
|
+
expect(setEnabled).toHaveBeenCalledWith('project', 1, true);
|
|
66
|
+
pending.reject(new Error('Could not save'));
|
|
67
|
+
await waitFor(() => expect(toggle).toBeEnabled());
|
|
68
|
+
expect(toggle).not.toBeChecked();
|
|
69
|
+
|
|
70
|
+
setEnabled.mockImplementationOnce(async () => {
|
|
71
|
+
store.configurations.project[0].enabled = true;
|
|
72
|
+
});
|
|
73
|
+
await fireEvent.click(toggle);
|
|
74
|
+
await waitFor(() => expect(toggle).toBeChecked());
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('opens the configuration from the action menu', async () => {
|
|
78
|
+
const { view, router } = await renderSection();
|
|
79
|
+
await fireEvent.click(view.getByRole('button', { name: 'Actions' }));
|
|
80
|
+
await fireEvent.click(await view.findByRole('menuitem', { name: 'Edit' }));
|
|
81
|
+
await waitFor(() =>
|
|
82
|
+
expect(router.currentRoute.value).toMatchObject({
|
|
83
|
+
name: SELF_HEALING_CONFIGURATION_VIEW,
|
|
84
|
+
params: { projectId: 'project', configurationId: '1' },
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('removes a configuration from the action menu only after confirmation', async () => {
|
|
90
|
+
const { view, store } = await renderSection();
|
|
91
|
+
const remove = vi.spyOn(store, 'remove').mockResolvedValue();
|
|
92
|
+
for (const answer of ['cancel', 'confirm']) {
|
|
93
|
+
confirm.mockResolvedValueOnce(answer);
|
|
94
|
+
await fireEvent.click(view.getByRole('button', { name: 'Actions' }));
|
|
95
|
+
await fireEvent.click(await view.findByRole('menuitem', { name: 'Delete' }));
|
|
96
|
+
await waitFor(() => expect(confirm).toHaveBeenCalled());
|
|
97
|
+
if (answer === 'cancel') expect(remove).not.toHaveBeenCalled();
|
|
98
|
+
}
|
|
99
|
+
await waitFor(() => expect(remove).toHaveBeenCalledWith('project', 1));
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('shows relative last activity and the prototype empty label', async () => {
|
|
103
|
+
const { view, store } = await renderSection();
|
|
104
|
+
expect(view.getByText('No failures yet')).toBeVisible();
|
|
105
|
+
store.configurations.project[0].lastActivity = new Date(Date.now() - 5 * 60_000).toISOString();
|
|
106
|
+
expect(await view.findByText('5 minutes ago')).toBeVisible();
|
|
107
|
+
expect(view.queryByText('No failures yet')).not.toBeInTheDocument();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('opens a new configuration in the current project', async () => {
|
|
111
|
+
const { view, router } = await renderSection();
|
|
112
|
+
await fireEvent.click(view.getByTestId('self-healing-create'));
|
|
113
|
+
await waitFor(() =>
|
|
114
|
+
expect(router.currentRoute.value).toMatchObject({
|
|
115
|
+
name: SELF_HEALING_CONFIGURATION_VIEW,
|
|
116
|
+
params: { projectId: 'project', configurationId: 'new' },
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
});
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { SelfHealingConfigurationDto } from '@n8n/api-types';
|
|
3
|
+
import {
|
|
4
|
+
N8nActionToggle,
|
|
5
|
+
N8nAvatar,
|
|
6
|
+
N8nButton,
|
|
7
|
+
N8nDataTableServer,
|
|
8
|
+
N8nIconButton,
|
|
9
|
+
N8nSwitch,
|
|
10
|
+
N8nText,
|
|
11
|
+
N8nTimeAgo,
|
|
12
|
+
useMessage,
|
|
13
|
+
type TableHeader,
|
|
14
|
+
} from '@n8n/design-system';
|
|
15
|
+
import { useToast } from '@n8n/composables/useToast';
|
|
16
|
+
import { useI18n } from '@n8n/i18n';
|
|
17
|
+
import { SELF_HEALING_CONFIGURATION_VIEW } from '@n8n/frontend-constants/self-healing';
|
|
18
|
+
import { useRootStore } from '@n8n/stores/useRootStore';
|
|
19
|
+
import { computed, nextTick, ref, watch } from 'vue';
|
|
20
|
+
import { useRoute, useRouter } from 'vue-router';
|
|
21
|
+
|
|
22
|
+
import { useSelfHealingStore } from '../self-healing.store';
|
|
23
|
+
|
|
24
|
+
const props = defineProps<{ projectId: string }>();
|
|
25
|
+
const store = useSelfHealingStore();
|
|
26
|
+
const rootStore = useRootStore();
|
|
27
|
+
const i18n = useI18n();
|
|
28
|
+
const toast = useToast();
|
|
29
|
+
const message = useMessage();
|
|
30
|
+
const router = useRouter();
|
|
31
|
+
const route = useRoute();
|
|
32
|
+
const sectionRef = ref<HTMLElement | null>(null);
|
|
33
|
+
|
|
34
|
+
const loading = ref(false);
|
|
35
|
+
const isUpdating = ref(false);
|
|
36
|
+
const failed = ref(false);
|
|
37
|
+
|
|
38
|
+
const configurations = computed(() => store.configurations[props.projectId] ?? []);
|
|
39
|
+
|
|
40
|
+
const headers = computed<Array<TableHeader<SelfHealingConfigurationDto>>>(() => [
|
|
41
|
+
{
|
|
42
|
+
title: i18n.baseText('selfHealing.config.scope'),
|
|
43
|
+
key: 'scope',
|
|
44
|
+
width: 240,
|
|
45
|
+
disableSort: true,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
title: i18n.baseText('selfHealing.config.peopleToNotify'),
|
|
49
|
+
key: 'reviewerIds',
|
|
50
|
+
width: 200,
|
|
51
|
+
disableSort: true,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
title: i18n.baseText('selfHealing.config.lastActivity'),
|
|
55
|
+
key: 'lastActivity',
|
|
56
|
+
width: 200,
|
|
57
|
+
disableSort: true,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
title: i18n.baseText('selfHealing.config.active'),
|
|
61
|
+
key: 'enabled',
|
|
62
|
+
width: 110,
|
|
63
|
+
disableSort: true,
|
|
64
|
+
},
|
|
65
|
+
{ title: '', key: 'actions', align: 'end', width: 46, disableSort: true, value: () => undefined },
|
|
66
|
+
]);
|
|
67
|
+
const configActions = computed(() => [
|
|
68
|
+
{ label: i18n.baseText('generic.edit'), value: 'edit' },
|
|
69
|
+
{ label: i18n.baseText('generic.delete'), value: 'delete', destructive: true },
|
|
70
|
+
]);
|
|
71
|
+
const reviewersById = computed(
|
|
72
|
+
() =>
|
|
73
|
+
new Map(store.options[props.projectId]?.reviewers.map((reviewer) => [reviewer.id, reviewer])),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
function scopeLabel(configuration: SelfHealingConfigurationDto) {
|
|
77
|
+
if (configuration.scope === 'all') {
|
|
78
|
+
return i18n.baseText('selfHealing.config.all');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return i18n.baseText('selfHealing.config.selectedCount', {
|
|
82
|
+
adjustToNumber: configuration.workflowIds.length,
|
|
83
|
+
interpolate: { count: configuration.workflowIds.length },
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function load() {
|
|
88
|
+
loading.value = true;
|
|
89
|
+
failed.value = false;
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
await store.load(props.projectId);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
failed.value = true;
|
|
95
|
+
toast.showError(error, i18n.baseText('selfHealing.config.loadError'));
|
|
96
|
+
} finally {
|
|
97
|
+
loading.value = false;
|
|
98
|
+
if (route.hash === '#self-healing') {
|
|
99
|
+
await nextTick();
|
|
100
|
+
sectionRef.value?.scrollIntoView({ block: 'start' });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
watch(() => props.projectId, load, { immediate: true });
|
|
106
|
+
|
|
107
|
+
function edit(id: number | 'new') {
|
|
108
|
+
void router.push({
|
|
109
|
+
name: SELF_HEALING_CONFIGURATION_VIEW,
|
|
110
|
+
params: { projectId: props.projectId, configurationId: String(id) },
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function reviewerName(id: string) {
|
|
115
|
+
const user = reviewersById.value.get(id);
|
|
116
|
+
return user
|
|
117
|
+
? [user.firstName, user.lastName].filter(Boolean).join(' ') || user.email
|
|
118
|
+
: i18n.baseText('selfHealing.config.unavailableReviewer');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function toggle(configuration: SelfHealingConfigurationDto) {
|
|
122
|
+
isUpdating.value = true;
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
await store.setEnabled(props.projectId, configuration.id, !configuration.enabled);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
toast.showError(error, i18n.baseText('selfHealing.config.saveError'));
|
|
128
|
+
} finally {
|
|
129
|
+
isUpdating.value = false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function remove(configuration: SelfHealingConfigurationDto) {
|
|
134
|
+
const answer = await message.confirm(
|
|
135
|
+
i18n.baseText('selfHealing.config.removeMessage'),
|
|
136
|
+
i18n.baseText('selfHealing.config.removeTitle'),
|
|
137
|
+
{
|
|
138
|
+
confirmButtonText: i18n.baseText('generic.delete'),
|
|
139
|
+
cancelButtonText: i18n.baseText('generic.cancel'),
|
|
140
|
+
type: 'warning',
|
|
141
|
+
},
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
if (answer !== 'confirm') {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
isUpdating.value = true;
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
await store.remove(props.projectId, configuration.id);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
toast.showError(error, i18n.baseText('selfHealing.config.removeError'));
|
|
154
|
+
} finally {
|
|
155
|
+
isUpdating.value = false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function onAction(configuration: SelfHealingConfigurationDto, action: string) {
|
|
160
|
+
if (action === 'edit') {
|
|
161
|
+
edit(configuration.id);
|
|
162
|
+
} else if (action === 'delete') {
|
|
163
|
+
await remove(configuration);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
</script>
|
|
167
|
+
|
|
168
|
+
<template>
|
|
169
|
+
<fieldset id="self-healing" ref="sectionRef" data-test-id="project-self-healing">
|
|
170
|
+
<h3>
|
|
171
|
+
<label>{{ i18n.baseText('selfHealing.config.heading') }}</label>
|
|
172
|
+
</h3>
|
|
173
|
+
<p v-if="loading">{{ i18n.baseText('selfHealing.config.loading') }}</p>
|
|
174
|
+
<N8nButton v-else-if="failed" type="button" variant="outline" @click="load">{{
|
|
175
|
+
i18n.baseText('selfHealing.config.retry')
|
|
176
|
+
}}</N8nButton>
|
|
177
|
+
<N8nText
|
|
178
|
+
v-else-if="!configurations.length"
|
|
179
|
+
size="small"
|
|
180
|
+
color="text-light"
|
|
181
|
+
:class="$style.empty"
|
|
182
|
+
>{{ i18n.baseText('selfHealing.config.empty') }}</N8nText
|
|
183
|
+
>
|
|
184
|
+
<div v-else :class="$style.table">
|
|
185
|
+
<N8nDataTableServer
|
|
186
|
+
:items-per-page="configurations.length"
|
|
187
|
+
:headers="headers"
|
|
188
|
+
:items="configurations"
|
|
189
|
+
:items-length="configurations.length"
|
|
190
|
+
:page-sizes="[configurations.length + 1]"
|
|
191
|
+
>
|
|
192
|
+
<template #[`item.scope`]="{ item }">
|
|
193
|
+
<N8nText size="medium" color="text-dark" data-test-id="self-healing-configuration-row">{{
|
|
194
|
+
scopeLabel(item)
|
|
195
|
+
}}</N8nText>
|
|
196
|
+
</template>
|
|
197
|
+
<template #[`item.reviewerIds`]="{ item }">
|
|
198
|
+
<div :class="$style.people">
|
|
199
|
+
<div v-for="id in item.reviewerIds" :key="id" :class="$style.person">
|
|
200
|
+
<N8nAvatar
|
|
201
|
+
:first-name="reviewersById.get(id)?.firstName"
|
|
202
|
+
:last-name="reviewersById.get(id)?.lastName"
|
|
203
|
+
size="xsmall"
|
|
204
|
+
/>
|
|
205
|
+
<N8nText
|
|
206
|
+
size="medium"
|
|
207
|
+
color="text-dark"
|
|
208
|
+
:class="$style.personName"
|
|
209
|
+
:title="reviewerName(id)"
|
|
210
|
+
>{{ reviewerName(id) }}</N8nText
|
|
211
|
+
>
|
|
212
|
+
</div>
|
|
213
|
+
</div>
|
|
214
|
+
</template>
|
|
215
|
+
<template #[`item.lastActivity`]="{ item }">
|
|
216
|
+
<N8nText size="medium" :color="item.lastActivity ? 'text-dark' : 'text-light'">
|
|
217
|
+
<N8nTimeAgo
|
|
218
|
+
v-if="item.lastActivity"
|
|
219
|
+
:date="item.lastActivity"
|
|
220
|
+
:locale="rootStore.defaultLocale"
|
|
221
|
+
/>
|
|
222
|
+
<template v-else>{{ i18n.baseText('selfHealing.config.noActivity') }}</template>
|
|
223
|
+
</N8nText>
|
|
224
|
+
</template>
|
|
225
|
+
<template #[`item.enabled`]="{ item }">
|
|
226
|
+
<N8nSwitch
|
|
227
|
+
:model-value="item.enabled"
|
|
228
|
+
:disabled="isUpdating"
|
|
229
|
+
:aria-label="i18n.baseText('selfHealing.config.enabled')"
|
|
230
|
+
data-test-id="self-healing-config-active"
|
|
231
|
+
@update:model-value="toggle(item)"
|
|
232
|
+
/>
|
|
233
|
+
</template>
|
|
234
|
+
<template #[`item.actions`]="{ item }">
|
|
235
|
+
<N8nActionToggle
|
|
236
|
+
:actions="configActions"
|
|
237
|
+
placement="bottom"
|
|
238
|
+
:disabled="isUpdating"
|
|
239
|
+
data-test-id="self-healing-config-actions"
|
|
240
|
+
@action="onAction(item, $event)"
|
|
241
|
+
>
|
|
242
|
+
<N8nIconButton
|
|
243
|
+
icon="ellipsis"
|
|
244
|
+
variant="ghost"
|
|
245
|
+
size="small"
|
|
246
|
+
:disabled="isUpdating"
|
|
247
|
+
:aria-label="i18n.baseText('selfHealing.config.actions')"
|
|
248
|
+
/>
|
|
249
|
+
</N8nActionToggle>
|
|
250
|
+
</template>
|
|
251
|
+
</N8nDataTableServer>
|
|
252
|
+
</div>
|
|
253
|
+
<N8nButton
|
|
254
|
+
variant="outline"
|
|
255
|
+
size="large"
|
|
256
|
+
icon="plus"
|
|
257
|
+
type="button"
|
|
258
|
+
data-test-id="self-healing-create"
|
|
259
|
+
@click="edit('new')"
|
|
260
|
+
>{{ i18n.baseText('selfHealing.config.create') }}</N8nButton
|
|
261
|
+
>
|
|
262
|
+
</fieldset>
|
|
263
|
+
</template>
|
|
264
|
+
|
|
265
|
+
<style module lang="scss">
|
|
266
|
+
.table {
|
|
267
|
+
margin-bottom: var(--spacing--sm);
|
|
268
|
+
|
|
269
|
+
:global(.table-scroll) {
|
|
270
|
+
scrollbar-gutter: auto;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.people {
|
|
275
|
+
display: flex;
|
|
276
|
+
flex-direction: column;
|
|
277
|
+
gap: var(--spacing--3xs);
|
|
278
|
+
padding: var(--spacing--2xs) 0;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.person {
|
|
282
|
+
display: flex;
|
|
283
|
+
align-items: center;
|
|
284
|
+
gap: var(--spacing--2xs);
|
|
285
|
+
min-width: 0;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
.personName {
|
|
289
|
+
overflow: hidden;
|
|
290
|
+
text-overflow: ellipsis;
|
|
291
|
+
white-space: nowrap;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
.empty {
|
|
295
|
+
display: block;
|
|
296
|
+
margin-bottom: var(--spacing--sm);
|
|
297
|
+
}
|
|
298
|
+
</style>
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SaveSelfHealingConfigurationDto,
|
|
3
|
+
SelfHealingConfigurationDto,
|
|
4
|
+
SelfHealingConfigurationOptions,
|
|
5
|
+
UpdateSelfHealingConfigurationDto,
|
|
6
|
+
} from '@n8n/api-types';
|
|
7
|
+
import { makeRestApiRequest, type IRestApiContext } from '@n8n/rest-api-client';
|
|
8
|
+
|
|
9
|
+
const path = (projectId: string) => `/projects/${projectId}/self-healing-configurations`;
|
|
10
|
+
|
|
11
|
+
export const fetchConfigurations = async (
|
|
12
|
+
context: IRestApiContext,
|
|
13
|
+
projectId: string,
|
|
14
|
+
): Promise<SelfHealingConfigurationDto[]> =>
|
|
15
|
+
await makeRestApiRequest(context, 'GET', path(projectId));
|
|
16
|
+
|
|
17
|
+
export const fetchConfigurationOptions = async (
|
|
18
|
+
context: IRestApiContext,
|
|
19
|
+
projectId: string,
|
|
20
|
+
): Promise<SelfHealingConfigurationOptions> =>
|
|
21
|
+
await makeRestApiRequest(context, 'GET', `${path(projectId)}/options`);
|
|
22
|
+
|
|
23
|
+
export const saveConfiguration = async (
|
|
24
|
+
context: IRestApiContext,
|
|
25
|
+
projectId: string,
|
|
26
|
+
input: SaveSelfHealingConfigurationDto | UpdateSelfHealingConfigurationDto,
|
|
27
|
+
id?: number,
|
|
28
|
+
): Promise<SelfHealingConfigurationDto> => {
|
|
29
|
+
if (id === undefined) {
|
|
30
|
+
return await makeRestApiRequest(context, 'POST', path(projectId), input);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return await makeRestApiRequest(context, 'PATCH', `${path(projectId)}/${id}`, input);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const setConfigurationEnabled = async (
|
|
37
|
+
context: IRestApiContext,
|
|
38
|
+
projectId: string,
|
|
39
|
+
id: number,
|
|
40
|
+
enabled: boolean,
|
|
41
|
+
): Promise<SelfHealingConfigurationDto> =>
|
|
42
|
+
await makeRestApiRequest(context, 'PATCH', `${path(projectId)}/${id}/enabled`, { enabled });
|
|
43
|
+
|
|
44
|
+
export const removeConfiguration = async (
|
|
45
|
+
context: IRestApiContext,
|
|
46
|
+
projectId: string,
|
|
47
|
+
id: number,
|
|
48
|
+
): Promise<void> => await makeRestApiRequest(context, 'DELETE', `${path(projectId)}/${id}`);
|