From ea1d0714b435c848c61f50a82c12f3eb78ac36b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 10 Sep 2024 08:28:34 +0200 Subject: [PATCH 01/12] initial commit --- client/homebrew/pages/vaultPage/vaultPage.jsx | 92 +++++++++++++++---- .../homebrew/pages/vaultPage/vaultPage.less | 76 +++++++++++---- server/vault.api.js | 9 ++ 3 files changed, 138 insertions(+), 39 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index a550ec578..2eb109c39 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -18,6 +18,9 @@ const request = require('../../utils/request-middleware.js'); const VaultPage = (props)=>{ const [pageState, setPageState] = useState(parseInt(props.query.page) || 1); + const [sortState, setSort] = useState(props.query.sort || 'title'); + const [dirState, setdir] = useState(props.query.dir || 'asc'); + //Response state const [brewCollection, setBrewCollection] = useState(null); const [totalBrews, setTotalBrews] = useState(null); @@ -34,7 +37,10 @@ const VaultPage = (props)=>{ useEffect(()=>{ disableSubmitIfFormInvalid(); - loadPage(pageState, true); + const initialSort = props.query.sort || 'title'; + const initialDir = props.query.dir || 'asc'; + const initialSorting = `${initialSort}/${initialDir}`; + loadPage(pageState, true, initialSorting); }, []); const updateStateWithBrews = (brews, page)=>{ @@ -43,7 +49,7 @@ const VaultPage = (props)=>{ setSearching(false); }; - const updateUrl = (titleValue, authorValue, countValue, v3Value, legacyValue, page)=>{ + const updateUrl = (titleValue, authorValue, countValue, v3Value, legacyValue, page, sort, dir)=>{ const url = new URL(window.location.href); const urlParams = new URLSearchParams(url.search); @@ -53,21 +59,25 @@ const VaultPage = (props)=>{ urlParams.set('v3', v3Value); urlParams.set('legacy', legacyValue); urlParams.set('page', page); + urlParams.set('sort', sort); + urlParams.set('dir', dir); url.search = urlParams.toString(); window.history.replaceState(null, '', url.toString()); }; - const performSearch = async (title, author, count, v3, legacy, page)=>{ - updateUrl(title, author, count, v3, legacy, page); + const performSearch = async (title, author, count, v3, legacy, page, sort, dir)=>{ + updateUrl(title, author, count, v3, legacy, page, sort, dir); - const response = await request.get( - `/api/vault?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}&count=${count}&page=${page}` - ).catch((error)=>{ - console.log('error at loadPage: ', error); - setError(error); - updateStateWithBrews([], 1); - }); + const response = await request + .get( + `/api/vault?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}&count=${count}&page=${page}&sort=${sort}&dir=${dir}` + ) + .catch((error)=>{ + console.log('error at loadPage: ', error); + setError(error); + updateStateWithBrews([], 1); + }); if(response.ok) updateStateWithBrews(response.body.brews, page); @@ -88,9 +98,8 @@ const VaultPage = (props)=>{ setTotalBrews(response.body.totalBrews); }; - const loadPage = async (page, updateTotal)=>{ - if(!validateForm()) - return; + const loadPage = async (page, updateTotal, sort)=>{ + if(!validateForm()) return; setSearching(true); setError(null); @@ -100,8 +109,11 @@ const VaultPage = (props)=>{ const count = countRef.current.value || 10; const v3 = v3Ref.current.checked != false; const legacy = legacyRef.current.checked != false; + const sortOption = sort && sort.split('/')[0] || 'title'; + const dir = sort && sort.split('/')[1] || 'asc'; + const pageProp = page || 1; - performSearch(title, author, count, v3, legacy, page); + performSearch(title, author, count, v3, legacy, pageProp, sortOption, dir); if(updateTotal) loadTotal(title, author, v3, legacy); @@ -248,6 +260,45 @@ const VaultPage = (props)=>{ ); + const renderSortOption = ( optionTitle, optionValue)=>{ + const oppositeDir = dirState === 'asc' ? 'desc' : 'asc'; + + return ( +
+ + {sortState === optionValue && ( + + )} +
+ ); + }; + + const renderSortBar = ()=>{ + + return ( +
+ {renderSortOption('Title', 'title', props.query.dir)} + {renderSortOption('Created Date', 'createdAt', props.query.dir)} + {renderSortOption('Updated Date', 'updatedAt', props.query.dir)} + {renderSortOption('Views', 'views', props.query.dir)} +
+ ); + }; + const renderPaginationControls = ()=>{ if(!totalBrews) return null; @@ -274,7 +325,7 @@ const VaultPage = (props)=>{ className={`pageNumber ${ pageState === startPage + index ? 'currentPage' : '' }`} - onClick={()=>loadPage(startPage + index, false)} + onClick={()=>loadPage(startPage + index)} > {startPage + index} @@ -284,7 +335,7 @@ const VaultPage = (props)=>{
{sortState === optionValue && ( - + )}
); From 4fd358771ac93d6c1845393c6ed071a8b8b9a066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Fri, 20 Sep 2024 20:25:33 +0200 Subject: [PATCH 05/12] fix class by suggestion --- client/homebrew/pages/vaultPage/vaultPage.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index 409103167..d8e557286 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -266,7 +266,7 @@ const VaultPage = (props)=>{ return (
{sortState === optionValue && ( @@ -319,7 +317,7 @@ const VaultPage = (props)=>{ className={`pageNumber ${ pageState === startPage + index ? 'currentPage' : '' }`} - onClick={()=>loadPage(startPage + index)} + onClick={()=>loadPage(startPage + index, false, sortState, dirState)} > {startPage + index} @@ -329,7 +327,7 @@ const VaultPage = (props)=>{
); - const renderSortOption = ( optionTitle, optionValue)=>{ + const renderSortOption = (optionTitle, optionValue)=>{ const oppositeDir = dirState === 'asc' ? 'desc' : 'asc'; return ( -
- - {sortState === optionValue && ( - - )} +
+ + {sortState === optionValue && ( + + )}
); }; const renderSortBar = ()=>{ - + return (
{renderSortOption('Title', 'title', props.query.dir)} @@ -314,9 +308,7 @@ const VaultPage = (props)=>{ .map((_, index)=>( loadPage(startPage + index, false, sortState, dirState)} > {startPage + index} @@ -373,7 +365,7 @@ const VaultPage = (props)=>{ if(error) { const errorText = ErrorIndex()[error.HBErrorCode.toString()] || ''; - + return (

Error: {errorText}

From 4353c010327bfc62a3ebfae039994bd899b25c51 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Fri, 20 Sep 2024 16:01:29 -0400 Subject: [PATCH 08/12] Update server/vault.api.js --- server/vault.api.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/vault.api.js b/server/vault.api.js index f3e0d74ac..88115af2d 100644 --- a/server/vault.api.js +++ b/server/vault.api.js @@ -30,9 +30,7 @@ const rendererConditions = (legacy, v3)=>{ }; const sortConditions = (sort, dir) => { - return { - [sort]: dir === 'asc' ? 1 : -1 - }; + return { [sort]: dir === 'asc' ? 1 : -1 }; } const findBrews = async (req, res)=>{ From 971be6375eab4c124f10bc8380f1f86b0fb29e2f Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Fri, 20 Sep 2024 16:02:09 -0400 Subject: [PATCH 09/12] lint --- server/vault.api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/vault.api.js b/server/vault.api.js index 88115af2d..8aa382f26 100644 --- a/server/vault.api.js +++ b/server/vault.api.js @@ -31,7 +31,7 @@ const rendererConditions = (legacy, v3)=>{ const sortConditions = (sort, dir) => { return { [sort]: dir === 'asc' ? 1 : -1 }; -} +}; const findBrews = async (req, res)=>{ const title = req.query.title || ''; From 58c6e6a446c5dda9051f5858d82f33f318c95803 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 03:35:10 +0000 Subject: [PATCH 10/12] Bump eslint from 9.10.0 to 9.11.0 Bumps [eslint](https://github.com/eslint/eslint) from 9.10.0 to 9.11.0. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/compare/v9.10.0...v9.11.0) --- updated-dependencies: - dependency-name: eslint dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package-lock.json | 24 ++++++++++++------------ package.json | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 16d308bf5..cb6fa7bb5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,7 +51,7 @@ }, "devDependencies": { "@stylistic/stylelint-plugin": "^3.0.1", - "eslint": "^9.10.0", + "eslint": "^9.11.0", "eslint-plugin-jest": "^28.8.3", "eslint-plugin-react": "^7.36.1", "globals": "^15.9.0", @@ -2073,9 +2073,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.10.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.10.0.tgz", - "integrity": "sha512-fuXtbiP5GWIn8Fz+LWoOMVf/Jxm+aajZYkhi6CuEm4SxymFM+eUWzbO9qXT+L0iCkL5+KGYMCSGxo686H19S1g==", + "version": "9.11.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.11.0.tgz", + "integrity": "sha512-LPkkenkDqyzTFauZLLAPhIb48fj6drrfMvRGSL9tS3AcZBSVTllemLSNyCvHNNL2t797S/6DJNSIwRwXgMO/eQ==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2091,9 +2091,9 @@ } }, "node_modules/@eslint/plugin-kit": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.1.0.tgz", - "integrity": "sha512-autAXT203ixhqei9xt+qkYOvY8l6LAFIdT2UXc/RPNeUVfqRF1BV94GTJyVPFKT8nFM6MyVJhjLj9E8JWvf5zQ==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.0.tgz", + "integrity": "sha512-vH9PiIMMwvhCx31Af3HiGzsVNULDbyVkHXwlemn/B0TFj/00ho3y55efXrUZTfQipxoHC5u4xq6zblww1zm1Ig==", "dev": true, "dependencies": { "levn": "^0.4.1" @@ -5829,17 +5829,17 @@ } }, "node_modules/eslint": { - "version": "9.10.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.10.0.tgz", - "integrity": "sha512-Y4D0IgtBZfOcOUAIQTSXBKoNGfY0REGqHJG6+Q81vNippW5YlKjHFj4soMxamKK1NXHUWuBZTLdU3Km+L/pcHw==", + "version": "9.11.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.11.0.tgz", + "integrity": "sha512-yVS6XODx+tMFMDFcG4+Hlh+qG7RM6cCJXtQhCKLSsr3XkLvWggHjCqjfh0XsPPnt1c56oaT6PMgW9XWQQjdHXA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.11.0", "@eslint/config-array": "^0.18.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.10.0", - "@eslint/plugin-kit": "^0.1.0", + "@eslint/js": "9.11.0", + "@eslint/plugin-kit": "^0.2.0", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.3.0", "@nodelib/fs.walk": "^1.2.8", diff --git a/package.json b/package.json index ff702fda7..deb1622f2 100644 --- a/package.json +++ b/package.json @@ -126,7 +126,7 @@ }, "devDependencies": { "@stylistic/stylelint-plugin": "^3.0.1", - "eslint": "^9.10.0", + "eslint": "^9.11.0", "eslint-plugin-jest": "^28.8.3", "eslint-plugin-react": "^7.36.1", "globals": "^15.9.0", From 1347374ff73585b243d15e958438ab950aba7808 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 13:54:45 +0000 Subject: [PATCH 11/12] Bump mongoose from 8.6.2 to 8.6.3 Bumps [mongoose](https://github.com/Automattic/mongoose) from 8.6.2 to 8.6.3. - [Release notes](https://github.com/Automattic/mongoose/releases) - [Changelog](https://github.com/Automattic/mongoose/blob/master/CHANGELOG.md) - [Commits](https://github.com/Automattic/mongoose/compare/8.6.2...8.6.3) --- updated-dependencies: - dependency-name: mongoose dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index cb6fa7bb5..9791d997e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,7 +38,7 @@ "marked-smartypants-lite": "^1.0.2", "markedLegacy": "npm:marked@^0.3.19", "moment": "^2.30.1", - "mongoose": "^8.6.2", + "mongoose": "^8.6.3", "nanoid": "3.3.4", "nconf": "^0.12.1", "react": "^18.3.1", @@ -10801,9 +10801,9 @@ } }, "node_modules/mongoose": { - "version": "8.6.2", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.6.2.tgz", - "integrity": "sha512-ErbDVvuUzUfyQpXvJ6sXznmZDICD8r6wIsa0VKjJtB6/LZncqwUn5Um040G1BaNo6L3Jz+xItLSwT0wZmSmUaQ==", + "version": "8.6.3", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.6.3.tgz", + "integrity": "sha512-++yRmm7hjMbqVA/8WeiygTnEfrFbiy+OBjQi49GFJIvCQuSYE56myyQWo4j5hbpcHjhHQU8NukMNGTwAWFWjIw==", "dependencies": { "bson": "^6.7.0", "kareem": "2.6.3", diff --git a/package.json b/package.json index deb1622f2..420a576cc 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,7 @@ "marked-smartypants-lite": "^1.0.2", "markedLegacy": "npm:marked@^0.3.19", "moment": "^2.30.1", - "mongoose": "^8.6.2", + "mongoose": "^8.6.3", "nanoid": "3.3.4", "nconf": "^0.12.1", "react": "^18.3.1", From c039a906242525daedd31994ad5ccc827caa2b27 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:17:32 +0000 Subject: [PATCH 12/12] Bump stylelint-config-recess-order from 5.1.0 to 5.1.1 Bumps [stylelint-config-recess-order](https://github.com/stormwarning/stylelint-config-recess-order) from 5.1.0 to 5.1.1. - [Release notes](https://github.com/stormwarning/stylelint-config-recess-order/releases) - [Changelog](https://github.com/stormwarning/stylelint-config-recess-order/blob/main/CHANGELOG.md) - [Commits](https://github.com/stormwarning/stylelint-config-recess-order/compare/v5.1.0...v5.1.1) --- updated-dependencies: - dependency-name: stylelint-config-recess-order dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9791d997e..6b041552e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -59,7 +59,7 @@ "jest-expect-message": "^1.1.3", "postcss-less": "^6.0.0", "stylelint": "^16.9.0", - "stylelint-config-recess-order": "^5.1.0", + "stylelint-config-recess-order": "^5.1.1", "stylelint-config-recommended": "^14.0.1", "supertest": "^7.0.0" }, @@ -13626,9 +13626,9 @@ } }, "node_modules/stylelint-config-recess-order": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/stylelint-config-recess-order/-/stylelint-config-recess-order-5.1.0.tgz", - "integrity": "sha512-ddapCF6B/kEtQYIFhQFReQ0dvK1ZdgJDM/SGFtIyeooYDbqaJqcOlGkRRGaVErCQYJY/bPSPsLRS2LdQtLJUVQ==", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/stylelint-config-recess-order/-/stylelint-config-recess-order-5.1.1.tgz", + "integrity": "sha512-eDAHWVBelzDbMbdMj15pSw0Ycykv5eLeriJdbGCp0zd44yvhgZLI+wyVHegzXp5NrstxTPSxl0fuOVKdMm0XLA==", "dev": true, "dependencies": { "stylelint-order": "^6.0.4" diff --git a/package.json b/package.json index 420a576cc..06edb3c0d 100644 --- a/package.json +++ b/package.json @@ -134,7 +134,7 @@ "jest-expect-message": "^1.1.3", "postcss-less": "^6.0.0", "stylelint": "^16.9.0", - "stylelint-config-recess-order": "^5.1.0", + "stylelint-config-recess-order": "^5.1.1", "stylelint-config-recommended": "^14.0.1", "supertest": "^7.0.0" }