foreman_snapshot_management 4.2.2 → 4.4.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/lib/foreman_snapshot_management/version.rb +1 -1
- data/webpack/components/SnapshotManagement/SnapshotManagementReducer.js +0 -7
- data/webpack/components/SnapshotManagement/SnapshotManagementSelectors.js +0 -1
- data/webpack/components/SnapshotManagement/__tests__/SnapshotManagement.test.js +35 -0
- data/webpack/components/SnapshotManagement/__tests__/__snapshots__/SnapshotManagementReducer.test.js.snap +0 -3
- data/webpack/components/SnapshotManagement/components/SnapshotForm/SnapshotForm.js +39 -74
- data/webpack/components/SnapshotManagement/components/SnapshotForm/SnapshotFormField.js +62 -0
- data/webpack/components/SnapshotManagement/components/SnapshotForm/SnapshotFormHelper.js +64 -0
- data/webpack/components/SnapshotManagement/components/SnapshotForm/__tests__/SnapshotForm.test.js +72 -24
- data/webpack/components/SnapshotManagement/components/SnapshotFormModal/SnapshotFormModal.js +40 -28
- data/webpack/components/SnapshotManagement/components/SnapshotFormModal/__tests__/SnapshotFormModal.test.js +37 -9
- data/webpack/components/SnapshotManagement/components/SnapshotFormModal/index.js +8 -2
- data/webpack/components/SnapshotManagement/components/SnapshotFormModal/useSnapshotFormModal.js +11 -2
- data/webpack/components/SnapshotManagement/components/SnapshotList/SnapshotList.js +185 -229
- data/webpack/components/SnapshotManagement/components/SnapshotList/SnapshotListHelper.js +55 -22
- data/webpack/components/SnapshotManagement/components/SnapshotList/__tests__/SnapshotList.test.js +73 -54
- data/webpack/components/SnapshotManagement/components/SnapshotList/snapshotList.scss +6 -0
- data/webpack/components/SnapshotManagement/index.js +0 -1
- data/webpack/components/SnapshotManagementCard/__tests__/SnapshotManagementCard.test.js +28 -17
- data/webpack/global_index.js +6 -3
- data/webpack/global_test_setup.js +3 -1
- data/webpack/test_setup.js +0 -5
- metadata +6 -7
- data/webpack/components/SnapshotManagement/components/SnapshotForm/__tests__/__snapshots__/SnapshotForm.test.js.snap +0 -571
- data/webpack/components/SnapshotManagement/components/SnapshotFormModal/__tests__/__snapshots__/SnapshotFormModal.test.js.snap +0 -44
- data/webpack/components/SnapshotManagement/components/SnapshotList/__tests__/__snapshots__/SnapshotList.test.js.snap +0 -1081
- data/webpack/components/SnapshotManagementCard/__tests__/__snapshots__/SnapshotManagementCard.test.js.snap +0 -122
|
@@ -1,24 +1,52 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
// shallowRenderComponentWithFixtures,
|
|
4
|
-
} from 'react-redux-test-utils';
|
|
5
|
-
// import configureStore from 'redux-mock-store';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
6
3
|
|
|
7
4
|
import SnapshotFormModal from '../SnapshotFormModal';
|
|
8
5
|
|
|
9
|
-
// const mockStore = configureStore([]);
|
|
10
|
-
|
|
11
6
|
const setModalClosed = () => null;
|
|
12
7
|
const fetchBulkParams = () => null;
|
|
13
8
|
const fixtures = {
|
|
14
9
|
normal: {
|
|
10
|
+
isOpen: true,
|
|
15
11
|
host: { id: 42, name: 'deep.thought' },
|
|
16
12
|
setModalClosed,
|
|
17
13
|
fetchBulkParams,
|
|
14
|
+
onSubmit: () => null,
|
|
18
15
|
},
|
|
19
16
|
};
|
|
20
17
|
|
|
21
18
|
describe('SnapshotFormModal', () => {
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
it('renders the modal with the host count', () => {
|
|
20
|
+
render(<SnapshotFormModal {...fixtures.normal} />);
|
|
21
|
+
expect(screen.getByText('Create snapshot')).toBeInTheDocument();
|
|
22
|
+
expect(
|
|
23
|
+
screen.getByText('1 host is selected for snapshot creation')
|
|
24
|
+
).toBeInTheDocument();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('renders nothing when closed', () => {
|
|
28
|
+
render(<SnapshotFormModal {...fixtures.normal} isOpen={false} />);
|
|
29
|
+
expect(screen.queryByText('Create snapshot')).not.toBeInTheDocument();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('renders plural count for multiple hosts', () => {
|
|
33
|
+
render(
|
|
34
|
+
<SnapshotFormModal
|
|
35
|
+
{...fixtures.normal}
|
|
36
|
+
host={null}
|
|
37
|
+
selectedHostsCount={3}
|
|
38
|
+
selectedHosts={[{ id: 1, name: 'a' }]}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
expect(
|
|
42
|
+
screen.getByText('3 hosts are selected for snapshot creation')
|
|
43
|
+
).toBeInTheDocument();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('hides the form without selection', () => {
|
|
47
|
+
render(<SnapshotFormModal {...fixtures.normal} host={null} />);
|
|
48
|
+
expect(
|
|
49
|
+
screen.queryByText(/selected for snapshot creation/)
|
|
50
|
+
).not.toBeInTheDocument();
|
|
51
|
+
});
|
|
24
52
|
});
|
|
@@ -3,9 +3,15 @@ import useSnapshotFormModal from './useSnapshotFormModal';
|
|
|
3
3
|
import SnapshotFormModal from './SnapshotFormModal';
|
|
4
4
|
|
|
5
5
|
const WrappedSnapshotFormModal = props => {
|
|
6
|
-
const { setModalClosed } = useSnapshotFormModal();
|
|
6
|
+
const { isOpen, setModalClosed } = useSnapshotFormModal();
|
|
7
7
|
|
|
8
|
-
return
|
|
8
|
+
return (
|
|
9
|
+
<SnapshotFormModal
|
|
10
|
+
isOpen={isOpen}
|
|
11
|
+
setModalClosed={setModalClosed}
|
|
12
|
+
{...props}
|
|
13
|
+
/>
|
|
14
|
+
);
|
|
9
15
|
};
|
|
10
16
|
|
|
11
17
|
export default WrappedSnapshotFormModal;
|
data/webpack/components/SnapshotManagement/components/SnapshotFormModal/useSnapshotFormModal.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useBulkModalOpen } from 'foremanReact/common/BulkModalStateHelper';
|
|
2
2
|
|
|
3
3
|
import { SNAPSHOT_FORM_MODAL } from './SnapshotFormModalConstants';
|
|
4
4
|
|
|
5
|
-
const useSnapshotFormModal = () =>
|
|
5
|
+
const useSnapshotFormModal = () => {
|
|
6
|
+
const { isOpen, open, close, toggle } = useBulkModalOpen(SNAPSHOT_FORM_MODAL);
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
isOpen,
|
|
10
|
+
setModalOpen: open,
|
|
11
|
+
setModalClosed: close,
|
|
12
|
+
toggleModal: toggle,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
6
15
|
|
|
7
16
|
export default useSnapshotFormModal;
|
|
@@ -1,267 +1,223 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import {
|
|
4
4
|
Alert,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from 'patternfly-
|
|
5
|
+
EmptyState,
|
|
6
|
+
EmptyStateBody,
|
|
7
|
+
TextArea,
|
|
8
|
+
TextInput,
|
|
9
|
+
} from '@patternfly/react-core';
|
|
10
|
+
import { Table, Thead, Tbody, Tr, Th, Td } from '@patternfly/react-table';
|
|
10
11
|
import { cloneDeep, findIndex } from 'lodash';
|
|
11
12
|
|
|
12
13
|
import { translate as __ } from 'foremanReact/common/I18n';
|
|
13
|
-
import {
|
|
14
|
-
Table,
|
|
15
|
-
TableBody,
|
|
16
|
-
column,
|
|
17
|
-
headerFormatterWithProps,
|
|
18
|
-
cellFormatterWithProps,
|
|
19
|
-
} from 'foremanReact/components/common/table';
|
|
20
14
|
import ShortDateTime from 'foremanReact/components/common/dates/ShortDateTime';
|
|
21
|
-
import AlertBody from 'foremanReact/components/common/Alert/AlertBody';
|
|
22
15
|
import Loading from 'foremanReact/components/Loading/Loading';
|
|
23
16
|
import 'foremanReact/redux/API';
|
|
24
17
|
|
|
25
18
|
import { renderListEntryButtons } from './SnapshotListHelper';
|
|
26
19
|
import './snapshotList.scss';
|
|
27
20
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
rollbackAction,
|
|
47
|
-
} = this.props;
|
|
48
|
-
|
|
49
|
-
const inlineEditController = {
|
|
50
|
-
isEditing: ({ rowData }) => rowData.backup !== undefined,
|
|
51
|
-
onActivate: ({ rowData }) => {
|
|
52
|
-
const rows = cloneDeep(this.state.rows);
|
|
53
|
-
const index = findIndex(rows, { id: rowData.id });
|
|
54
|
-
|
|
55
|
-
rows[index].backup = cloneDeep(rows[index]);
|
|
56
|
-
|
|
57
|
-
this.setState({ rows, editMode: true });
|
|
58
|
-
},
|
|
59
|
-
onConfirm: ({ rowData }) => {
|
|
60
|
-
const rows = cloneDeep(this.state.rows);
|
|
61
|
-
const index = findIndex(rows, { id: rowData.id });
|
|
62
|
-
|
|
63
|
-
delete rows[index].backup;
|
|
64
|
-
|
|
65
|
-
this.setState({ rows, editMode: false });
|
|
66
|
-
updateAction(host, rowData);
|
|
67
|
-
},
|
|
68
|
-
onCancel: ({ rowData }) => {
|
|
69
|
-
const rows = cloneDeep(this.state.rows);
|
|
70
|
-
const index = findIndex(rows, { id: rowData.id });
|
|
71
|
-
|
|
72
|
-
rows[index] = cloneDeep(rows[index].backup);
|
|
73
|
-
delete rows[index].backup;
|
|
21
|
+
const SnapshotList = ({
|
|
22
|
+
host,
|
|
23
|
+
loadSnapshots,
|
|
24
|
+
deleteAction,
|
|
25
|
+
updateAction,
|
|
26
|
+
rollbackAction,
|
|
27
|
+
isLoading,
|
|
28
|
+
isWorking,
|
|
29
|
+
hasError,
|
|
30
|
+
error,
|
|
31
|
+
snapshots,
|
|
32
|
+
canDelete,
|
|
33
|
+
canRevert,
|
|
34
|
+
canUpdate,
|
|
35
|
+
capabilities,
|
|
36
|
+
}) => {
|
|
37
|
+
const [editMode, setEditMode] = useState(false);
|
|
38
|
+
const [rows, setRows] = useState(() => cloneDeep(snapshots));
|
|
74
39
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const index = findIndex(rows, { id: rowData.id });
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
loadSnapshots(host.id);
|
|
42
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
43
|
+
}, []);
|
|
80
44
|
|
|
81
|
-
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
setRows(cloneDeep(snapshots));
|
|
47
|
+
}, [snapshots]);
|
|
82
48
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const renderButtons = renderListEntryButtons(
|
|
89
|
-
canDelete,
|
|
90
|
-
canRevert,
|
|
91
|
-
canUpdate,
|
|
92
|
-
host,
|
|
93
|
-
rollbackAction,
|
|
94
|
-
deleteAction,
|
|
95
|
-
inlineEditController
|
|
96
|
-
);
|
|
97
|
-
const inlineEditButtonCellFormatter = inlineEditFormatterFactory({
|
|
98
|
-
isEditing: additionalData => this.state.editMode,
|
|
99
|
-
renderValue: renderButtons(false),
|
|
100
|
-
renderEdit: renderButtons(true),
|
|
49
|
+
const updateRow = (rowData, change) =>
|
|
50
|
+
setRows(currentRows => {
|
|
51
|
+
const newRows = cloneDeep(currentRows);
|
|
52
|
+
const index = findIndex(newRows, { id: rowData.id });
|
|
53
|
+
return change(newRows, index);
|
|
101
54
|
});
|
|
102
55
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
additionalData.rowData.formatted_created_at
|
|
117
|
-
)
|
|
118
|
-
date = (
|
|
119
|
-
<span className="snapshot-date">
|
|
120
|
-
<ShortDateTime
|
|
121
|
-
date={new Date(additionalData.rowData.formatted_created_at)}
|
|
122
|
-
defaultValue={__('N/A')}
|
|
123
|
-
showRelativeTimeTooltip
|
|
124
|
-
/>
|
|
125
|
-
</span>
|
|
126
|
-
);
|
|
127
|
-
return (
|
|
128
|
-
<span className="static description">
|
|
129
|
-
{value}
|
|
130
|
-
<br />
|
|
131
|
-
{date}
|
|
132
|
-
</span>
|
|
133
|
-
);
|
|
134
|
-
},
|
|
135
|
-
renderEdit: (value, additionalData) => {
|
|
136
|
-
let type = 'input';
|
|
137
|
-
if (additionalData.property === 'description') type = 'textarea';
|
|
138
|
-
return (
|
|
139
|
-
<FormControl
|
|
140
|
-
type="text"
|
|
141
|
-
defaultValue={value}
|
|
142
|
-
onBlur={e =>
|
|
143
|
-
inlineEditController.onChange(e.target.value, additionalData)
|
|
144
|
-
}
|
|
145
|
-
componentClass={type}
|
|
146
|
-
/>
|
|
147
|
-
);
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
const editCellFormatters = [cellFormatterWithProps];
|
|
151
|
-
if (canUpdate) editCellFormatters.unshift(inlineEditFormatter);
|
|
56
|
+
const inlineEditController = {
|
|
57
|
+
isEditing: ({ rowData }) => rowData.backup !== undefined,
|
|
58
|
+
onActivate: ({ rowData }) => {
|
|
59
|
+
updateRow(rowData, (newRows, index) => {
|
|
60
|
+
newRows[index].backup = cloneDeep(newRows[index]);
|
|
61
|
+
return newRows;
|
|
62
|
+
});
|
|
63
|
+
setEditMode(true);
|
|
64
|
+
},
|
|
65
|
+
onConfirm: ({ rowData }) => {
|
|
66
|
+
const index = findIndex(rows, { id: rowData.id });
|
|
67
|
+
const updated = cloneDeep(rows[index]);
|
|
68
|
+
delete updated.backup;
|
|
152
69
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
[
|
|
164
|
-
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
)
|
|
176
|
-
);
|
|
177
|
-
return columns;
|
|
178
|
-
}
|
|
70
|
+
updateRow(rowData, (newRows, i) => {
|
|
71
|
+
delete newRows[i].backup;
|
|
72
|
+
return newRows;
|
|
73
|
+
});
|
|
74
|
+
setEditMode(false);
|
|
75
|
+
updateAction(host, updated);
|
|
76
|
+
},
|
|
77
|
+
onCancel: ({ rowData }) => {
|
|
78
|
+
updateRow(rowData, (newRows, index) => {
|
|
79
|
+
newRows[index] = cloneDeep(newRows[index].backup);
|
|
80
|
+
delete newRows[index].backup;
|
|
81
|
+
return newRows;
|
|
82
|
+
});
|
|
83
|
+
setEditMode(false);
|
|
84
|
+
},
|
|
85
|
+
onChange: (value, { rowData, property }) => {
|
|
86
|
+
updateRow(rowData, (newRows, index) => {
|
|
87
|
+
newRows[index][property] = value;
|
|
88
|
+
return newRows;
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
};
|
|
179
92
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
93
|
+
const getBodyMessage = () => {
|
|
94
|
+
if (isLoading || isWorking) return <Loading textSize="sm" />;
|
|
183
95
|
|
|
184
|
-
|
|
185
|
-
componentWillReceiveProps(newProps) {
|
|
186
|
-
if (newProps.snapshots !== this.props.snapshots) {
|
|
187
|
-
this.setState({ rows: newProps.snapshots });
|
|
188
|
-
}
|
|
189
|
-
if (newProps.needsReload) {
|
|
190
|
-
newProps.loadSnapshots(newProps.host.id);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
getBodyMessage() {
|
|
195
|
-
if (this.props.isLoading || this.props.isWorking)
|
|
196
|
-
return <Loading textSize="sm" />;
|
|
197
|
-
|
|
198
|
-
if (this.props.hasError)
|
|
96
|
+
if (hasError)
|
|
199
97
|
return (
|
|
200
98
|
<Alert
|
|
201
99
|
variant="danger"
|
|
202
100
|
isInline
|
|
203
101
|
title={__('Failed to load snapshot list')}
|
|
102
|
+
ouiaId="snapshot-list-error"
|
|
204
103
|
>
|
|
205
|
-
|
|
206
|
-
{/* IMHO the line-break should be done by AlertBody :-( */}
|
|
207
|
-
<br />
|
|
208
|
-
{this.props.error.message}
|
|
209
|
-
</AlertBody>
|
|
104
|
+
{error?.message}
|
|
210
105
|
</Alert>
|
|
211
106
|
);
|
|
212
107
|
|
|
213
108
|
return undefined;
|
|
214
|
-
}
|
|
109
|
+
};
|
|
215
110
|
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
const
|
|
111
|
+
const renderCell = (rowData, property, isEditingRow) => {
|
|
112
|
+
const value = rowData[property];
|
|
113
|
+
const editable = property !== 'name' || capabilities.editableSnapshotName;
|
|
114
|
+
|
|
115
|
+
if (isEditingRow && editable) {
|
|
116
|
+
const Input = property === 'description' ? TextArea : TextInput;
|
|
117
|
+
return (
|
|
118
|
+
<Input
|
|
119
|
+
aria-label={property}
|
|
120
|
+
value={value || ''}
|
|
121
|
+
onChange={(_event, newValue) =>
|
|
122
|
+
inlineEditController.onChange(newValue, {
|
|
123
|
+
rowData,
|
|
124
|
+
property,
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
{...(property === 'description'
|
|
128
|
+
? {}
|
|
129
|
+
: { ouiaId: `snapshot-${property}-input` })}
|
|
130
|
+
/>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
219
133
|
|
|
220
134
|
return (
|
|
221
|
-
<
|
|
222
|
-
{
|
|
223
|
-
<
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
bodyMessage={bodyMessage}
|
|
235
|
-
inlineEdit
|
|
236
|
-
components={{
|
|
237
|
-
body: {
|
|
238
|
-
row: PfTable.InlineEditRow,
|
|
239
|
-
cell: cellProps => cellProps.children,
|
|
240
|
-
},
|
|
241
|
-
}}
|
|
242
|
-
>
|
|
243
|
-
<PfTable.Header key="header" />
|
|
244
|
-
<TableBody
|
|
245
|
-
key="body"
|
|
246
|
-
columns={columns}
|
|
247
|
-
rows={this.state.rows}
|
|
248
|
-
message={bodyMessage}
|
|
249
|
-
rowKey="id"
|
|
250
|
-
onRow={(rowData, { rowIndex }) => ({
|
|
251
|
-
role: 'row',
|
|
252
|
-
isEditing: () => this.inlineEditController.isEditing({ rowData }),
|
|
253
|
-
onCancel: () =>
|
|
254
|
-
this.inlineEditController.onCancel({ rowData, rowIndex }),
|
|
255
|
-
onConfirm: () =>
|
|
256
|
-
this.inlineEditController.onConfirm({ rowData, rowIndex }),
|
|
257
|
-
last: rowIndex === this.state.rows.length - 1,
|
|
258
|
-
})}
|
|
259
|
-
/>
|
|
260
|
-
</Table>
|
|
261
|
-
</div>
|
|
135
|
+
<span className="static description">
|
|
136
|
+
{value}
|
|
137
|
+
<br />
|
|
138
|
+
{property === 'name' && rowData.formatted_created_at && (
|
|
139
|
+
<span className="snapshot-date">
|
|
140
|
+
<ShortDateTime
|
|
141
|
+
date={new Date(rowData.formatted_created_at)}
|
|
142
|
+
defaultValue={__('N/A')}
|
|
143
|
+
showRelativeTimeTooltip
|
|
144
|
+
/>
|
|
145
|
+
</span>
|
|
146
|
+
)}
|
|
147
|
+
</span>
|
|
262
148
|
);
|
|
263
|
-
}
|
|
264
|
-
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const bodyMessage = getBodyMessage();
|
|
152
|
+
const hasActions = canDelete || canUpdate || canRevert;
|
|
153
|
+
const renderButtons = renderListEntryButtons(
|
|
154
|
+
canDelete,
|
|
155
|
+
canRevert,
|
|
156
|
+
canUpdate,
|
|
157
|
+
host,
|
|
158
|
+
rollbackAction,
|
|
159
|
+
deleteAction,
|
|
160
|
+
inlineEditController
|
|
161
|
+
);
|
|
162
|
+
const columnCount = hasActions ? 3 : 2;
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<div>
|
|
166
|
+
<Table
|
|
167
|
+
aria-label={__('Snapshot List')}
|
|
168
|
+
variant="compact"
|
|
169
|
+
ouiaId="snapshot-list-table"
|
|
170
|
+
>
|
|
171
|
+
<Thead>
|
|
172
|
+
<Tr ouiaId="snapshot-list-row-head">
|
|
173
|
+
<Th>{__('Snapshot')}</Th>
|
|
174
|
+
<Th>{__('Description')}</Th>
|
|
175
|
+
{hasActions && <Th>{__('Action')}</Th>}
|
|
176
|
+
</Tr>
|
|
177
|
+
</Thead>
|
|
178
|
+
<Tbody>
|
|
179
|
+
{bodyMessage && (
|
|
180
|
+
<Tr ouiaId="snapshot-list-rows">
|
|
181
|
+
<Td colSpan={columnCount}>{bodyMessage}</Td>
|
|
182
|
+
</Tr>
|
|
183
|
+
)}
|
|
184
|
+
{!bodyMessage && rows.length === 0 && (
|
|
185
|
+
<Tr ouiaId="snapshot-list-row-empty">
|
|
186
|
+
<Td colSpan={columnCount}>
|
|
187
|
+
<EmptyState>
|
|
188
|
+
<EmptyStateBody>{__('No snapshots found')}</EmptyStateBody>
|
|
189
|
+
</EmptyState>
|
|
190
|
+
</Td>
|
|
191
|
+
</Tr>
|
|
192
|
+
)}
|
|
193
|
+
{!bodyMessage &&
|
|
194
|
+
rows.map(rowData => {
|
|
195
|
+
const isEditingRow = inlineEditController.isEditing({ rowData });
|
|
196
|
+
return (
|
|
197
|
+
<Tr key={rowData.id} ouiaId={`snapshot-row-${rowData.id}`}>
|
|
198
|
+
<Td dataLabel={__('Snapshot')}>
|
|
199
|
+
{renderCell(rowData, 'name', isEditingRow)}
|
|
200
|
+
</Td>
|
|
201
|
+
<Td dataLabel={__('Description')}>
|
|
202
|
+
{renderCell(rowData, 'description', isEditingRow)}
|
|
203
|
+
</Td>
|
|
204
|
+
{hasActions && (
|
|
205
|
+
<Td
|
|
206
|
+
dataLabel={__('Action')}
|
|
207
|
+
className="action-buttons"
|
|
208
|
+
isActionCell
|
|
209
|
+
>
|
|
210
|
+
{renderButtons(rowData, isEditingRow, editMode)}
|
|
211
|
+
</Td>
|
|
212
|
+
)}
|
|
213
|
+
</Tr>
|
|
214
|
+
);
|
|
215
|
+
})}
|
|
216
|
+
</Tbody>
|
|
217
|
+
</Table>
|
|
218
|
+
</div>
|
|
219
|
+
);
|
|
220
|
+
};
|
|
265
221
|
|
|
266
222
|
SnapshotList.propTypes = {
|
|
267
223
|
/*
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Button
|
|
2
|
+
import { Button } from '@patternfly/react-core';
|
|
3
|
+
import {
|
|
4
|
+
PencilAltIcon,
|
|
5
|
+
HistoryIcon,
|
|
6
|
+
TrashIcon,
|
|
7
|
+
CheckIcon,
|
|
8
|
+
TimesIcon,
|
|
9
|
+
} from '@patternfly/react-icons';
|
|
3
10
|
|
|
4
11
|
import { sprintf, translate as __ } from 'foremanReact/common/I18n';
|
|
5
12
|
|
|
@@ -13,58 +20,84 @@ export const renderListEntryButtons = (
|
|
|
13
20
|
snapshotRollbackAction,
|
|
14
21
|
snapshotDeleteAction,
|
|
15
22
|
inlineEditController
|
|
16
|
-
) =>
|
|
23
|
+
) => (rowData, isEditingRow, disabled) => {
|
|
24
|
+
if (isEditingRow) {
|
|
25
|
+
return (
|
|
26
|
+
<div className="snapshot-action-buttons">
|
|
27
|
+
<Button
|
|
28
|
+
key="confirm-button"
|
|
29
|
+
variant="plain"
|
|
30
|
+
aria-label={__('Confirm')}
|
|
31
|
+
onClick={() => inlineEditController.onConfirm({ rowData })}
|
|
32
|
+
ouiaId={`snapshot-confirm-button-${rowData.id}`}
|
|
33
|
+
>
|
|
34
|
+
<CheckIcon />
|
|
35
|
+
</Button>
|
|
36
|
+
<Button
|
|
37
|
+
key="cancel-button"
|
|
38
|
+
variant="plain"
|
|
39
|
+
aria-label={__('Cancel')}
|
|
40
|
+
onClick={() => inlineEditController.onCancel({ rowData })}
|
|
41
|
+
ouiaId={`snapshot-cancel-edit-button-${rowData.id}`}
|
|
42
|
+
>
|
|
43
|
+
<TimesIcon />
|
|
44
|
+
</Button>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
17
49
|
const buttons = [];
|
|
18
50
|
|
|
19
|
-
// Edit Button
|
|
20
51
|
if (canUpdate) {
|
|
21
52
|
buttons.push(
|
|
22
53
|
<Button
|
|
23
54
|
key="edit-button"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
55
|
+
variant="plain"
|
|
56
|
+
isDisabled={disabled}
|
|
57
|
+
aria-label={__('edit entry')}
|
|
58
|
+
onClick={() => inlineEditController.onActivate({ rowData })}
|
|
59
|
+
ouiaId={`snapshot-edit-button-${rowData.id}`}
|
|
27
60
|
>
|
|
28
|
-
<
|
|
61
|
+
<PencilAltIcon />
|
|
29
62
|
</Button>
|
|
30
63
|
);
|
|
31
64
|
}
|
|
32
65
|
|
|
33
|
-
// Rollback button
|
|
34
66
|
if (canRevert) {
|
|
35
67
|
buttons.push(
|
|
36
68
|
<Button
|
|
37
69
|
key="rollback-button"
|
|
38
|
-
|
|
39
|
-
|
|
70
|
+
variant="plain"
|
|
71
|
+
isDisabled={disabled}
|
|
72
|
+
aria-label={__('Rollback')}
|
|
40
73
|
onClick={() =>
|
|
41
|
-
window.confirm(
|
|
42
|
-
|
|
43
|
-
) && snapshotRollbackAction(host, additionalData.rowData)
|
|
74
|
+
window.confirm(sprintf(__('Rollback to "%s"?'), rowData.name)) &&
|
|
75
|
+
snapshotRollbackAction(host, rowData)
|
|
44
76
|
}
|
|
77
|
+
ouiaId={`snapshot-rollback-button-${rowData.id}`}
|
|
45
78
|
>
|
|
46
|
-
<
|
|
79
|
+
<HistoryIcon />
|
|
47
80
|
</Button>
|
|
48
81
|
);
|
|
49
82
|
}
|
|
50
83
|
|
|
51
|
-
// Delete Button
|
|
52
84
|
if (canDelete) {
|
|
53
85
|
buttons.push(
|
|
54
86
|
<Button
|
|
55
87
|
key="delete-button"
|
|
56
|
-
|
|
57
|
-
|
|
88
|
+
variant="plain"
|
|
89
|
+
isDisabled={disabled}
|
|
90
|
+
aria-label={__('Delete')}
|
|
58
91
|
onClick={() =>
|
|
59
|
-
window.confirm(
|
|
60
|
-
|
|
61
|
-
) && snapshotDeleteAction(host, additionalData.rowData)
|
|
92
|
+
window.confirm(sprintf(__('Delete Snapshot "%s"?'), rowData.name)) &&
|
|
93
|
+
snapshotDeleteAction(host, rowData)
|
|
62
94
|
}
|
|
95
|
+
ouiaId={`snapshot-delete-button-${rowData.id}`}
|
|
63
96
|
>
|
|
64
|
-
<
|
|
97
|
+
<TrashIcon />
|
|
65
98
|
</Button>
|
|
66
99
|
);
|
|
67
100
|
}
|
|
68
101
|
|
|
69
|
-
return <
|
|
102
|
+
return <div className="snapshot-action-buttons">{buttons}</div>;
|
|
70
103
|
};
|