Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: date field to format date before displaying, org unit filters #456

Merged
merged 6 commits into from
Dec 5, 2024

Conversation

flaminic
Copy link
Contributor

@flaminic flaminic commented Dec 3, 2024

No description provided.

Copy link

netlify bot commented Dec 3, 2024

Deploy Preview for dhis2-maintenance-app-beta ready!

Name Link
🔨 Latest commit d11d229
🔍 Latest deploy log https://app.netlify.com/sites/dhis2-maintenance-app-beta/deploys/6751b9358d94ce00086a45b9
😎 Deploy Preview https://deploy-preview-456--dhis2-maintenance-app-beta.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@flaminic flaminic force-pushed the DHIS2-17898/field-fixes branch from 017a11b to 66383ef Compare December 3, 2024 13:11
@flaminic flaminic force-pushed the DHIS2-17898/field-fixes branch from 69364f2 to c521cad Compare December 3, 2024 14:09
@flaminic flaminic force-pushed the DHIS2-17898/field-fixes branch from c521cad to d1be798 Compare December 3, 2024 14:11
@flaminic flaminic requested a review from Birkbjo December 3, 2024 14:11
<IdentifiableFilter />
<div className={css.filterWrapper}>
<IdentifiableFilter />
<DynamicFilters />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually want additional filters for orgunits? It does make it a bit weird. eg. if we had a filter to filter on a certain level - how do we display the tree?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah that's a good point. Probably not right? prob best to remove filters from public view all together?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok @Birkbjo i just removed the filter tabs all together

@@ -10,7 +10,8 @@ export function OrganisationUnitSelector() {
const fieldName = 'parent'
const { input, meta } = useField(fieldName, { format: (value) => value })
const userRootOrgUnits = useCurrentUserRootOrgUnits()
const userRootOrgUnitsIds = userRootOrgUnits.map((unit) => `/${unit.id}`)
const userRootOrgUnitsIds = userRootOrgUnits.map((unit) => `${unit.id}`)
const userRootOrgUnitsPaths = userRootOrgUnits.map((unit) => `/${unit.id}`)
Copy link
Member

@Birkbjo Birkbjo Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works if the root is on level one. We need the path. But if this is just for initiallyExpanded, I think we can just use the first lowest level root. If you had multiple roots on level 1 - you probably dont want to expand both?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need for expanded right. The main point of this change was to send ids without / in front to OrganisationUnitTree roots. But for expanded, i am actually not sure what we should use if there is nothing selected. What do you think? we can also decide to leave everything collapsed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the paths

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in general we just want to expand the first root?

@flaminic flaminic requested a review from Birkbjo December 4, 2024 08:08
})

const { input, meta } = useField<string | undefined>(name)

useEffect(() => {
if (input.value) {
const dateWithNoTimestamp = input.value.substring(0, 10)
Copy link
Member

@Birkbjo Birkbjo Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this an useEffect and not done in handleChange below? Is it because we just want this on the initial value when editing?

Eg. the server will give us date with timestamp, but the Calendar-component does not?

I think we also could use format and/or parse in useField.

    const { input, meta } = useField<string | undefined>(name, {
        format: (value) => value && value.substring(0,10),
    })

This would strip the timezone from "input.value", but wouldn't touch whats in the formState. But I think that should be fine, if the calendar-component gives us the right string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is because we only want it to work for the initial value (not only, it's ok if we rerun it every time, but handleChange does not run without an event occurring). Tried with format before, but the calendar library gives a validation error because of the format on the value, so users would need to touch the field before pressing save. Not sure if you have other ideas on how to achieve this? (i'm removing the onblur, i don't think that's needed )

@flaminic flaminic requested a review from Birkbjo December 4, 2024 13:08
@flaminic flaminic force-pushed the DHIS2-17898/field-fixes branch from df1beda to 8e49e88 Compare December 4, 2024 13:29
@@ -47,7 +54,7 @@ export function DateField({
validationText: i18n.t('Required'),
})
} else {
setValidation(payload?.validation || { error: false })
setValidation(payload?.validation || { error: false, valid: true })
}
input.onChange(payload?.calendarDateString || '')
input.onBlur()
Copy link
Member

@Birkbjo Birkbjo Dec 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cant select the line below, but I think this:
valid={validation?.valid && input?.value !== ''}

should also check for undefined? Right now you will get a "Check" next to the field if it's undefined. Or is this intentional?
We could also format undefined to '' though.

eg:

      format: (value) =>
            value ? value.substring(0, 10) : '',

@flaminic flaminic force-pushed the DHIS2-17898/field-fixes branch 2 times, most recently from d822c50 to 4b334da Compare December 5, 2024 11:06
@flaminic flaminic requested a review from Birkbjo December 5, 2024 11:09
@@ -37,12 +37,15 @@ const style = z.object({
icon: z.string().optional(),
})

const dateWithoutTimestampSchema = z.coerce.date()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be pedantic, this is now just a date schema, right? It doesn't actually do what the variable name says. In that case we would want something like:

const dateWithoutTimestampSchema = z
            .string()
            .transform((v) => v.substring(0, 10))
            .pipe(z.string().date()),

@flaminic flaminic force-pushed the DHIS2-17898/field-fixes branch from 4b334da to 75d59ad Compare December 5, 2024 12:47
@flaminic flaminic requested a review from Birkbjo December 5, 2024 12:47
@flaminic flaminic force-pushed the DHIS2-17898/field-fixes branch from 75d59ad to cee7f4a Compare December 5, 2024 12:52
@@ -67,7 +71,7 @@ export const Component = () => {
})}
section={section}
initialValues={orgUnit.data}
validate={validate}
schema={organisationUnitSchema}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess this is a remnant from trying the FormBase2?

@flaminic flaminic force-pushed the DHIS2-17898/field-fixes branch from cee7f4a to c76fde1 Compare December 5, 2024 14:08
@flaminic flaminic force-pushed the DHIS2-17898/field-fixes branch from c76fde1 to d11d229 Compare December 5, 2024 14:31
@flaminic flaminic requested a review from Birkbjo December 5, 2024 14:34
@flaminic flaminic merged commit 8537bce into master Dec 5, 2024
10 checks passed
@flaminic flaminic deleted the DHIS2-17898/field-fixes branch December 5, 2024 14:36
dhis2-bot added a commit that referenced this pull request Dec 5, 2024
## [0.19.2](v0.19.1...v0.19.2) (2024-12-05)

### Bug Fixes

* date field to format date before displaying, org unit filters ([#456](#456)) ([8537bce](8537bce))
* refresh list view on close of dialog ([#461](#461)) ([c10d79f](c10d79f))
* **categoryCombo:** validation and load optionSize on initial load [skip release] ([#457](#457)) ([a1a6110](a1a6110))
* **categoryOption:** load formName [skip release] ([#458](#458)) ([bb3baee](bb3baee))
* **categoryOptionGroups:** add custom attributesection to group/groupset [skip release] ([#459](#459)) ([5c853bc](5c853bc))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 0.19.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants