Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function* toggleEntity({ entity }) {
// Get the supported blocks.
const blocks = Blocks.create(data.select(EDITOR_STORE).getBlocks(), data.dispatch(EDITOR_STORE));
const mainType = entity.mainType || "thing";
const onClassNames = ["disambiguated", `wl-${mainType.replace(/\s/, "-")}`];
// Build a css selector to select all the annotations for the provided entity.
const annotationSelector = makeEntityAnnotationsSelector(entity);
// Collect the annotations that have been switch on/off.
const occurrences = [];
if (0 === entity.occurrences.length) {
// Switch on.
blocks.replace(
new RegExp(``, "gi"),
(match, annotationId, classNames) => {
const newClassNames = mergeArray(classNames.split(/\s+/), onClassNames);
saveProduct() {
if ( this.state.isSavingProduct ) {
return;
}
const { attributes, setAttributes } = this.props;
const { email } = attributes;
const { saveEntityRecord } = dispatch( 'core' );
this.setState( { isSavingProduct: true }, () => {
saveEntityRecord( 'postType', SIMPLE_PAYMENTS_PRODUCT_POST_TYPE, this.toApi() )
.then( record => {
if ( record ) {
setAttributes( { productId: record.id } );
}
return record;
} )
.catch( error => {
// Nothing we can do about errors without details at the moment
if ( ! error || ! error.data ) {
return;
}
.forEach(({ clientId }) => {
dispatch("core/editor").selectBlock(clientId);
});
// Reselect whatever was selected in the beginning.
expect( gen.next().value ).toEqual(
put( disableEdits() )
);
expect( gen.next().value ).toEqual(
call( sagas.fetchStatus )
);
const response = { done: false, items_created: 1, last_created_at: '2019-11-07 00:00:00' };
expect( gen.next( response ).value ).toEqual(
put( actions.setSeriesQueueStatus( response ) )
);
expect( gen.next().value ).toEqual(
call(
[ wpDispatch( 'core/notices' ), 'createSuccessNotice' ],
sagas.NOTICES[ sagas.NOTICE_EDITING_SERIES ],
{ id: sagas.NOTICE_EDITING_SERIES, isDismissible: false }
)
);
expect( gen.next().value ).toEqual(
call(
[ wpDispatch( 'core/notices' ), 'createSuccessNotice' ],
`${ sprintf( sagas.NOTICES[ sagas.NOTICE_PROGRESS_ON_SERIES_CREATION_COUNT ], response.items_created ) } ${ sprintf( sagas.NOTICES[ sagas.NOTICE_PROGRESS_ON_SERIES_CREATION ], momentUtils.toDate( momentUtils.toMoment( response.last_created_at ) ) ) }`,
{ id: sagas.NOTICE_PROGRESS_ON_SERIES_CREATION, isDismissible: true }
)
);
expect( gen.next( false ).value ).toEqual(
select( selectors.isCompleted )
);
port1.onmessage = ( { data: confirmed } ) => {
port1.close();
if ( confirmed !== true ) {
return;
}
dispatch( 'core/editor' ).replaceBlock(
blocks[ 0 ].clientId,
rawHandler( {
HTML: blocks[ 0 ].originalContent,
} )
);
};
} );
const blockIndex = getBlockIndex( rootClientID );
let noticeMessage = null;
const noticeOptions = {
id: 'amp-errors-notice-removed-cta',
};
if ( this.props.attributes.hasMultipleCtaBlocks ) {
removeBlock( this.props.clientId );
noticeMessage = __( 'Multiple CTA Layers are not allowed, the block was removed.', 'amp' );
} else if ( 0 === blockIndex ) {
removeBlock( this.props.clientId );
noticeMessage = __( 'CTA layer is not allowed on the first page, the block was removed.', 'amp' );
}
if ( noticeMessage ) {
dispatch( 'core/notices' ).createNotice( 'warning', noticeMessage, noticeOptions );
}
}
function _dispatch() {
const args = [].slice.call( arguments, 2 );
const d = wpDispatch( arguments[ 0 ] );
const f = arguments[ 1 ];
d[ f ]( ...args );
}
const method = isTemporary ? 'POST' : 'PUT';
try {
const updatedReusableBlock = await apiFetch( { path, data, method } );
dispatch( {
type: 'SAVE_REUSABLE_BLOCK_SUCCESS',
updatedId: updatedReusableBlock.id,
id,
} );
const message = isTemporary ? __( 'Block created.' ) : __( 'Block updated.' );
dataDispatch( 'core/notices' ).createSuccessNotice( message, {
id: REUSABLE_BLOCK_NOTICE_ID,
type: 'snackbar',
} );
dataDispatch( 'core/block-editor' ).__unstableSaveReusableBlock( id, updatedReusableBlock.id );
} catch ( error ) {
dispatch( { type: 'SAVE_REUSABLE_BLOCK_FAILURE', id } );
dataDispatch( 'core/notices' ).createErrorNotice( error.message, {
id: REUSABLE_BLOCK_NOTICE_ID,
} );
}
};
function* setBibliography({ items, meta }: Processor.Bibliography) {
const blocksList = select('core/block-editor').getBlocks();
const bibliographyBlock = blocksList.find(
block => block.name === 'abt/bibliography',
);
if (items.length > 0 && bibliographyBlock) {
yield dispatch('core/block-editor').updateBlockAttributes(
bibliographyBlock.clientId,
{ ...meta, items },
);
} else if (items.length > 0 && !bibliographyBlock) {
yield dispatch('core/block-editor').insertBlock(
createBlock('abt/bibliography', {
...meta,
items,
}),
blocksList.length,
undefined,
false,
);
} else if (items.length === 0 && bibliographyBlock) {
yield dispatch('core/block-editor').removeBlock(
bibliographyBlock.clientId,
const { MODEL_NAME: TICKET } = ticketModel;
if ( ! isModelEntityOfModel( ticketEntity, TICKET ) ) {
return;
}
if ( ! window.confirm(
__(
'Are you sure you want to delete this Ticket?',
'event_espresso'
)
) ) {
return;
}
const {
trashEntityById,
persistTrashesForModel,
} = dispatch( 'eventespresso/core' );
await trashEntityById(
TICKET,
ticketEntity.id
);
persistTrashesForModel( TICKET );
};