-
Notifications
You must be signed in to change notification settings - Fork 14
[OGUI-1803] Add Restrictions for arrays #3211
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
Open
Deaponn
wants to merge
13
commits into
dev
Choose a base branch
from
feature/CNF/OGUI-1803/array-restrictions
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,142
−345
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6cdd922
feature: add Restrictions for arrays
Deaponn d2e96cc
refactor: improve code and docs
Deaponn b59f011
feat: implement rendering of Arrays
Deaponn 657364d
test: add tests for the new functions and update docs
Deaponn 39b87d4
test: add more tests
Deaponn 5438ad9
feat: implement calculation of ArrayRestrictions
Deaponn 4edb1d4
test: add more tests
Deaponn 23c9cea
test: fix failing test spec
Deaponn 1cd140c
feat: implement array rendering on the frontend
Deaponn d1ea186
Merge branch 'dev' into feature/CNF/OGUI-1803/array-restrictions
Deaponn 3cdc6bf
Merge branch 'dev' into feature/CNF/OGUI-1803/array-restrictions
Deaponn e83269f
fix: form not hydrating properly
Deaponn 17ea4a3
fix: refactor how getDefaultValues works with arrays
Deaponn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
68 changes: 68 additions & 0 deletions
68
Configuration/webapp/app/components/form/components/widgets/ArrayWidget.tsx
This file contains hidden or 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,68 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
| * See http://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
| * All rights not expressly granted are reserved. | ||
| * | ||
| * This software is distributed under the terms of the GNU General Public | ||
| * License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
| * | ||
| * In applying this license CERN does not waive the privileges and immunities | ||
| * granted to it by virtue of its status as an Intergovernmental Organization | ||
| * or submit itself to any jurisdiction. | ||
| */ | ||
|
|
||
| import { useState, type ReactElement } from 'react'; | ||
| import { Accordion, AccordionDetails, Stack } from '@mui/material'; | ||
| import { AccordionHeader } from '../AccordionHeader'; | ||
| import type { ArrayRestrictions, FormArrayValue } from '../../types'; | ||
| import { RawViewModal } from '../../raw-view/RawViewModal'; | ||
| import { Form } from '../../Form'; | ||
| import type { Control } from 'react-hook-form'; | ||
| import type { InputsType } from '~/routes/configuration'; | ||
| import { KEY_SEPARATOR } from '../../constants'; | ||
|
|
||
| interface ArrayWidgetProps { | ||
| sectionTitle: string; | ||
| sectionPrefix: string; | ||
| items: FormArrayValue; | ||
| itemsRestrictions: ArrayRestrictions; | ||
| control: Control<InputsType>; | ||
| } | ||
|
|
||
| export const ArrayWidget = ({ | ||
| sectionTitle, | ||
| sectionPrefix, | ||
| items, | ||
| itemsRestrictions, | ||
| control, | ||
| }: ArrayWidgetProps): ReactElement => { | ||
| const [isRawModalOpen, setIsRawModalOpen] = useState(false); | ||
| const [arrayRestrictions] = itemsRestrictions; // [arrayRestrictions, objectBlueprint, arrayBlueprint] | ||
|
|
||
| return ( | ||
| <> | ||
| <Accordion defaultExpanded> | ||
| <AccordionHeader title={sectionTitle} showRawViewModal={() => setIsRawModalOpen(true)} /> | ||
| <AccordionDetails> | ||
| <Stack spacing={2}> | ||
| {items.map((item, idx) => ( | ||
| <Form | ||
| key={idx} | ||
| sectionTitle={`Item #${idx}`} | ||
| sectionPrefix={`${sectionPrefix}${KEY_SEPARATOR}${idx}`} | ||
| value={item} | ||
| restrictions={arrayRestrictions[idx] ?? [[], null, null]} | ||
| control={control} | ||
| /> | ||
| ))} | ||
| </Stack> | ||
| </AccordionDetails> | ||
| </Accordion> | ||
|
|
||
| {isRawModalOpen && ( | ||
| <RawViewModal onClose={() => setIsRawModalOpen(false)} title={sectionTitle} data={items} /> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
79 changes: 79 additions & 0 deletions
79
Configuration/webapp/app/components/form/components/widgets/ObjectWidget.tsx
This file contains hidden or 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,79 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2019-2020 CERN and copyright holders of ALICE O2. | ||
| * See http://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
| * All rights not expressly granted are reserved. | ||
| * | ||
| * This software is distributed under the terms of the GNU General Public | ||
| * License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
| * | ||
| * In applying this license CERN does not waive the privileges and immunities | ||
| * granted to it by virtue of its status as an Intergovernmental Organization | ||
| * or submit itself to any jurisdiction. | ||
| */ | ||
|
|
||
| import { useState, type FC, type PropsWithChildren } from 'react'; | ||
| import Accordion from '@mui/material/Accordion'; | ||
| import AccordionDetails from '@mui/material/AccordionDetails'; | ||
| import Stack from '@mui/material/Stack'; | ||
| import { AccordionHeader } from '../AccordionHeader'; | ||
| import { RawViewModal } from '../../raw-view/RawViewModal'; | ||
| import type { Control } from 'react-hook-form'; | ||
| import { type InputsType } from '~/routes/configuration'; | ||
| import type { FormObjectValue, ObjectRestrictions } from '../../types'; | ||
| import { KEY_SEPARATOR } from '../../constants'; | ||
| import { Form } from '../../Form'; | ||
|
|
||
| interface ObjectWidgetProps extends PropsWithChildren { | ||
| sectionTitle: string; | ||
| sectionPrefix: string; | ||
| items: FormObjectValue; | ||
| itemsRestrictions: ObjectRestrictions; | ||
| control: Control<InputsType>; | ||
| } | ||
|
|
||
| /** | ||
| * Form component. | ||
| * @param {ObjectWidgetProps} props - The props of the form. | ||
| * @param {string} props.sectionTitle - The title of the section. | ||
| * @param {string} props.sectionPrefix - The prefix of the section. | ||
| * @param {FormItem} props.items - The items of the form. | ||
| * @param {FormRestrictions} props.itemsRestrictions - The restrictions of the items. | ||
| * @param {Control<InputsType>} props.control - The control of the form. | ||
| * @returns {ReactElement} The form component. | ||
| */ | ||
| export const ObjectWidget: FC<ObjectWidgetProps> = ({ | ||
| sectionTitle, | ||
| sectionPrefix, | ||
| items, | ||
| itemsRestrictions, | ||
| control, | ||
| }) => { | ||
| const [isRawModalOpen, setIsRawModalOpen] = useState<boolean>(false); | ||
|
|
||
| return ( | ||
| <> | ||
| <Accordion defaultExpanded> | ||
| <AccordionHeader title={sectionTitle} showRawViewModal={() => setIsRawModalOpen(true)} /> | ||
| <AccordionDetails> | ||
| <Stack spacing={2}> | ||
| {Object.entries(items).map(([key, value]) => ( | ||
| <Form | ||
| key={key} | ||
| sectionTitle={key} | ||
| sectionPrefix={`${sectionPrefix}${KEY_SEPARATOR}${key}`} | ||
| value={value} | ||
| restrictions={itemsRestrictions[key]} | ||
| control={control} | ||
| /> | ||
| ))} | ||
| </Stack> | ||
| </AccordionDetails> | ||
| </Accordion> | ||
|
|
||
| {isRawModalOpen && ( | ||
| <RawViewModal onClose={() => setIsRawModalOpen(false)} title={sectionTitle} data={items} /> | ||
| )} | ||
| </> | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.