English
detail.head_info.render.before
About 496 wordsAbout 2 min
2025-12-16
Promise-style hook
This hook is called before the detail page header component is rendered, allowing business logic or UI changes before display.
Purpose
- Add, remove, or reset header action buttons
- Modify or inject data required by the header component
Parameters
functional registers the hook callback. The host passes the following parameters:
| Parameter | Description | Type | Allowed Values | Default |
|---|---|---|---|---|
| context | Event context containing common parameters | Object | -- | -- |
| plugin | Current plugin runtime information; business logic normally does not need it | Object | -- | -- |
| context.component | Current header component configuration | Object | -- | -- |
Return Value
The hook may return an object or Promise<Object> with the following optional properties. A direct throw from a synchronous callback is caught and logged by the PWC adapter. The current Detail wrapper does not handle a rejected Promise, so catch and report asynchronous failures inside the hook and resolve a usable result.
| Property | Description | Type |
|---|---|---|
| buttons | Adds, removes, or resets object action buttons | Object |
| component | Properties shallow-merged into the current header component configuration | Object |
buttons
| Property | Description | Type |
|---|---|---|
| add | Custom buttons to add | Array<IButton> |
| del | Button action values to remove | Array<string> |
| reset | Existing buttons to rename or override | Array<IButton> |
IButton
| Parameter | Description | Type | Required for add | Required for reset |
|---|---|---|---|---|
| action | Unique button identifier; reset matches existing buttons by this value | string | Yes | Yes |
| label | Button label | string | Yes | No |
| attrs | Button attributes; only class, icon, and type are consumed | Object | No | No |
| beforeAction | Processes built-in API parameters before execution | (params: Object) => Promise<Object> | No | No |
| parseParam | Legacy alias of beforeAction; new code should use beforeAction | (params: Object) => Promise<Object> | No | No |
| callback | Custom click handler with signature callback({ next }) | Function | No | No |
beforeAction(params) must return Promise<Object>. The resolved object is shallow-merged into built-in API parameters. A rejection prevents the built-in API call, and the host does not automatically handle that error.
In callback({ next }), call next(options) to continue the original built-in behavior. Optional options are shallow-merged into the button parameters. Omitting next() skips built-in behavior. A completely new custom action must implement its own business logic. The host neither waits for nor catches a Promise returned by callback, so handle asynchronous failures inside the callback.
Basic Examples
Basic Usage
export default class Plugin {
apply() {
return [{
event: 'detail.head_info.render.before',
functional: this.renderBefore.bind(this)
}];
}
renderBefore(context, plugin) {
return Promise.resolve();
}
}Customize Buttons
export default class Plugin {
apply() {
return [{
event: 'detail.head_info.render.before',
functional: this.renderBefore.bind(this)
}];
}
renderBefore(context, plugin) {
return Promise.resolve({
buttons: {
del: ['ChangeOwner'],
add: [{
action: 'cancel',
label: 'Cancel',
callback() {
alert('Cancel button clicked');
}
}],
reset: [{
action: 'Edit',
label: 'Edit from Plugin',
beforeAction(params) {
return Promise.resolve({ fromPlugin: true });
}
}, {
action: 'Clone',
label: 'Clone',
callback({ next }) {
alert('Run custom clone logic');
next();
}
}]
}
});
}
}Customize Component Data
return Promise.resolve({
component: {
...context.component,
exposedButton: 4
}
});Notes
- Refreshing the detail page triggers this hook again, so the logic must be idempotent.
- Use
next()inside a button callback to continue standard built-in behavior.
