Skip to content

Commit

Permalink
fix: merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminic committed Jan 16, 2025
2 parents a209094 + 7527246 commit 59e0a92
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 74 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [0.23.1](https://github.com/dhis2/maintenance-app-beta/compare/v0.23.0...v0.23.1) (2025-01-16)


### Bug Fixes

* **validation:** use dynamic schema validator for common fields ([#494](https://github.com/dhis2/maintenance-app-beta/issues/494)) ([0ff52ee](https://github.com/dhis2/maintenance-app-beta/commit/0ff52eeb757a4c1a9484ab70841bd08566d34668))

# [0.23.0](https://github.com/dhis2/maintenance-app-beta/compare/v0.22.0...v0.23.0) (2025-01-15)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maintenance-app",
"version": "0.23.0",
"version": "0.23.1",
"description": "",
"license": "BSD-3-Clause",
"private": true,
Expand Down
11 changes: 8 additions & 3 deletions src/components/form/fields/DescriptionField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import i18n from '@dhis2/d2-i18n'
import { createMaxCharacterLength, TextAreaFieldFF } from '@dhis2/ui'
import React from 'react'
import { Field as FieldRFF } from 'react-final-form'
import { SchemaSection } from '../../../lib'

Check warning on line 5 in src/components/form/fields/DescriptionField.tsx

View workflow job for this annotation

GitHub Actions / lint

'SchemaSection' is defined but never used

export function DescriptionField({ helpText }: { helpText?: string }) {
const validate = createMaxCharacterLength(2000)
const validateMaxLength = createMaxCharacterLength(2000)

export function DescriptionField({
helpText,
}: {
helpText?: string
}) {
return (
<FieldRFF
component={TextAreaFieldFF}
Expand All @@ -14,7 +19,7 @@ export function DescriptionField({ helpText }: { helpText?: string }) {
name="description"
label={i18n.t('Description')}
helpText={helpText}
validate={validate}
validate={validateMaxLength}
validateFields={[]}
/>
)
Expand Down
39 changes: 4 additions & 35 deletions src/components/form/fields/NameField.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,9 @@
import i18n from '@dhis2/d2-i18n'
import { InputFieldFF } from '@dhis2/ui'
import React, { useMemo } from 'react'
import React from 'react'
import { Field as FieldRFF, useField } from 'react-final-form'
import { useParams } from 'react-router-dom'
import {
composeAsyncValidators,
required,
useCheckMaxLengthFromSchema,
useIsFieldValueUnique,
SchemaSection,
} from '../../../lib'

function useValidator({ schemaSection }: { schemaSection: SchemaSection }) {
const params = useParams()
const modelId = params.id as string
const checkIsValueTaken = useIsFieldValueUnique({
model: schemaSection.namePlural,
field: 'name',
id: modelId,
})

const checkMaxLength = useCheckMaxLengthFromSchema(
schemaSection.name,
'name'
)

return useMemo(
() =>
composeAsyncValidators<string>([
checkIsValueTaken,
checkMaxLength,
required,
]),
[checkIsValueTaken, checkMaxLength]
)
}
import { SchemaSection } from '../../../lib'
import { useValidator } from '../../../lib/models/useFieldValidators'

export function NameField({
schemaSection,
Expand All @@ -43,7 +12,7 @@ export function NameField({
helpText?: string
schemaSection: SchemaSection
}) {
const validator = useValidator({ schemaSection })
const validator = useValidator({ schemaSection, property: 'name' })
const { meta } = useField('name', {
subscription: { validating: true },
})
Expand Down
39 changes: 4 additions & 35 deletions src/components/form/fields/ShortNameField.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,9 @@
import i18n from '@dhis2/d2-i18n'
import { InputFieldFF } from '@dhis2/ui'
import React, { useMemo } from 'react'
import React from 'react'
import { Field as FieldRFF, useField } from 'react-final-form'
import { useParams } from 'react-router-dom'
import {
SchemaSection,
composeAsyncValidators,
required,
useCheckMaxLengthFromSchema,
useIsFieldValueUnique,
} from '../../../lib'

function useValidator({ schemaSection }: { schemaSection: SchemaSection }) {
const params = useParams()
const modelId = params.id as string
const checkIsValueTaken = useIsFieldValueUnique({
model: schemaSection.namePlural,
field: 'name',
id: modelId,
})

const checkMaxLength = useCheckMaxLengthFromSchema(
schemaSection.name,
'shortName'
)

return useMemo(
() =>
composeAsyncValidators<string>([
checkIsValueTaken,
checkMaxLength,
required,
]),
[checkIsValueTaken, checkMaxLength]
)
}
import { SchemaSection } from '../../../lib'
import { useValidator } from '../../../lib/models/useFieldValidators'

export function ShortNameField({
helpText,
Expand All @@ -43,7 +12,7 @@ export function ShortNameField({
helpText?: string
schemaSection: SchemaSection
}) {
const validator = useValidator({ schemaSection })
const validator = useValidator({ schemaSection, property: 'shortName' })
const { meta } = useField('shortName', {
subscription: { validating: true },
})
Expand Down

0 comments on commit 59e0a92

Please sign in to comment.