-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update connection type field action "Move to section heading" (#3118)
* Rename delete to remove * Add move to section modal * Use SimpleSelect and hide parent section option
- Loading branch information
Showing
5 changed files
with
214 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
frontend/src/pages/connectionTypes/manage/ConnectionTypeFieldMoveModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import * as React from 'react'; | ||
import { Form, FormGroup, Modal } from '@patternfly/react-core'; | ||
import { ConnectionTypeField, ConnectionTypeFieldType } from '~/concepts/connectionTypes/types'; | ||
import DashboardModalFooter from '~/concepts/dashboard/DashboardModalFooter'; | ||
import SimpleSelect, { SimpleSelectOption } from '~/components/SimpleSelect'; | ||
|
||
type Props = { | ||
row: { field: ConnectionTypeField; index: number }; | ||
fields?: ConnectionTypeField[]; | ||
onClose: () => void; | ||
onSubmit: (field: ConnectionTypeField, index: number) => void; | ||
}; | ||
|
||
export const ConnectionTypeMoveFieldToSectionModal: React.FC<Props> = ({ | ||
row, | ||
fields: fields, | ||
onClose, | ||
onSubmit, | ||
}) => { | ||
const options = React.useMemo(() => { | ||
const parentSectionIndex = fields?.findLastIndex( | ||
(r, i) => r.type === ConnectionTypeFieldType.Section && i < row.index, | ||
); | ||
|
||
const temp: SimpleSelectOption[] = []; | ||
for (let i = 0; fields && i < fields.length; i++) { | ||
if (fields[i].type === ConnectionTypeFieldType.Section && i !== parentSectionIndex) { | ||
temp.push({ label: fields[i].name, key: String(i) }); | ||
} | ||
} | ||
|
||
return temp; | ||
}, [fields, row]); | ||
|
||
const [selectedSection, setSelectedSection] = React.useState<SimpleSelectOption | undefined>( | ||
options[0], | ||
); | ||
|
||
return ( | ||
<Modal | ||
isOpen | ||
title="Move to section" | ||
onClose={onClose} | ||
variant="medium" | ||
footer={ | ||
<DashboardModalFooter | ||
submitLabel="Move" | ||
onCancel={onClose} | ||
onSubmit={() => { | ||
if (selectedSection) { | ||
onSubmit(row.field, Number(selectedSection.key)); | ||
onClose(); | ||
} | ||
}} | ||
isSubmitDisabled={!selectedSection} | ||
alertTitle="" | ||
/> | ||
} | ||
> | ||
Select the section heading that <b>{row.field.name}</b> will be moved to. | ||
<Form> | ||
<FormGroup fieldId="sectionHeading" label="Section heading" isRequired> | ||
<SimpleSelect | ||
id="sectionHeading" | ||
dataTestId="section-heading-select" | ||
options={options} | ||
value={selectedSection?.key} | ||
onChange={(key) => setSelectedSection(options.find((s) => s.key === key))} | ||
isFullWidth | ||
isDisabled={options.length === 1} | ||
/> | ||
</FormGroup> | ||
</Form> | ||
</Modal> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters