-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #357 from IQSS/feature/336-dynamically-render-form…
…-fields Feature/336 dynamically render form fields
- Loading branch information
Showing
38 changed files
with
5,251 additions
and
346 deletions.
There are no files selected for viewing
14 changes: 3 additions & 11 deletions
14
packages/design-system/src/lib/components/accordion/Accordion.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
10 changes: 6 additions & 4 deletions
10
packages/design-system/src/lib/components/accordion/AccordionBody.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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { ReactNode } from 'react' | ||
import { ElementType, ReactNode } from 'react' | ||
import { Accordion as AccordionBS } from 'react-bootstrap' | ||
|
||
interface AccordionBodyProps { | ||
interface AccordionBodyProps extends React.HTMLAttributes<HTMLElement> { | ||
children: ReactNode | ||
bsPrefix?: string | ||
as?: ElementType | ||
} | ||
|
||
export function AccordionBody({ children }: AccordionBodyProps) { | ||
return <AccordionBS.Body>{children}</AccordionBS.Body> | ||
export function AccordionBody({ children, ...rest }: AccordionBodyProps) { | ||
return <AccordionBS.Body {...rest}>{children}</AccordionBS.Body> | ||
} |
11 changes: 7 additions & 4 deletions
11
packages/design-system/src/lib/components/accordion/AccordionHeader.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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import { ReactNode } from 'react' | ||
import { ElementType, ReactNode } from 'react' | ||
import { Accordion as AccordionBS } from 'react-bootstrap' | ||
|
||
interface AccordionHeaderProps { | ||
interface AccordionHeaderProps extends React.HTMLAttributes<HTMLElement> { | ||
children: ReactNode | ||
onClick?: () => void | ||
bsPrefix?: string | ||
as?: ElementType | ||
} | ||
|
||
export function AccordionHeader({ children }: AccordionHeaderProps) { | ||
return <AccordionBS.Header>{children}</AccordionBS.Header> | ||
export function AccordionHeader({ children, ...rest }: AccordionHeaderProps) { | ||
return <AccordionBS.Header {...rest}>{children}</AccordionBS.Header> | ||
} |
10 changes: 6 additions & 4 deletions
10
packages/design-system/src/lib/components/accordion/AccordionItem.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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import { ReactNode } from 'react' | ||
import { ElementType, ReactNode } from 'react' | ||
import { Accordion as AccordionBS } from 'react-bootstrap' | ||
|
||
interface AccordionItemProps { | ||
export interface AccordionItemProps extends React.HTMLAttributes<HTMLElement> { | ||
eventKey: string | ||
children: ReactNode | ||
bsPrefix?: string | ||
as?: ElementType | ||
} | ||
|
||
export function AccordionItem({ eventKey, children }: AccordionItemProps) { | ||
return <AccordionBS.Item eventKey={eventKey}>{children}</AccordionBS.Item> | ||
export function AccordionItem({ children, ...rest }: AccordionItemProps) { | ||
return <AccordionBS.Item {...rest}>{children}</AccordionBS.Item> | ||
} |
8 changes: 4 additions & 4 deletions
8
...s/design-system/src/lib/components/form/form-checkbox-group/FormCheckboxGroup.module.scss
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
@import "src/lib/assets/styles/design-tokens/typography.module"; | ||
@import 'src/lib/assets/styles/design-tokens/typography.module'; | ||
|
||
.title { | ||
padding-top: calc(0.375rem + 1px); | ||
padding-bottom: calc(0.375rem + 1px); | ||
display: inline-block; | ||
margin-bottom: 0.5rem; | ||
font-weight: $dv-font-weight-bold; | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
packages/design-system/tests/component/form/form-group/FormGroup.spec.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,19 @@ | ||
import { FormGroup } from '../../../../src/lib/components/form/form-group/FormGroup' | ||
import { Form } from '../../../../src/lib/components/form/Form' | ||
|
||
describe('FormGroup', () => { | ||
it('should render childrens correctly even trough react fragments', () => { | ||
cy.mount( | ||
<Form> | ||
<FormGroup controlId="some-control-id"> | ||
<> | ||
<label htmlFor="username">Username</label> | ||
<input type="text" id="username" /> | ||
</> | ||
</FormGroup> | ||
</Form> | ||
) | ||
|
||
cy.findByText('Username').should('exist') | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -11,3 +11,104 @@ export interface MetadataFieldInfo { | |
|
||
export const METADATA_FIELD_DISPLAY_FORMAT_PLACEHOLDER = '#VALUE' | ||
export const METADATA_FIELD_DISPLAY_FORMAT_NAME_PLACEHOLDER = '#NAME' | ||
|
||
// 👇👇 New types for #336 | ||
|
||
export interface MetadataBlockInfo2 { | ||
id: number | ||
name: string | ||
displayName: string | ||
metadataFields: Record<string, MetadataField2> | ||
displayOnCreate: boolean // If true, the block will be displayed on the create dataset form | ||
} | ||
|
||
export interface MetadataField2 { | ||
name: string | ||
displayName: string | ||
title: string | ||
type: TypeMetadataField | ||
typeClass: TypeClassMetadataField | ||
watermark: WatermarkMetadataField | ||
description: string | ||
multiple: boolean | ||
isControlledVocabulary: boolean | ||
displayFormat: string | ||
isRequired: boolean | ||
displayOrder: number | ||
controlledVocabularyValues?: string[] | ||
childMetadataFields?: Record<string, MetadataField2> | ||
displayOnCreate: boolean // If true, the field will be displayed on the create metadata block | ||
} | ||
|
||
export const TypeMetadataFieldOptions = { | ||
Date: 'DATE', | ||
Email: 'EMAIL', | ||
Float: 'FLOAT', | ||
Int: 'INT', | ||
None: 'NONE', | ||
Text: 'TEXT', | ||
Textbox: 'TEXTBOX', | ||
URL: 'URL' | ||
} as const | ||
|
||
export type TypeMetadataField = | ||
(typeof TypeMetadataFieldOptions)[keyof typeof TypeMetadataFieldOptions] | ||
|
||
// export enum TypeMetadataField { | ||
// Date = 'DATE', | ||
// Email = 'EMAIL', | ||
// Float = 'FLOAT', | ||
// Int = 'INT', | ||
// None = 'NONE', | ||
// Text = 'TEXT', | ||
// Textbox = 'TEXTBOX', | ||
// URL = 'URL' | ||
// } | ||
|
||
export const TypeClassMetadataFieldOptions = { | ||
Compound: 'compound', | ||
ControlledVocabulary: 'controlledVocabulary', | ||
Primitive: 'primitive' | ||
} as const | ||
|
||
export type TypeClassMetadataField = | ||
(typeof TypeClassMetadataFieldOptions)[keyof typeof TypeClassMetadataFieldOptions] | ||
|
||
// export enum TypeClassMetadataField { | ||
// Compound = 'compound', | ||
// ControlledVocabulary = 'controlledVocabulary', | ||
// Primitive = 'primitive' | ||
// } | ||
|
||
export const WatermarkMetadataFieldOptions = { | ||
Empty: '', | ||
EnterAFloatingPointNumber: 'Enter a floating-point number.', | ||
EnterAnInteger: 'Enter an integer.', | ||
FamilyNameGivenNameOrOrganization: 'FamilyName, GivenName or Organization', | ||
HTTPS: 'https://', | ||
NameEmailXyz: '[email protected]', | ||
OrganizationXYZ: 'Organization XYZ', | ||
The1FamilyNameGivenNameOr2Organization: '1) FamilyName, GivenName or 2) Organization', | ||
The1FamilyNameGivenNameOr2OrganizationXYZ: '1) Family Name, Given Name or 2) Organization XYZ', | ||
WatermarkEnterAnInteger: 'Enter an integer...', | ||
YYYYOrYYYYMMOrYYYYMMDD: 'YYYY or YYYY-MM or YYYY-MM-DD', | ||
YyyyMmDD: 'YYYY-MM-DD' | ||
} as const | ||
|
||
export type WatermarkMetadataField = | ||
(typeof WatermarkMetadataFieldOptions)[keyof typeof WatermarkMetadataFieldOptions] | ||
|
||
// export enum WatermarkMetadataField { | ||
// Empty = '', | ||
// EnterAFloatingPointNumber = 'Enter a floating-point number.', | ||
// EnterAnInteger = 'Enter an integer.', | ||
// FamilyNameGivenNameOrOrganization = 'FamilyName, GivenName or Organization', | ||
// HTTPS = 'https://', | ||
// NameEmailXyz = '[email protected]', | ||
// OrganizationXYZ = 'Organization XYZ', | ||
// The1FamilyNameGivenNameOr2Organization = '1) FamilyName, GivenName or 2) Organization', | ||
// The1FamilyNameGivenNameOr2OrganizationXYZ = '1) Family Name, Given Name or 2) Organization XYZ', | ||
// WatermarkEnterAnInteger = 'Enter an integer...', | ||
// YYYYOrYYYYMMOrYYYYMMDD = 'YYYY or YYYY-MM or YYYY-MM-DD', | ||
// YyyyMmDD = 'YYYY-MM-DD' | ||
// } |
3 changes: 2 additions & 1 deletion
3
src/metadata-block-info/domain/repositories/MetadataBlockInfoRepository.ts
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { MetadataBlockInfo } from '../models/MetadataBlockInfo' | ||
import { MetadataBlockInfo, MetadataBlockInfo2 } from '../models/MetadataBlockInfo' | ||
|
||
export interface MetadataBlockInfoRepository { | ||
getByName: (name: string) => Promise<MetadataBlockInfo | undefined> | ||
getByColecctionId: (collectionId: string, create: boolean) => Promise<MetadataBlockInfo2[]> | ||
} |
14 changes: 14 additions & 0 deletions
14
src/metadata-block-info/domain/useCases/getMetadataBlockInfoByCollectionId.ts
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,14 @@ | ||
import { MetadataBlockInfo2 } from '../models/MetadataBlockInfo' | ||
import { MetadataBlockInfoRepository } from '../repositories/MetadataBlockInfoRepository' | ||
|
||
export async function getMetadataBlockInfoByCollectionId( | ||
metadataBlockInfoRepository: MetadataBlockInfoRepository, | ||
collectionId: string, | ||
create: boolean | ||
): Promise<MetadataBlockInfo2[]> { | ||
return metadataBlockInfoRepository | ||
.getByColecctionId(collectionId, create) | ||
.catch((error: Error) => { | ||
throw new Error(error.message) | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
import { CreateDatasetForm } from './CreateDatasetForm' | ||
import { ReactElement } from 'react' | ||
import { DatasetJSDataverseRepository } from '../../dataset/infrastructure/repositories/DatasetJSDataverseRepository' | ||
import { MetadataBlockInfoJSDataverseRepository } from '../../metadata-block-info/infrastructure/repositories/MetadataBlockInfoJSDataverseRepository' | ||
import { MetadataBlockInfoMockRepository } from '../../stories/create-dataset/MetadataBlockInfoMockRepository' | ||
|
||
const repository = new DatasetJSDataverseRepository() | ||
const _metadataBlockInfoRepository = new MetadataBlockInfoJSDataverseRepository() | ||
const metadataBlockInfoMockRepository = new MetadataBlockInfoMockRepository() | ||
|
||
export class CreateDatasetFactory { | ||
static create(): ReactElement { | ||
return <CreateDatasetForm repository={repository} /> | ||
return ( | ||
<CreateDatasetForm | ||
repository={repository} | ||
metadataBlockInfoRepository={metadataBlockInfoMockRepository} | ||
/> | ||
) | ||
} | ||
} |
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,7 @@ | ||
.header { | ||
margin: 0.5em 0; | ||
} | ||
|
||
.container { | ||
// margin: 0.5rem 0; | ||
} |
Oops, something went wrong.