Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #61 from ecmwf-projects/COPDS-1400-download-form-i…
Browse files Browse the repository at this point in the history
…mprovements

Copds 1400 download form improvements
  • Loading branch information
pelusanchez authored Dec 26, 2023
2 parents 0b52f45 + 4118f84 commit 25b9dfc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ecmwf-projects/cads-ui-library",
"version": "8.1.0",
"version": "8.2.2",
"description": "Common UI kit library",
"repository": {
"type": "git",
Expand Down
12 changes: 12 additions & 0 deletions src/widgets/RequiredErrorMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react'
import { Error } from './Widget'

export const RequiredErrorMessage = ({ show = false }: { show?: boolean }) => {
if (!show) {
return null
}

return (
<Error data-error='required'>At least one selection must be made</Error>
)
}
12 changes: 6 additions & 6 deletions src/widgets/StringChoiceWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import {
ReservedSpace,
WidgetActionsWrapper,
WidgetHeader,
WidgetTitle,
Error
WidgetTitle
} from './Widget'

import { isDisabled, useBypassRequired } from '../utils'
import { RequiredErrorMessage } from './RequiredErrorMessage'

export interface StringChoiceWidgetDetails {
columns: number
Expand Down Expand Up @@ -140,8 +140,10 @@ const StringChoiceWidget = ({

const [defaultValue] = selection || []

const requiredError = !bypassed && required && !selection?.length

return (
<Widget data-stylizable='widget'>
<Widget data-stylizable='widget' data-widget-required={requiredError}>
<WidgetHeader>
<WidgetActionsWrapper data-stylizable='widget-action-wrapper'>
<WidgetTitle
Expand Down Expand Up @@ -174,9 +176,7 @@ const StringChoiceWidget = ({
/>
</WidgetHeader>
<ReservedSpace data-stylizable='widget string-choice reserved-error-space'>
{!bypassed && required && !selection?.length ? (
<Error>At least one selection must be made</Error>
) : null}
<RequiredErrorMessage show={requiredError} />
</ReservedSpace>
<Fieldset name={name} ref={fieldSetRef} disabled={fieldsetDisabled}>
<Legend>{label}</Legend>
Expand Down
10 changes: 5 additions & 5 deletions src/widgets/StringListArrayWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
WidgetActionsWrapper,
WidgetHeader,
WidgetTitle,
Error,
ReservedSpace
} from './Widget'

Expand All @@ -34,6 +33,7 @@ import {
useBypassRequired,
useWidgetSelection
} from '../utils'
import { RequiredErrorMessage } from './RequiredErrorMessage'

declare global {
interface Set<T> {
Expand Down Expand Up @@ -354,8 +354,10 @@ const StringListArrayWidget = ({

const allValues = getAllValues(allGroups)

const requiredError = !bypassed && required && !selection[name]?.length

return (
<Widget data-stylizable='widget'>
<Widget data-stylizable='widget' data-widget-required={requiredError}>
<WidgetHeader>
<WidgetActionsWrapper data-stylizable='widget-action-wrapper'>
<WidgetTitle
Expand Down Expand Up @@ -430,9 +432,7 @@ const StringListArrayWidget = ({
/>
</WidgetHeader>
<ReservedSpace data-stylizable='widget string-listarray reserved-error-space'>
{!bypassed && required && !selection[name]?.length ? (
<Error>At least one selection must be made</Error>
) : null}
<RequiredErrorMessage show={requiredError} />
</ReservedSpace>
<Fieldset name={name} ref={fieldSetRef} disabled={fieldsetDisabled}>
<Legend>{label}</Legend>
Expand Down
10 changes: 5 additions & 5 deletions src/widgets/StringListWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
WidgetActionsWrapper,
WidgetHeader,
WidgetTitle,
Error,
ReservedSpace
} from './Widget'

Expand All @@ -30,6 +29,7 @@ import {
useBypassRequired,
useWidgetSelection
} from '../utils'
import { RequiredErrorMessage } from './RequiredErrorMessage'

declare global {
interface Set<T> {
Expand Down Expand Up @@ -122,8 +122,10 @@ const StringListWidget = ({
return Boolean(selection.find(sel => sel === value))
}

const requiredError = !bypassed && required && !selection[name]?.length

return (
<Widget data-stylizable='widget'>
<Widget data-stylizable='widget' data-widget-required={requiredError}>
<WidgetHeader>
<WidgetActionsWrapper data-stylizable='widget-action-wrapper'>
<WidgetTitle
Expand Down Expand Up @@ -188,9 +190,7 @@ const StringListWidget = ({
/>
</WidgetHeader>
<ReservedSpace>
{!bypassed && required && !selection[name]?.length ? (
<Error>At least one selection must be made</Error>
) : null}
<RequiredErrorMessage show={requiredError} />
</ReservedSpace>
<Fieldset name={name} ref={fieldSetRef} disabled={fieldsetDisabled}>
<Legend>{label}</Legend>
Expand Down

0 comments on commit 25b9dfc

Please sign in to comment.