foreman_scc_manager 5.1.0 → 5.3.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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/foreman_scc_manager/locale/de/foreman_scc_manager.js +42 -9
- data/app/assets/javascripts/foreman_scc_manager/locale/el/foreman_scc_manager.js +42 -9
- data/app/assets/javascripts/foreman_scc_manager/locale/en/foreman_scc_manager.js +38 -5
- data/app/assets/javascripts/foreman_scc_manager/locale/fr/foreman_scc_manager.js +43 -10
- data/app/assets/javascripts/foreman_scc_manager/locale/ja/foreman_scc_manager.js +43 -10
- data/app/assets/javascripts/foreman_scc_manager/locale/ka/foreman_scc_manager.js +43 -10
- data/app/assets/javascripts/foreman_scc_manager/locale/ko/foreman_scc_manager.js +43 -10
- data/app/assets/javascripts/foreman_scc_manager/locale/zh_CN/foreman_scc_manager.js +43 -10
- data/app/controllers/api/v2/scc_accounts_controller.rb +2 -0
- data/app/controllers/scc_accounts_controller.rb +0 -3
- data/app/views/api/v2/scc_accounts/main.json.rabl +1 -1
- data/app/views/scc_accounts/index.html.erb +14 -33
- data/lib/foreman_scc_manager/version.rb +1 -1
- data/locale/de/LC_MESSAGES/foreman_scc_manager.mo +0 -0
- data/locale/de/foreman_scc_manager.po +46 -18
- data/locale/el/LC_MESSAGES/foreman_scc_manager.mo +0 -0
- data/locale/el/foreman_scc_manager.po +43 -15
- data/locale/en/LC_MESSAGES/foreman_scc_manager.mo +0 -0
- data/locale/en/foreman_scc_manager.po +38 -11
- data/locale/foreman_scc_manager.pot +105 -50
- data/locale/fr/LC_MESSAGES/foreman_scc_manager.mo +0 -0
- data/locale/fr/foreman_scc_manager.po +47 -19
- data/locale/ja/LC_MESSAGES/foreman_scc_manager.mo +0 -0
- data/locale/ja/foreman_scc_manager.po +47 -16
- data/locale/ka/LC_MESSAGES/foreman_scc_manager.mo +0 -0
- data/locale/ka/foreman_scc_manager.po +44 -21
- data/locale/ko/LC_MESSAGES/foreman_scc_manager.mo +0 -0
- data/locale/ko/foreman_scc_manager.po +46 -18
- data/locale/zh_CN/LC_MESSAGES/foreman_scc_manager.mo +0 -0
- data/locale/zh_CN/foreman_scc_manager.po +47 -17
- data/test/controllers/api/v2/scc_accounts_test.rb +30 -0
- data/test/fixtures/models/scc_accounts.yml +2 -0
- data/webpack/components/SCCAccountIndex/SCCAccountIndex.scss +26 -0
- data/webpack/components/SCCAccountIndex/SCCAccountIndex.test.js +291 -0
- data/webpack/components/SCCAccountIndex/SCCAccountIndexActions.js +205 -0
- data/webpack/components/SCCAccountIndex/SCCAccountIndexConstants.js +9 -0
- data/webpack/components/SCCAccountIndex/index.js +262 -0
- data/webpack/components/SCCProductPage/EmptySccProducts.js +10 -7
- data/webpack/components/SCCProductPage/components/SCCProductPicker/components/SCCGenericPicker/index.js +25 -11
- data/webpack/components/SCCProductPage/components/SCCProductPicker/components/SCCTreePicker/components/SCCRepoPicker/index.js +1 -1
- data/webpack/components/SCCProductPage/components/SCCProductPicker/styles.scss +8 -3
- data/webpack/components/SCCProductPage/sccProductPage.scss +5 -0
- data/webpack/index.js +6 -0
- metadata +8 -3
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/* eslint-disable react/prop-types, global-require */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import {
|
|
5
|
+
render,
|
|
6
|
+
screen,
|
|
7
|
+
within,
|
|
8
|
+
fireEvent,
|
|
9
|
+
waitFor,
|
|
10
|
+
} from '@testing-library/react';
|
|
11
|
+
|
|
12
|
+
import SccAccountsIndex from './index';
|
|
13
|
+
import { deleteSccAccountAction } from './SCCAccountIndexActions';
|
|
14
|
+
|
|
15
|
+
jest.mock('foremanReact/common/I18n', () => ({ translate: (s) => s }), {
|
|
16
|
+
virtual: true,
|
|
17
|
+
});
|
|
18
|
+
jest.mock('foremanReact/common/helpers', () => ({ foremanUrl: (p) => p }), {
|
|
19
|
+
virtual: true,
|
|
20
|
+
});
|
|
21
|
+
jest.mock('react-redux', () => ({ useDispatch: () => jest.fn() }), {
|
|
22
|
+
virtual: true,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
jest.mock(
|
|
26
|
+
'./SCCAccountIndexActions',
|
|
27
|
+
() => ({
|
|
28
|
+
deleteSccAccountAction: jest.fn(),
|
|
29
|
+
}),
|
|
30
|
+
{ virtual: true }
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
jest.mock(
|
|
34
|
+
'@patternfly/react-core',
|
|
35
|
+
() => {
|
|
36
|
+
const { forwardRef } = require('react');
|
|
37
|
+
const PageSection = ({ children }) => <section>{children}</section>;
|
|
38
|
+
|
|
39
|
+
const Button = ({
|
|
40
|
+
children,
|
|
41
|
+
onClick,
|
|
42
|
+
component,
|
|
43
|
+
href,
|
|
44
|
+
'aria-label': ariaLabel,
|
|
45
|
+
}) => {
|
|
46
|
+
if (component === 'a') {
|
|
47
|
+
return (
|
|
48
|
+
<a href={href} onClick={onClick} aria-label={ariaLabel}>
|
|
49
|
+
{children}
|
|
50
|
+
</a>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
return (
|
|
54
|
+
<button type="button" onClick={onClick} aria-label={ariaLabel}>
|
|
55
|
+
{children}
|
|
56
|
+
</button>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const Dropdown = ({ isOpen, onSelect, onOpenChange, toggle, children }) => (
|
|
61
|
+
<div>
|
|
62
|
+
{typeof toggle === 'function' ? toggle({ current: null }) : null}
|
|
63
|
+
{isOpen ? (
|
|
64
|
+
<div data-testid="menu">
|
|
65
|
+
{children}
|
|
66
|
+
<button
|
|
67
|
+
type="button"
|
|
68
|
+
aria-label="Close menu"
|
|
69
|
+
onClick={() => {
|
|
70
|
+
if (onSelect) onSelect();
|
|
71
|
+
if (onOpenChange) onOpenChange(false);
|
|
72
|
+
}}
|
|
73
|
+
/>
|
|
74
|
+
</div>
|
|
75
|
+
) : null}
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const DropdownList = ({ children }) => <div role="menu">{children}</div>;
|
|
80
|
+
|
|
81
|
+
const DropdownItem = ({ children, onClick, isDisabled }) => (
|
|
82
|
+
<div
|
|
83
|
+
role="menuitem"
|
|
84
|
+
aria-disabled={!!isDisabled}
|
|
85
|
+
onClick={(e) => {
|
|
86
|
+
if (!isDisabled && onClick) onClick(e);
|
|
87
|
+
}}
|
|
88
|
+
>
|
|
89
|
+
{children}
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const MenuToggle = forwardRef(
|
|
94
|
+
({ children, onClick, 'aria-label': ariaLabel }, ref) => (
|
|
95
|
+
<button
|
|
96
|
+
ref={ref}
|
|
97
|
+
type="button"
|
|
98
|
+
aria-label={ariaLabel}
|
|
99
|
+
onClick={onClick}
|
|
100
|
+
>
|
|
101
|
+
{children}
|
|
102
|
+
</button>
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const Modal = ({ title, isOpen, children, actions }) =>
|
|
107
|
+
isOpen ? (
|
|
108
|
+
<div role="dialog" aria-label={title}>
|
|
109
|
+
<h2>{title}</h2>
|
|
110
|
+
{children}
|
|
111
|
+
{Array.isArray(actions) &&
|
|
112
|
+
actions.map((node, i) => <div key={i}>{node}</div>)}
|
|
113
|
+
</div>
|
|
114
|
+
) : null;
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
__esModule: true,
|
|
118
|
+
PageSection,
|
|
119
|
+
Button,
|
|
120
|
+
Dropdown,
|
|
121
|
+
DropdownList,
|
|
122
|
+
DropdownItem,
|
|
123
|
+
MenuToggle,
|
|
124
|
+
Modal,
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
{ virtual: true }
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
jest.mock(
|
|
131
|
+
'@patternfly/react-table',
|
|
132
|
+
() => ({
|
|
133
|
+
__esModule: true,
|
|
134
|
+
Table: ({ children, ..._rest }) => <table>{children}</table>,
|
|
135
|
+
Thead: ({ children }) => <thead>{children}</thead>,
|
|
136
|
+
Tbody: ({ children }) => <tbody>{children}</tbody>,
|
|
137
|
+
Tr: ({ children }) => <tr>{children}</tr>,
|
|
138
|
+
Th: ({ children }) => <th>{children}</th>,
|
|
139
|
+
Td: ({ children }) => <td>{children}</td>,
|
|
140
|
+
}),
|
|
141
|
+
{ virtual: true }
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
// Helpers
|
|
145
|
+
const renderComponent = (initialAccounts = []) =>
|
|
146
|
+
render(<SccAccountsIndex initialAccounts={initialAccounts} />);
|
|
147
|
+
|
|
148
|
+
const openActionsMenu = () => {
|
|
149
|
+
fireEvent.click(screen.getByLabelText('Actions menu'));
|
|
150
|
+
return screen.getByTestId('menu');
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const getRowByAccountName = (name) =>
|
|
154
|
+
screen.getByRole('row', { name: new RegExp(name, 'i') });
|
|
155
|
+
|
|
156
|
+
// Tests
|
|
157
|
+
describe('SccAccountsIndex', () => {
|
|
158
|
+
beforeEach(() => {
|
|
159
|
+
jest.clearAllMocks();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('renders without crashing and shows the Add button', () => {
|
|
163
|
+
renderComponent();
|
|
164
|
+
expect(screen.getByText('Add SCC account')).toBeInTheDocument();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('shows expected table headers', () => {
|
|
168
|
+
renderComponent();
|
|
169
|
+
['Name', 'Products', 'Last synced', 'Actions'].forEach((h) => {
|
|
170
|
+
expect(screen.getByText(h)).toBeInTheDocument();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('renders rows from props (names + product counts) with edit links', () => {
|
|
175
|
+
const data = [
|
|
176
|
+
{ id: 1, name: 'Acc A', scc_products_with_repos_count: 2 },
|
|
177
|
+
{ id: 2, name: 'Acc B', scc_products_with_repos_count: 5 },
|
|
178
|
+
];
|
|
179
|
+
renderComponent(data);
|
|
180
|
+
|
|
181
|
+
expect(screen.getByRole('link', { name: 'Acc A' })).toHaveAttribute(
|
|
182
|
+
'href',
|
|
183
|
+
'/scc_accounts/1/edit'
|
|
184
|
+
);
|
|
185
|
+
expect(screen.getByRole('link', { name: 'Acc B' })).toHaveAttribute(
|
|
186
|
+
'href',
|
|
187
|
+
'/scc_accounts/2/edit'
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const rowA = getRowByAccountName('Acc A');
|
|
191
|
+
const rowB = getRowByAccountName('Acc B');
|
|
192
|
+
expect(within(rowA).getByText('2')).toBeInTheDocument();
|
|
193
|
+
expect(within(rowB).getByText('5')).toBeInTheDocument();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('shows correct "Last synced" content: link when task exists, "never synced" otherwise', () => {
|
|
197
|
+
const data = [
|
|
198
|
+
{
|
|
199
|
+
id: 10,
|
|
200
|
+
name: 'Successful Sync',
|
|
201
|
+
scc_products_with_repos_count: 1,
|
|
202
|
+
sync_status: 'success',
|
|
203
|
+
sync_task: { id: 'task-123' },
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
id: 11,
|
|
207
|
+
name: 'Failed Sync',
|
|
208
|
+
scc_products_with_repos_count: 0,
|
|
209
|
+
sync_status: 'error',
|
|
210
|
+
sync_task: { id: 'task-456' },
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
id: 12,
|
|
214
|
+
name: 'No Sync',
|
|
215
|
+
scc_products_with_repos_count: 0,
|
|
216
|
+
sync_status: null,
|
|
217
|
+
},
|
|
218
|
+
];
|
|
219
|
+
renderComponent(data);
|
|
220
|
+
|
|
221
|
+
const successRow = getRowByAccountName('Successful Sync');
|
|
222
|
+
expect(
|
|
223
|
+
within(successRow).getByRole('link', { name: 'success' })
|
|
224
|
+
).toHaveAttribute('href', '/foreman_tasks/tasks/task-123');
|
|
225
|
+
|
|
226
|
+
const errorRow = getRowByAccountName('Failed Sync');
|
|
227
|
+
expect(
|
|
228
|
+
within(errorRow).getByRole('link', { name: 'error' })
|
|
229
|
+
).toHaveAttribute('href', '/foreman_tasks/tasks/task-456');
|
|
230
|
+
|
|
231
|
+
const noSyncRow = getRowByAccountName('No Sync');
|
|
232
|
+
expect(within(noSyncRow).getByText('never synced')).toBeInTheDocument();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('delete flow: open modal, confirm calls action, cancel closes modal', async () => {
|
|
236
|
+
const data = [
|
|
237
|
+
{
|
|
238
|
+
id: 5,
|
|
239
|
+
name: 'ToDelete',
|
|
240
|
+
scc_products_with_repos_count: 0,
|
|
241
|
+
sync_status: 'never synced',
|
|
242
|
+
},
|
|
243
|
+
];
|
|
244
|
+
renderComponent(data);
|
|
245
|
+
|
|
246
|
+
const menu = openActionsMenu();
|
|
247
|
+
fireEvent.click(within(menu).getByRole('menuitem', { name: 'Delete' }));
|
|
248
|
+
|
|
249
|
+
const dialog = screen.getByRole('dialog');
|
|
250
|
+
fireEvent.click(within(dialog).getByRole('button', { name: 'Delete' }));
|
|
251
|
+
|
|
252
|
+
expect(deleteSccAccountAction).toHaveBeenCalledWith(
|
|
253
|
+
expect.any(Function), // dispatch
|
|
254
|
+
5, // accountId
|
|
255
|
+
expect.any(Function), // setAccounts
|
|
256
|
+
expect.any(Function), // setDeleteOpen
|
|
257
|
+
expect.any(Object) // deletingIdRef
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
fireEvent.click(
|
|
261
|
+
within(screen.getByRole('dialog')).getByRole('button', { name: 'Cancel' })
|
|
262
|
+
);
|
|
263
|
+
await waitFor(() =>
|
|
264
|
+
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
const menu2 = openActionsMenu();
|
|
268
|
+
fireEvent.click(within(menu2).getByRole('menuitem', { name: 'Delete' }));
|
|
269
|
+
fireEvent.click(
|
|
270
|
+
within(screen.getByRole('dialog')).getByRole('button', { name: 'Cancel' })
|
|
271
|
+
);
|
|
272
|
+
await waitFor(() =>
|
|
273
|
+
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
|
274
|
+
);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('empty state: renders headers and no data rows', () => {
|
|
278
|
+
renderComponent([]);
|
|
279
|
+
|
|
280
|
+
['Name', 'Products', 'Last synced', 'Actions'].forEach((h) => {
|
|
281
|
+
expect(screen.getByText(h)).toBeInTheDocument();
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
expect(screen.getAllByRole('row')).toHaveLength(1);
|
|
285
|
+
|
|
286
|
+
expect(screen.queryByLabelText('Actions menu')).not.toBeInTheDocument();
|
|
287
|
+
expect(
|
|
288
|
+
screen.queryByRole('button', { name: 'Select Products' })
|
|
289
|
+
).not.toBeInTheDocument();
|
|
290
|
+
});
|
|
291
|
+
});
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { APIActions } from 'foremanReact/redux/API';
|
|
2
|
+
import { translate as __ } from 'foremanReact/common/I18n';
|
|
3
|
+
|
|
4
|
+
import { INITIAL_DELAY, MAX_DELAY, BACKOFF } from './SCCAccountIndexConstants';
|
|
5
|
+
|
|
6
|
+
const isDone = (state, result) =>
|
|
7
|
+
state === 'stopped' || result === 'success' || result === 'error';
|
|
8
|
+
|
|
9
|
+
const nextDelay = (prevDelay, changed) => {
|
|
10
|
+
const base = changed ? INITIAL_DELAY : prevDelay;
|
|
11
|
+
const next = Math.min(Math.ceil(base * BACKOFF), MAX_DELAY);
|
|
12
|
+
return next;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const schedule = (taskTimeoutRef, taskId, ms, fn) => {
|
|
16
|
+
if (taskTimeoutRef.current[taskId])
|
|
17
|
+
clearTimeout(taskTimeoutRef.current[taskId]);
|
|
18
|
+
taskTimeoutRef.current[taskId] = setTimeout(fn, ms);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const deriveSyncStatus = (done, result, endedAt, state, fallback) => {
|
|
22
|
+
if (!done) return state || fallback;
|
|
23
|
+
return result === 'success' ? endedAt || __('finished') : __('error');
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const checkUntilChanged = (
|
|
27
|
+
dispatch,
|
|
28
|
+
taskId,
|
|
29
|
+
accountId,
|
|
30
|
+
setAccounts,
|
|
31
|
+
taskTimeoutRef,
|
|
32
|
+
lastStateRef,
|
|
33
|
+
delay = INITIAL_DELAY
|
|
34
|
+
) => {
|
|
35
|
+
if (!taskId) return;
|
|
36
|
+
|
|
37
|
+
dispatch(
|
|
38
|
+
APIActions.get({
|
|
39
|
+
key: `task_${taskId}`,
|
|
40
|
+
url: `/foreman_tasks/api/tasks/${taskId}`,
|
|
41
|
+
handleSuccess: (payload) => {
|
|
42
|
+
const task = payload?.data ?? payload;
|
|
43
|
+
const { state, result, ended_at: endedAt } = task || {};
|
|
44
|
+
const prev = lastStateRef.current[accountId];
|
|
45
|
+
const done = isDone(state, result);
|
|
46
|
+
|
|
47
|
+
setAccounts((prevState) =>
|
|
48
|
+
prevState.map((acc) => {
|
|
49
|
+
if (acc.id !== accountId) {
|
|
50
|
+
return acc;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const syncStatus = deriveSyncStatus(
|
|
54
|
+
done,
|
|
55
|
+
result,
|
|
56
|
+
endedAt,
|
|
57
|
+
state,
|
|
58
|
+
acc.sync_status
|
|
59
|
+
);
|
|
60
|
+
return {
|
|
61
|
+
...acc,
|
|
62
|
+
sync_status: syncStatus,
|
|
63
|
+
sync_task: {
|
|
64
|
+
...(acc.sync_task || {}),
|
|
65
|
+
id: taskId,
|
|
66
|
+
ended_at: endedAt,
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
lastStateRef.current[accountId] = state;
|
|
73
|
+
|
|
74
|
+
if (done) {
|
|
75
|
+
if (taskTimeoutRef.current[taskId])
|
|
76
|
+
clearTimeout(taskTimeoutRef.current[taskId]);
|
|
77
|
+
delete taskTimeoutRef.current[taskId];
|
|
78
|
+
delete lastStateRef.current[accountId];
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const changed = state !== prev;
|
|
83
|
+
const newDelay = nextDelay(delay, changed);
|
|
84
|
+
|
|
85
|
+
schedule(taskTimeoutRef, taskId, newDelay, () =>
|
|
86
|
+
checkUntilChanged(
|
|
87
|
+
dispatch,
|
|
88
|
+
taskId,
|
|
89
|
+
accountId,
|
|
90
|
+
setAccounts,
|
|
91
|
+
taskTimeoutRef,
|
|
92
|
+
lastStateRef,
|
|
93
|
+
newDelay
|
|
94
|
+
)
|
|
95
|
+
);
|
|
96
|
+
},
|
|
97
|
+
handleError: () => {
|
|
98
|
+
const newDelay = nextDelay(delay, false);
|
|
99
|
+
schedule(taskTimeoutRef, taskId, newDelay, () =>
|
|
100
|
+
checkUntilChanged(
|
|
101
|
+
dispatch,
|
|
102
|
+
taskId,
|
|
103
|
+
accountId,
|
|
104
|
+
setAccounts,
|
|
105
|
+
taskTimeoutRef,
|
|
106
|
+
lastStateRef,
|
|
107
|
+
newDelay
|
|
108
|
+
)
|
|
109
|
+
);
|
|
110
|
+
},
|
|
111
|
+
errorToast: () => null,
|
|
112
|
+
})
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const syncSccAccountAction = (
|
|
117
|
+
dispatch,
|
|
118
|
+
accountId,
|
|
119
|
+
setAccounts,
|
|
120
|
+
taskTimeoutRef,
|
|
121
|
+
lastStateRef
|
|
122
|
+
) => {
|
|
123
|
+
if (!accountId) return;
|
|
124
|
+
|
|
125
|
+
dispatch(
|
|
126
|
+
APIActions.put({
|
|
127
|
+
key: `syncSccAccount_${accountId}`,
|
|
128
|
+
url: `/api/v2/scc_accounts/${accountId}/sync`,
|
|
129
|
+
successToast: () => __('Sync task started.'),
|
|
130
|
+
errorToast: () => __('Failed to start sync task.'),
|
|
131
|
+
handleSuccess: (resp) => {
|
|
132
|
+
const taskId = resp?.data?.id;
|
|
133
|
+
const initialState = resp?.data?.state || 'planned';
|
|
134
|
+
|
|
135
|
+
lastStateRef.current[accountId] = initialState;
|
|
136
|
+
|
|
137
|
+
setAccounts((prev) =>
|
|
138
|
+
prev.map((acc) =>
|
|
139
|
+
acc.id === accountId
|
|
140
|
+
? {
|
|
141
|
+
...acc,
|
|
142
|
+
sync_status: initialState || __('running'),
|
|
143
|
+
}
|
|
144
|
+
: acc
|
|
145
|
+
)
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
if (taskTimeoutRef.current[taskId]) {
|
|
149
|
+
clearTimeout(taskTimeoutRef.current[taskId]);
|
|
150
|
+
}
|
|
151
|
+
taskTimeoutRef.current[taskId] = setTimeout(() => {
|
|
152
|
+
checkUntilChanged(
|
|
153
|
+
dispatch,
|
|
154
|
+
taskId,
|
|
155
|
+
accountId,
|
|
156
|
+
setAccounts,
|
|
157
|
+
taskTimeoutRef,
|
|
158
|
+
lastStateRef
|
|
159
|
+
);
|
|
160
|
+
}, 15000);
|
|
161
|
+
},
|
|
162
|
+
handleError: () => {
|
|
163
|
+
setAccounts((prev) =>
|
|
164
|
+
prev.map((acc) =>
|
|
165
|
+
acc.id === accountId
|
|
166
|
+
? {
|
|
167
|
+
...acc,
|
|
168
|
+
sync_status: __('error'),
|
|
169
|
+
taskId: null,
|
|
170
|
+
}
|
|
171
|
+
: acc
|
|
172
|
+
)
|
|
173
|
+
);
|
|
174
|
+
},
|
|
175
|
+
})
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export const deleteSccAccountAction = (
|
|
180
|
+
dispatch,
|
|
181
|
+
id,
|
|
182
|
+
setAccounts,
|
|
183
|
+
setDeleteOpen,
|
|
184
|
+
deletingIdRef
|
|
185
|
+
) => {
|
|
186
|
+
if (!id) return;
|
|
187
|
+
|
|
188
|
+
dispatch(
|
|
189
|
+
APIActions.delete({
|
|
190
|
+
key: `deleteSccAccount_${id}`,
|
|
191
|
+
url: `/api/v2/scc_accounts/${id}`,
|
|
192
|
+
successToast: () => __('SCC account deleted successfully.'),
|
|
193
|
+
errorToast: () => __('Failed to delete SCC account.'),
|
|
194
|
+
handleSuccess: () => {
|
|
195
|
+
setAccounts((prev) => prev.filter((acc) => acc.id !== id));
|
|
196
|
+
setDeleteOpen(false);
|
|
197
|
+
deletingIdRef.current = null;
|
|
198
|
+
},
|
|
199
|
+
handleError: () => {
|
|
200
|
+
setDeleteOpen(false);
|
|
201
|
+
deletingIdRef.current = null;
|
|
202
|
+
},
|
|
203
|
+
})
|
|
204
|
+
);
|
|
205
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { translate as __ } from 'foremanReact/common/I18n';
|
|
2
|
+
|
|
3
|
+
export const WARN_DELETE = __(
|
|
4
|
+
'WARNING: If you want to switch SCC accounts and retain the synchronized content, DO NOT delete your old SCC account, even if it is expired. Please change the login and password of your SCC account, instead.\n\nIf you delete your old SCC account, you CANNOT reuse existing repositories, products, content views, and composite content views.\n\n Do you Really want to delete this SCC account %acc_name?'
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
export const INITIAL_DELAY = 5000;
|
|
8
|
+
export const MAX_DELAY = 30000;
|
|
9
|
+
export const BACKOFF = 1.5;
|