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.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/lib/foreman_snapshot_management/version.rb +1 -1
  3. data/webpack/components/SnapshotManagement/SnapshotManagementReducer.js +0 -7
  4. data/webpack/components/SnapshotManagement/SnapshotManagementSelectors.js +0 -1
  5. data/webpack/components/SnapshotManagement/__tests__/SnapshotManagement.test.js +35 -0
  6. data/webpack/components/SnapshotManagement/__tests__/__snapshots__/SnapshotManagementReducer.test.js.snap +0 -3
  7. data/webpack/components/SnapshotManagement/components/SnapshotForm/SnapshotForm.js +39 -74
  8. data/webpack/components/SnapshotManagement/components/SnapshotForm/SnapshotFormField.js +62 -0
  9. data/webpack/components/SnapshotManagement/components/SnapshotForm/SnapshotFormHelper.js +64 -0
  10. data/webpack/components/SnapshotManagement/components/SnapshotForm/__tests__/SnapshotForm.test.js +72 -24
  11. data/webpack/components/SnapshotManagement/components/SnapshotFormModal/SnapshotFormModal.js +40 -28
  12. data/webpack/components/SnapshotManagement/components/SnapshotFormModal/__tests__/SnapshotFormModal.test.js +37 -9
  13. data/webpack/components/SnapshotManagement/components/SnapshotFormModal/index.js +8 -2
  14. data/webpack/components/SnapshotManagement/components/SnapshotFormModal/useSnapshotFormModal.js +11 -2
  15. data/webpack/components/SnapshotManagement/components/SnapshotList/SnapshotList.js +185 -229
  16. data/webpack/components/SnapshotManagement/components/SnapshotList/SnapshotListHelper.js +55 -22
  17. data/webpack/components/SnapshotManagement/components/SnapshotList/__tests__/SnapshotList.test.js +73 -54
  18. data/webpack/components/SnapshotManagement/components/SnapshotList/snapshotList.scss +6 -0
  19. data/webpack/components/SnapshotManagement/index.js +0 -1
  20. data/webpack/components/SnapshotManagementCard/__tests__/SnapshotManagementCard.test.js +28 -17
  21. data/webpack/global_index.js +6 -3
  22. data/webpack/global_test_setup.js +3 -1
  23. data/webpack/test_setup.js +0 -5
  24. metadata +6 -7
  25. data/webpack/components/SnapshotManagement/components/SnapshotForm/__tests__/__snapshots__/SnapshotForm.test.js.snap +0 -571
  26. data/webpack/components/SnapshotManagement/components/SnapshotFormModal/__tests__/__snapshots__/SnapshotFormModal.test.js.snap +0 -44
  27. data/webpack/components/SnapshotManagement/components/SnapshotList/__tests__/__snapshots__/SnapshotList.test.js.snap +0 -1081
  28. data/webpack/components/SnapshotManagementCard/__tests__/__snapshots__/SnapshotManagementCard.test.js.snap +0 -122
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed70e565cb06f031a3744c6f1affb5067dbdcad2f27e3ff2dda36b6f13bcc6cc
4
- data.tar.gz: 436122d914bb2dec114c9e6f9ea94669d7ddace54cd4262daab492f11b46cff0
3
+ metadata.gz: 3b2e76449b98ca917dcf0ad387d49d524c61493f099c55315b7a4ee5adb53096
4
+ data.tar.gz: 2302e1a8ec12c4913f844d49d843e274338ed571e36ecef118be115ad97e5ace
5
5
  SHA512:
6
- metadata.gz: 8ac852b61943b902559a13e717e16b842cb896e2b520aa6a3e4e791d28689a8c7be153778a5526cf8f7cfa864cd85d92b80f33c3cc46ece57f1bd85097d88369
7
- data.tar.gz: dbbfb4540746a27ec83402bef564b266263b7c6b331bba9091fdaa4b7e003e9bd8a804f444f1311c137e67878c73cdaf1afb48c27b3a37a912c415a4a41ee468
6
+ metadata.gz: 73eb608bd9c6a6803a2310016535c5420e055291e5c269d3aac90be0a9babd7d662d68c34d5c3adf3f35716c953c1aa97e50b826d73511ac57e29dd1cfb01817
7
+ data.tar.gz: 37dfd4c7bafc970c9ac719948c5c8ca8c53c1c5a1d0d46e720687532aa2a040dac5f68a7ff9ede1ecffee9c408a5c9a832307ffb48318f286ec42a4650104fd7
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForemanSnapshotManagement
4
- VERSION = '4.2.2'
4
+ VERSION = '4.4.0'
5
5
  end
@@ -30,29 +30,22 @@ export default (state = initialState, action) => {
30
30
  const rollbackTypes = actionTypeGenerator(SNAPSHOT_ROLLBACK);
31
31
 
32
32
  switch (action.type) {
33
- case 'SNAPSHOT_FORM_SUBMITTED':
34
- return state.merge({
35
- needsReload: true,
36
- });
37
33
  case listTypes.REQUEST:
38
34
  return state.merge({
39
35
  snapshots: [],
40
36
  isLoading: true,
41
37
  hasError: false,
42
- needsReload: false,
43
38
  });
44
39
  case listTypes.SUCCESS:
45
40
  return state.merge({
46
41
  snapshots: response.results,
47
42
  isLoading: false,
48
- needsReload: false,
49
43
  });
50
44
  case listTypes.FAILURE:
51
45
  return state.merge({
52
46
  error: response,
53
47
  hasError: true,
54
48
  isLoading: false,
55
- needsReload: false,
56
49
  });
57
50
  case deleteTypes.REQUEST:
58
51
  return state.merge({
@@ -5,4 +5,3 @@ export const selectIsLoading = state => snapshotMgmt(state).isLoading;
5
5
  export const selectIsWorking = state => snapshotMgmt(state).isWorking;
6
6
  export const selectHasError = state => snapshotMgmt(state).hasError;
7
7
  export const selectError = state => snapshotMgmt(state).error;
8
- export const selectNeedsReload = state => snapshotMgmt(state).needsReload;
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+
5
+ import SnapshotManagement from '../SnapshotManagement';
6
+
7
+ const mockSetModalOpen = jest.fn();
8
+
9
+ jest.mock('../components/SnapshotFormModal', () => () => (
10
+ <div data-testid="form-modal" />
11
+ ));
12
+ jest.mock('../components/SnapshotFormModal/useSnapshotFormModal', () => ({
13
+ __esModule: true,
14
+ default: () => ({ setModalOpen: mockSetModalOpen }),
15
+ }));
16
+ jest.mock('../components/SnapshotList/SnapshotList', () => () => (
17
+ <div data-testid="snapshot-list" />
18
+ ));
19
+
20
+ const host = { id: 42, name: 'deep.thought', ignored: 'x' };
21
+
22
+ describe('SnapshotManagement', () => {
23
+ it('renders only the list without create permission', () => {
24
+ render(<SnapshotManagement host={host} onSubmit={jest.fn()} />);
25
+ expect(screen.getByTestId('snapshot-list')).toBeInTheDocument();
26
+ expect(screen.queryByTestId('form-modal')).not.toBeInTheDocument();
27
+ });
28
+
29
+ it('opens the modal from the create button', () => {
30
+ render(<SnapshotManagement host={host} canCreate onSubmit={jest.fn()} />);
31
+ expect(screen.getByTestId('form-modal')).toBeInTheDocument();
32
+ userEvent.click(screen.getByText('Create Snapshot'));
33
+ expect(mockSetModalOpen).toHaveBeenCalled();
34
+ });
35
+ });
@@ -62,7 +62,6 @@ Object {
62
62
  "hasError": true,
63
63
  "isLoading": false,
64
64
  "isWorking": false,
65
- "needsReload": false,
66
65
  "snapshots": Array [
67
66
  Object {
68
67
  "children_ids": null,
@@ -81,7 +80,6 @@ Object {
81
80
  "hasError": false,
82
81
  "isLoading": true,
83
82
  "isWorking": false,
84
- "needsReload": false,
85
83
  "snapshots": Array [],
86
84
  }
87
85
  `;
@@ -91,7 +89,6 @@ Object {
91
89
  "hasError": false,
92
90
  "isLoading": false,
93
91
  "isWorking": false,
94
- "needsReload": false,
95
92
  "snapshots": Array [],
96
93
  }
97
94
  `;
@@ -1,11 +1,8 @@
1
1
  import React, { useState } from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import * as Yup from 'yup';
4
3
  import { Formik } from 'formik';
5
4
 
6
5
  import { translate as __ } from 'foremanReact/common/I18n';
7
- import TextField from 'foremanReact/components/common/forms/TextField';
8
- import { FieldLevelHelp } from 'patternfly-react';
9
6
 
10
7
  import {
11
8
  Form as PfForm,
@@ -13,6 +10,8 @@ import {
13
10
  Button,
14
11
  Card,
15
12
  CardBody,
13
+ FormGroup,
14
+ Popover,
16
15
  Select,
17
16
  SelectList,
18
17
  SelectOption,
@@ -22,6 +21,13 @@ import {
22
21
  Spinner,
23
22
  } from '@patternfly/react-core';
24
23
 
24
+ import { HelpIcon } from '@patternfly/react-icons';
25
+
26
+ import SnapshotFormField from './SnapshotFormField';
27
+ import {
28
+ buildValidationSchema,
29
+ buildSnapshotPayload,
30
+ } from './SnapshotFormHelper';
25
31
  import './snapshotForm.scss';
26
32
 
27
33
  const SnapshotForm = ({
@@ -34,25 +40,7 @@ const SnapshotForm = ({
34
40
  host,
35
41
  selectAllMode,
36
42
  }) => {
37
- let nameValidation = Yup.string().max(80, 'Too Long!');
38
- if (capabilities.limitSnapshotNameFormat)
39
- nameValidation = nameValidation
40
- .min(2, 'Too Short!')
41
- .matches(
42
- /^[A-z]\w+$/,
43
- __(
44
- 'Name must contain at least 2 characters starting with alphabet. Valid characters are A-Z a-z 0-9 _'
45
- )
46
- )
47
- .max(40, 'Too Long!');
48
-
49
- const validationSchema = Yup.object().shape({
50
- name: nameValidation.required('is required'),
51
- description: Yup.string(),
52
- includeRam: Yup.bool(),
53
- useQuiesce: Yup.bool(),
54
- snapshotMode: Yup.string(),
55
- });
43
+ const validationSchema = buildValidationSchema(capabilities);
56
44
 
57
45
  const [snapshotMode, setSnapshotMode] = useState('');
58
46
  const [isSelectOpen, setIsSelectOpen] = useState(false);
@@ -81,38 +69,12 @@ const SnapshotForm = ({
81
69
  actions.setSubmitting(true);
82
70
 
83
71
  try {
84
- if (snapshotMode === 'quiesce') {
85
- values.useQuiesce = true;
86
- values.includeRam = false;
87
- } else if (snapshotMode === 'include_ram') {
88
- values.includeRam = true;
89
- values.useQuiesce = false;
90
- }
91
-
92
- let mode = 'full';
93
- if (values.includeRam) {
94
- mode = 'include_ram';
95
- } else if (values.useQuiesce) {
96
- mode = 'quiesce';
97
- }
98
-
99
- const submitValues = {
100
- mode,
101
- snapshot: {
102
- name: values.name,
103
- description: values.description || '',
104
- },
105
- };
106
-
107
- const singleHostId = host?.id;
108
-
109
- const payload = {
110
- included: {
111
- search: host ? `id = ${singleHostId}` : fetchBulkParams(),
112
- },
113
- ...(singleHostId && { hostId: singleHostId }),
114
- ...submitValues,
115
- };
72
+ const payload = buildSnapshotPayload(
73
+ values,
74
+ snapshotMode,
75
+ host,
76
+ fetchBulkParams
77
+ );
116
78
  await onSubmit(payload, actions);
117
79
  } catch (error) {
118
80
  if (actions.setStatus) {
@@ -140,40 +102,44 @@ const SnapshotForm = ({
140
102
  ouiaId="snapshot-form-card"
141
103
  >
142
104
  <CardBody>
143
- <PfForm onSubmit={formikSubmit} ouiaId="snapshot-form">
144
- <TextField
105
+ <PfForm onSubmit={formikSubmit}>
106
+ <SnapshotFormField
145
107
  name="name"
146
108
  type="text"
147
109
  required
148
110
  label={__('Name')}
149
111
  ouiaId="snapshot-name-field"
150
- inputClassName="pf-v5-u-w-90"
151
112
  />
152
113
 
153
- <TextField
114
+ <SnapshotFormField
154
115
  name="description"
155
116
  type="textarea"
156
117
  label={__('Description')}
157
118
  ouiaId="snapshot-description-field"
158
- inputClassName="pf-v5-u-w-90"
159
119
  />
160
120
 
161
- <div>
162
- <label className="pf-v5-c-form__label">
163
- <span className="pf-v5-c-form__label-text">
164
- {__('Snapshot Mode')}
165
- </span>
166
- <FieldLevelHelp
167
- buttonClass="field-help"
168
- placement="top"
169
- content={__(
121
+ <FormGroup
122
+ label={__('Snapshot Mode')}
123
+ fieldId="snapshot-mode-select"
124
+ labelIcon={
125
+ <Popover
126
+ bodyContent={__(
170
127
  "Select Snapshot Mode between 'Disk only' (default) or mutually exclusive options, 'Memory' (includes RAM) and 'Quiesce'."
171
128
  )}
172
- />
173
- </label>
174
-
129
+ >
130
+ <Button
131
+ variant="plain"
132
+ aria-label={__('Snapshot mode help')}
133
+ ouiaId="snapshot-mode-help-button"
134
+ >
135
+ <HelpIcon />
136
+ </Button>
137
+ </Popover>
138
+ }
139
+ >
175
140
  <div className="pf-v5-u-mt-sm">
176
141
  <Select
142
+ id="snapshot-mode-select"
177
143
  isOpen={isSelectOpen}
178
144
  selected={snapshotMode || undefined}
179
145
  onOpenChange={setIsSelectOpen}
@@ -187,8 +153,7 @@ const SnapshotForm = ({
187
153
  ref={toggleRef}
188
154
  onClick={() => setIsSelectOpen(prev => !prev)}
189
155
  isExpanded={isSelectOpen}
190
- isFullWidth
191
- className="pf-v5-c-form-control"
156
+ style={{ width: '100%' }}
192
157
  aria-label={__('Snapshot mode')}
193
158
  ouiaId="snapshot-mode-toggle"
194
159
  >
@@ -231,7 +196,7 @@ const SnapshotForm = ({
231
196
  </HelperText>
232
197
  )}
233
198
  </div>
234
- </div>
199
+ </FormGroup>
235
200
 
236
201
  {status && (
237
202
  <HelperText isLiveRegion className="pf-v5-u-mt-sm">
@@ -0,0 +1,62 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Field } from 'formik';
4
+ import {
5
+ FormGroup,
6
+ FormHelperText,
7
+ HelperText,
8
+ HelperTextItem,
9
+ TextArea,
10
+ TextInput,
11
+ } from '@patternfly/react-core';
12
+
13
+ const SnapshotFormField = ({ name, label, type, required, ouiaId }) => (
14
+ <Field name={name}>
15
+ {({ field, form }) => {
16
+ const error = form.touched[name] && form.errors[name];
17
+ const Input = type === 'textarea' ? TextArea : TextInput;
18
+ return (
19
+ <FormGroup
20
+ label={label}
21
+ isRequired={required}
22
+ fieldId={`snapshot-form-${name}`}
23
+ >
24
+ <Input
25
+ id={`snapshot-form-${name}`}
26
+ name={field.name}
27
+ value={field.value || ''}
28
+ onChange={field.onChange}
29
+ onBlur={field.onBlur}
30
+ validated={error ? 'error' : 'default'}
31
+ className="pf-v5-u-w-90"
32
+ {...(type === 'textarea'
33
+ ? { resizeOrientation: 'vertical' }
34
+ : { type, ouiaId })}
35
+ />
36
+ {error && (
37
+ <FormHelperText>
38
+ <HelperText>
39
+ <HelperTextItem variant="error">{error}</HelperTextItem>
40
+ </HelperText>
41
+ </FormHelperText>
42
+ )}
43
+ </FormGroup>
44
+ );
45
+ }}
46
+ </Field>
47
+ );
48
+
49
+ SnapshotFormField.propTypes = {
50
+ name: PropTypes.string.isRequired,
51
+ label: PropTypes.string.isRequired,
52
+ type: PropTypes.string,
53
+ required: PropTypes.bool,
54
+ ouiaId: PropTypes.string.isRequired,
55
+ };
56
+
57
+ SnapshotFormField.defaultProps = {
58
+ type: 'text',
59
+ required: false,
60
+ };
61
+
62
+ export default SnapshotFormField;
@@ -0,0 +1,64 @@
1
+ import * as Yup from 'yup';
2
+
3
+ import { translate as __ } from 'foremanReact/common/I18n';
4
+
5
+ const MAX_SNAPSHOT_NAME_LENGTH = 80;
6
+ const LIMITED_MAX_SNAPSHOT_NAME_LENGTH = 40;
7
+
8
+ export const buildValidationSchema = capabilities => {
9
+ let nameValidation = Yup.string().max(MAX_SNAPSHOT_NAME_LENGTH, 'Too Long!');
10
+ if (capabilities.limitSnapshotNameFormat)
11
+ nameValidation = nameValidation
12
+ .min(2, 'Too Short!')
13
+ .matches(
14
+ /^[A-z]\w+$/,
15
+ __(
16
+ 'Name must contain at least 2 characters starting with alphabet. Valid characters are A-Z a-z 0-9 _'
17
+ )
18
+ )
19
+ .max(LIMITED_MAX_SNAPSHOT_NAME_LENGTH, 'Too Long!');
20
+
21
+ return Yup.object().shape({
22
+ name: nameValidation.required('is required'),
23
+ description: Yup.string(),
24
+ includeRam: Yup.bool(),
25
+ useQuiesce: Yup.bool(),
26
+ snapshotMode: Yup.string(),
27
+ });
28
+ };
29
+
30
+ export const buildSnapshotPayload = (
31
+ values,
32
+ snapshotMode,
33
+ host,
34
+ fetchBulkParams
35
+ ) => {
36
+ if (snapshotMode === 'quiesce') {
37
+ values.useQuiesce = true;
38
+ values.includeRam = false;
39
+ } else if (snapshotMode === 'include_ram') {
40
+ values.includeRam = true;
41
+ values.useQuiesce = false;
42
+ }
43
+
44
+ let mode = 'full';
45
+ if (values.includeRam) {
46
+ mode = 'include_ram';
47
+ } else if (values.useQuiesce) {
48
+ mode = 'quiesce';
49
+ }
50
+
51
+ const singleHostId = host?.id;
52
+
53
+ return {
54
+ included: {
55
+ search: host ? `id = ${singleHostId}` : fetchBulkParams(),
56
+ },
57
+ ...(singleHostId && { hostId: singleHostId }),
58
+ mode,
59
+ snapshot: {
60
+ name: values.name,
61
+ description: values.description || '',
62
+ },
63
+ };
64
+ };
@@ -1,30 +1,78 @@
1
- import { testComponentSnapshotsWithFixtures } from 'react-redux-test-utils';
1
+ import React from 'react';
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
2
4
 
3
5
  import SnapshotForm from '../SnapshotForm';
4
6
 
5
- const fetchBulkParams = () => null;
6
-
7
- const fixtures = {
8
- render: { hostId: 42, onSubmit: () => null, fetchBulkParams },
9
- 'render with limitSnapshotNameFormat capability': {
10
- hostId: 42,
11
- onSubmit: () => null,
12
- fetchBulkParams,
13
- capabilities: { limitSnapshotNameFormat: true },
14
- },
15
- 'render with optional Props': {
16
- hostId: 42,
17
- onSubmit: () => null,
18
- fetchBulkParams,
19
- initialValues: {
20
- name: 'Snapshot1',
21
- description: 'Hello World',
22
- includeRam: true,
23
- },
24
- },
25
- };
7
+ const fetchBulkParams = () => 'bulk search';
8
+ const baseProps = { hostId: 42, onSubmit: jest.fn(), fetchBulkParams };
26
9
 
27
10
  describe('SnapshotForm', () => {
28
- describe('rendering', () =>
29
- testComponentSnapshotsWithFixtures(SnapshotForm, fixtures));
11
+ beforeEach(() => jest.clearAllMocks());
12
+
13
+ it('renders the form fields', () => {
14
+ render(<SnapshotForm {...baseProps} />);
15
+ expect(screen.getAllByRole('textbox')).toHaveLength(2);
16
+ expect(screen.getAllByRole('textbox')[1]).toBeInTheDocument();
17
+ expect(screen.getByText('Select snapshot mode')).toBeInTheDocument();
18
+ });
19
+
20
+ it('renders with initial values', () => {
21
+ render(
22
+ <SnapshotForm
23
+ {...baseProps}
24
+ initialValues={{
25
+ name: 'Snapshot1',
26
+ description: 'Hello World',
27
+ includeRam: true,
28
+ }}
29
+ />
30
+ );
31
+ expect(screen.getAllByRole('textbox')[0]).toHaveValue('Snapshot1');
32
+ expect(screen.getAllByRole('textbox')[1]).toHaveValue('Hello World');
33
+ });
34
+
35
+ it('validates the name with limitSnapshotNameFormat capability', async () => {
36
+ render(
37
+ <SnapshotForm
38
+ {...baseProps}
39
+ capabilities={{ limitSnapshotNameFormat: true }}
40
+ />
41
+ );
42
+ const input = screen.getAllByRole('textbox')[0];
43
+ userEvent.type(input, '1');
44
+ userEvent.tab();
45
+ expect(
46
+ await screen.findByText(
47
+ /Name must contain at least 2 characters|Too Short/
48
+ )
49
+ ).toBeInTheDocument();
50
+ });
51
+
52
+ it('submits a single host snapshot', async () => {
53
+ const onSubmit = jest.fn();
54
+ const setModalClosed = jest.fn();
55
+ render(
56
+ <SnapshotForm
57
+ {...baseProps}
58
+ host={{ id: 42, name: 'deep.thought' }}
59
+ onSubmit={onSubmit}
60
+ setModalClosed={setModalClosed}
61
+ initialValues={{
62
+ name: 'Snap',
63
+ description: 'desc',
64
+ includeRam: false,
65
+ }}
66
+ />
67
+ );
68
+ userEvent.click(screen.getByRole('button', { name: /submit|create/i }));
69
+ await waitFor(() => expect(onSubmit).toHaveBeenCalled());
70
+ expect(onSubmit.mock.calls[0][0]).toMatchObject({
71
+ mode: 'full',
72
+ hostId: 42,
73
+ included: { search: 'id = 42' },
74
+ snapshot: { name: 'Snap', description: 'desc' },
75
+ });
76
+ await waitFor(() => expect(setModalClosed).toHaveBeenCalled());
77
+ });
30
78
  });
@@ -1,12 +1,18 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import { Title, Text, TextContent } from '@patternfly/react-core';
4
- import ForemanModal from 'foremanReact/components/ForemanModal';
3
+ import {
4
+ Modal,
5
+ ModalVariant,
6
+ Title,
7
+ Text,
8
+ TextContent,
9
+ } from '@patternfly/react-core';
5
10
  import { translate as __, sprintf } from 'foremanReact/common/I18n';
6
11
  import SnapshotForm from '../SnapshotForm';
7
12
  import { SNAPSHOT_FORM_MODAL } from './SnapshotFormModalConstants';
8
13
 
9
14
  const SnapshotFormModal = ({
15
+ isOpen,
10
16
  selectedHosts,
11
17
  selectedHostsCount,
12
18
  setModalClosed,
@@ -16,36 +22,40 @@ const SnapshotFormModal = ({
16
22
  }) => {
17
23
  const displayCount = selectedHostsCount === 0 ? 1 : selectedHostsCount;
18
24
  const hasSelection = selectedHostsCount > 0 || host;
25
+ const header = (
26
+ <TextContent className="pf-v5-u-mb-md">
27
+ <Title headingLevel="h1" size="3xl" ouiaId="snapshot-modal-title">
28
+ {__('Create snapshot')}
29
+ </Title>
30
+
31
+ {hasSelection && (
32
+ <Text
33
+ component="small"
34
+ className="pf-v5-u-color-200 pf-v5-u-font-size-sm pf-v5-u-mt-sm"
35
+ ouiaId="snapshot-modal-hosts-count"
36
+ >
37
+ {sprintf(
38
+ displayCount === 1
39
+ ? __('%s host is selected for snapshot creation')
40
+ : __('%s hosts are selected for snapshot creation'),
41
+ displayCount
42
+ )}
43
+ </Text>
44
+ )}
45
+ </TextContent>
46
+ );
19
47
 
20
48
  return (
21
- <ForemanModal
49
+ <Modal
22
50
  id={SNAPSHOT_FORM_MODAL}
23
- enforceFocus
51
+ variant={ModalVariant.medium}
52
+ isOpen={isOpen}
53
+ onClose={setModalClosed}
54
+ onEscapePress={setModalClosed}
55
+ header={header}
56
+ aria-label={__('Create snapshot')}
24
57
  ouiaId="snapshot-form-modal"
25
58
  >
26
- <ForemanModal.Header closeButton={false}>
27
- <TextContent className="pf-v5-u-mb-md">
28
- <Title headingLevel="h1" size="3xl" ouiaId="snapshot-modal-title">
29
- {__('Create snapshot')}
30
- </Title>
31
-
32
- {hasSelection && (
33
- <Text
34
- component="small"
35
- className="pf-v5-u-color-200 pf-v5-u-font-size-sm pf-v5-u-mt-sm"
36
- ouiaId="snapshot-modal-hosts-count"
37
- >
38
- {sprintf(
39
- displayCount === 1
40
- ? __('%s host is selected for snapshot creation')
41
- : __('%s hosts are selected for snapshot creation'),
42
- displayCount
43
- )}
44
- </Text>
45
- )}
46
- </TextContent>
47
- </ForemanModal.Header>
48
-
49
59
  {hasSelection && (
50
60
  <SnapshotForm
51
61
  setModalClosed={setModalClosed}
@@ -55,11 +65,12 @@ const SnapshotFormModal = ({
55
65
  {...props}
56
66
  />
57
67
  )}
58
- </ForemanModal>
68
+ </Modal>
59
69
  );
60
70
  };
61
71
 
62
72
  SnapshotFormModal.propTypes = {
73
+ isOpen: PropTypes.bool,
63
74
  selectedHosts: PropTypes.arrayOf(
64
75
  PropTypes.shape({
65
76
  id: PropTypes.number.isRequired,
@@ -82,6 +93,7 @@ SnapshotFormModal.propTypes = {
82
93
  };
83
94
 
84
95
  SnapshotFormModal.defaultProps = {
96
+ isOpen: false,
85
97
  selectedHosts: [],
86
98
  selectedHostsCount: 0,
87
99
  host: null,