-
Notifications
You must be signed in to change notification settings - Fork 201
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
kie-issues#1542: Implement ListField in the “form-code-generator-patternfly-theme” package #2826
Open
ljmotta
wants to merge
15
commits into
apache:main
Choose a base branch
from
ljmotta:kie-issues-1542
base: main
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.
Open
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
53363e3
WIP
ljmotta fdf929d
Merge remote-tracking branch 'origin' into kie-issues-1542
ljmotta 5124525
Change BoolField, CheckBoxGroup and RadioField
ljmotta 80be77a
Change DateField and SelectField
ljmotta 8e7a57b
Use pf icons
ljmotta b8d4ffa
Add ListField snapshot to rat-excludes
ljmotta c87dcd5
WIP - investigating missing icon import
ljmotta 858291d
Add pf icon imports in NestedField
ljmotta a109611
Add patternfly react icons import
ljmotta 0431d8c
Update snapshots and ListField test
ljmotta 04fa3ee
Merge remote-tracking branch 'origin/main' into kie-issues-1542
ljmotta eb62b03
Clean up
ljmotta c8b962d
Fix any type
ljmotta b71be9b
Fix field id and state type
ljmotta c01f8e8
Update snapshots
ljmotta 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 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
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
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
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
148 changes: 148 additions & 0 deletions
148
packages/form-code-generator-patternfly-theme/src/uniforms/ListField.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,148 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import React, { useContext } from "react"; | ||
import { connectField, context, HTMLFieldProps, joinName } from "uniforms/cjs"; | ||
import { getInputReference, getStateCode, renderField } from "./utils/Utils"; | ||
import { codeGenContext } from "./CodeGenContext"; | ||
import { FormInput, InputReference } from "../api"; | ||
import { ARRAY } from "./utils/dataTypes"; | ||
import { renderListItemFragmentWithContext } from "./rendering/RenderingUtils"; | ||
import { ListItemProps } from "./rendering/ListItemField"; | ||
|
||
export type ListFieldProps = HTMLFieldProps< | ||
unknown[], | ||
HTMLDivElement, | ||
{ | ||
itemProps?: ListItemProps; | ||
maxCount?: number; | ||
minCount?: number; | ||
} | ||
>; | ||
|
||
const List: React.FC<ListFieldProps> = (props: ListFieldProps) => { | ||
const ref: InputReference = getInputReference(props.name, ARRAY); | ||
|
||
const uniformsContext = useContext(context); | ||
const codegenCtx = useContext(codeGenContext); | ||
|
||
const listItem = renderListItemFragmentWithContext( | ||
uniformsContext, | ||
"$", | ||
{ | ||
isListItem: true, | ||
indexVariableName: "itemIndex", | ||
listName: props.name, | ||
listStateName: ref.stateName, | ||
listStateSetter: ref.stateSetter, | ||
}, | ||
props.disabled | ||
); | ||
|
||
const getNewItemProps = () => { | ||
const typeName = listItem?.ref.dataType.name; | ||
if (typeName?.endsWith("[]")) { | ||
return listItem?.ref.dataType.defaultValue ?? []; | ||
} | ||
switch (typeName) { | ||
case "string": | ||
return listItem?.ref.dataType.defaultValue ?? ""; | ||
case "number": | ||
return listItem?.ref.dataType.defaultValue ?? null; | ||
case "boolean": | ||
return listItem?.ref.dataType.defaultValue ?? false; | ||
case "object": | ||
return listItem?.ref.dataType.defaultValue ?? {}; | ||
default: // any | ||
return listItem?.ref.dataType.defaultValue; | ||
} | ||
}; | ||
|
||
const jsxCode = `<div fieldId={'${props.id}'}> | ||
<Split hasGutter> | ||
<SplitItem> | ||
{'${props.label}' && ( | ||
<label className={"pf-c-form__label"}> | ||
<span className={"pf-c-form__label-text"}> | ||
${props.label} | ||
</span> | ||
</label> | ||
)} | ||
</SplitItem> | ||
<SplitItem isFilled /> | ||
<SplitItem> | ||
<Button | ||
name='$' | ||
variant='plain' | ||
style={{ paddingLeft: '0', paddingRight: '0' }} | ||
disabled={${props.maxCount === undefined ? props.disabled : `${props.disabled} || !(${props.maxCount} <= (${ref.stateName}?.length ?? -1))`}} | ||
onClick={() => { | ||
!${props.disabled} && ${props.maxCount === undefined ? `${ref.stateSetter}((${ref.stateName} ?? []).concat([${getNewItemProps()}]))` : `!(${props.maxCount} <= (${ref.stateName}?.length ?? -1)) && ${ref.stateSetter}((${ref.stateName} ?? []).concat([]))`}; | ||
}} | ||
> | ||
<PlusCircleIcon color='#0088ce' /> | ||
</Button> | ||
</SplitItem> | ||
</Split> | ||
<div> | ||
{${ref.stateName}?.map((_, itemIndex) => | ||
(<div | ||
key={itemIndex} | ||
style={{ | ||
marginBottom: '1rem', | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
<div style={{ width: '100%', marginRight: '10px' }}>${listItem?.jsxCode}</div> | ||
<div> | ||
<Button | ||
disabled={${props.minCount === undefined ? props.disabled : `${props.disabled} || (${props.minCount} >= (${ref.stateName}?.length ?? -1))`}} | ||
variant='plain' | ||
style={{ paddingLeft: '0', paddingRight: '0' }} | ||
onClick={() => { | ||
const value = [...${ref.stateName}] | ||
value.splice(itemIndex, 1); | ||
!${props.disabled} && ${props.minCount === undefined ? `${ref.stateSetter}(value)` : `!(${props.minCount} >= (${ref.stateName}?.length ?? -1)) && ${ref.stateSetter}(value)`}; | ||
}} | ||
> | ||
<MinusCircleIcon color='#cc0000' /> | ||
</Button> | ||
</div> | ||
</div>) | ||
)} | ||
</div> | ||
</div>`; | ||
|
||
const element: FormInput = { | ||
ref, | ||
pfImports: [...new Set(["Split", "SplitItem", "Button", ...(listItem?.pfImports ?? [])])], | ||
pfIconImports: [...new Set(["PlusCircleIcon", "MinusCircleIcon", ...(listItem?.pfIconImports ?? [])])], | ||
reactImports: [...new Set([...(listItem?.reactImports ?? [])])], | ||
jsxCode, | ||
stateCode: getStateCode(ref.stateName, ref.stateSetter, "any[]", "[]"), | ||
isReadonly: props.disabled, | ||
}; | ||
|
||
codegenCtx?.rendered.push(element); | ||
|
||
return renderField(element); | ||
}; | ||
|
||
export default connectField(List); |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to add one private field into
CandidateDate
like:Also getters and setters added and constructor adapted. However then in the run of
mvn clean quarkus:dev -Pdevelopment
ofprocess-compact-architecture
can not display the hiring form.In other words, does patternfly forms support list fields only for
number
,string
andboolean
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure of what happened here. The form code was correctly generated? Can you share it here, please? What is a
Offer
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Offer
is class from process-compact-architecture example.Here is the
CandidateData.java
and here is
hiring.tsx
: