Skip to content

Commit

Permalink
✨ Rename export files for blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ZafarKamal123 committed Sep 25, 2023
1 parent f1be67d commit 1db5167
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 91 deletions.
2 changes: 1 addition & 1 deletion build/styles-manager-addon.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-polyfill', 'wp-url'), 'version' => '41ccf148fce02b94acc665a25e0cd4bb');
<?php return array('dependencies' => array('lodash', 'react', 'react-dom', 'wp-polyfill', 'wp-url'), 'version' => 'a076bffbaea56bc0cd2845ef77cb47fd');
4 changes: 2 additions & 2 deletions build/styles-manager-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -14297,10 +14297,10 @@ function Post(props) {
onChange: function onChange() {
return toggleStatus();
}
}), Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("span", null, Object(lodash__WEBPACK_IMPORTED_MODULE_3__["truncate"])(currentPost.title.rendered, {
}), Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("span", null, !Object(lodash__WEBPACK_IMPORTED_MODULE_3__["isEmpty"])(currentPost.title.rendered) ? Object(lodash__WEBPACK_IMPORTED_MODULE_3__["truncate"])(currentPost.title.rendered, {
length: 20,
omission: '...'
}))), Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("div", {
}) : Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__["__"])('Untitled Style', 'gutenberghub-styles-manager'))), Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])("div", {
className: "gsm-action-buttons-wrapper"
}, Object(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__["createElement"])(_wordpress_components__WEBPACK_IMPORTED_MODULE_5__["Button"], {
showTooltip: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function render( $attributes, $block_content, $block_instance ) {
$block_name = $block_name[1];
}

$style_class = 'is-style-' . _wp_to_kebab_case( $current_post->post_title );
$style_class = 'is-style-' . _wp_to_kebab_case( ! empty( $current_post->post_title ) ? $current_post->post_title : (string) $current_post->ID );

$new_content = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ public function maybe_export() {
)
);

$export_data = array(
'term_details' => get_term_by( 'id', $term_id, Gutenberghub_Styles_Manager_Blocks::$taxonomy ),
$term_details = get_term_by( 'id', $term_id, Gutenberghub_Styles_Manager_Blocks::$taxonomy );
$export_data = array(
'term_details' => $term_details,
'posts' => array(),
);

$export_name = strtolower( $term_details->name ) . '.json';

if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
Expand All @@ -85,7 +88,7 @@ public function maybe_export() {

// Set the headers for a JSON file download.
header( 'Content-Type: application/json' );
header( 'Content-Disposition: attachment; filename=export.json' );
header( 'Content-Disposition: attachment; filename=' . $export_name );
echo json_encode( $export_data, JSON_PRETTY_PRINT );
exit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function register() {
}

// Step 5: Preparing css.
$selector = _wp_to_kebab_case( $style->post_title );
$selector = _wp_to_kebab_case( ! empty( $style->post_title ) ? $style->post_title : (string) $style->ID );

$css = str_replace( 'selector', '.is-style-' . $selector, $css );

Expand All @@ -109,7 +109,7 @@ public function register() {
array(
'inline_style' => $css,
'name' => $selector,
'label' => $style->post_title,
'label' => empty( $style->post_title ) ? __( 'Untitled Style', 'block-options' ) : $style->post_title,
)
);
}
Expand Down
44 changes: 38 additions & 6 deletions languages/editorskit.pot
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,46 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"X-Generator: babel-plugin-makepot\n"

#: src/addons/styles-manager/admin/components/sidebar/index.js:100
msgid "Search Block"
#: src/addons/styles-manager/admin/components/content/post.js:112
msgid "Untitled Style"
msgstr ""

#: src/addons/styles-manager/admin/components/sidebar/index.js:75
msgid "Namespace"
#: src/addons/styles-manager/admin/components/content/post.js:124
msgid "Edit"
msgstr ""

#: src/addons/styles-manager/admin/components/sidebar/index.js:87
msgid "Block"
#: src/addons/styles-manager/admin/components/content/post.js:131
msgid "Fullscreen"
msgstr ""

#: src/addons/styles-manager/admin/components/content/post.js:139
msgid "More Actions"
msgstr ""

#: src/addons/styles-manager/admin/components/content/post.js:174
msgid "Delete Style"
msgstr ""

#: src/addons/styles-manager/admin/components/content/post.js:177
msgid "You wont be able to recover this style, are you sure?"
msgstr ""

#: src/addons/styles-manager/admin/components/content/post.js:193
msgid "Cancel"
msgstr ""

#: src/addons/styles-manager/admin/components/content/post.js:203
msgid "Deleting"
msgstr ""

#: src/addons/styles-manager/admin/components/content/post.js:204
msgid "Delete"
msgstr ""

#: src/addons/styles-manager/admin/components/content/post.js:53
msgid "Something went wrong when deleting the style."
msgstr ""

#: src/addons/styles-manager/admin/components/content/post.js:77
msgid "Something went wrong when deactivate the style."
msgstr ""
144 changes: 68 additions & 76 deletions src/addons/styles-manager/admin/components/content/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,198 +22,190 @@ import deletePost from '../../services/delete-post';
import togglePostStatus from '../../services/toggle-post-status';
import useNotices from '../../store/notice.store';


function Post( props ) {
const [ isFullScreen, setFullScreen ] = useState( false );
const [ askDelete, setAskDelete ] = useState( false );
function Post(props) {
const [isFullScreen, setFullScreen] = useState(false);
const [askDelete, setAskDelete] = useState(false);

const currentPost = props.post;
const activeTerm = useManager( ( state ) => state.activeTerm );
const createNotice = useNotices( ( state ) => state.addNotice );
const activeTerm = useManager((state) => state.activeTerm);
const createNotice = useNotices((state) => state.addNotice);

const editPostLink = getEditPostLink( currentPost.id, activeTerm );
const editPostLink = getEditPostLink(currentPost.id, activeTerm);

// @ts-ignore
const isActive = currentPost.meta?.gsm_active ?? false;

const { mutate: deleteCurrentPost, isLoading: isDeleting } = useMutation(
() =>
deletePost( {
deletePost({
id: currentPost.id,
postType: 'gsm_styles',
} ),
}),
{
onSuccess: () => {
client.invalidateQueries( 'posts' );
setAskDelete( false );
client.invalidateQueries('posts');
setAskDelete(false);
},
onError: () => {
setAskDelete( false );
createNotice( {
setAskDelete(false);
createNotice({
status: 'error',
title: __(
'Something went wrong when deleting the style.',
'gutenberghub-styles-manager'
),
} );
});
},
}
);

const { mutate: toggleStatus, isLoading: isToggling } = useMutation(
() =>
togglePostStatus( {
togglePostStatus({
id: currentPost.id,
postType: 'gsm_styles',
currentStatus: isActive,
} ),
}),
{
onSuccess: () => {
client.invalidateQueries( [ 'posts' ] );
client.invalidateQueries(['posts']);
},

onError: () => {
createNotice( {
createNotice({
status: 'error',
title: __(
'Something went wrong when deactivate the style.',
'gutenberghub-styles-manager'
),
} );
});
},
}
);

const previewLink = addQueryArgs( currentPost.link, { preview: true } );
const previewLink = addQueryArgs(currentPost.link, { preview: true });

return (
<div className="gsm-card-wrapper">
<div className="gsm-card-item">
<div className="gsm-style-preview-iframe">
<iframe scrolling="no" src={ previewLink } />
<iframe scrolling="no" src={previewLink} />
</div>
<div className="gsm-info-wrapper">
<div className="gsm-style-preview-title">
{ isToggling ? (
{isToggling ? (
<Spinner />
) : (
<ToggleControl
label={ null }
checked={ isActive }
onChange={ () => toggleStatus() }
label={null}
checked={isActive}
onChange={() => toggleStatus()}
/>
) }
)}

<span>
{ truncate( currentPost.title.rendered, {
length: 20,
omission: '...',
} ) }
{!isEmpty(currentPost.title.rendered)
? truncate(currentPost.title.rendered, {
length: 20,
omission: '...',
})
: __(
'Untitled Style',
'gutenberghub-styles-manager'
)}
</span>
</div>
<div className="gsm-action-buttons-wrapper">
<Button
showTooltip
icon={ edit }
href={ editPostLink }
icon={edit}
href={editPostLink}
target="_blank"
label={ __(
'Edit',
'gutenberghub-styles-manager'
) }
label={__('Edit', 'gutenberghub-styles-manager')}
/>

<Button
icon={ fullscreen }
icon={fullscreen}
showTooltip
onClick={ () => setFullScreen( true ) }
label={ __(
onClick={() => setFullScreen(true)}
label={__(
'Fullscreen',
'gutenberghub-styles-manager'
) }
)}
/>

<DropdownMenu
icon={ moreVertical }
label={ __(
icon={moreVertical}
label={__(
'More Actions',
'gutenberghub-styles-manager'
) }
controls={ [
)}
controls={[
{
title: __(
'Delete',
'gutenberghub-styles-manager'
),
icon: trash,
onClick: () => setAskDelete( true ),
onClick: () => setAskDelete(true),
},
] }
]}
/>
</div>
</div>
</div>

{ isFullScreen && (
{isFullScreen && (
<Modal
//@ts-ignore
isFullScreen
title={ currentPost.title.rendered }
onRequestClose={ () => setFullScreen( false ) }
title={currentPost.title.rendered}
onRequestClose={() => setFullScreen(false)}
>
<div className="gsm-preview-wrapper">
<iframe scrolling="no" src={ currentPost.link } />
<iframe scrolling="no" src={currentPost.link} />
</div>
</Modal>
) }
)}

{ askDelete && (
{askDelete && (
<Modal
onRequestClose={ () => setAskDelete( false ) }
title={ __(
'Delete Style',
'gutenberghub-styles-manager'
) }
onRequestClose={() => setAskDelete(false)}
title={__('Delete Style', 'gutenberghub-styles-manager')}
>
<p>
{ __(
{__(
'You wont be able to recover this style, are you sure?',
'gutenberghub-styles-manager'
) }
)}
</p>

<div
style={ {
style={{
display: 'flex',
justifyContent: 'flex-end',
} }
}}
>
<Button
variant="secondary"
onClick={ () => setAskDelete( false ) }
onClick={() => setAskDelete(false)}
>
{ __( 'Cancel', 'gutenberghub-styles-manager' ) }
{__('Cancel', 'gutenberghub-styles-manager')}
</Button>
<Button
isDestructive
variant="primary"
isBusy={ isDeleting }
style={ { marginLeft: 5 } }
onClick={ () => deleteCurrentPost() }
isBusy={isDeleting}
style={{ marginLeft: 5 }}
onClick={() => deleteCurrentPost()}
>
{ isDeleting
? __(
'Deleting',
'gutenberghub-styles-manager'
)
: __(
'Delete',
'gutenberghub-styles-manager'
) }
{isDeleting
? __('Deleting', 'gutenberghub-styles-manager')
: __('Delete', 'gutenberghub-styles-manager')}
</Button>
</div>
</Modal>
) }
)}
</div>
);
}
Expand Down

0 comments on commit 1db5167

Please sign in to comment.