Skip to content

Commit

Permalink
Merge branch 'feat/json-schema' of https://github.com/alleslabs/celat…
Browse files Browse the repository at this point in the history
…one-frontend into feat/schema-migrate
  • Loading branch information
poomthiti committed Aug 10, 2023
2 parents 1a47e30 + 18302cb commit b728e17
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

- [#470](https://github.com/alleslabs/celatone-frontend/pull/470) Fix json schema array field default behavior
- [#456](https://github.com/alleslabs/celatone-frontend/pull/456) Fix pool count chip in pool transaction table
- [#454](https://github.com/alleslabs/celatone-frontend/pull/454) Fix contract selection loading state for other folders
- [#452](https://github.com/alleslabs/celatone-frontend/pull/452) Fix public project data on the account details and code details page still remains when switching network
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Grid, GridItem } from "@chakra-ui/react";
import type { ObjectFieldTemplateProps } from "@rjsf/utils";
import { canExpand, getTemplate, getUiOptions } from "@rjsf/utils";
import type {
ObjectFieldTemplatePropertyType,
ObjectFieldTemplateProps,
} from "@rjsf/utils";
import {
canExpand,
getSchemaType,
getTemplate,
getUiOptions,
} from "@rjsf/utils";

interface ObjectFieldTemplatePropertyTypeWithRequired
extends ObjectFieldTemplatePropertyType {
required?: boolean;
}

const ObjectFieldTemplate = <T = any, F = any>(
props: ObjectFieldTemplateProps<T, F>
Expand Down Expand Up @@ -39,17 +52,30 @@ const ObjectFieldTemplate = <T = any, F = any>(
/>
)}
<Grid gap={4} my={2}>
{properties.map((element, index) =>
element.hidden ? (
{properties.map((element, index) => {
// NOTE: required array field doesn't create an empty array as a default
const elementType = getSchemaType(element.content.props.schema);
const elementRequired = (
element as ObjectFieldTemplatePropertyTypeWithRequired
).required;
if (
typeof elementType === "string" &&
elementType === "array" &&
elementRequired &&
!Array.isArray((formData as Record<string, object>)[element.name])
)
(formData as Record<string, object>)[element.name] = [];

return element.hidden ? (
element.content
) : (
<GridItem
key={`${idSchema.$id}-${element.name}-${index.toString()}`}
>
{element.content}
</GridItem>
)
)}
);
})}
{canExpand<T, F>(schema, uiSchema, formData) && (
<GridItem justifySelf="flex-end">
<AddButton
Expand Down

0 comments on commit b728e17

Please sign in to comment.