-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
DataViews: Type the ItemActions component #61400
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import type { ReactNode } from 'react'; | ||
import type { ReactElement, ReactNode } from 'react'; | ||
|
||
interface Option { | ||
value: any; | ||
|
@@ -164,3 +164,78 @@ export interface ViewList extends ViewBase { | |
} | ||
|
||
export type View = ViewList | ViewBase; | ||
|
||
interface ActionBase { | ||
/** | ||
* The unique identifier of the action. | ||
*/ | ||
id: string; | ||
|
||
/** | ||
* The label of the action. | ||
*/ | ||
label: string; | ||
|
||
/** | ||
* The icon of the action. (Either a string or an SVG element) | ||
* This should be IconType from the components package | ||
* but that import is breaking typescript build for the moment. | ||
*/ | ||
icon?: any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it turns out that it was the import of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😆 Just when #61486 is almost ready. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some detail: I think this works around the issue that #61486 addresses. The problem was a symptom of the |
||
|
||
/** | ||
* Whether the action is disabled. | ||
*/ | ||
disabled?: boolean; | ||
|
||
/** | ||
* Whether the action is destructive. | ||
*/ | ||
isDestructive?: boolean; | ||
|
||
/** | ||
* Whether the action is a primary action. | ||
*/ | ||
isPrimary?: boolean; | ||
|
||
/** | ||
* Whether the item passed as an argument supports the current action. | ||
*/ | ||
isEligible?: ( item: Item ) => boolean; | ||
} | ||
|
||
export interface ActionModal extends ActionBase { | ||
/** | ||
* Modal to render when the action is triggered. | ||
*/ | ||
RenderModal: ( { | ||
items, | ||
closeModal, | ||
onActionStart, | ||
onActionPerformed, | ||
}: { | ||
items: Item[]; | ||
closeModal?: () => void; | ||
onActionStart?: ( items: Item[] ) => void; | ||
onActionPerformed?: ( items: Item[] ) => void; | ||
} ) => ReactElement; | ||
|
||
/** | ||
* Whether to hide the modal header. | ||
*/ | ||
hideModalHeader?: boolean; | ||
|
||
/** | ||
* The header of the modal. | ||
*/ | ||
modalHeader?: string; | ||
} | ||
|
||
export interface ActionButton extends ActionBase { | ||
/** | ||
* The callback to execute when the action is triggered. | ||
*/ | ||
callback: ( items: Item[] ) => void; | ||
} | ||
|
||
export type Action = ActionModal | ActionButton; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more readable, I like it. Is this related to any TypeScript thing I should be aware of or just an unrelated change that was nice to have?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, basically when you do this, typescript is able to figure out the type of action that has the "RenderModal" defined. If you keep the old check, typescript will complain that RenderModal may or may not be defined.