Skip to content

RFF ArrayFields #1801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"core-js": "^3.18.3",
"enzyme": "^3.11.0",
"final-form": "^4.20.4",
"final-form-arrays": "^3.1.0",
"fuzzysort": "^1.1.4",
"javascript-time-ago": "^2.5.9",
"jspdf": "^2.4.0",
Expand All @@ -67,6 +68,7 @@
"react-datepicker": "^4.10.0",
"react-dom": "^17.0.2",
"react-final-form": "^6.5.7",
"react-final-form-arrays": "^3.1.4",
"react-final-form-listeners": "^1.0.3",
"react-helmet": "^6.1.0",
"react-hotkeys-hook": "^3.4.4",
Expand Down
56 changes: 56 additions & 0 deletions src/components/forms/RFFComponents.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CButton,
CFormCheck,
CFormFeedback,
CFormInput,
Expand All @@ -12,9 +13,11 @@ import {
import Select from 'react-select'
import AsyncSelect from 'react-select/async'
import { Field } from 'react-final-form'
import { FieldArray } from 'react-final-form-arrays'
import React from 'react'
import PropTypes from 'prop-types'
import { useRef } from 'react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'

/*
wrapper classes for React Final Form with CoreUI
Expand Down Expand Up @@ -167,6 +170,59 @@ RFFCFormInput.propTypes = {
placeholder: PropTypes.string,
}

export const RFFCFormInputArray = ({ name, label, className = 'mb-3' }) => {
return (
<>
<FieldArray name={name}>
{({ fields }) => (
<div>
<div className="mb-2">
{label && (
<CFormLabel className="me-2" htmlFor={name}>
{label}
</CFormLabel>
)}
<CButton
onClick={() => fields.push({ Key: '', Value: '' })}
className="circular-button"
title={'+'}
>
<FontAwesomeIcon icon={'plus'} />
</CButton>
</div>
{fields.map((name, index) => (
<div key={name} className={className}>
<div>
<Field name={`${name}.Key`} component="input">
{({ input, meta }) => {
return <CFormInput placeholder="Key" {...input} className="mb-2" />
}}
</Field>
<Field name={`${name}.Value`} component="input">
{({ input, meta }) => {
return <CFormInput placeholder="Value" {...input} className="mb-2" />
}}
</Field>
</div>
<CButton
onClick={() => fields.remove(index)}
className={`circular-button`}
title={'-'}
>
<FontAwesomeIcon icon={'minus'} />
</CButton>
</div>
))}
</div>
)}
</FieldArray>
</>
)
}
RFFCFormInputArray.propTypes = {
...sharedPropTypes,
}

export const RFFCFormRadio = ({
name,
label,
Expand Down
2 changes: 2 additions & 0 deletions src/components/forms/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
RFFCFormTextarea,
RFFCFormSelect,
RFFSelectSearch,
RFFCFormInputArray,
} from 'src/components/forms/RFFComponents'

export {
Expand All @@ -20,4 +21,5 @@ export {
RFFCFormTextarea,
RFFCFormSelect,
RFFSelectSearch,
RFFCFormInputArray,
}
34 changes: 27 additions & 7 deletions src/views/cipp/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Condition,
RFFCFormCheck,
RFFCFormInput,
RFFCFormInputArray,
RFFCFormRadio,
RFFCFormSwitch,
RFFCFormTextarea,
Expand Down Expand Up @@ -36,6 +37,7 @@ import 'react-datepicker/dist/react-datepicker.css'
import TenantListSelector from 'src/components/utilities/TenantListSelector'
import { ModalService, TenantSelector } from 'src/components/utilities'
import CippCodeOffCanvas from 'src/components/utilities/CippCodeOffcanvas'
import arrayMutators from 'final-form-arrays'

const Offcanvas = (row, rowIndex, formatExtraData) => {
const [ExecuteGetRequest, getResults] = useLazyGenericGetRequestQuery()
Expand Down Expand Up @@ -110,6 +112,7 @@ const Scheduler = () => {
Parameters: values.parameters,
ScheduledTime: unixTime,
Recurrence: values.Recurrence,
AdditionalProperties: values.additional,
PostExecution: {
Webhook: values.webhook,
Email: values.email,
Expand Down Expand Up @@ -199,6 +202,9 @@ const Scheduler = () => {
<CippContentCard title="Add Task" icon={faEdit}>
<Form
onSubmit={onSubmit}
mutators={{
...arrayMutators,
}}
initialValues={{ taskName }}
initialValuesEqual={() => true}
render={({ handleSubmit, submitting, values }) => {
Expand Down Expand Up @@ -315,12 +321,22 @@ const Scheduler = () => {
/>
</>
) : (
<RFFCFormInput
type="text"
key={idx}
name={`parameters.${param.Name}`}
label={`${param.Name}`}
/>
<>
{param.Type === 'System.Collections.Hashtable' ? (
<RFFCFormInputArray
name={`parameters.${param.Name}`}
label={`${param.Name}`}
key={idx}
/>
) : (
<RFFCFormInput
type="text"
key={idx}
name={`parameters.${param.Name}`}
label={`${param.Name}`}
/>
)}
</>
)}
</CCol>
</CTooltip>
Expand All @@ -332,7 +348,11 @@ const Scheduler = () => {
}}
</FormSpy>
</CRow>

<CRow className="mb-3">
<CCol>
<RFFCFormInputArray name={`additional`} label="Additional Properties" />
</CCol>
</CRow>
<CRow className="mb-3">
<CCol>
<label>Send results to</label>
Expand Down