Skip to content

Commit

Permalink
Merge pull request #152 from alleyinteractive/feature/pre-publish-checks
Browse files Browse the repository at this point in the history
Feature: Pre Publish Checks
  • Loading branch information
efuller authored Jun 21, 2024
2 parents 568cc03 + b943ff6 commit 0df8922
Show file tree
Hide file tree
Showing 14 changed files with 385 additions and 744 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
php-tests:
strategy:
matrix:
php: [8.0, 8.1, 8.2]
php: [8.1, 8.2]
wordpress: ["latest"]
uses: alleyinteractive/.github/.github/workflows/php-tests.yml@main
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ node_modules
# Cache files
.phpcs/*.json
.phpunit.result.cache
.phpunit.cache

# Ignore temporary OS files
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: alleyinteractive

Tags: alleyinteractive, wp-newsletter-builder

Stable tag: 0.3.24
Stable tag: 0.3.25

Requires at least: 6.2

Expand Down
67 changes: 33 additions & 34 deletions blocks/email-settings/edit.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
/**
* Retrieves the translation of text.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-i18n/
*/
import { MultiSelect } from 'react-multi-select-component';
import { __ } from '@wordpress/i18n';
import { TextControl, Spinner, SelectControl } from '@wordpress/components';
import apiFetch from '@wordpress/api-fetch';
import { useEffect, useState } from '@wordpress/element';
import { dispatch } from '@wordpress/data';
import { parse } from '@wordpress/blocks';

/**
* React hook that is used to mark the block wrapper element.
* It provides all the necessary props like the class name.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-block-editor/#useblockprops
*/
import { dispatch, useSelect } from '@wordpress/data';
import { BlockInstance, parse } from '@wordpress/blocks';
import { useBlockProps } from '@wordpress/block-editor';

// import { usePostMeta } from '@alleyinteractive/block-editor-tools';

import { MultiSelect } from 'react-multi-select-component';

import EmailTypeSelector from '../../components/emailTypeSelector';

import usePostMeta from '../../hooks/usePostMeta';

/**
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
* Those files can contain any CSS code that gets applied to the editor.
*
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
*/
import './index.scss';

interface BlockEditor {
getBlocksByName: (attribute: string) => string[];
getBlocksByClientId: (attribute: string) => BlockInstance[];
}

interface ListResult {
ListID: string;
Name: string;
Expand All @@ -50,14 +33,6 @@ interface Window {
};
}

/**
* The edit function describes the structure of your block in the context of the
* editor. This represents what the editor will render when the block is used.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-edit-save/#edit
*
* @return {WPElement} Element to render.
*/
export default function Edit() {
const [meta, setMeta] = usePostMeta();
const {
Expand All @@ -70,6 +45,14 @@ export default function Edit() {
nb_newsletter_suppression_group: suppressionGroup,
} = meta;

const contentController = useSelect((select) => {
const { getBlocksByName, getBlocksByClientId } = select('core/block-editor') as BlockEditor;
return {
getEmailSettingsBlocks: () => getBlocksByName('wp-newsletter-builder/email-settings'),
getBlocksByClientId,
};
}, []);

const {
newsletterBuilder: {
usesSuppressionLists = false,
Expand All @@ -93,7 +76,23 @@ export default function Edit() {
};

const contentHandler = (content: string) => {
dispatch('core/block-editor').resetBlocks(parse(content));
const emailSettingsBlockIds = contentController.getEmailSettingsBlocks();
const emailSettingsBlockInstances = contentController
.getBlocksByClientId(emailSettingsBlockIds[0]);

const parsedContentFromTemplate = parse(content);

const emailSettingsBlockAlreadyPresent = parsedContentFromTemplate
.filter((parsedBlock) => parsedBlock.name === 'wp-newsletter-builder/email-settings');

let newBlocks: BlockInstance[] = [];
if (emailSettingsBlockAlreadyPresent.length === 0) {
newBlocks = [...emailSettingsBlockInstances, ...parsedContentFromTemplate];
} else {
newBlocks = [...parsedContentFromTemplate];
}

dispatch('core/block-editor').resetBlocks(newBlocks);
};

const [lists, setLists] = useState<ListResult[]>([]);
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"alleyinteractive/composer-wordpress-autoloader": "^1.0",
"campaignmonitor/createsend-php": "^7.0",
"sendgrid/sendgrid": "^8.1",
Expand All @@ -24,7 +24,7 @@
"require-dev": {
"alleyinteractive/alley-coding-standards": "^2.0",
"alleyinteractive/wordpress-fieldmanager": "^1.6",
"mantle-framework/testkit": "^1.1",
"mantle-framework/testkit": "^1.1.2",
"szepeviktor/phpstan-wordpress": "^1.3"
},
"config": {
Expand Down
Loading

0 comments on commit 0df8922

Please sign in to comment.