Skip to content

Commit

Permalink
Merge branch 'develop' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
dkotter committed Feb 29, 2024
2 parents 5940aa0 + c69c24a commit c70c19b
Show file tree
Hide file tree
Showing 14 changed files with 1,958 additions and 1,761 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@ jobs:
- name: Install Node dependencies
run: npm ci --omit=optional

- name: Install eslint-plugin-prettier v5.0.0 # Do this to get around a bug in the version that @10up/eslint-config requires.
run: npm install eslint-plugin-prettier@^5.0.0

- name: Get updated JS files
id: changed-files
uses: tj-actions/changed-files@v39
uses: tj-actions/changed-files@v41
with:
files: |
**/*.js
- name: Run JS linting
if: ${{ steps.changed-files.outputs.any_changed == 'true' }}
run: |
npx 10up-toolkit lint-js ${{ steps.changed-files.outputs.all_changed_files }}
run: ./node_modules/.bin/10up-toolkit lint-js ${{ steps.changed-files.outputs.all_changed_files }}
2 changes: 1 addition & 1 deletion .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v39
uses: tj-actions/changed-files@v41
with:
files: |
**/*.php
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
v20.11.0
24 changes: 21 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,35 @@ All notable changes to this project will be documented in this file, per [the Ke

## [Unreleased] - TBD

## [1.5.4] - 2024-02-29

### Added

- Support for the WordPress.org plugin preview (props [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#38](https://github.com/10up/block-catalog/pull/38)).

### Changed

- Significantly improved performance of block catalog reset on larger WordPress installations (props [@dsawardekar](https://github.com/dsawardekar), [@Sidsector9](https://github.com/Sidsector9) via [#41](https://github.com/10up/block-catalog/pull/41)).
- Clean up NPM dependencies and update the minimum node version to 20 (props [@Sidsector9](https://github.com/Sidsector9), [@dsawardekar](https://github.com/dsawardekar) via [#43](https://github.com/10up/block-catalog/pull/43)).

### Security

- Bump `tj-actions/changed-files` from 39 to 41 (props [@dependabot](https://github.com/apps/dependabot), [@peterwilsoncc](https://github.com/peterwilsoncc) via [#39](https://github.com/10up/block-catalog/pull/39)).
- Bump `follow-redirects` from 1.15.2 to 1.15.4 (props [@dependabot](https://github.com/apps/dependabot), [@Sidsector9](https://github.com/Sidsector9) via [#40](https://github.com/10up/block-catalog/pull/40)).

## [1.5.3] - 2023-11-23

### Fixed

- PHP 8.2 deprecation warnings
- PHP 8.2 deprecation warnings (props [@dsawardekar](https://github.com/dsawardekar), [@ravinderk](https://github.com/ravinderk) via [#34](https://github.com/10up/block-catalog/pull/34)).

### Added

PHPUnit 9.x support
- PHPUnit 9.x support (props [@dsawardekar](https://github.com/dsawardekar), [@ravinderk](https://github.com/ravinderk) via [#34](https://github.com/10up/block-catalog/pull/34)).

### Security

Bumps sharp from 0.32.3 to 0.32.6
- Bump `sharp` from 0.32.3 to 0.32.6 (props [@dependabot](https://github.com/apps/dependabot), [@faisal-alvi](https://github.com/faisal-alvi) via [#32](https://github.com/10up/block-catalog/pull/32)).

## [1.5.2] - 2023-11-16

Expand Down Expand Up @@ -99,6 +115,8 @@ Bumps sharp from 0.32.3 to 0.32.6
- Initial release

[Unreleased]: https://github.com/10up/block-catalog/compare/trunk...develop
[1.5.4]: https://github.com/10up/block-catalog/compare/1.5.3...1.5.4
[1.5.3]: https://github.com/10up/block-catalog/compare/1.5.2...1.5.3
[1.5.2]: https://github.com/10up/block-catalog/compare/1.5.1...1.5.2
[1.5.1]: https://github.com/10up/block-catalog/compare/1.5.0...1.5.1
[1.5.0]: https://github.com/10up/block-catalog/compare/1.4.0...1.5.0
Expand Down
2 changes: 1 addition & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The following individuals are responsible for curating the list of issues, respo

Thank you to all the people who have already contributed to this repository via bug reports, code, design, ideas, project management, translation, testing, etc.

[Darshan Sawardekar (@dsawardekar)](https://github.com/dsawardekar), [Taylor Lovett (@tlovett1)](https://github.com/tlovett1), [Darin Kotter (@dkotter)](https://github.com/dkotter), [Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Brooke Campbell](https://www.linkedin.com/in/brookecampbelldesign/), [Faisal Alvi (@faisal-alvi)](https://github.com/faisal-alvi), [Peter Wilson (@peterwilsoncc)](https://github.com/peterwilsoncc), [Depandabot (@dependabot)](https://github.com/apps/dependabot), [Sumit Bagthariya (@qasumitbagthariya)](https://github.com/qasumitbagthariya).
[Darshan Sawardekar (@dsawardekar)](https://github.com/dsawardekar), [Taylor Lovett (@tlovett1)](https://github.com/tlovett1), [Darin Kotter (@dkotter)](https://github.com/dkotter), [Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Brooke Campbell](https://www.linkedin.com/in/brookecampbelldesign/), [Faisal Alvi (@faisal-alvi)](https://github.com/faisal-alvi), [Peter Wilson (@peterwilsoncc)](https://github.com/peterwilsoncc), [Depandabot (@dependabot)](https://github.com/apps/dependabot), [Sumit Bagthariya (@qasumitbagthariya)](https://github.com/qasumitbagthariya), [Ravinder Kumar (@ravinderk)](https://github.com/ravinderk), [Siddharth Thevaril (@Sidsector9)](https://github.com/Sidsector9).

## Libraries

Expand Down
67 changes: 6 additions & 61 deletions assets/js/admin/indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ class Indexer extends EventTarget {

cancel() {
this.cancelPending();
this.triggerEvent('indexCancel', { progress: this.progress, total: this.total });
this.triggerEvent('indexCancel', {
progress: this.progress,
total: this.total,
});
}

loadTerms(opts) {
Expand Down Expand Up @@ -150,69 +153,11 @@ class Indexer extends EventTarget {
});
}

async deleteIndex(ids, opts) {
async deleteIndex(opts) {
this.progress = 0;
this.completed = 0;
this.failures = 0;
this.total = ids.length;
this.triggerEvent('deleteIndexStart', { progress: 0, total: this.total });

const chunks = this.toChunks(ids, opts.batchSize || 50);
const n = chunks.length;

for (let i = 0; i < n; i++) {
const batch = chunks[i];
try {
await this.deleteIndexBatch(batch, opts); // eslint-disable-line no-await-in-loop
} catch (e) {
this.failures += batch.length;
this.triggerEvent('deleteIndexError', e);
}
}

this.triggerEvent('deleteIndexComplete', {
progress: this.progress,
total: this.total,
completed: this.completed,
failures: this.failures,
});
}

async deleteIndexBatch(batch, opts = {}) {
const fetchOpts = {
url: opts.endpoint,
method: 'POST',
data: {
term_ids: batch,
},
...opts,
};

const promise = this.apiFetch(fetchOpts);

promise.then((res) => {
if (res.errors) {
this.failures += batch.length;
this.triggerEvent('deleteIndexError', res);
} else if (!res.success && res.data) {
this.failures += batch.length;
this.triggerEvent('deleteIndexError', res);
} else {
this.completed += batch.length;
}

this.progress += batch.length;
this.triggerEvent('deleteIndexProgress', {
progress: this.progress,
total: this.total,
...res,
});
});

return promise;
}

deleteIndexBulk(opts) {
this.total = 0;
this.triggerEvent('deleteIndexStart');

const fetchOpts = {
Expand Down
63 changes: 4 additions & 59 deletions assets/js/admin/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ class ToolsApp {
this.onIndex('indexCancel', 'didIndexCancel');
this.onIndex('indexError', 'didIndexError');

this.onIndex('loadTermsStart', 'didLoadTermsStart');
this.onIndex('loadTermsComplete', 'didLoadTermsComplete');
this.onIndex('loadTermsError', 'didLoadTermsError');

this.onIndex('deleteIndexStart', 'didDeleteIndexStart');
this.onIndex('deleteIndexProgress', 'didDeleteIndexProgress');
this.onIndex('deleteIndexComplete', 'didDeleteIndexComplete');
Expand Down Expand Up @@ -247,57 +243,6 @@ class ToolsApp {
this.updateProgress();
}

didLoadTermsStart() {
const message = __('Loading block catalog terms to delete ...', 'block-catalog');

this.setState({ status: 'loading-terms', message });
this.hideErrors();
this.setNotice('');

window.scrollTo(0, 0);
}

didLoadTermsComplete(event) {
const message = __('Loaded terms to delete, starting ...', 'block-catalog');
this.setState({ status: 'loaded-terms', message, ...event.detail });

const opts = {
batchSize: this.settings?.delete_index_batch_size,
endpoint: this.settings?.delete_index_endpoint,
};

let { terms } = this.state;
terms = terms.map((term) => term.id);

this.indexer.deleteIndex(terms, opts);
}

didLoadTermsError(event) {
const err = event.detail || {};

let message = __('Failed to load terms to delete.', 'block-catalog');

if (err?.terms?.length === 0) {
message = __('Block catalog is empty, nothing to delete.', 'block-catalog');
this.setState({ status: 'load-terms-error', message: '', error: '' });
this.setNotice(message, 'error');
return;
}

if (err?.message) {
message += ` (${err?.code} - ${err.message})`;
}

if (err?.data?.message) {
message += ` (${err.data.message})`;
} else if (typeof err?.data === 'string') {
message += ` (${err.data})`;
}

this.setState({ status: 'load-terms-error', message: '', error: err });
this.setNotice(message, 'error');
}

didDeleteIndexStart(event) {
const message = __('Deleting Index ...', 'block-catalog');
this.setState({ status: 'deleting', message, ...event.detail });
Expand All @@ -324,10 +269,10 @@ class ToolsApp {
);

this.setNotice(message, 'error');
} else if (event.detail?.completed) {
} else if (event.detail?.removed) {
message = sprintf(
__('Deleted %d block catalog term(s) successfully.', 'block-catalog'),
event.detail?.completed,
event.detail?.removed,
);

this.setNotice(message, 'success');
Expand Down Expand Up @@ -390,10 +335,10 @@ class ToolsApp {
}

const opts = {
endpoint: this.settings.terms_endpoint,
endpoint: this.settings.delete_index_endpoint,
};

this.indexer.loadTerms(opts);
this.indexer.deleteIndex(opts);
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions block-catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/**
* Plugin Name: Block Catalog
* Description: Easily keep track of which Gutenberg Blocks are used across your site.
* Version: 1.5.3
* Version: 1.5.4
* Requires at least: 5.7
* Requires PHP: 7.4
* Author: Darshan Sawardekar, 10up
* Author: 10up
* Author URI: https://10up.com
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand All @@ -16,7 +16,7 @@
*/

// Useful global constants.
define( 'BLOCK_CATALOG_PLUGIN_VERSION', '1.5.3' );
define( 'BLOCK_CATALOG_PLUGIN_VERSION', '1.5.4' );
define( 'BLOCK_CATALOG_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'BLOCK_CATALOG_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'BLOCK_CATALOG_PLUGIN_INC', BLOCK_CATALOG_PLUGIN_PATH . 'includes/' );
Expand Down
Loading

0 comments on commit c70c19b

Please sign in to comment.