From b6c60d63a93ccada12608b55d794496a8d69f903 Mon Sep 17 00:00:00 2001 From: MariaAga Date: Tue, 20 Aug 2024 15:20:25 +0100 Subject: [PATCH] Fixes #37755 - drop oval code leftovers in React --- webpack/components/EditableInput.js | 166 -------------------------- webpack/components/EditableInput.scss | 3 - webpack/helpers/formFieldsHelper.js | 114 ------------------ 3 files changed, 283 deletions(-) delete mode 100644 webpack/components/EditableInput.js delete mode 100644 webpack/components/EditableInput.scss delete mode 100644 webpack/helpers/formFieldsHelper.js diff --git a/webpack/components/EditableInput.js b/webpack/components/EditableInput.js deleted file mode 100644 index 4c1ddcaf..00000000 --- a/webpack/components/EditableInput.js +++ /dev/null @@ -1,166 +0,0 @@ -import React, { useState } from 'react'; -import PropTypes from 'prop-types'; -import { translate as __ } from 'foremanReact/common/I18n'; -import { - Button, - Split, - SplitItem, - Spinner, - FormGroup, -} from '@patternfly/react-core'; -import { - TimesIcon, - CheckIcon, - PencilAltIcon, - ExclamationCircleIcon, -} from '@patternfly/react-icons'; - -import './EditableInput.scss'; - -const EditableInput = props => { - const [editing, setEditing] = useState(false); - const [submitting, setSubmitting] = useState(false); - const [inputValue, setInputValue] = useState(props.value); - const [error, setError] = useState(''); - const [touched, setTouched] = useState(false); - - const stopSubmitting = () => setSubmitting(false); - - const handleSubmit = event => { - event.preventDefault(); - onSubmit(); - }; - - const onFinish = () => { - setSubmitting(false); - setEditing(false); - }; - - const onSubmit = () => { - setSubmitting(true); - props.onConfirm(inputValue, onFinish, stopSubmitting, onError); - }; - - const onError = err => { - setTouched(false); - setError(err); - }; - - const onCancel = () => { - setInputValue(props.value); - setEditing(false); - setError(''); - }; - - const onChange = value => { - if (!touched) { - setTouched(true); - } - setInputValue(value); - }; - - const editBtn = ( - - - - ); - - if (!editing) { - return ( - - {props.value || {__('None provided')}} - {props.allowed && editBtn} - - ); - } - - const Component = props.component; - - const shouldValidate = (isTouched, err) => { - if (!isTouched) { - return err ? 'error' : 'success'; - } - return 'noval'; - }; - - const valid = shouldValidate(touched, error); - - return ( - - -
- } - validated={valid} - > - - -
-
- - - - - - - - {submitting && ( - - )} - -
- ); -}; - -EditableInput.propTypes = { - allowed: PropTypes.bool.isRequired, - value: PropTypes.string, - onConfirm: PropTypes.func.isRequired, - attrName: PropTypes.string.isRequired, - component: PropTypes.object.isRequired, - inputProps: PropTypes.object, -}; - -EditableInput.defaultProps = { - inputProps: {}, - value: '', -}; - -export default EditableInput; diff --git a/webpack/components/EditableInput.scss b/webpack/components/EditableInput.scss deleted file mode 100644 index 81048f26..00000000 --- a/webpack/components/EditableInput.scss +++ /dev/null @@ -1,3 +0,0 @@ -.inline-edit-icon { - padding-top: 2px; -} diff --git a/webpack/helpers/formFieldsHelper.js b/webpack/helpers/formFieldsHelper.js deleted file mode 100644 index fd830f38..00000000 --- a/webpack/helpers/formFieldsHelper.js +++ /dev/null @@ -1,114 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; - -import { - FormGroup, - TextInput, - TextArea, - FormSelect, - FormSelectOption, -} from '@patternfly/react-core'; -import { ExclamationCircleIcon } from '@patternfly/react-icons'; - -export const SelectField = props => { - const { selectItems, field, form } = props; - const fieldProps = wrapFieldProps(field); - - const valid = shouldValidate(form, field.name); - - return ( - } - validated={valid} - > - - - {selectItems.map((item, idx) => ( - - ))} - - - ); -}; - -SelectField.propTypes = { - selectItems: PropTypes.array, - label: PropTypes.string.isRequired, - isRequired: PropTypes.bool, - field: PropTypes.object.isRequired, - form: PropTypes.object.isRequired, - blankLabel: PropTypes.string.isRequired, -}; -SelectField.defaultProps = { - selectItems: [], - isRequired: false, -}; - -const wrapFieldProps = fieldProps => { - const { onChange } = fieldProps; - // modify onChange args to correctly wire formik with pf4 input handlers - const wrappedOnChange = (value, event) => { - onChange(event); - }; - - return { ...fieldProps, onChange: wrappedOnChange }; -}; - -const shouldValidate = (form, fieldName) => { - if (form.touched[fieldName]) { - return form.errors[fieldName] ? 'error' : 'success'; - } - - return 'noval'; -}; - -const fieldWithHandlers = Component => { - const Subcomponent = ({ label, form, field, isRequired, ...rest }) => { - const fieldProps = wrapFieldProps(field); - const valid = shouldValidate(form, field.name); - - return ( - } - validated={valid} - > - - - ); - }; - - Subcomponent.propTypes = { - form: PropTypes.object.isRequired, - field: PropTypes.object.isRequired, - label: PropTypes.string.isRequired, - isRequired: PropTypes.bool, - }; - - Subcomponent.defaultProps = { - isRequired: false, - }; - - return Subcomponent; -}; - -export const TextField = fieldWithHandlers(TextInput); -export const TextAreaField = fieldWithHandlers(TextArea);