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(types): add type declarations for components #1399

Merged
merged 54 commits into from
Oct 12, 2023
Merged

Conversation

Birkbjo
Copy link
Member

@Birkbjo Birkbjo commented Sep 6, 2023

Adds type declarations for the public API of all components.

https://dhis2.atlassian.net/browse/LIBS-527

Todos:

  • re-export types from collections
  • Add types to files-prop in package.jsons
  • Add types to types: property in package.jsons
  • fix eslint errors (does not support typescript - tried to disable but no luck )

Public-facing components, hooks & functions

The types of the following units need to be verified by the reviewers:

  • Alert (Mozafar)
    • AlertBar
    • AlertStack
  • Box (Mozafar)
  • Button (Mozafar)
    • Button
    • ButtonStrip
    • SplitButton
    • DropdownButton
  • Calendar (Mozafar)
    • Calendar
    • CalendarInput
  • Card (Mozafar)
  • Center (Mozafar)
  • Checkbox (Mozafar)
    • Checkbox
    • CheckboxField
  • Chip (Mozafar)
  • Cover (Mozafar)
  • Css (Mozafar)
    • CssReset
    • CssVariables
  • Divider (Mozafar)
  • Field (Mozafar)
    • Field
    • FieldGroup
    • FieldSet
  • FileInput (Mozafar)
    • FileInput
    • FileList
    • FileListItem
    • FileListPlaceholder
    • FileInputField
    • FileInputFieldWithList
  • HeaderBar (Mozafar)
  • Help (Mozafar)
  • Input
    • Input
    • InputField
    • [x] InputFieldProps
  • IntersectionDetector (Mozafar)
  • Label (Mozafar)
  • Layer (Mozafar)
  • Legend (Mozafar)
  • Loader (Mozafar)
    • LinearLoader
    • CircularLoader
  • Logo (Mozafar)
    • Logo
    • LogoWhite
    • LogoIcon
    • LogoIconWhite
  • Menu (Mozafar)
    • MenuDivider
    • MenuItem
    • MenuSectionHeader
    • Menu
    • FlyoutMenu
  • Modal (Mozafar)
    • Modal
    • ModalActions
    • ModalContent
    • ModalTitle
  • Node (Mozafar)
  • NoticeBox (Mozafar)
  • OrganisationUnitTree (@Mohammer5)
    • OrganisationUnitTree
    • OrganisationUnitTreeRootError
    • OrganisationUnitTreeRootLoading
    • getAllExpandedOrgUnitPaths
  • Pagination (Mozafar)
  • Popover (Mozafar)
  • Popper (Mozafar)
    • Popper
    • getReferenceElement do we type these or not?
    • getBaseModifiers
    • usePopper
  • Portal (Mozafar)
  • Radio (Mozafar)
  • Required (Mozafar)
  • SegmentedControl (Mozafar)
  • Select (@Mohammer5)
    • MultiSelect
    • MultiSelectField
    • MultiSelectOption
    • SingleSelect
    • SingleSelectField
    • SingleSelectOption
  • SelectorBar (Mozafar)
    • SelectorBar
    • SelectorBarItem Types missing
  • SharingDialog
  • StatusIcon
  • Switch
    • Switch
    • SwitchField
  • Tab
    • Tab
    • TabBar
  • Table (Mozafar)
    • Table
    • TableFoot
    • TableBody missing loading props
    • TableHead
    • TableCell
    • TableCellHead
    • TableRow
    • TableRowHead
    • StackedTable
    • StackedTableHead
    • StackedTableBody
    • StackedTableFoot
    • StackedTableCell
    • StackedTableCellHead
    • StackedTableRow
    • StackedTableRowHead
    • DataTable
    • DataTableBody
    • DataTableCell
    • DataTableColumnHeader
    • DataTableFoot
    • DataTableHead
    • DataTableRow
    • DataTableToolbar
  • Tag (Mozafar)
  • TextArea (Mozafar)
    • TextArea
    • TextAreaField
  • Tooltip (Mozafar)
  • Transfer (@Mohammer5)
    • Transfer
    • TransferOption
  • UserAvatar (Mozafar)

@dhis2-bot
Copy link
Contributor

dhis2-bot commented Sep 6, 2023

🚀 Deployed on https://pr-1399--dhis2-ui.netlify.app

@dhis2-bot dhis2-bot temporarily deployed to netlify September 6, 2023 23:56 Inactive
@cypress
Copy link

cypress bot commented Sep 7, 2023

Passing run #3072 ↗︎

0 583 0 0 Flakiness 0

Details:

style: fix selector-bar style
Project: ui Commit: 4388b385b0
Status: Passed Duration: 09:06 💡
Started: Oct 10, 2023 12:09 PM Ended: Oct 10, 2023 12:18 PM

Review all test suite changes for PR #1399 ↗︎

@dhis2-bot dhis2-bot temporarily deployed to netlify September 7, 2023 11:06 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify September 7, 2023 11:24 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify September 7, 2023 13:57 Inactive
| '200'
| '100'
| '050'
export type ColorProp = `${ColorBase}${ColorVariant}` | 'white'
Copy link
Member Author

Choose a reason for hiding this comment

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

Gotta love template literals

@Birkbjo Birkbjo marked this pull request as ready for review September 7, 2023 15:09
@Birkbjo Birkbjo requested review from a team as code owners September 7, 2023 15:09
@dhis2-bot dhis2-bot temporarily deployed to netlify September 7, 2023 15:17 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify September 7, 2023 15:26 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify September 7, 2023 15:38 Inactive
/**
* the calendar to use such gregory, ethiopic, nepali - full supported list here: https://github.com/dhis2/multi-calendar-dates/blob/main/src/constants/calendars.ts
*/
calendar: CalendarPickerOptions['calendar']
Copy link
Member Author

Choose a reason for hiding this comment

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

These are worth a look @kabaros

@dhis2-bot dhis2-bot temporarily deployed to netlify September 7, 2023 15:49 Inactive
@Birkbjo Birkbjo changed the base branch from master to alpha September 7, 2023 16:43
@dhis2-bot dhis2-bot temporarily deployed to netlify September 7, 2023 16:46 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify September 7, 2023 18:48 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify September 7, 2023 20:05 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify September 8, 2023 14:46 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify September 8, 2023 15:08 Inactive
maxWidth?: string
minHeight?: string
minWidth?: string
overflow?: string
Copy link
Collaborator

Choose a reason for hiding this comment

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

this type matches the propTypes now, but it should be tighter probably like this .. or a union type of the properties here

do you think we should take this as an opportunity to update things like that, or leave it for future?

* deletions or data changes.
* Mutually exclusive with `primary` and `secondary` props
*/
destructive?: boolean
Copy link
Collaborator

Choose a reason for hiding this comment

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

we're not expressing that they are mutually exclusive in the type .. for the future, we can add something like https://github.com/maninak/ts-xor to express that

* Callback to trigger on click.
* Called with args `({ value, name }, event)`
*/
onClick?: ButtonEventHandler<React.MouseEvent<HTMLButtonElement>>
Copy link
Collaborator

Choose a reason for hiding this comment

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

soo helpful .. for these custom handlers we have

export const Button: React.FC<ButtonProps>

export interface ButtonStripProps {
children?: React.ReactNode
Copy link
Collaborator

Choose a reason for hiding this comment

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

should children here be something like

type StripChildren = React.ReactElement<ButtonProps> | React.ReactElement<ButtonProps>[];

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, I don't think we should be more restrictive than necessary? Wasn't like that in props, and you could eg wrap your buttons in a div.

export const AlertBar: React.FC<AlertBarProps>

export interface AlertStackProps {
children?: React.ReactNode
Copy link
Collaborator

Choose a reason for hiding this comment

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

same .. restrict children to Alert?

Copy link
Member Author

Choose a reason for hiding this comment

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

This would also be more strict than props. And again, Im usually against being that strict as there are valid reasons for wrapping elements.

export const Field: React.FC<FieldProps>

export interface FieldGroupProps {
children?: React.ReactNode
Copy link
Collaborator

Choose a reason for hiding this comment

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

children could be tightened as well to Field | Field[]

*/
onBackdropClick?: LayerBackdropClickHandler
/**
* Click handler - DEPRECATED
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we use @deprecated directive to get jsdoc hint (I know it's just copied from the propTypes, but seems useless to just write DEPRECATED like this)

React.KeyboardEvent<HTMLInputElement>
>

export interface FileInputProps {
Copy link
Collaborator

Choose a reason for hiding this comment

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

for all of these, we should also create types for the React Final Forms wrappers, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I focused on components for now. Can take a look.

@@ -0,0 +1,42 @@
import * as React from 'react'
import { StrictModifier } from 'react-popper'
import { VirtualElement, Options as PopperOptions } from '@popperjs/core'
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice to finally be able to reference the actual types

@@ -0,0 +1,43 @@
import * as React from 'react'
import { LayerBackdropClickHandler } from '@dhis2-ui/layer'
Copy link
Collaborator

@kabaros kabaros Sep 14, 2023

Choose a reason for hiding this comment

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

will this type be picked up properly the way we're publishing the types? (I couldn't get it to work locally) ..

(same comment in other places importing from @dhis2-u/...)

rereading how things are built, it should be picked up

components/selector-bar/types/index.d.ts Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we also type other methods exposed here (that are not components), i.e. getReferenceElement, getBaseModifiers, usePopper

Copy link
Member Author

@Birkbjo Birkbjo Sep 15, 2023

Choose a reason for hiding this comment

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

They're not exposed from collections/ui. And thus considered internal for now. But yeah, ideally they would be.

Copy link
Collaborator

@kabaros kabaros left a comment

Choose a reason for hiding this comment

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

It all looks good to me 👏🏿 - the only things I am requesting changes for are the missing types. The rest is just FYI.

children?: React.ReactNode
className?: string
dataTest?: string
role?: string
Copy link
Collaborator

Choose a reason for hiding this comment

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

msising loading: boolean

Copy link
Member Author

Choose a reason for hiding this comment

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

Table does not have loading property (only DataTableBody.


export const StackedTable: React.FC<StackedTableProps>

/** DATATABLE */
Copy link
Collaborator

@kabaros kabaros Sep 25, 2023

Choose a reason for hiding this comment

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

not sure why DataTable types are not under DataTable component to follow the other patterns?

Copy link
Member Author

@Birkbjo Birkbjo Oct 6, 2023

Choose a reason for hiding this comment

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

Currently this follows the same pattern. The table folder-structure is a bit more nested than others. I've just added types to the root package - not to the nested folders within a package. And DataTable and Table are in the same component package (Table).

Copy link
Contributor

@Mohammer5 Mohammer5 left a comment

Choose a reason for hiding this comment

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

Select

components/select/types/index.d.ts Show resolved Hide resolved
components/select/types/index.d.ts Show resolved Hide resolved
components/select/types/index.d.ts Show resolved Hide resolved
components/select/types/index.d.ts Show resolved Hide resolved
@dhis2-bot dhis2-bot temporarily deployed to netlify October 5, 2023 14:26 Inactive
…sfer

chore(transferoption): add missing onClick/onDoubleClick prop TS types
@dhis2-bot dhis2-bot temporarily deployed to netlify October 6, 2023 13:20 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify October 9, 2023 10:08 Inactive
Copy link
Contributor

@Mohammer5 Mohammer5 left a comment

Choose a reason for hiding this comment

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

My change requests have been implemented. Unblocking merging the PR from my side

@dhis2-bot dhis2-bot temporarily deployed to netlify October 10, 2023 12:04 Inactive
@Birkbjo Birkbjo merged commit d3e74c5 into alpha Oct 12, 2023
13 checks passed
@Birkbjo Birkbjo deleted the add-type-declarations branch October 12, 2023 12:35
dhis2-bot added a commit that referenced this pull request Oct 12, 2023
## [8.14.2-alpha.1](v8.14.1...v8.14.2-alpha.1) (2023-10-12)

### Bug Fixes

* **types:** add type declarations for components ([#1399](#1399)) ([d3e74c5](d3e74c5))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 8.14.2-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

dhis2-bot added a commit that referenced this pull request Nov 28, 2023
# [8.16.0-alpha.1](v8.15.0...v8.16.0-alpha.1) (2023-11-28)

### Bug Fixes

* **package:** include types in exports field ([e16036b](e16036b))
* minor type fixes ([#1416](#1416)) ([71f4537](71f4537))
* **types:** add type declarations for components ([#1399](#1399)) ([d3e74c5](d3e74c5))

### Features

* **types:** add types for forms collection ([#1415](#1415)) ([2e9d91a](2e9d91a))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 8.16.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Birkbjo added a commit that referenced this pull request Dec 8, 2023
* fix(types): add type declarations for components (#1399)

* fix: add types for popers

* style: prettier constants decl

* fix: rexport types from ui

* fix: generate type script

* chore: ignore declaration files

* fix: add types for icons

* fix: add types for alert, box, button

* fix: add types for input

* fix: add types for calendar

* fix: add types for checkbox

* fix: add types card, center, chip, cover, css

* fix: add types for divier and field

* fix: add types for file-input

* fix: add types for logo, modal, node

* fix: add types for headerbar, help, intersection, label, layer

* fix: add types for legend, loader, menu, notice-box

* fix: add types for orgunit-tree

* fix: add types for portal, tab, tooltip

* fix: add types for equired, statusicon, tag, useravatar

* fix: add types for pagination

* fix: edit input payloads, add radio types

* fix: add types for segmented-control

* fix: add types for select

* fix: add types for selector-bar,switch

* fix: add types for sharing-dialog and modal

* fix: add types for transfer

* fix: add types for textarea

* fix: add types for table

* fix: rexport declarations from collections/ui

* style: run prettier

* fix: remove generate-types script

* fix: name conflicts

* fix: name conflicts in rexport

* chore: add @types/react to dependencies

* fix: typo

* style: run prettier on icons

* fix: move files to types-folder and update packages

* chore: eslint ignore *.d.ts

* chore: run prettier

* fix: fix types in package.json

* fix: add forward prop types to datacell

* style: prettier on package.json

* style: prettier

* fix: cleanup

* chore: use range for peer-dep @react/types

* fix: fix onClick type for layer

* chore: move @types/react to peerdep

* refactor(org unit tree): rename root error & loading to match exported name

* chore(transferoption): add missing onClick/onDoubleClick prop TS types

* chore(org unit tree): add missing / fix public TS types

* fix(selector-bar): add types for selector-bar-item

* style: fix selector-bar style

---------

Co-authored-by: Jan-Gerke Salomon <[email protected]>
Co-authored-by: Jan-Gerke Salomon <[email protected]>

* chore(release): cut 8.14.2-alpha.1 [skip release]

## [8.14.2-alpha.1](v8.14.1...v8.14.2-alpha.1) (2023-10-12)

### Bug Fixes

* **types:** add type declarations for components ([#1399](#1399)) ([d3e74c5](d3e74c5))

* feat(types): add types for forms collection (#1415)

* feat: add types for FF field-wrappers

* feat(types): add types for transformers and validators

* fix: mirror folder-structure for types

* fix: remove old-types structure

* fix(types): cleanup

* style: run prettier

* refactor: rename overridden type name to rest

* style: run prettier

* fix(types): make selected payload always present

* chore(release): cut 8.15.0-alpha.1 [skip release]

# [8.15.0-alpha.1](v8.14.2-alpha.1...v8.15.0-alpha.1) (2023-10-19)

### Features

* **types:** add types for forms collection ([#1415](#1415)) ([2e9d91a](2e9d91a))

* fix: minor type fixes (#1416)

* fix(types): make value and name always present in eventpayload

* fix(types): export payloads and handlers

* style: run prettier

* chore(release): cut 8.15.0-alpha.2 [skip release]

# [8.15.0-alpha.2](v8.15.0-alpha.1...v8.15.0-alpha.2) (2023-10-20)

### Bug Fixes

* minor type fixes ([#1416](#1416)) ([71f4537](71f4537))

* chore(changelog): merge changelog correctly

* fix(package): include types in exports field

* chore(release): cut 8.15.0-alpha.3 [skip release]

# [8.15.0-alpha.3](v8.15.0-alpha.2...v8.15.0-alpha.3) (2023-11-20)

### Bug Fixes

* **package:** include types in exports field ([e16036b](e16036b))
* **pagination:** add row padding on small screens and demo stories ([b373859](b373859))
* **portal:** get default mount node at execution time ([20ab2ca](20ab2ca))
* **translations:** sync translations from transifex (master) ([f7cc472](f7cc472))
* **translations:** sync translations from transifex (master) ([7ea15fe](7ea15fe))
* **translations:** sync translations from transifex (master) ([fb22f68](fb22f68))
* **translations:** sync translations from transifex (master) ([071453c](071453c))
* **translations:** sync translations from transifex (master) ([4a8b0b3](4a8b0b3))
* **translations:** sync translations from transifex (master) ([ac1b242](ac1b242))
* **translations:** sync translations from transifex (master) ([28e0da7](28e0da7))

* chore(changelog): merge changelog

* chore(release): cut 8.16.0-alpha.1 [skip release]

# [8.16.0-alpha.1](v8.15.0...v8.16.0-alpha.1) (2023-11-28)

### Bug Fixes

* **package:** include types in exports field ([e16036b](e16036b))
* minor type fixes ([#1416](#1416)) ([71f4537](71f4537))
* **types:** add type declarations for components ([#1399](#1399)) ([d3e74c5](d3e74c5))

### Features

* **types:** add types for forms collection ([#1415](#1415)) ([2e9d91a](2e9d91a))

* fix(types): minor type fixes (#1434) [skip release]

* fix(types): add types for sharedPropTypes

* docs(types): align type comments with propTypes

* chore(changelog): align changelog with master

* chore(release): cut 8.16.0-alpha.2 [skip release]

# [8.16.0-alpha.2](v8.16.0-alpha.1...v8.16.0-alpha.2) (2023-11-29)

### Bug Fixes

* **prop-type:** fix deprecation of buttonVariantPropType ([#1433](#1433)) ([81644a8](81644a8))
* **types:** minor type fixes ([#1434](#1434)) [skip release] ([5e1068d](5e1068d))

---------

Co-authored-by: Jan-Gerke Salomon <[email protected]>
Co-authored-by: Jan-Gerke Salomon <[email protected]>
Co-authored-by: @dhis2-bot <[email protected]>
dhis2-bot added a commit that referenced this pull request Dec 8, 2023
# [9.0.0](v8.16.0...v9.0.0) (2023-12-08)

### Bug Fixes

* **constants:** remove buttonVariantProptype from constants ([#1436](#1436)) ([d4dc535](d4dc535))
* **package:** include types in exports field ([e16036b](e16036b))
* **types:** add type declarations for components ([#1399](#1399)) ([d3e74c5](d3e74c5))
* **types:** minor type fixes ([#1434](#1434)) [skip release] ([5e1068d](5e1068d))
* minor type fixes ([#1416](#1416)) ([71f4537](71f4537))

### Features

* **types:** add types for forms collection ([#1415](#1415)) ([2e9d91a](2e9d91a))

### BREAKING CHANGES

* **constants:** `buttonVariantPropType` has been removed from constants.
This is mostly intended for internal use, but was part of the public API.
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 9.0.0 🎉

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
Development

Successfully merging this pull request may close these issues.

None yet

4 participants