Line data Source code
1 43 : import React from 'react';
2 :
3 : import { Button } from "@patternfly/react-core/dist/esm/components/Button";
4 : import { Checkbox } from "@patternfly/react-core/dist/esm/components/Checkbox";
5 : import { FormGroup } from "@patternfly/react-core/dist/esm/components/Form";
6 : import { FormSelect, FormSelectOption } from "@patternfly/react-core/dist/esm/components/FormSelect";
7 : import { TextInput } from "@patternfly/react-core/dist/esm/components/TextInput";
8 : import { Grid } from "@patternfly/react-core/dist/esm/layouts/Grid";
9 : import { TrashIcon } from '@patternfly/react-icons';
10 : import { FormHelper } from "cockpit-components-form-helper.jsx";
11 :
12 : import cockpit from 'cockpit';
13 : import { FileAutoComplete } from 'cockpit-components-file-autocomplete.jsx';
14 :
15 : import * as utils from './util.js';
16 :
17 43 : const _ = cockpit.gettext;
18 :
19 5 : export function validateVolume(value, key) {
20 5 : switch (key) {
21 5 : case "hostPath":
22 5 : break;
23 5 : case "containerPath":
24 5 : if (!value)
25 1 : return _("Container path must not be empty");
26 :
27 5 : break;
28 0 : default:
29 0 : console.error(`Unknown key "${key}"`); // not-covered: unreachable assertion
30 5 : }
31 5 : }
32 :
33 5 : export const Volume = ({ id, item, onChange, idx, removeitem, _additem, options, _itemCount, validationFailed, onValidationChange }) =>
34 : (
35 5 : <Grid hasGutter id={id}>
36 5 : <FormGroup className="pf-m-4-col-on-md"
37 5 : id={id + "-host-path-group"}
38 5 : label={_("Host path")}
39 5 : fieldId={id + "-host-path"}
40 : >
41 5 : <FileAutoComplete id={id + "-host-path"}
42 5 : value={item.hostPath || ''}
43 5 : onChange={value => {
44 5 : utils.validationClear(validationFailed, "hostPath", onValidationChange);
45 4 : utils.validationDebounce(() => onValidationChange({ ...validationFailed, hostPath: validateVolume(value, "hostPath") }));
46 5 : onChange(idx, 'hostPath', value);
47 5 : }} />
48 3 : <FormHelper helperTextInvalid={validationFailed?.hostPath} />
49 5 : </FormGroup>
50 5 : <FormGroup className="pf-m-3-col-on-md"
51 5 : id={id + "-container-path-group"}
52 5 : label={_("Container path")}
53 5 : fieldId={id + "-container-path"}
54 5 : isRequired
55 : >
56 5 : <TextInput id={id + "-container-path"}
57 5 : value={item.containerPath || ''}
58 1 : validated={validationFailed?.containerPath ? "error" : "default"}
59 5 : onChange={(_event, value) => {
60 5 : utils.validationClear(validationFailed, "containerPath", onValidationChange);
61 5 : utils.validationDebounce(() => onValidationChange({ ...validationFailed, containerPath: validateVolume(value, "containerPath") }));
62 5 : onChange(idx, 'containerPath', value);
63 5 : }} />
64 3 : <FormHelper helperTextInvalid={validationFailed?.containerPath} />
65 5 : </FormGroup>
66 5 : <FormGroup className="pf-m-2-col-on-md" label={_("Mode")} fieldId={id + "-mode"}>
67 5 : <Checkbox id={id + "-mode"}
68 5 : label={_("Writable")}
69 5 : isChecked={item.mode == "rw"}
70 0 : onChange={(_event, value) => onChange(idx, 'mode', value ? "rw" : "ro")} />
71 5 : </FormGroup>
72 5 : { options && options.selinuxAvailable &&
73 5 : <FormGroup className="pf-m-3-col-on-md" label={_("SELinux")} fieldId={id + "-selinux"}>
74 5 : <FormSelect id={id + "-selinux"} className='pf-v6-c-form-control'
75 5 : value={item.selinux}
76 4 : onChange={(_event, value) => onChange(idx, 'selinux', value)}>
77 5 : <FormSelectOption value='' key='' label={_("No label")} />
78 5 : <FormSelectOption value='z' key='z' label={_("Shared")} />
79 5 : <FormSelectOption value='Z' key='Z' label={_("Private")} />
80 5 : </FormSelect>
81 5 : </FormGroup> }
82 5 : <FormGroup className="pf-m-1-col-on-md remove-button-group">
83 5 : <Button variant='plain'
84 5 : className="btn-close"
85 5 : id={id + "-btn-close"}
86 5 : aria-label={_("Remove item")}
87 5 : size="sm"
88 5 : icon={<TrashIcon />}
89 2 : onClick={() => removeitem(idx)} />
90 5 : </FormGroup>
91 5 : </Grid>
92 : );
|