Skip to content

Commit

Permalink
Validate hostPath based on the error callback from FileAutoComplete
Browse files Browse the repository at this point in the history
  • Loading branch information
jelly committed Nov 10, 2023
1 parent c3c4a3f commit 40d33d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/ImageRunModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,8 @@ export class ImageRunModal extends React.Component {
validationFailed.publish = publishValidation;

const volumesValidation = volumes.map(a => {
// We can't validate hostPath as that happens via an error callback.
return {
hostPath: validateVolume(a.hostPath, "hostPath"),
containerPath: validateVolume(a.containerPath, "containerPath"),
};
});
Expand Down Expand Up @@ -659,6 +659,7 @@ export class ImageRunModal extends React.Component {
* Index needs to corellate with a row number
*/
dynamicListOnValidationChange = (value, key) => {
console.log('dynamic list validation', value, key);
const validationFailedDelta = { ...this.state.validationFailed };

validationFailedDelta[key] = value;
Expand Down Expand Up @@ -1139,6 +1140,7 @@ export class ImageRunModal extends React.Component {
</Tabs>
</Form>
);
console.log(dialogValues);
return (
<Modal isOpen
position="top" variant="medium"
Expand Down
8 changes: 6 additions & 2 deletions src/Volume.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const _ = cockpit.gettext;
export function validateVolume(value, key) {
switch (key) {
case "hostPath":
if (value)
return value;
break;
case "containerPath":
if (!value)
Expand All @@ -38,9 +40,11 @@ export const Volume = ({ id, item, onChange, idx, removeitem, additem, options,
>
<FileAutoComplete id={id + "-host-path"}
value={item.hostPath || ''}
onChange={value => {
onChange={(value, error) => {
console.log(`value: ${value}, error: ${error}`);
console.log(validationFailed);
utils.validationClear(validationFailed, "hostPath", onValidationChange);
utils.validationDebounce(() => onValidationChange({ ...validationFailed, hostPath: validateVolume(value, "hostPath") }));
utils.validationDebounce(() => onValidationChange({ ...validationFailed, hostPath: validateVolume(error, "hostPath") }));
onChange(idx, 'hostPath', value);
}} />
<FormHelper helperTextInvalid={validationFailed?.hostPath} />
Expand Down

0 comments on commit 40d33d0

Please sign in to comment.