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

Secret update preview control + hidden blocks #2022

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions future/includes/gutenberg/blocks/entry-field/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Disabled from 'shared/js/disabled';

import './editor.scss';

/*global gkGravityViewBlocks*/
export default function Edit( { attributes, setAttributes, name: blockName } ) {
const {
viewId,
Expand All @@ -20,7 +21,7 @@ export default function Edit( { attributes, setAttributes, name: blockName } ) {
fieldSettingOverrides,
previewBlock,
previewAsShortcode,
showPreviewImage
showPreviewImage,
} = attributes;

const previewImage = gkGravityViewBlocks[ blockName ]?.previewImage && <img className="preview-image" src={ gkGravityViewBlocks[ blockName ]?.previewImage } alt={ __( 'Block preview image.', 'gk-gravityview' ) } />;
Expand All @@ -29,14 +30,32 @@ export default function Edit( { attributes, setAttributes, name: blockName } ) {
return previewImage;
}

if ( !gkGravityViewBlocks?.views?.length ) {
if ( ! gkGravityViewBlocks?.views?.length ) {
return <NoViewsNotice blockPreviewImage={ previewImage } newViewUrl={ gkGravityViewBlocks?.create_new_view_url } />;
}

const shouldPreview = ( previewBlock && viewId && entryId && fieldId );

const fieldSettingOverridesHelpLabel = __( 'These are space-separated overrides for field settings (e.g., title, label, etc.) using the key="value" format. See the [link]GravityView documentation[/link] for more information.', 'gk-gravityview' ).replace( '[link]', '<a href="https://docs.gravitykit.com/article/462-gvfield-embed-gravity-forms-field-values">' ).replace( '[/link]', '</a>' );

/**
* Sets the selected View from the ViewSelect object.
*
* @since $ver$
*
* @param {number} _viewId The View ID.
*/
function selectView( _viewId ) {
const selectedView = gkGravityViewBlocks.views.find( option => option.value === _viewId );

setAttributes( {
viewId: _viewId,
secret: selectedView?.secret,
previewBlock: previewBlock && ! _viewId ? false : previewBlock,
entryId: '',
} );
}

return (
<div { ...useBlockProps() }>
<InspectorControls>
Expand All @@ -46,16 +65,7 @@ export default function Edit( { attributes, setAttributes, name: blockName } ) {
<ViewSelector
viewId={ viewId }
isSidebar={ true }
onChange={ ( _viewId ) => {
const selectedView = gkGravityViewBlocks.views.find( option => option.value === _viewId );

setAttributes( {
viewId: _viewId,
secret: selectedView?.secret,
previewBlock: false,
entryId: '',
} );
} }
onChange={ selectView }
/>

<EntrySelector
Expand Down Expand Up @@ -107,7 +117,7 @@ export default function Edit( { attributes, setAttributes, name: blockName } ) {

<ViewSelector
viewId={ viewId }
onChange={ ( viewId ) => setAttributes( { viewId, previewBlock: false, entryId: '' } ) }
onChange={ selectView }
/>

<EntrySelector
Expand Down
31 changes: 20 additions & 11 deletions future/includes/gutenberg/blocks/entry/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Disabled from 'shared/js/disabled';

import './editor.scss';

/*global gkGravityViewBlocks*/
export default function Edit( { attributes, setAttributes, name: blockName } ) {
const {
viewId,
Expand All @@ -33,6 +34,23 @@ export default function Edit( { attributes, setAttributes, name: blockName } ) {
return <NoViewsNotice blockPreviewImage={ previewImage } newViewUrl={ gkGravityViewBlocks?.create_new_view_url } />;
}

/**
* Sets the selected View from the ViewSelect object.
*
* @since $ver$
*
* @param {number} _viewId The View ID.
*/
function selectView( _viewId ) {
const selectedView = gkGravityViewBlocks.views.find( option => option.value === _viewId );
setAttributes( {
viewId: _viewId,
secret: selectedView?.secret,
previewBlock: false,
entryId: '',
} );
}

return (
<div { ...useBlockProps() }>
<InspectorControls>
Expand All @@ -42,16 +60,7 @@ export default function Edit( { attributes, setAttributes, name: blockName } ) {
<ViewSelector
viewId={ viewId }
isSidebar={ true }
onChange={ ( _viewId ) => {
const selectedView = gkGravityViewBlocks.views.find( option => option.value === _viewId );

setAttributes( {
viewId: _viewId,
secret: selectedView?.secret,
previewBlock: false,
entryId: '',
} );
} }
onChange={ selectView }
/>

<EntrySelector
Expand Down Expand Up @@ -82,7 +91,7 @@ export default function Edit( { attributes, setAttributes, name: blockName } ) {

<ViewSelector
viewId={ viewId }
onChange={ ( viewId ) => setAttributes( { viewId, previewBlock: false, entryId: '' } ) }
onChange={ selectView }
/>

<EntrySelector
Expand Down
30 changes: 20 additions & 10 deletions future/includes/gutenberg/blocks/view/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Disabled from 'shared/js/disabled';

import './editor.scss';

/*global gkGravityViewBlocks*/
export default function Edit( { attributes, setAttributes, name: blockName } ) {
const {
viewId,
Expand Down Expand Up @@ -89,6 +90,23 @@ export default function Edit( { attributes, setAttributes, name: blockName } ) {
return <div dangerouslySetInnerHTML={ { __html: contentEl.innerHTML } } />;
};

/**
* Sets the selected View from the ViewSelect object.
*
* @since $ver$
*
* @param {number} _viewId The View ID.
*/
function selectView( _viewId ) {
const selectedView = gkGravityViewBlocks.views.find( option => option.value === _viewId );

setAttributes( {
viewId: _viewId,
secret: selectedView?.secret,
previewBlock: previewBlock && ! _viewId ? false : previewBlock,
} );
}

return (
<div { ...useBlockProps() }>
<InspectorControls>
Expand All @@ -98,15 +116,7 @@ export default function Edit( { attributes, setAttributes, name: blockName } ) {
<ViewSelector
viewId={ viewId }
isSidebar={ true }
onChange={ ( _viewId ) => {
const selectedView = gkGravityViewBlocks.views.find( option => option.value === _viewId );

setAttributes( {
viewId: _viewId,
secret: selectedView?.secret,
previewBlock: previewBlock && !_viewId ? false : previewBlock,
} );
} }
onChange={ selectView }
/>

<PreviewControl
Expand Down Expand Up @@ -317,7 +327,7 @@ export default function Edit( { attributes, setAttributes, name: blockName } ) {

<ViewSelector
viewId={ viewId }
onChange={ ( _viewId ) => setAttributes( { viewId: _viewId, previewBlock: previewBlock && !_viewId ? false : previewBlock } ) }
onChange={ selectView }
/>

<PreviewControl
Expand Down
2 changes: 1 addition & 1 deletion future/includes/gutenberg/build/entry-field.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '85cf0061c86e85f7070a');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '126886dd65a95b932b62');
2 changes: 1 addition & 1 deletion future/includes/gutenberg/build/entry-field.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion future/includes/gutenberg/build/entry.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '2a8211267eef0c031160');
<?php return array('dependencies' => array('react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '49ed214f4662c1c315da');
2 changes: 1 addition & 1 deletion future/includes/gutenberg/build/entry.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion future/includes/gutenberg/build/view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('moment', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '113a762ec3a23dc47814');
<?php return array('dependencies' => array('moment', 'react', 'react-dom', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-url'), 'version' => '5e18f20feef7b3108f23');
2 changes: 1 addition & 1 deletion future/includes/gutenberg/build/view.js

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions future/includes/gutenberg/class-gv-gutenberg-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace GravityKit\GravityView\Gutenberg;

use GravityKit\GravityView\Foundation\Helpers\Arr;
use GravityView_Roles_Capabilities;
use GV\View;
use GVCommon;

Expand All @@ -23,11 +22,6 @@ public function __construct() {
return;
}

// Only show blocks for a user with `publish_gravityviews` capabilities.
if ( ! GravityView_Roles_Capabilities::has_cap( 'publish_gravityviews' ) ) {
return;
}

add_filter( 'block_categories_all', array( $this, 'add_block_category' ) );

add_filter( 'enqueue_block_assets', array( $this, 'localize_block_assets' ) );
Expand Down
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Beautifully display your Gravity Forms entries. Learn more on [gravitykit.com](h
= develop =

* Added: Ability to perform exact-match searches in the search bar by enclosing search terms in quotation marks.
* Fixed: Secrets would not be added to blocks when selecting the view from the preview window.
* Fixed: Blocks would not be shown on the page without certain capabilities.

__Developer Updates:__

Expand Down