From eaff090efb5d2b107e0581a77fe87e22838a9751 Mon Sep 17 00:00:00 2001 From: Ramon Date: Tue, 10 Aug 2021 16:03:31 -0300 Subject: [PATCH 01/54] Remove custom rules in .eslintrc.js --- .eslintrc.js | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 50841733c..fe7a1d0ff 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,27 +2,7 @@ const defaultEslintrc = require('10up-toolkit/config/.eslintrc'); module.exports = { ...defaultEslintrc, - extends: '@10up/eslint-config', - plugins: ['react'], globals: { - wp: true, jQuery: true, - }, - rules: { - 'react/jsx-uses-react': 'error', - 'react/jsx-uses-vars': 'error', - 'no-console': [1], - 'no-alert': [1], - camelcase: [1], - 'no-debugger': [1], - 'no-unused-vars': [1], - 'import/no-extraneous-dependencies': ['error', { devDependencies: true }], - 'no-plusplus': [0], - 'import/prefer-default-export': [0], - 'no-lonely-if': [0], - 'func-names': [0], - }, - env: { - browser: true, - }, + } }; From ade6f01c905f1a28cd8aaf181c50d389c274461f Mon Sep 17 00:00:00 2001 From: Ramon Date: Tue, 10 Aug 2021 16:09:44 -0300 Subject: [PATCH 02/54] Fix JSDoc lint issues in autosuggest.js --- assets/js/autosuggest.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/assets/js/autosuggest.js b/assets/js/autosuggest.js index 89e76ea2c..3f48e8cda 100644 --- a/assets/js/autosuggest.js +++ b/assets/js/autosuggest.js @@ -68,7 +68,7 @@ function selectAutosuggestItem(input, text) { * Fires events when autosuggest results are clicked, * and if GA tracking is activated * - * @param {object} detail - value to pass on to the Custom Event + * @param {Object} detail - value to pass on to the Custom Event */ function triggerAutosuggestEvent(detail) { const event = new CustomEvent('ep-autosuggest-click', { detail }); @@ -113,7 +113,7 @@ function goToAutosuggestItem(searchTerm, url) { * * @param {Node} input - search input * @param {Node} element - search term result item - * @returns {Function} calls the submitSearchForm function + * @return {Function} calls the submitSearchForm function */ function selectItem(input, element) { if (epas.action === 'navigate') { @@ -128,7 +128,7 @@ function selectItem(input, element) { * Build the search query from the search text - the query is generated in PHP * and passed into the front end as window.epas = { "query... * - * @returns {string} json string + * @return {string} json string */ function getJsonQuery() { if (typeof window.epas === 'undefined') { @@ -147,9 +147,9 @@ function getJsonQuery() { * * @param {string} searchText - user search string * @param {string} placeholder - placeholder text to replace - * @param {object} options - Autosuggest settings + * @param {Object} options - Autosuggest settings * @param {string} options.query - JSON query string to pass to ElasticSearch - * @returns {string} json representation of search query + * @return {string} json representation of search query */ function buildSearchQuery(searchText, placeholder, { query }) { const newQuery = replaceGlobally(query, placeholder, searchText); @@ -161,7 +161,7 @@ function buildSearchQuery(searchText, placeholder, { query }) { * * @param {string} query - json string * @param {string} searchTerm - user search term - * @returns {object} AJAX object request + * @return {Object} AJAX object request */ async function esSearch(query, searchTerm) { const fetchConfig = { @@ -211,7 +211,7 @@ async function esSearch(query, searchTerm) { * * @param {Array} options - search results * @param {string} input - search string - * @returns {boolean} return true + * @return {boolean} return true */ function updateAutosuggestBox(options, input) { let i; @@ -295,7 +295,7 @@ function updateAutosuggestBox(options, input) { /** * Hide the auto suggest box * - * @returns {boolean} returns true + * @return {boolean} returns true */ function hideAutosuggestBox() { const lists = document.querySelectorAll('.autosuggest-list'); @@ -322,7 +322,7 @@ function hideAutosuggestBox() { * * @param {Array} hits - ES results * @param {string} searchTerm - user search term - * @returns {object} formatted hits + * @return {Object} formatted hits */ function checkForOrderedPosts(hits, searchTerm) { const toInsert = {}; @@ -498,7 +498,7 @@ function init() { /** * helper function to get the currently selected result * - * @returns {number} index of the selected search result + * @return {number} index of the selected search result */ const getSelectedResultIndex = () => { const resultsArr = Array.from(results); @@ -579,7 +579,7 @@ function init() { * Get the searched post types from the search form. * * @param {HTMLFormElement} form - form containing the search input field - * @returns {Array} - post types + * @return {Array} - post types * @since 3.6.0 */ function getPostTypesFromForm(form) { From 0ca009d8fa840373827eef040b238e904c241eee Mon Sep 17 00:00:00 2001 From: Ramon Date: Tue, 10 Aug 2021 16:12:18 -0300 Subject: [PATCH 03/54] Refactor to declare variables after return statement in autosuggest.js --- assets/js/autosuggest.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/js/autosuggest.js b/assets/js/autosuggest.js index 3f48e8cda..7c8b35407 100644 --- a/assets/js/autosuggest.js +++ b/assets/js/autosuggest.js @@ -603,10 +603,6 @@ function init() { * @param {Node} input - search input field */ const fetchResults = async (input) => { - const searchText = input.value; - const placeholder = 'ep_autosuggest_placeholder'; - const postTypes = getPostTypesFromForm(input.form); - // retrieves the PHP-genereated query to pass to ElasticSearch const queryJSON = getJsonQuery(); @@ -614,6 +610,10 @@ function init() { return; } + const searchText = input.value; + const placeholder = 'ep_autosuggest_placeholder'; + const postTypes = getPostTypesFromForm(input.form); + if (searchText.length >= 2) { setFormIsLoading(true, input); From 6568e395361672250db62c9e756e5f24b561ca64 Mon Sep 17 00:00:00 2001 From: Ramon Date: Tue, 10 Aug 2021 16:14:31 -0300 Subject: [PATCH 04/54] Fix JSDoc in related-posts/Edit.js --- assets/js/blocks/related-posts/Edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/blocks/related-posts/Edit.js b/assets/js/blocks/related-posts/Edit.js index e1c33e13d..fea8c7bb7 100644 --- a/assets/js/blocks/related-posts/Edit.js +++ b/assets/js/blocks/related-posts/Edit.js @@ -15,7 +15,7 @@ class Edit extends Component { /** * Setup class * - * @param {object} props Component properties + * @param {Object} props Component properties */ constructor(props) { super(props); From 20e41855ca963ca859d9e598a160e5c7bcfff8ac Mon Sep 17 00:00:00 2001 From: Ramon Date: Tue, 10 Aug 2021 16:18:16 -0300 Subject: [PATCH 05/54] Remove unused 'number' field state in related-posts/Edit.js --- assets/js/blocks/related-posts/Edit.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/assets/js/blocks/related-posts/Edit.js b/assets/js/blocks/related-posts/Edit.js index fea8c7bb7..5f74acd62 100644 --- a/assets/js/blocks/related-posts/Edit.js +++ b/assets/js/blocks/related-posts/Edit.js @@ -20,13 +20,8 @@ class Edit extends Component { constructor(props) { super(props); - const { - attributes: { number }, - } = props; - this.state = { posts: false, - number, }; } From bac0e6eefaffb0074900dd6564acfa7298f76b75 Mon Sep 17 00:00:00 2001 From: Ramon Date: Tue, 10 Aug 2021 16:24:22 -0300 Subject: [PATCH 06/54] Update to use post ID in key instead of array index in related-posts/Edit.js --- assets/js/blocks/related-posts/Edit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/js/blocks/related-posts/Edit.js b/assets/js/blocks/related-posts/Edit.js index 5f74acd62..f8a7b91b7 100644 --- a/assets/js/blocks/related-posts/Edit.js +++ b/assets/js/blocks/related-posts/Edit.js @@ -82,10 +82,10 @@ class Edit extends Component { ) : (