ljmotta commented on code in PR #2826: URL: https://github.com/apache/incubator-kie-tools/pull/2826#discussion_r1913182582
########## packages/form-code-generator-patternfly-theme/src/uniforms/ListField.tsx: ########## @@ -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; + } Review Comment: I'm not sure of what happened here. The form code was correctly generated? Can you share it here, please? What is a `Offer`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
