Add support for “primary” admin notice actions.
This commit is contained in:
parent
a382fd6143
commit
db5a1b7348
|
@ -73,6 +73,7 @@ class StoreAlerts extends Component {
|
||||||
<Button
|
<Button
|
||||||
key={ action.name }
|
key={ action.name }
|
||||||
isDefault
|
isDefault
|
||||||
|
isPrimary={ action.primary }
|
||||||
href={ action.url }
|
href={ action.url }
|
||||||
onClick={ '' === action.status ? noop : markStatus }
|
onClick={ '' === action.status ? noop : markStatus }
|
||||||
>
|
>
|
||||||
|
|
|
@ -170,6 +170,7 @@ class WC_Admin_Install {
|
||||||
label varchar(255) NOT NULL,
|
label varchar(255) NOT NULL,
|
||||||
query longtext NOT NULL,
|
query longtext NOT NULL,
|
||||||
status varchar(255) NOT NULL,
|
status varchar(255) NOT NULL,
|
||||||
|
is_primary boolean DEFAULT 0 NOT NULL,
|
||||||
PRIMARY KEY (action_id),
|
PRIMARY KEY (action_id),
|
||||||
KEY note_id (note_id)
|
KEY note_id (note_id)
|
||||||
) $collate;
|
) $collate;
|
||||||
|
|
|
@ -200,13 +200,13 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
|
|
||||||
$actions = $wpdb->get_results(
|
$actions = $wpdb->get_results(
|
||||||
$wpdb->prepare(
|
$wpdb->prepare(
|
||||||
"SELECT name, label, query, status FROM {$wpdb->prefix}wc_admin_note_actions WHERE note_id = %d",
|
"SELECT name, label, query, status, is_primary FROM {$wpdb->prefix}wc_admin_note_actions WHERE note_id = %d",
|
||||||
$note->get_id()
|
$note->get_id()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if ( $actions ) {
|
if ( $actions ) {
|
||||||
foreach ( $actions as $action ) {
|
foreach ( $actions as $action ) {
|
||||||
$note->add_action( $action->name, $action->label, $action->query, $action->status );
|
$note->add_action( $action->name, $action->label, $action->query, $action->status, $action->is_primary );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,6 +236,7 @@ class WC_Admin_Notes_Data_Store extends WC_Data_Store_WP implements WC_Object_Da
|
||||||
'label' => $action->label,
|
'label' => $action->label,
|
||||||
'query' => $action->query,
|
'query' => $action->query,
|
||||||
'status' => $action->status,
|
'status' => $action->status,
|
||||||
|
'is_primary' => $action->primary,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -470,12 +470,14 @@ class WC_Admin_Note extends WC_Data {
|
||||||
* @param string $label Note label (e.g. presented as button label).
|
* @param string $label Note label (e.g. presented as button label).
|
||||||
* @param string $query Note query (for redirect).
|
* @param string $query Note query (for redirect).
|
||||||
* @param string $status The status to set for the action should on click.
|
* @param string $status The status to set for the action should on click.
|
||||||
|
* @param boolean $primary Whether or not this is the primary action. Defaults to false.
|
||||||
*/
|
*/
|
||||||
public function add_action( $name, $label, $query, $status = '' ) {
|
public function add_action( $name, $label, $query, $status = '', $primary = false ) {
|
||||||
$name = wc_clean( $name );
|
$name = wc_clean( $name );
|
||||||
$label = wc_clean( $label );
|
$label = wc_clean( $label );
|
||||||
$query = wc_clean( $query );
|
$query = wc_clean( $query );
|
||||||
$status = wc_clean( $status );
|
$status = wc_clean( $status );
|
||||||
|
$primary = (bool) $primary;
|
||||||
|
|
||||||
if ( empty( $name ) ) {
|
if ( empty( $name ) ) {
|
||||||
$this->error( 'admin_note_invalid_data', __( 'The admin note action name prop cannot be empty.', 'woocommerce-admin' ) );
|
$this->error( 'admin_note_invalid_data', __( 'The admin note action name prop cannot be empty.', 'woocommerce-admin' ) );
|
||||||
|
@ -485,6 +487,7 @@ class WC_Admin_Note extends WC_Data {
|
||||||
$this->error( 'admin_note_invalid_data', __( 'The admin note action label prop cannot be empty.', 'woocommerce-admin' ) );
|
$this->error( 'admin_note_invalid_data', __( 'The admin note action label prop cannot be empty.', 'woocommerce-admin' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @todo - maybe allow empty queries? for dismissals that don't need navigation.
|
||||||
if ( empty( $query ) ) {
|
if ( empty( $query ) ) {
|
||||||
$this->error( 'admin_note_invalid_data', __( 'The admin note action query prop cannot be empty.', 'woocommerce-admin' ) );
|
$this->error( 'admin_note_invalid_data', __( 'The admin note action query prop cannot be empty.', 'woocommerce-admin' ) );
|
||||||
}
|
}
|
||||||
|
@ -494,6 +497,7 @@ class WC_Admin_Note extends WC_Data {
|
||||||
'label' => $label,
|
'label' => $label,
|
||||||
'query' => $query,
|
'query' => $query,
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
|
'primary' => $primary,
|
||||||
);
|
);
|
||||||
|
|
||||||
$note_actions = $this->get_prop( 'actions', 'edit' );
|
$note_actions = $this->get_prop( 'actions', 'edit' );
|
||||||
|
|
|
@ -49,7 +49,8 @@ class WC_Admin_Notes_Historical_Data {
|
||||||
'get-started',
|
'get-started',
|
||||||
__( 'Get Started', 'woocommerce-admin' ),
|
__( 'Get Started', 'woocommerce-admin' ),
|
||||||
'?page=wc-admin#/analytics/settings',
|
'?page=wc-admin#/analytics/settings',
|
||||||
'actioned'
|
'actioned',
|
||||||
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$note->save();
|
$note->save();
|
||||||
|
|
Loading…
Reference in New Issue