diff --git a/README.md b/README.md index 71ddc468..ed0b0ea9 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ http://it2810-03.idi.ntnu.no/project2/ ## Core features - **Plant Match:** Plants matching the most preferences come first, otherwise the order is random. The deck is kept while the user visits other pages, so they can continue where they left off. -- **My Matches:** Collects liked plants from both Plant Match and Explore Plants. The user only stores plant ids, and the list is fetched one page at a time, so responses do not grow with the number of matches. +- **My Matches:** Collects liked plants from both Plant Match and Explore Plants, with the same search, filters and match counts as Explore Plants. Both pages can also sort the plants by how well they match the user's preferences. The user only stores plant ids, and the list is fetched one page at a time, so responses do not grow with the number of matches. - **Explore Plants:** Search, filtering, sorting and pagination run in the backend, so the frontend only receives one page at a time, whatever the size of the collection. The state is kept in the URL, so a view survives a refresh and can be shared as a link. Each filter value shows how many plants it would give, and values that would give none can't be chosen, so filtering never ends in an empty list. - **Plant Owner Test:** Four questions give one of six plant owner types, whose picture can be used as profile picture. The result also suggests one preference each for watering, light and care level, based on the answers and the description of the type. The user chooses which of them to add, and they are added to the preferences they already have, so PlantMatch puts plants that suit them first right away. - **Walkthrough:** A short guide opens on the first visit and explains what the user can do on each page. It can be reopened at any time with the ? button, starts at the current page (or at the welcome step on the home page), links to each page and lets the user change language without closing it. diff --git a/backend/package-lock.json b/backend/package-lock.json index a6dc9902..af07cd56 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -31,12 +31,12 @@ } }, "node_modules/@apollo/cache-control-types": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@apollo/cache-control-types/-/cache-control-types-1.0.3.tgz", - "integrity": "sha512-F17/vCp7QVwom9eG7ToauIKdAxpSoadsJnqIfyryLFSkLSOEqu+eC5Z3N8OXcUVStuOMcNHlyraRsA6rRICu4g==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@apollo/cache-control-types/-/cache-control-types-1.1.0.tgz", + "integrity": "sha512-XluQ6uZQXyhsVz+wIHhFU6m/aVWhq6CNKalROjDM3VPxcOhI5h771UKbw+hbO2VavExRroYfxuAxBVYCztNrHw==", "license": "MIT", "peerDependencies": { - "graphql": "14.x || 15.x || 16.x" + "graphql": "14.x || 15.x || 16.x || 17.x" } }, "node_modules/@apollo/protobufjs": { @@ -65,9 +65,9 @@ } }, "node_modules/@apollo/server": { - "version": "5.5.1", - "resolved": "https://registry.npmjs.org/@apollo/server/-/server-5.5.1.tgz", - "integrity": "sha512-Rn3g5TJQsMSUY23CWZTghWdBWyjX7dP1eaEBPkvmM2RHi82cDcpgTIkSCbGvtTUEGjwopLv1AAooU/n7iIZ20A==", + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/@apollo/server/-/server-5.5.2.tgz", + "integrity": "sha512-VTEEQdI2T6L5h9DFe/Bh75EBnGabqdFvYYbLjGwJ2G2kKik5gWINBpkK6vLfEwBaSgL2mBjd1o9GDBn+xde/AQ==", "license": "MIT", "dependencies": { "@apollo/cache-control-types": "^1.0.3", @@ -80,7 +80,9 @@ "@apollo/utils.logger": "^3.0.0", "@apollo/utils.usagereporting": "^2.1.0", "@apollo/utils.withrequired": "^3.0.0", - "@graphql-tools/schema": "^10.0.0", + "@graphql-tools/merge": "^9.1.1 <9.2.5", + "@graphql-tools/schema": "^10.0.0 <10.1.2", + "@graphql-tools/utils": "^10.9.1 || ^11.0.0 || >=12.0.0 <12.0.2", "async-retry": "^1.2.1", "body-parser": "^2.2.2", "content-type": "^1.0.5", @@ -99,18 +101,18 @@ } }, "node_modules/@apollo/server-gateway-interface": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@apollo/server-gateway-interface/-/server-gateway-interface-2.0.0.tgz", - "integrity": "sha512-3HEMD6fSantG2My3jWkb9dvfkF9vJ4BDLRjMgsnD790VINtuPaEp+h3Hg9HOHiWkML6QsOhnaRqZ+gvhp3y8Nw==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@apollo/server-gateway-interface/-/server-gateway-interface-2.2.0.tgz", + "integrity": "sha512-Ue+d80lwbLNt1+RADRDKZhYDRkLWpozUrNRhTMBhA4IvDfx6uvkOPorRwQD4gwg1dAD4nRN8d4/SpaIpsWM/kg==", "license": "MIT", "dependencies": { "@apollo/usage-reporting-protobuf": "^4.1.1", - "@apollo/utils.fetcher": "^3.0.0", - "@apollo/utils.keyvaluecache": "^4.0.0", - "@apollo/utils.logger": "^3.0.0" + "@apollo/utils.fetcher": "^2.0.0 || ^3.0.0", + "@apollo/utils.keyvaluecache": "^2.1.0 || ^3.0.0 || ^4.0.0", + "@apollo/utils.logger": "^2.0.0 || ^3.0.0" }, "peerDependencies": { - "graphql": "14.x || 15.x || 16.x" + "graphql": "14.x || 15.x || 16.x || 17.x" } }, "node_modules/@apollo/usage-reporting-protobuf": { @@ -268,9 +270,9 @@ } }, "node_modules/@babel/helper-string-parser": { - "version": "7.29.13", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.13.tgz", - "integrity": "sha512-fWegr+WsEsiMVW4KUNdIIzzMTZSzNiqhy0//6+2MRi2d5NFNsL/AYwBQW8eBnRbTBVRnDVzjaJEUqKaCWjMMdQ==", + "version": "7.29.15", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.29.15.tgz", + "integrity": "sha512-C2FuapQ2Kh1OnVHAoLi5rD3GBJ8COb9Q609T6HEpLqaBAo560PDP5OxBE5dCI/h951MBO/+bCUYU5SZ+8ZlV+w==", "dev": true, "license": "MIT", "engines": { @@ -288,13 +290,13 @@ } }, "node_modules/@babel/parser": { - "version": "7.29.13", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.13.tgz", - "integrity": "sha512-fJM50YYjlTiBhgdkGmC1tBpv+FMAyo4annf2X6Aks+0yRlaiVkYW/3f07xAfVVkYIoZ9fFZp+mEThUFnuybhkQ==", + "version": "7.29.15", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.29.15.tgz", + "integrity": "sha512-RpKWyisHoP81twtSCgmE02iU0RnPcq1DN5bBEbpUePrjA9Q3wXhufnCJrrayPpoZieqFh3zyZQqwtSK0gGccRA==", "dev": true, "license": "MIT", "dependencies": { - "@babel/types": "^7.29.11" + "@babel/types": "^7.29.15" }, "bin": { "parser": "bin/babel-parser.js" @@ -304,13 +306,13 @@ } }, "node_modules/@babel/types": { - "version": "7.29.11", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.11.tgz", - "integrity": "sha512-WCsemW40Cpc6gouC1SrY6PBaZ+oLRlEVY9XBvZBI7il/HyUrb2nJ505wE1MHEFyDZNnrWDEuy4jL50WVHfTTSQ==", + "version": "7.29.15", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.29.15.tgz", + "integrity": "sha512-/XKpKDakL//LZ66bq1XsZOswuqeI5MZqPLDu18o3XdkU1fNJ7bdPtzgnc4ZNS+bBGHV0FJG8jjb8SwcC3nNVQQ==", "dev": true, "license": "MIT", "dependencies": { - "@babel/helper-string-parser": "^7.29.11", + "@babel/helper-string-parser": "^7.29.15", "@babel/helper-validator-identifier": "^7.29.7" }, "engines": { @@ -873,15 +875,15 @@ } }, "node_modules/@eslint/config-array": { - "version": "0.23.5", - "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.23.5.tgz", - "integrity": "sha512-Y3kKLvC1dvTOT+oGlqNQ1XLqK6D1HU2YXPc52NmAlJZbMMWDzGYXMiPRJ8TYD39muD/OTjlZmNJ4ib7dvSrMBA==", + "version": "0.23.6", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.23.6.tgz", + "integrity": "sha512-WrTH7nioI9QPY4NZGnsywmecswJdgeq4BCM76qok9VgjTO29ZgUzUvcuJLVPYVQM4uDbaPBU0M33R9DIxI8X3w==", "dev": true, "license": "Apache-2.0", "dependencies": { "@eslint/object-schema": "^3.0.5", "debug": "^4.3.1", - "minimatch": "^10.2.4" + "minimatch": "^11.0.5" }, "engines": { "node": "^20.19.0 || ^22.13.0 || >=24" @@ -959,12 +961,12 @@ } }, "node_modules/@graphql-tools/merge": { - "version": "9.2.8", - "resolved": "https://registry.npmjs.org/@graphql-tools/merge/-/merge-9.2.8.tgz", - "integrity": "sha512-OsCEmJ9RIMT4LB/1jBbyKHe7pMIlfGhLAQ0FVNaZqteydDUC+rTI9wZ+yaKqxQpPOFFycD+UtMhovg19lPq92Q==", + "version": "9.2.4", + "resolved": "https://registry.npmjs.org/@graphql-tools/merge/-/merge-9.2.4.tgz", + "integrity": "sha512-vV+8uWNWn0+OsqT0r22lZuoT0cTe6fBqBtpLHre2rriLjI/ZTrsOHmabLPTUOyzgFnRrS2PzFSYGL3zKL1Wj4Q==", "license": "MIT", "dependencies": { - "@graphql-tools/utils": "^12.1.0", + "@graphql-tools/utils": "^12.0.1", "tslib": "^2.4.0" }, "engines": { @@ -975,13 +977,13 @@ } }, "node_modules/@graphql-tools/schema": { - "version": "10.1.5", - "resolved": "https://registry.npmjs.org/@graphql-tools/schema/-/schema-10.1.5.tgz", - "integrity": "sha512-F0Onw0ZBREakKGqcgsKhdSCjOXgmntzQWL0QA+/WrwKmnJ7nJRyGKUJavwuVZL2TrXblaIUvQxm4t1h3FuA3cA==", + "version": "10.1.1", + "resolved": "https://registry.npmjs.org/@graphql-tools/schema/-/schema-10.1.1.tgz", + "integrity": "sha512-24jJghRxEW+SG1lbJ45Zg9HEZ8ZKS923ihbFjOicspFLpryxJkWp6gZJ7D8tCVaSAhli4x1+1wDPAfhT8mLqxg==", "license": "MIT", "dependencies": { - "@graphql-tools/merge": "^9.2.8", - "@graphql-tools/utils": "^12.1.0", + "@graphql-tools/merge": "^9.2.4", + "@graphql-tools/utils": "^12.0.1", "tslib": "^2.4.0" }, "engines": { @@ -992,13 +994,13 @@ } }, "node_modules/@graphql-tools/utils": { - "version": "12.1.0", - "resolved": "https://registry.npmjs.org/@graphql-tools/utils/-/utils-12.1.0.tgz", - "integrity": "sha512-+mOuIX7u83/BHG0L9JviMzKid1j35cxOWhLoox47TXHAJ6Tnn30RgrmEQPmk1FhmaQbhJEcwYBDVyieUvZopJw==", + "version": "12.0.1", + "resolved": "https://registry.npmjs.org/@graphql-tools/utils/-/utils-12.0.1.tgz", + "integrity": "sha512-8YC6jn4xYDS6YTY6xDAgQAs/nGgvzRaIGHS8GeSfVItQzNK7Ms24CQtE3EJY+amvR+tBnhRSX0N83aGj+V/RIg==", "license": "MIT", "dependencies": { "@graphql-typed-document-node/core": "^3.1.1", - "@whatwg-node/promise-helpers": "^2.0.0", + "@whatwg-node/promise-helpers": "^1.0.0", "cross-inspect": "1.0.1", "tslib": "^2.4.0" }, @@ -1084,10 +1086,17 @@ "url": "https://github.com/sponsors/nzakas" } }, + "node_modules/@isaacs/nonrecursive-glob-match": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@isaacs/nonrecursive-glob-match/-/nonrecursive-glob-match-1.1.0.tgz", + "integrity": "sha512-GPm/Dbvk5RLmhRnxXIa7nTpK0xtl4E0wj0MslsuNiJ1FIROU+2+9lgUC/dgF7Ey4QCWhfEsgxilMRMCdHPfDfw==", + "dev": true, + "license": "BlueOak-1.0.0" + }, "node_modules/@jridgewell/resolve-uri": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", - "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.3.tgz", + "integrity": "sha512-lhTtjtoEArWBjismtfS761S9Hlyn+nIZqOZVYoZ1Xn82PMNMVnk+jj/NhC4fAXGTs7ydONcJiR5vyQBTMDu27g==", "dev": true, "license": "MIT", "engines": { @@ -1533,17 +1542,17 @@ } }, "node_modules/@rolldown/pluginutils": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.1.0.tgz", - "integrity": "sha512-K+NU2HDCEem4sClgHH4ZZXwdJeNFkJo+hRk479DIwdIviAPN2hFJH1KHHwg8CxHQXvi0M5XY4deTXINfIiSG6w==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.1.1.tgz", + "integrity": "sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA==", "dev": true, "license": "MIT", "peer": true }, "node_modules/@tybys/wasm-util": { - "version": "0.10.4", - "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.4.tgz", - "integrity": "sha512-W3c4gRigFS0T/Ma4qIYF3GDAc5AQdHb1yL5znJT1Zv1YaD9Kitx656wBjvr19qbiosmZT8lWDM5BEMynUqX65A==", + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.5.tgz", + "integrity": "sha512-dOGOPxlaNV+G046mZzN+9C0dAcQZeSKcXiVaM0TYy/LM4ttTmgSBDxYfovcYI8Em3+eAbiAYpvWLOv8+ZVRJKA==", "dev": true, "license": "MIT", "optional": true, @@ -1623,17 +1632,17 @@ } }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.72.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.72.2.tgz", - "integrity": "sha512-222PKFXKihmFpi/pS5njoBgdAqsPhj2/GBmFbrNw8Tq8gEG9Sv+kSlKFy4u2q+mJv9ZzJgM2Gkv/bUzRZwZw5g==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.73.0.tgz", + "integrity": "sha512-UkygMFer53Yzn29MCYFTHf34hGXf5KJhiDWfIm1tXtXRrym1CS6l5H9Y3yCtPWChpC0/f93H88gdj8tN0dd4kw==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.12.2", - "@typescript-eslint/scope-manager": "8.72.2", - "@typescript-eslint/type-utils": "8.72.2", - "@typescript-eslint/utils": "8.72.2", - "@typescript-eslint/visitor-keys": "8.72.2", + "@typescript-eslint/scope-manager": "8.73.0", + "@typescript-eslint/type-utils": "8.73.0", + "@typescript-eslint/utils": "8.73.0", + "@typescript-eslint/visitor-keys": "8.73.0", "ignore": "^7.0.5", "natural-compare": "^1.4.0", "ts-api-utils": "^2.5.0" @@ -1646,15 +1655,15 @@ "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "@typescript-eslint/parser": "^8.72.2", + "@typescript-eslint/parser": "^8.73.0", "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", "typescript": ">=4.8.4 <6.1.0" } }, "node_modules/@typescript-eslint/eslint-plugin/node_modules/ignore": { - "version": "7.0.14", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.14.tgz", - "integrity": "sha512-wCBiZ77u1tuWde6G/nfOtLaCTYcFDU5yCzARzK10y+rLhzYoL7a7yEemcopcc2Mzow7gZOIjnV2ym1NYmdiJOQ==", + "version": "7.0.16", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.16.tgz", + "integrity": "sha512-52N+Y4HRMOJmbLmr+DqO4iSRyyB7N52gm7PWCT6h0p978+oKbqHCB7gIJIwZvBUsjlSdWbrBFqUSmIFNZMpn0A==", "dev": true, "license": "MIT", "engines": { @@ -1662,16 +1671,16 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.72.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.72.2.tgz", - "integrity": "sha512-llP+T1YuJOLlxEciP6OyQGtz5SMxyn+9LA2BvZw5RmToGVa1y4beEDVQL6Gje7T5WFYh19WREjDCN9Ev4gm5AA==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.73.0.tgz", + "integrity": "sha512-AuL45bVcmssHfZ3Di3cs9Q0l4gBm4ZFVrJOQEE7VpqW+PVgQaEwSwazz4TVIiFabXkk6U51EprYDwqw+HR8ePw==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/scope-manager": "8.72.2", - "@typescript-eslint/types": "8.72.2", - "@typescript-eslint/typescript-estree": "8.72.2", - "@typescript-eslint/visitor-keys": "8.72.2", + "@typescript-eslint/scope-manager": "8.73.0", + "@typescript-eslint/types": "8.73.0", + "@typescript-eslint/typescript-estree": "8.73.0", + "@typescript-eslint/visitor-keys": "8.73.0", "debug": "^4.4.3" }, "engines": { @@ -1687,14 +1696,14 @@ } }, "node_modules/@typescript-eslint/project-service": { - "version": "8.72.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.72.2.tgz", - "integrity": "sha512-6y5dLTZdHhI8Eh3yIQ/bfQhRKwn5e+TpJj64o18Cngc0iW/BCrVvrr6zGYqXPnYH31u6YXAYiFh0+qxX5mybJw==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.73.0.tgz", + "integrity": "sha512-/pEf8Rc4Mjk+qJnY0uO1+Gadeal8uv50xpuic+srG2vIVatA0XxvWMUeMtFvs6OCHqftiQ7/+qH4aehG5stzIA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/tsconfig-utils": "^8.72.2", - "@typescript-eslint/types": "^8.72.2", + "@typescript-eslint/tsconfig-utils": "^8.73.0", + "@typescript-eslint/types": "^8.73.0", "debug": "^4.4.3" }, "engines": { @@ -1709,14 +1718,14 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.72.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.72.2.tgz", - "integrity": "sha512-iIoMJ6/8c1/QpFNyFjU0d1YzPco4MsZjQw0k3V+vfzNWAFmUmvhlyMoYEoYYDQZXc+J6Gi1X5XcxlzW2taIIGQ==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.73.0.tgz", + "integrity": "sha512-/TjD738Iq2rzj5z0ixVOi+TsvgjAzZPLPaH1yWdDBytR/HTR5gMpyYWZeCe5WTQZLwk3ho8AV7U3muoQCRtXBQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.72.2", - "@typescript-eslint/visitor-keys": "8.72.2" + "@typescript-eslint/types": "8.73.0", + "@typescript-eslint/visitor-keys": "8.73.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1727,9 +1736,9 @@ } }, "node_modules/@typescript-eslint/tsconfig-utils": { - "version": "8.72.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.72.2.tgz", - "integrity": "sha512-+h3iCgZXuTNtoLXcnnjP12ZUHLMqoUcIHPfQrFEXTUqvb9dF8QK9b5nv5VtSo5fLkdHuks8ehbTzZj3rImAm9w==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.73.0.tgz", + "integrity": "sha512-lmtCFOfYaJfpqZywGuXi4FpNtE+NQ+YLe3T0K9rtEDcW8ZuGWvfI++pj8r05sYMI8vWT2CYK4rWyedmD6Rp4og==", "dev": true, "license": "MIT", "engines": { @@ -1744,15 +1753,15 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.72.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.72.2.tgz", - "integrity": "sha512-STfkR38qIdhfkLpgtXnUjAzsNy4xouqiBO0lrVc/Wpk9Kem5/aHXUx1J8dGC16zpdYN1+yc2ILQ28er1kXX7ag==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.73.0.tgz", + "integrity": "sha512-MOC9i4xy1F7KcDde7Ip8jf1SrRiALb2Km4UWxGNjUE2YlhjIEo1ayE27GHIwIQyfWuHTmEonQT14uyurlyC6aA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.72.2", - "@typescript-eslint/typescript-estree": "8.72.2", - "@typescript-eslint/utils": "8.72.2", + "@typescript-eslint/types": "8.73.0", + "@typescript-eslint/typescript-estree": "8.73.0", + "@typescript-eslint/utils": "8.73.0", "debug": "^4.4.3", "ts-api-utils": "^2.5.0" }, @@ -1769,9 +1778,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.72.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.72.2.tgz", - "integrity": "sha512-Xfn37OLZx03+PCU7qWx9DTv2FCRh1E6fk2+wONeNY15HXIwtcwuveaSwVpGAUptkNmPQegRxW5JyRel9T7wrog==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.73.0.tgz", + "integrity": "sha512-O/1ytYzflF16QDKXx4/qOXg1IuZp+n7hr9t+S0nv7N/2Tl8rJiNCshztV1gcSUvHbPtoX3+zmNbtSAyVbzxVfw==", "dev": true, "license": "MIT", "engines": { @@ -1783,18 +1792,18 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.72.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.72.2.tgz", - "integrity": "sha512-pQEGqIK/cqEvKivVWaFLYpe7XYejFxfuAOi4mu1oAWFvIo36aRHI9esRFTUxcIy/z8N482RJyH+LpZB0ZIU7Ow==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.73.0.tgz", + "integrity": "sha512-InjlBkSdWceIwIBWSwS3ENUp+i0O02PGX3Zv2wnihWJC1WDVGvG7mTHuf8b57uAaITj94d6tRPDH+sUEtXdRQQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/project-service": "8.72.2", - "@typescript-eslint/tsconfig-utils": "8.72.2", - "@typescript-eslint/types": "8.72.2", - "@typescript-eslint/visitor-keys": "8.72.2", + "@typescript-eslint/project-service": "8.73.0", + "@typescript-eslint/tsconfig-utils": "8.73.0", + "@typescript-eslint/types": "8.73.0", + "@typescript-eslint/visitor-keys": "8.73.0", "debug": "^4.4.3", - "minimatch": "^10.2.2", + "minimatch": "^11.0.1", "semver": "^7.7.3", "tinyglobby": "^0.2.15", "ts-api-utils": "^2.5.0" @@ -1807,20 +1816,26 @@ "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { + "@typescript/native": "npm:typescript@>=7.1.0-dev.20261009.1 || >=7.1.0-beta <7.1.0-dev", "typescript": ">=4.8.4 <6.1.0" + }, + "peerDependenciesMeta": { + "@typescript/native": { + "optional": true + } } }, "node_modules/@typescript-eslint/utils": { - "version": "8.72.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.72.2.tgz", - "integrity": "sha512-hv3eRYbpPbbpezuax1EfGrzpa3C4ySgNZkPUkLOWOAjU8HsOKowEDAr8C7nsNl1C+SBSKDpvno6VKHnlhvp9iA==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.73.0.tgz", + "integrity": "sha512-j2SVJJvVkXdUL0WcEzo4vEH1mO1vIi8KlVukcYA2MgMZvYN2LlZR4PmsW+GTSxSW24j6Q/EP7+MOifLtg5hmsA==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.9.1", - "@typescript-eslint/scope-manager": "8.72.2", - "@typescript-eslint/types": "8.72.2", - "@typescript-eslint/typescript-estree": "8.72.2" + "@typescript-eslint/scope-manager": "8.73.0", + "@typescript-eslint/types": "8.73.0", + "@typescript-eslint/typescript-estree": "8.73.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1835,13 +1850,13 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.72.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.72.2.tgz", - "integrity": "sha512-NAGrjn0Pitjqzq/GkgMC4kBYm233PQ8GffyQ9+kTA3AlNQYEzOf25EIM02BAHZv5FRJSpHpJk+OGUxVkOB93GQ==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.73.0.tgz", + "integrity": "sha512-k4lsFVpRZICbltkIEEH4hZRkwXkqDF1GHBpClKQOHQY+RkoZAAuyc1ci3I6p+CB6v3U4jaHIUshc4RzzQXZWLg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.72.2", + "@typescript-eslint/types": "8.73.0", "eslint-visitor-keys": "^5.0.0" }, "engines": { @@ -1853,9 +1868,9 @@ } }, "node_modules/@vitest/coverage-v8": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-5.1.0.tgz", - "integrity": "sha512-OY9aShBQG5KOIw2zCo9fDoCHI9RHliNHJ//nM7m6jGg41Hyke9JOGWmeMlK74xYErsxMoK8mIB3gAeEyFVA7LA==", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-5.1.1.tgz", + "integrity": "sha512-xL4NkbVx/UqqDHaXSOyvB8qsSoLQ+dVNGR9H2Bh/4ggQtmaPFNPUC9gZQwKZePLOQ6WDcgwXVnPulFW9eCHt0w==", "dev": true, "license": "MIT", "dependencies": { @@ -1872,8 +1887,8 @@ "url": "https://opencollective.com/vitest" }, "peerDependencies": { - "@vitest/browser": "5.1.0", - "vitest": "5.1.0" + "@vitest/browser": "5.1.1", + "vitest": "5.1.1" }, "peerDependenciesMeta": { "@vitest/browser": { @@ -1882,9 +1897,9 @@ } }, "node_modules/@vitest/istanbul-lib-coverage": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@vitest/istanbul-lib-coverage/-/istanbul-lib-coverage-2.1.0.tgz", - "integrity": "sha512-WOjuS+xcjSIy7ruYBQ+9BUcV7XZQ0FyVcbWbWxW9TRx/kLGx5SQaeFRIFDJxjNplb6YsT7SpKo2zuXXUo91OIQ==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@vitest/istanbul-lib-coverage/-/istanbul-lib-coverage-2.1.1.tgz", + "integrity": "sha512-pF9nMHHuyQzyEXdkWX3d4wElEKjymfL5TEoofegJn/jK2WjmTLOcJKfJ7/YwYGYdbZf8Ebrt4VDUoBPiTuO9zg==", "dev": true, "license": "MIT", "engines": { @@ -1892,29 +1907,29 @@ } }, "node_modules/@vitest/istanbul-lib-report": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@vitest/istanbul-lib-report/-/istanbul-lib-report-2.1.0.tgz", - "integrity": "sha512-+ZFta25nWtGCOBG9/IET8w1RO5Oawsd6H8Uf6AJ9EA/StFuKVtKAEJEJ6uRt84OH+T4YkI0ASmIHAhRA+0KVxw==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@vitest/istanbul-lib-report/-/istanbul-lib-report-2.1.1.tgz", + "integrity": "sha512-Qba+8OpQQAbWrmq3u1olh6jqE/vyW4OYJe6TLrrTBpXhjJhbY7Os69wyVvMQmNA64KJhGd5nQ/c7l4io8tPCHQ==", "dev": true, "license": "MIT", "dependencies": { - "@vitest/istanbul-lib-coverage": "2.1.0" + "@vitest/istanbul-lib-coverage": "2.1.1" }, "engines": { "node": ">=22" } }, "node_modules/@vitest/mocker": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-5.1.0.tgz", - "integrity": "sha512-5umB9/jlWcqVS6fsrFmv5Gdnpu6wAUio/lEOwAmvB7v+lFo/IW2B9FhAD0p19GCULTgMzLCdUmuCDCnAzWgppQ==", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-5.1.1.tgz", + "integrity": "sha512-b2OgTB4+3ImWIVafXKazJXwLKwQxUNnix6b3xUvUTMh7RyXlrtzoxfZr8aEz9zkHOMAS4K5lu3TvFWoiVeVTQg==", "dev": true, "license": "MIT", "dependencies": { "@jridgewell/trace-mapping": "0.3.31", - "@vitest/spy": "5.1.0", + "@vitest/spy": "5.1.1", "estree-walker": "^3.0.3", - "magic-string": "^1.4.3" + "magic-string": "^1.4.5" }, "funding": { "url": "https://opencollective.com/vitest" @@ -1933,9 +1948,9 @@ } }, "node_modules/@vitest/spy": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-5.1.0.tgz", - "integrity": "sha512-2DPO5OMHWKrBngC+fCmTQqemNF0gidRhp3lxbBmRhW+M1XJrfgPpqNqWVevXtn2f2ufD5ZaR1B6B641aAlcX5A==", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-5.1.1.tgz", + "integrity": "sha512-6K8C6alQG1/Yc8/ZI22iJS7JEsxPdVzqtqDq+/xM4Z0mGVykemMVjLhqMy/q6/IHYG3kKD8hKSwRen/ZdyI9vQ==", "dev": true, "license": "MIT", "funding": { @@ -1943,15 +1958,15 @@ } }, "node_modules/@whatwg-node/promise-helpers": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@whatwg-node/promise-helpers/-/promise-helpers-2.0.2.tgz", - "integrity": "sha512-RKVGTBAuYfObHxUFjlTFmlDndmuXBxkN56yj3z6EQpNpT55R/xaMhTi4+9yXZ5UoDXbKLAsZHCP8ycoWHM/Vdg==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@whatwg-node/promise-helpers/-/promise-helpers-1.3.2.tgz", + "integrity": "sha512-Nst5JdK47VIl9UcGwtv2Rcgyn5lWtZ0/mhRQ4G8NN2isxpq2TO30iqHzmwoJycjWuyUfg3GFXqP/gFHXeV57IA==", "license": "MIT", "dependencies": { - "tslib": "^2.9.1" + "tslib": "^2.6.3" }, "engines": { - "node": ">=22.15.0" + "node": ">=16.0.0" } }, "node_modules/acorn": { @@ -2086,9 +2101,9 @@ } }, "node_modules/bare-buffer": { - "version": "3.7.1", - "resolved": "https://registry.npmjs.org/bare-buffer/-/bare-buffer-3.7.1.tgz", - "integrity": "sha512-cIjZnSO+y89ykVX9x96OVnA6tGORBn7vGJ/e3PCbBHMEyfMNG/ixzOS0lLa6saMlWcs69bSKjxFyDwjK152OMg==", + "version": "3.7.3", + "resolved": "https://registry.npmjs.org/bare-buffer/-/bare-buffer-3.7.3.tgz", + "integrity": "sha512-77owW16RX6YgdOzddHtM0oGz8wsd0/F9k/0coz6TPmjUHnr/9FwWODVMNKwyYWM/a/ESdTum855nfQxnsKUygA==", "dev": true, "license": "Apache-2.0", "engines": { @@ -2111,9 +2126,9 @@ } }, "node_modules/bare-fs": { - "version": "4.8.4", - "resolved": "https://registry.npmjs.org/bare-fs/-/bare-fs-4.8.4.tgz", - "integrity": "sha512-MPC2eyrpbk3A873sK4y6rk+Iv4o2enxTjHZ8zH3HO0mjrpm5XjnguY2XmfidIsDV6vnjpbMBKUAJpV0ISD2SsQ==", + "version": "4.8.5", + "resolved": "https://registry.npmjs.org/bare-fs/-/bare-fs-4.8.5.tgz", + "integrity": "sha512-5gborbd4IEFpnyqAiwD0tl6sH9fvPvIaK2hdM8DXU+xAMxSB7B3D3D04CD21k4T5C6u5Oxw3iajkBQhNLxINKg==", "dev": true, "license": "Apache-2.0", "dependencies": { @@ -2136,9 +2151,9 @@ } }, "node_modules/bare-path": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/bare-path/-/bare-path-3.1.2.tgz", - "integrity": "sha512-ZyKbsuuqK6Ag0K8pX6V5Txq6XeJRvY+wXucnFGRjiyVYP9YWDpIQugk/b+enRYrEYBJaqLzghRQpXPMR7341Nw==", + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/bare-path/-/bare-path-3.1.3.tgz", + "integrity": "sha512-8r+FVU/o4zcFmpCDqbqAYhHHbtXPP+cyZKo7DRGRWc7OLlNs4TMaSQEpXL/sIdzyEG0M7RHw4B7xYMGrTc+qrg==", "dev": true, "license": "Apache-2.0" }, @@ -2171,9 +2186,9 @@ } }, "node_modules/bare-url": { - "version": "2.5.6", - "resolved": "https://registry.npmjs.org/bare-url/-/bare-url-2.5.6.tgz", - "integrity": "sha512-iqkXHkW65De+BT14nHLiBFbNuJ/DdMrZaVNJ1IXPctpK6b1olUJ5Qmy8QBvwROajTiGztso2n82kFEvCsNG7Rg==", + "version": "2.5.8", + "resolved": "https://registry.npmjs.org/bare-url/-/bare-url-2.5.8.tgz", + "integrity": "sha512-G5KTe5Bj6z5pqIxcn3lWlIFIv0rkXbccx0T0Xuf7t4RapfSWvFlcVbrwYXxFZ00PC4lp57OCIk6uXP/r3GbpDw==", "dev": true, "license": "Apache-2.0", "dependencies": { @@ -2490,9 +2505,9 @@ "license": "MIT" }, "node_modules/encodeurl": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.1.tgz", - "integrity": "sha512-Ev/hIyePLZtpL98x562lvPtenrUfGr0lfaf44HFZ+hDEwso7ccV9QAZrEVLg0hxNAzygaAFxy2dYaAKKM0G06A==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.3.tgz", + "integrity": "sha512-mIteYONiEfc4xWf2F1WXovh1c8npzS00vNeiUPdwFF+QlVJni+gNvpQltLMQhob8rew/bWWc/bGTuUr0EUGt0w==", "license": "MIT", "engines": { "node": ">= 0.8" @@ -2601,9 +2616,9 @@ } }, "node_modules/eslint": { - "version": "10.14.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.14.0.tgz", - "integrity": "sha512-T0pNsxkb9IKmtQjhpK3d7nWOpFv+YHuMbTJnSVMoQblF0onvXfErrtp4V1jHtsQPan7dKaGVD0q1WCXnzMF31A==", + "version": "10.15.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-10.15.0.tgz", + "integrity": "sha512-+5Wg4p+ze3sG1WErYgUO/3H1IQIfFBymVUA0Fo/XTeBOLS6UQIUekpSJ8sdRkn7O7wjh84b55w/roqavH2aScg==", "dev": true, "license": "MIT", "workspaces": [ @@ -2612,7 +2627,7 @@ "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.2", - "@eslint/config-array": "^0.23.5", + "@eslint/config-array": "^0.23.6", "@eslint/config-helpers": "^0.7.0", "@eslint/core": "^1.2.1", "@eslint/plugin-kit": "^0.7.3", @@ -2637,7 +2652,7 @@ "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "json-stable-stringify-without-jsonify": "^1.0.1", - "minimatch": "^10.2.6", + "minimatch": "^11.0.5", "natural-compare": "^1.4.0", "optionator": "^0.9.3" }, @@ -3287,9 +3302,9 @@ "license": "ISC" }, "node_modules/js-tokens": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-10.0.0.tgz", - "integrity": "sha512-lM/UBzQmfJRo9ABXbPWemivdCW8V2G8FHaHdypQaIy523snUjog0W71ayWXTjiR+ixeMyVHN2XcpnTd/liPg/Q==", + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-10.0.1.tgz", + "integrity": "sha512-XMt+uh+yEs6srFvEb/pEe4IMvbtoXVdNxF7lZFU+I9sdWI641L97L+gXQMTGm1x3RjPUVizNVjHueclXr0U7sw==", "dev": true, "license": "MIT" }, @@ -3756,25 +3771,26 @@ } }, "node_modules/minimatch": { - "version": "10.2.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-10.2.6.tgz", - "integrity": "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A==", + "version": "11.0.9", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.9.tgz", + "integrity": "sha512-KCFkfyjqerNlSstjlhIGNXIKZGA/6O4V4RlhZ+Dsr621SPPw0mzlypE9D9ZOoPiVefHID+j7/XuMMlqfD/F60Q==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { - "brace-expansion": "^5.0.8" + "@isaacs/nonrecursive-glob-match": "^1.1.0", + "brace-expansion": "^5.0.12" }, "engines": { - "node": "18 || 20 || >=22" + "node": "20 || >=22" }, "funding": { "url": "https://github.com/sponsors/isaacs" } }, "node_modules/mongodb": { - "version": "7.8.0", - "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.8.0.tgz", - "integrity": "sha512-p2NKagbQ41+daACG/ZSvhTzeAo+DoEyWE9Cmpf/SyP3pTC43+X0mwKE/44PpKtCxp5wOxnXz+t2pXEZRSkt9Yg==", + "version": "7.9.1", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-7.9.1.tgz", + "integrity": "sha512-OWtk/bcf8tx4Qe6lB8OsMksOwGGhC2FH+zl5UNwE+L7uz2VQDhCcnJThAvInEaBrEDaSsUWlMRbuFR4/TjF44w==", "license": "Apache-2.0", "dependencies": { "@mongodb-js/saslprep": "^1.5.0", @@ -3818,37 +3834,37 @@ } }, "node_modules/mongodb-connection-string-url": { - "version": "7.0.2", - "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-7.0.2.tgz", - "integrity": "sha512-ZoS07RoFqpKYQwAk59qmrx8+jJHNHU30UjlU96QktiGn1ltvDr+vCznLX5DiUBLEpMAHatHNWV1nM/74ul66kA==", + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-7.0.3.tgz", + "integrity": "sha512-5I/pX3C2gPEz1EDdYMdZwBx1b/jE/f+J+KItSUJ02uQZ66bbe7kHKjv2uqCHJWaMCagem3dyfWqoAcv+XYZ6aw==", "license": "Apache-2.0", "dependencies": { "@types/whatwg-url": "^13.0.0", - "whatwg-url": "^14.1.0" + "whatwg-url": "^15.0.1" }, "engines": { "node": ">=20.19.0" } }, "node_modules/mongodb-memory-server": { - "version": "11.3.0", - "resolved": "https://registry.npmjs.org/mongodb-memory-server/-/mongodb-memory-server-11.3.0.tgz", - "integrity": "sha512-8ZCDrraqKqmAikoeKuEq+16jeWdVKwjtEAuMxxeQctHiGSGYt17W9LmoRzV1Nwnz7owyxwDKMhow4IVkNYYRKw==", + "version": "11.4.0", + "resolved": "https://registry.npmjs.org/mongodb-memory-server/-/mongodb-memory-server-11.4.0.tgz", + "integrity": "sha512-yi/NFqse40EcRkCLMp+jPiPvGdDwFSRHQdIT7SfA/JPdg5avl7Gj36/0CCMp8NoVfr2bOMi5dwGQI0aeSdR4AQ==", "dev": true, "hasInstallScript": true, "license": "MIT", "dependencies": { - "mongodb-memory-server-core": "11.3.0", - "tslib": "^2.8.1" + "mongodb-memory-server-core": "11.4.0", + "tslib": "^2.9.1" }, "engines": { "node": ">=20.19.0" } }, "node_modules/mongodb-memory-server-core": { - "version": "11.3.0", - "resolved": "https://registry.npmjs.org/mongodb-memory-server-core/-/mongodb-memory-server-core-11.3.0.tgz", - "integrity": "sha512-QBu/RsRpBfcNd5CrBDfCzqcaFPaYpivUzGYUy9YgVc3up78ff0gIHQVD9PLmBLOOxFX6BM9hU6YT0HocZH+s1g==", + "version": "11.4.0", + "resolved": "https://registry.npmjs.org/mongodb-memory-server-core/-/mongodb-memory-server-core-11.4.0.tgz", + "integrity": "sha512-I4pmBybIQeTzeIfVO/CGyrgqVMZM/rBeYSvVgJTcYD9W+AUj4G8vNHvTPyX89/qI1ip1GiQoaqZxySylRbBHxQ==", "dev": true, "license": "MIT", "dependencies": { @@ -3856,13 +3872,13 @@ "camelcase": "^6.3.0", "debug": "^4.4.3", "find-cache-dir": "^3.3.2", - "follow-redirects": "^1.16.0", + "follow-redirects": "^1.16.3", "https-proxy-agent": "^7.0.6", "mongodb": "~7.5.0", "new-find-package-json": "^2.0.0", "semver": "^7.8.5", "tar-stream": "^3.2.1", - "tslib": "^2.8.1", + "tslib": "^2.9.1", "yauzl": "^3.4.0" }, "engines": { @@ -4001,9 +4017,9 @@ } }, "node_modules/object-inspect": { - "version": "1.13.4", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", - "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.14.0.tgz", + "integrity": "sha512-IVgHNlp/jwQX271+Xzoq9LZNTWXxZK+cEOrGBOBxXNbn7fapnZ+Ts6TVMgNOuAezwG2wdtnMX97tTPK6VEnuOQ==", "license": "MIT", "engines": { "node": ">= 0.4" @@ -4238,9 +4254,9 @@ } }, "node_modules/postcss": { - "version": "8.5.32", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.32.tgz", - "integrity": "sha512-LJlKCCAUFKOuZxipUdYw1NzIITEsPcgyOG9LkvRJvuKj/bRzbuRY0ARXvL0pWGpsZvn8jku+LMep2eU0seHp8g==", + "version": "8.5.33", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.33.tgz", + "integrity": "sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ==", "dev": true, "funding": [ { @@ -4560,13 +4576,13 @@ } }, "node_modules/source-map-js": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.2.tgz", - "integrity": "sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==", + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.4.tgz", + "integrity": "sha512-J7ZjMvHd9O1fcT/5V09QWaaSl2BbWx3F6O08spde82Namf9UB0GxRVIPiNbVsdKkoizHiSpTodo3vp2bAy91MA==", "dev": true, "license": "BSD-3-Clause", "engines": { - "node": ">=0.10.0" + "node": ">=6.0.0" } }, "node_modules/sparse-bitfield": { @@ -4640,9 +4656,9 @@ } }, "node_modules/tinybench": { - "version": "6.2.3", - "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-6.2.3.tgz", - "integrity": "sha512-Al01C2JIBnO2CXCAPbpAl6sUiOZHeThGtHYNTa51JRw9PyWOCdr+9Ong05R4qg/Sk3+H645E8ov1h2c58ityNw==", + "version": "6.2.4", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-6.2.4.tgz", + "integrity": "sha512-SQ52jEncXxbMCzJuY2A/jGIbbAu6NYsBWW7grz2pNE+EnzQdoGaoBfpk4qC/opE7qiUcGmGgaGIz5EoHdS1O9w==", "dev": true, "license": "MIT", "engines": { @@ -4710,15 +4726,15 @@ } }, "node_modules/tr46": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz", - "integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-6.0.0.tgz", + "integrity": "sha512-bLVMLPtstlZ4iMQHpFHTR7GAGj2jxi8Dg0s2h2MafAE4uSWF98FC/3MomU51iQAMf8/qDUbKWf5GxuvvVcXEhw==", "license": "MIT", "dependencies": { "punycode": "^2.3.1" }, "engines": { - "node": ">=18" + "node": ">=20" } }, "node_modules/ts-api-utils": { @@ -4832,16 +4848,16 @@ } }, "node_modules/typescript-eslint": { - "version": "8.72.2", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.72.2.tgz", - "integrity": "sha512-c/+AKMW1KB81r28Sp0AAdcyXj5dzNmAsZFcsrxKbZTKmcBK2xIwBR31dcSYSDu3bKmzXe8GKrSxO+eDQ401Uzg==", + "version": "8.73.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.73.0.tgz", + "integrity": "sha512-+EnKy9rkYPun4l+kG2bDuYWQ6y1tGVgdR/tY1U9AC6h21CjEwOoc7gsjwe0FXB8uWFzk4QiCFbuRWgX758PiAg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/eslint-plugin": "8.72.2", - "@typescript-eslint/parser": "8.72.2", - "@typescript-eslint/typescript-estree": "8.72.2", - "@typescript-eslint/utils": "8.72.2" + "@typescript-eslint/eslint-plugin": "8.73.0", + "@typescript-eslint/parser": "8.73.0", + "@typescript-eslint/typescript-estree": "8.73.0", + "@typescript-eslint/utils": "8.73.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -4970,22 +4986,22 @@ } }, "node_modules/vitest": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/vitest/-/vitest-5.1.0.tgz", - "integrity": "sha512-MzmNFnrwa8v8lF1bLxw3UJ4EREwVOVb75VqJZmUDRjJ6EluK/x9th7qTbaeDk41WxE1GxWqmTXcdsfobfH5sOA==", + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-5.1.1.tgz", + "integrity": "sha512-trVmzUFOSraCZcI3uZIMD5FqBh4atFkC/XuJP/IU7qtyQay0FCs3Ia+0QiQ2JJwGyWG/xrcBoJNel2+O7kEZ0g==", "dev": true, "license": "MIT", "dependencies": { "@types/chai": "^5.2.2", - "@vitest/mocker": "5.1.0", + "@vitest/mocker": "5.1.1", "chai": "^6.3.0", "es-module-lexer": "^2.3.2", "expect-type": "^1.4.0", - "magic-string": "^1.4.3", + "magic-string": "^1.4.5", "obug": "^3.0.0", "picomatch": "^4.0.7", "std-env": "^4.3.0", - "tinybench": "^6.2.2", + "tinybench": "^6.2.3", "tinyexec": "^1.3.1", "tinyglobby": "^0.2.17", "why-is-node-running": "3.2.1" @@ -5003,12 +5019,12 @@ "@edge-runtime/vm": "*", "@opentelemetry/api": "^1.9.0", "@types/node": "^22.0.0 || >=24.0.0", - "@vitest/browser-playwright": "5.1.0", - "@vitest/browser-preview": "5.1.0", + "@vitest/browser-playwright": "5.1.1", + "@vitest/browser-preview": "5.1.1", "@vitest/browser-webdriverio": "^5.0.0-beta.5 || >=5.0.0", - "@vitest/coverage-istanbul": "5.1.0", - "@vitest/coverage-v8": "5.1.0", - "@vitest/ui": "5.1.0", + "@vitest/coverage-istanbul": "5.1.1", + "@vitest/coverage-v8": "5.1.1", + "@vitest/ui": "5.1.1", "happy-dom": "*", "jsdom": "*", "vite": "^6.4.0 || ^7.0.0 || ^8.0.0" @@ -5053,12 +5069,12 @@ } }, "node_modules/webidl-conversions": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", - "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-8.0.1.tgz", + "integrity": "sha512-BMhLD/Sw+GbJC21C/UgyaZX41nPt8bUTg+jWyDeg7e7YN4xOM05YPSIXceACnXVtqyEw/LMClUQMtMZ+PGGpqQ==", "license": "BSD-2-Clause", "engines": { - "node": ">=12" + "node": ">=20" } }, "node_modules/whatwg-mimetype": { @@ -5071,16 +5087,16 @@ } }, "node_modules/whatwg-url": { - "version": "14.2.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", - "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "version": "15.1.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-15.1.0.tgz", + "integrity": "sha512-2ytDk0kiEj/yu90JOAp44PVPUkO9+jVhyf+SybKlRHSDlvOOZhdPIrr7xTH64l4WixO2cP+wQIcgujkGBPPz6g==", "license": "MIT", "dependencies": { - "tr46": "^5.1.0", - "webidl-conversions": "^7.0.0" + "tr46": "^6.0.0", + "webidl-conversions": "^8.0.0" }, "engines": { - "node": ">=18" + "node": ">=20" } }, "node_modules/which": { diff --git a/backend/src/queryBuilders.ts b/backend/src/queryBuilders.ts index 99305ca5..270e9b97 100644 --- a/backend/src/queryBuilders.ts +++ b/backend/src/queryBuilders.ts @@ -1,9 +1,9 @@ import type { Document, Filter, ObjectId } from "mongodb"; import type { - ExplorePlantsArgs, FilterCounts, FilterParam, PlantDoc, + PlantFilterArgs, } from "./types.js"; // Helpers for searching, filtering and sorting plants @@ -28,9 +28,32 @@ const rankOf = (order: string[], value: unknown): Document => ({ }, }); -// Builds the aggregation stages that handle sorting -export const buildSortStages = (sort?: string): Document[] => { +// The preferences that exist, without duplicates. Unknown ones are left out. +export const knownPreferences = (preferences?: string[] | null): string[] => + [...new Set(preferences ?? [])].filter((p) => + Object.hasOwn(PREFERENCE_MATCHERS, p), + ); + +// The plants matching the most of the given preferences first, with the same +// score as Plant Match uses. Plants that match equally well are sorted by +// name. Without preferences, the plants are sorted by name. +const byPreferenceStages = (preferences: string[]): Document[] => + preferences.length === 0 + ? [{ $sort: { commonName: 1, _id: 1 } }] + : [ + { $addFields: { matchScore: matchScore(preferences) } }, + { $sort: { matchScore: -1, commonName: 1, _id: 1 } }, + ]; + +// Builds the aggregation stages that handle sorting. preferences is only +// used by the "preferences" sort order. +export const buildSortStages = ( + sort?: string, + preferences: string[] = [], +): Document[] => { switch (sort) { + case "preferences": + return byPreferenceStages(preferences); case "name_desc": // _id is also reversed, so the sort can read the commonName index backwards return [{ $sort: { commonName: -1, _id: -1 } }]; @@ -71,6 +94,7 @@ export const buildSortStages = (sort?: string): Document[] => { export const buildMatchSortStages = ( sort: string | undefined, matchedPlantIds: ObjectId[], + preferences: string[] = [], ): Document[] => { const byMatchOrder = (direction: 1 | -1): Document[] => [ { @@ -82,6 +106,8 @@ export const buildMatchSortStages = ( ]; switch (sort) { + case "preferences": + return byPreferenceStages(preferences); case "oldest": return byMatchOrder(1); case "name_asc": @@ -95,10 +121,8 @@ export const buildMatchSortStages = ( } }; -// Builds the MongoDB filter for the search and filters on Explore Plants -export const buildExploreFilter = ( - args: ExplorePlantsArgs, -): Filter => { +// Builds the MongoDB filter for the search and filters on Explore Plants and My Matches +export const buildPlantFilter = (args: PlantFilterArgs): Filter => { const filter: Filter = {}; if (args.search?.trim()) { const search = { $regex: escapeRegex(args.search.trim()), $options: "i" }; @@ -125,8 +149,8 @@ export const buildExploreFilter = ( return filter; }; -// The values each filter can have. Must match FILTERS in -// frontend/src/pages/explorePlants/ExplorePlantsPage.tsx +// The values each filter can have. Must match PLANT_FILTERS in +// frontend/src/components/plantSearchForm/plantFilters.ts export const FILTER_OPTIONS: Record = { watering: ["minimum", "average", "frequent"], sunlight: ["full_sun", "part_shade", "filtered_shade"], @@ -138,22 +162,27 @@ const facetKey = (param: string, value: string) => `${param}:${value}`; // Stages that count, for every filter value, how many plants the user would get // by choosing it. The value replaces the current choice in that filter, while the -// search and the other filters stay. Uses buildExploreFilter, so the counts +// search and the other filters stay. Uses buildPlantFilter, so the counts // always agree with the results. All counts are done in one query. -export const buildFilterCountStages = (args: ExplorePlantsArgs): Document[] => { +// baseFilter limits which plants are counted at all, e.g. only the user's +// matches on My Matches. On Explore Plants every plant is counted. +export const buildFilterCountStages = ( + args: PlantFilterArgs, + baseFilter: Filter = {}, +): Document[] => { const facets: Record = {}; for (const [param, options] of Object.entries(FILTER_OPTIONS)) { // "" is "All": nothing chosen in this filter, so only the search and the other filters count for (const value of ["", ...options]) { facets[facetKey(param, value)] = [ - { $match: buildExploreFilter({ ...args, [param]: value }) }, + { $match: buildPlantFilter({ ...args, [param]: value }) }, { $count: "count" }, ]; } } return [ - // Only the plants matching the search need to be looked at - { $match: buildExploreFilter({ search: args.search }) }, + // Only the plants matching the base filter and the search need to be looked at + { $match: { ...baseFilter, ...buildPlantFilter({ search: args.search }) } }, { $facet: facets }, ]; }; diff --git a/backend/src/resolvers.ts b/backend/src/resolvers.ts index 67ed8d96..bbd00cd9 100644 --- a/backend/src/resolvers.ts +++ b/backend/src/resolvers.ts @@ -1,23 +1,25 @@ import { GraphQLError } from "graphql"; import { ObjectId } from "mongodb"; -import type { Document, WithId } from "mongodb"; +import type { Document, Filter, WithId } from "mongodb"; import { db } from "./db.js"; import { - buildExploreFilter, + buildPlantFilter, buildFilterCountStages, buildMatchSortStages, buildSortStages, + knownPreferences, matchScore, PREFERENCE_MATCHERS, toFilterCounts, } from "./queryBuilders.js"; import type { ExplorePlantsArgs, - ExplorePage, GetPlantsArgs, MyMatchesArgs, Plant, PlantDoc, + PlantFilterArgs, + PlantPage, UpdateUserPreferencesArgs, UpdateUserProfileArgs, User, @@ -112,6 +114,42 @@ const cleanText = ( return trimmed || null; }; +// One page of plants for Explore Plants and My Matches: the plants matching the +// base filter (on My Matches the user's matches) and the user's search and +// filters, the total count, and the match counts for the filter values, so the +// frontend can show them and disable the values that would give no plants. +// The three queries run at the same time. +const findPlantPage = async ( + baseFilter: Filter, + args: PlantFilterArgs & { limit?: number | null; offset?: number | null }, + sortStages: Document[], +): Promise => { + const filter = { ...baseFilter, ...buildPlantFilter(args) }; + + const [docs, totalCount, [facets]] = await Promise.all([ + plants + .aggregate>([ + { $match: filter }, + ...sortStages, + { $skip: clampOffset(args.offset) }, + { $limit: clampLimit(args.limit, DEFAULT_PAGE_SIZE) }, + ]) + .toArray(), + plants.countDocuments(filter), + plants + .aggregate>( + buildFilterCountStages(args, baseFilter), + ) + .toArray(), + ]); + + return { + plants: docs.map(toPlant), + totalCount, + filterCounts: toFilterCounts(facets), + }; +}; + // Applies an update to one user and returns the updated user, or null if not found const updateUser = async ( userId: string, @@ -138,9 +176,7 @@ export const resolvers = { const objectId = toObjectId(id); return objectId ? [objectId] : []; }); - const preferences = [...new Set(args.preferences ?? [])].filter((p) => - Object.hasOwn(PREFERENCE_MATCHERS, p), - ); + const preferences = knownPreferences(args.preferences); // Without preferences the plants come in random order. With preferences // the best matches come first, and plants with the same score are shuffled. @@ -184,34 +220,12 @@ export const resolvers = { explorePlants: async ( _parent: unknown, args: ExplorePlantsArgs, - ): Promise => { - const filter = buildExploreFilter(args); - - const [docs, totalCount, [facets]] = await Promise.all([ - plants - .aggregate>([ - { $match: filter }, - ...buildSortStages(args.sort), - { $skip: clampOffset(args.offset) }, - { $limit: clampLimit(args.limit, DEFAULT_PAGE_SIZE) }, - ]) - .toArray(), - plants.countDocuments(filter), - // Match counts for the filter values, so the frontend can show them - // and disable the values that would give no plants - plants - .aggregate>( - buildFilterCountStages(args), - ) - .toArray(), - ]); - - return { - plants: docs.map(toPlant), - totalCount, - filterCounts: toFilterCounts(facets), - }; - }, + ): Promise => + findPlantPage( + {}, + args, + buildSortStages(args.sort, knownPreferences(args.preferences)), + ), getUser: async ( _parent: unknown, @@ -223,35 +237,37 @@ export const resolvers = { return doc ? toUser(doc) : null; }, - // One page of the user's matched plants, sorted. Only the ids are stored on - // the user, so the plants are looked up and sorted in the plants collection. - // An unknown or malformed user id gives an empty page. + // One page of the user's matched plants, searched, filtered and sorted. + // Only the ids are stored on the user, so the plants are looked up and + // sorted in the plants collection. An unknown or malformed user id gives an + // empty page. myMatches: async ( _parent: unknown, args: MyMatchesArgs, - ): Promise<{ plants: Plant[]; totalCount: number }> => { + ): Promise => { const _id = toObjectId(args.userId); const user = _id - ? await users.findOne({ _id }, { projection: { matchedPlantIds: 1 } }) + ? await users.findOne( + { _id }, + { projection: { matchedPlantIds: 1, preferences: 1 } }, + ) : null; const matchedPlantIds = user?.matchedPlantIds ?? []; - if (matchedPlantIds.length === 0) return { plants: [], totalCount: 0 }; + if (matchedPlantIds.length === 0) { + return { plants: [], totalCount: 0, filterCounts: toFilterCounts() }; + } // Only plants that still exist are shown and counted (e.g. after a reseed) - const filter = { _id: { $in: matchedPlantIds } }; - const [docs, totalCount] = await Promise.all([ - plants - .aggregate>([ - { $match: filter }, - ...buildMatchSortStages(args.sort, matchedPlantIds), - { $skip: clampOffset(args.offset) }, - { $limit: clampLimit(args.limit, DEFAULT_PAGE_SIZE) }, - ]) - .toArray(), - plants.countDocuments(filter), - ]); - - return { plants: docs.map(toPlant), totalCount }; + return findPlantPage( + { _id: { $in: matchedPlantIds } }, + args, + // The user's saved preferences, for the "preferences" sort order + buildMatchSortStages( + args.sort, + matchedPlantIds, + knownPreferences(user?.preferences), + ), + ); }, }, diff --git a/backend/src/schema.ts b/backend/src/schema.ts index 87193276..046f3a3c 100644 --- a/backend/src/schema.ts +++ b/backend/src/schema.ts @@ -8,12 +8,17 @@ export const typeDefs = ` watering: String careLevel: String sort: String + preferences: [String!] limit: Int = 12 offset: Int = 0 - ): ExplorePage! + ): PlantPage! getUser(userId: ID!): User myMatches( userId: ID! + search: String + sunlight: String + watering: String + careLevel: String sort: String limit: Int = 12 offset: Int = 0 @@ -33,11 +38,6 @@ export const typeDefs = ` removeUserMatch(userId: ID!, plantId: ID!): User } - type PlantPage { - plants: [Plant!]! - totalCount: Int! - } - type OptionCount { value: String! count: Int! @@ -49,7 +49,7 @@ export const typeDefs = ` careLevel: [OptionCount!]! } - type ExplorePage { + type PlantPage { plants: [Plant!]! totalCount: Int! filterCounts: FilterCounts! diff --git a/backend/src/types.ts b/backend/src/types.ts index ffe1d580..82126a3e 100644 --- a/backend/src/types.ts +++ b/backend/src/types.ts @@ -35,17 +35,24 @@ export interface GetPlantsArgs { preferences?: string[] | null; } -export interface ExplorePlantsArgs { - search?: string; - sunlight?: string; - watering?: string; - careLevel?: string; +// The search and filters on Explore Plants and My Matches +export interface PlantFilterArgs { + search?: string | null; + sunlight?: string | null; + watering?: string | null; + careLevel?: string | null; +} + +export interface ExplorePlantsArgs extends PlantFilterArgs { sort?: string; + // The user's preferences, for the "preferences" sort order. Explore Plants + // has no user id, so the frontend sends them, like for getPlants. + preferences?: string[] | null; limit?: number | null; offset?: number | null; } -// The filters on Explore Plants +// The filters on Explore Plants and My Matches export type FilterParam = "watering" | "sunlight" | "careLevel"; // How many plants a filter value would give, with the current search and other filters @@ -56,9 +63,9 @@ export interface OptionCount { export type FilterCounts = Record; -// What explorePlants returns. A separate type from PlantPage, since -// My Matches also uses PlantPage but has no filters to count. -export interface ExplorePage { +// One page of plants, as explorePlants and myMatches return it, with the +// total count and the match counts for the filters +export interface PlantPage { plants: Plant[]; totalCount: number; filterCounts: FilterCounts; @@ -107,7 +114,7 @@ export interface UserMatchArgs extends UserIdArgs { plantId: string; } -export interface MyMatchesArgs extends UserIdArgs { +export interface MyMatchesArgs extends UserIdArgs, PlantFilterArgs { sort?: string; limit?: number | null; offset?: number | null; diff --git a/backend/tests/server.test.ts b/backend/tests/server.test.ts index 7ef20356..ed5d0704 100644 --- a/backend/tests/server.test.ts +++ b/backend/tests/server.test.ts @@ -226,8 +226,8 @@ describe("plants", () => { ]; const EXPLORE = ` - query ($search: String, $sunlight: String, $watering: String, $careLevel: String, $sort: String, $limit: Int, $offset: Int) { - explorePlants(search: $search, sunlight: $sunlight, watering: $watering, careLevel: $careLevel, sort: $sort, limit: $limit, offset: $offset) { + query ($search: String, $sunlight: String, $watering: String, $careLevel: String, $sort: String, $preferences: [String!], $limit: Int, $offset: Int) { + explorePlants(search: $search, sunlight: $sunlight, watering: $watering, careLevel: $careLevel, sort: $sort, preferences: $preferences, limit: $limit, offset: $offset) { totalCount plants { name } } @@ -460,6 +460,28 @@ describe("plants", () => { expect((await explore({ sort })).names).toEqual(expected); }); + it("sorts by the preferences sent, by name when plants match equally well", async () => { + // Daisy and Fern (giant) match both, Basil ("Moderate") only medium care + expect( + ( + await explore({ + sort: "preferences", + preferences: ["averageWater", "mediumCare", "unknown"], + }) + ).names, + ).toEqual(["Daisy", "Fern (giant)", "Basil", "Aloe", "Cactus", "Fern"]); + + // Without preferences there is nothing to sort by, so the order is by name + expect((await explore({ sort: "preferences" })).names).toEqual([ + "Aloe", + "Basil", + "Cactus", + "Daisy", + "Fern", + "Fern (giant)", + ]); + }); + const FILTER_COUNTS = ` query ($search: String, $watering: String) { explorePlants(search: $search, watering: $watering) { @@ -734,6 +756,117 @@ describe("my matches", () => { totalCount: 0, }); }); + + const FILTERED_MATCHES = ` + query ($userId: ID!, $search: String, $watering: String) { + myMatches(userId: $userId, search: $search, watering: $watering) { + totalCount + plants { name } + filterCounts { + watering { value count } + careLevel { value count } + } + } + } + `; + + type FilteredPage = Page & { + filterCounts: Record; + }; + + // The names, the total count and the filter counts as + // { watering: { "": 3, minimum: 2, ... }, ... }, easier to read in the tests + async function filteredMatches(variables: Record) { + const result = await execute<{ myMatches: FilteredPage }>( + FILTERED_MATCHES, + variables, + ); + expect(result.errors).toBeUndefined(); + const page = result.data!.myMatches; + return { + names: page.plants.map((p) => p.name), + totalCount: page.totalCount, + counts: Object.fromEntries( + Object.entries(page.filterCounts).map(([param, options]) => [ + param, + Object.fromEntries(options.map((o) => [o.value, o.count])), + ]), + ), + }; + } + + // Matches Basil, Cactus and Aloe in that order. Daisy is not matched, so + // it must never be shown or counted on My Matches. + async function userWithVariedMatches() { + const { id } = await createUser(); + const [aloe, basil, cactus] = await insertPlants( + { commonName: "Aloe", watering: "Minimum", careLevel: "Low" }, + { commonName: "Basil", watering: "Frequent", careLevel: "Medium" }, + { commonName: "Cactus", watering: "Minimum", careLevel: "High" }, + { commonName: "Daisy", watering: "Minimum", careLevel: "Low" }, + ); + for (const plantId of [basil, cactus, aloe]) { + await addMatch(id, plantId); + } + return id; + } + + it("filters and counts only among the user's matches", async () => { + const id = await userWithVariedMatches(); + + expect(await filteredMatches({ userId: id, watering: "minimum" })).toEqual({ + // Newest first, and Daisy is left out even though it has minimum watering + names: ["Aloe", "Cactus"], + totalCount: 2, + counts: { + // Choosing another watering value replaces "minimum" + watering: { "": 3, minimum: 2, average: 0, frequent: 1 }, + // Only Aloe and Cactus have minimum watering + careLevel: { "": 2, low: 1, medium: 0, high: 1 }, + }, + }); + }); + + it("searches only among the user's matches", async () => { + const id = await userWithVariedMatches(); + + const page = await filteredMatches({ userId: id, search: "a" }); + // Daisy also contains "a", but is not a match + expect(page.names).toEqual(["Aloe", "Cactus", "Basil"]); + expect(page.counts.watering).toEqual({ + "": 3, + minimum: 2, + average: 0, + frequent: 1, + }); + + expect( + (await filteredMatches({ userId: id, search: "cact" })).names, + ).toEqual(["Cactus"]); + }); + + it("sorts the matches by the user's saved preferences", async () => { + const id = await userWithVariedMatches(); + await updatePreferences(id, ["frequentWater", "hardCare"]); + + // Basil and Cactus match one each and are sorted by name, Aloe matches none + expect( + (await myMatches({ userId: id, sort: "preferences" })).names, + ).toEqual(["Basil", "Cactus", "Aloe"]); + }); + + it("gives zero counts for a user without matches", async () => { + const { id } = await createUser(); + + expect(await filteredMatches({ userId: id })).toEqual({ + names: [], + totalCount: 0, + counts: { + watering: { "": 0, minimum: 0, average: 0, frequent: 0 }, + careLevel: { "": 0, low: 0, medium: 0, high: 0 }, + }, + }); + }); }); describe("error messages", () => { diff --git a/docs/architecture.md b/docs/architecture.md index 8474f7ce..1f33d298 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -22,7 +22,7 @@ Perenual API → seedDataFetch.js ─┐ Frontend: React + Apollo Client (localStorage: userId, theme, language, walkthroughSeen, URL: Explore state, - sessionStorage: My Matches sort, Plant Match deck) + sessionStorage: My Matches search, filters and sort, Plant Match deck) ``` The plant data was fetched from the Perenual API once with the script `seedDataFetch.js` and stored in our own database, which has 120 plants. The frontend never talks to the database directly. All data goes through the GraphQL API in the backend: @@ -44,23 +44,23 @@ The frontend is built with React and TypeScript (Vite). | ----------------- | -------------------- | ------------------------------------------------------------------------------------ | | `/` | `PlantMatchPage` | Swipe through preference-ranked plants (`getPlants`) and match with them | | `/explorePlants` | `ExplorePlantsPage` | Search, filter, sort and paginate all plants (`explorePlants`) | - | `/myMatches` | `MyMatchesPage` | List, sort, paginate and remove the user's matches (`myMatches`) | + | `/myMatches` | `MyMatchesPage` | Search, filter, sort, paginate and remove the user's matches (`myMatches`) | | `/profile` | `ProfilePage` | Edit name, description, profile picture and preferences | | `/plantOwnerTest` | `PlantOwnerTestPage` | A quiz whose result can be set as the profile picture, and that suggests preferences | | `*` | `NotFoundPage` | 404 page for unknown paths, with a link back to Plant Match | - **User state:** `UserProvider` (`context/UserContext.tsx`) loads the current user from the backend and makes it available through `useUser()`. The hooks `useProfile` and `useMatchedPlants` wrap the user mutations, so pages do not call GraphQL directly for user data. The user queries and mutations themselves live in `graphql/user/` (see [GraphQL operations](#graphql-operations-in-the-frontend)). - **Error messages:** `ErrorMessageProvider` (`context/ErrorMessageContext.tsx`) wraps the app and makes `showError()` available through `useErrorMessage()`. `useMatchedPlants` uses it to show an error message when adding or removing a match fails. -- **Reusable logic in hooks:** Logic without UI is kept in hooks. `useDebounce` delays updates while the user is typing (used for search and for saving the profile text). `useExploreParams` keeps the Explore search, filters, sort order and page in the URL, and sends the user back to page 1 when the search, a filter or the sort order changes. It uses `useUrlParams`, which reads the page number and updates the URL (with React Router's `useSearchParams`). `useSessionState` stores state in `sessionStorage`, for example the sort order on My Matches. +- **Reusable logic in hooks:** Logic without UI is kept in hooks. `useDebounce` delays updates while the user is typing (used for search and for saving the profile text). `useExploreParams` keeps the Explore search, filters, sort order and page in the URL, and sends the user back to page 1 when the search, a filter or the sort order changes. It uses `useUrlParams`, which reads the page number and updates the URL (with React Router's `useSearchParams`). `useMyMatchesParams` does the same for My Matches, but keeps the search, filters and sort order in `sessionStorage` with `useSessionState`, since the matches belong to the user in this browser and a link to them could not be shared. - `usePlantDeck` keeps the remaining Plant Match cards in `sessionStorage` while the user visits another page. It sends the saved preferences with each batch, and changing the preferences clears the current deck and fetches a new first batch so the order reflects the new preferences. Stale responses from the previous deck are ignored. -- **Reusable components:** Shared UI is kept in `components/`. `Pagination` shows previous/next and numbered pages, `FilterSelect` is a labelled dropdown for one filter, and `SortMenu` is a sort button with a menu that can be used with the keyboard. `MatchButton` adds a plant to My Matches (✿) or removes it (✖), `ErrorMessage` shows a short error message, and `LanguageSwitcher` is used both in the sidebar and in the walkthrough. The components take already translated texts, so they can be used on other pages. +- **Reusable components:** Shared UI is kept in `components/`. `Pagination` shows previous/next and numbered pages, `PlantSearchForm` is the search field, filters, sort menu and reset button used on both Explore Plants and My Matches (the filters are listed once in `plantFilters.ts`), `FilterSelect` is a labelled dropdown for one filter, and `SortMenu` is a sort button with a menu that can be used with the keyboard. `MatchButton` adds a plant to My Matches (✿) or removes it (✖), `ErrorMessage` shows a short error message, and `LanguageSwitcher` is used both in the sidebar and in the walkthrough. The components take already translated texts, so they can be used on other pages. - **Plant Owner Test:** The questions, results and suggestions are data in `pages/plantOwnerTest/plantOwnerTest.ts`, so the page only shows them. `getPlantOwnerResult()` gives the result from the location and watering answers. `getSuggestedPreferences()` gives three preference ids from the answers and the result: - **Watering** from the result: the minimalists get `minimumWater`, the average gardeners `averageWater`, and the dreaming city gardener and the garden expert `frequentWater`. - **Light** from the light answer. There is no preference for partial sun, so it suggests `partShade`, since those plants are listed as "part sun/part shade" in the data and match the part shade preference. - **Care level** from the result where its description says something about care: `easyCare` for the minimalists ("hardy plants") and `hardCare` for the dreaming city gardener and the garden expert ("a lot of attention"). The average gardeners get it from the time answer (10 minutes: `easyCare`, 30 minutes or 1 hour: `mediumCare`, 1 day: `hardCare`). `SuggestedPreferences.tsx` shows the suggestions that the user does not already have as toggle buttons, all chosen from the start. Nothing is saved until the user clicks "Add to my preferences", which runs `updateUserPreferences` with the saved preferences plus the chosen suggestions, so no preference is removed. It uses an optimistic response like the buttons on the profile page, so the profile and Plant Match are updated at once. The suggestions are shown above "Use as profile picture", since that button takes the user to the profile page. - + - **Walkthrough:** The guide for new users is in `components/walkthrough/`, and is made up of three parts: - **The steps are data:** `walkthroughSteps.ts` lists the steps in order. Each step has an `id`, a picture (one of the avatars) and, if it is about a page, the `route` of that page. The texts are in the translation files under `walkthrough.steps.`. A step can also have a `mobileHint`, a sentence that is only shown on small screens, such as how to open the menu with ☰, since the sidebar is always visible on large screens. It is hidden with CSS at the same breakpoint as the sidebar. A new step therefore only needs one line in the list and a title and text in each language. `stepForPath()` finds the step for the current page. - **`App.tsx` decides when it is open:** The walkthrough opens by itself when `walkthroughSeen` is not in `localStorage`, and the key is set when it is closed, so it is only shown once. The ? button in the `Header` opens it again at the step for the current page (`stepForPath`). When it closes, focus goes back to the ? button, except when the "Go to" link has moved the user to another page, where focus moves to the start of the new page like for any other navigation. @@ -121,12 +121,12 @@ The backend exposes a single GraphQL endpoint. With GraphQL, the frontend asks f **Queries** -| Query | Description | -| -------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `getPlants(limit = 50, excludeIds, preferences): [Plant]` | Returns up to `limit` plants (at most 50) for the match page, leaving out the plants in `excludeIds` so each batch only has new plants (malformed ids are ignored). Without `preferences` the order is random (MongoDB `$sample`). With `preferences`, each plant gets a score: the number of the preferences it matches on watering, sunlight and care level ("Low" counts as easy care, "Medium" and "Moderate" as medium care). The highest scores come first and plants with the same score are shuffled. Unknown preferences are ignored. | -| `explorePlants(search, sunlight, watering, careLevel, sort, limit = 12, offset = 0): ExplorePage!` | Search on common or scientific name (case-insensitive), filter on sunlight, watering and care level, sort and paginate (`limit` is kept between 1 and 50, and a negative `offset` counts as 0). Returns the plants on the page and `totalCount` for the whole result. Sort can be `name_desc`, `watering_asc` or `careLevel_asc`; the default is name A–Z. Also returns `filterCounts`: for every filter value, and for "All" (an empty value), the number of plants it would give instead of the current choice in the same filter, together with the search and the other filters. The counts use the same filter as the results, so they always agree, and are done in one `$facet` aggregation. | -| `getUser(userId): User` | Returns the user, or `null` if the id is unknown or malformed. | -| `myMatches(userId, sort, limit = 12, offset = 0): PlantPage!` | Returns one page of the user's matched plants and `totalCount` (`limit` and `offset` are kept within the same bounds as in `explorePlants`). Sort can be `oldest`, `name_asc` or `name_desc`; the default is newest first. The order of `matchedPlantIds` is the order the plants were matched, so no date is needed. An unknown or malformed user id gives an empty page. | +| Query | Description | +| ------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `getPlants(limit = 50, excludeIds, preferences): [Plant]` | Returns up to `limit` plants (at most 50) for the match page, leaving out the plants in `excludeIds` so each batch only has new plants (malformed ids are ignored). Without `preferences` the order is random (MongoDB `$sample`). With `preferences`, each plant gets a score: the number of the preferences it matches on watering, sunlight and care level ("Low" counts as easy care, "Medium" and "Moderate" as medium care). The highest scores come first and plants with the same score are shuffled. Unknown preferences are ignored. | +| `explorePlants(search, sunlight, watering, careLevel, sort, preferences, limit = 12, offset = 0): PlantPage!` | Search on common or scientific name (case-insensitive), filter on sunlight, watering and care level, sort and paginate (`limit` is kept between 1 and 50, and a negative `offset` counts as 0). Returns the plants on the page and `totalCount` for the whole result. Sort can be `name_desc`, `watering_asc`, `careLevel_asc` or `preferences`; the default is name A–Z. `preferences` puts the plants matching the most of the sent preferences first, with the same score as Plant Match, and sorts plants that match equally well by name. Also returns `filterCounts`: for every filter value, and for "All" (an empty value), the number of plants it would give instead of the current choice in the same filter, together with the search and the other filters. The counts use the same filter as the results, so they always agree, and are done in one `$facet` aggregation. | +| `getUser(userId): User` | Returns the user, or `null` if the id is unknown or malformed. | +| `myMatches(userId, search, sunlight, watering, careLevel, sort, limit = 12, offset = 0): PlantPage!` | Returns one page of the user's matched plants and `totalCount`, searched and filtered like in `explorePlants`, with `filterCounts` counted only among the user's matches (`limit` and `offset` are kept within the same bounds as in `explorePlants`). Sort can be `oldest`, `name_asc`, `name_desc` or `preferences`; the default is newest first. `preferences` uses the preferences saved on the user, like in `explorePlants`. The order of `matchedPlantIds` is the order the plants were matched, so no date is needed. An unknown or malformed user id gives an empty page. | **Mutations** @@ -141,8 +141,7 @@ The backend exposes a single GraphQL endpoint. With GraphQL, the frontend asks f **Types** - `Plant`: `id`, `name`, `imageURL`, `scientificName`, `description`, `watering`, `sunlight`, `careLevel` -- `PlantPage`: `plants`, `totalCount` -- `ExplorePage`: `plants`, `totalCount`, `filterCounts`. `FilterCounts` has `watering`, `sunlight` and `careLevel`, each a list of `OptionCount` (`value`, `count`). Explore has its own type, since My Matches also uses `PlantPage` but has no filters to count. +- `PlantPage`: `plants`, `totalCount`, `filterCounts`. `FilterCounts` has `watering`, `sunlight` and `careLevel`, each a list of `OptionCount` (`value`, `count`). Both `explorePlants` and `myMatches` return it, and share the code that builds it (`findPlantPage` in `resolvers.ts`). - `User`: `id`, `name`, `description`, `profilePicture`, `preferences`, `matchedPlantIds`, `createdAt` `User.matchedPlantIds` only returns the ids, so the pages that just need to know whether a plant is matched do not fetch the whole plants with images. The plants themselves are fetched one page at a time with `myMatches`, which only shows and counts plants that still exist (for example after a reseed). @@ -222,14 +221,14 @@ MongoDB runs on the course VM and only listens on `127.0.0.1`, so it cannot be r ## Where state is kept -| Where | What | Why | -| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| MongoDB `users` | Profile (name, description, picture), preferences and matched plants | Persistent user data that should survive closing the browser | -| `localStorage` | The user id (`userId`), the theme (`theme`), the language (`language`) and whether the walkthrough has been seen (`walkthroughSeen`) | Lets the browser find its user again on the next visit without a login, keeps the chosen theme and language between visits, and only opens the walkthrough by itself on the first visit | -| URL parameters | Explore search, filters, sort and page (`search`, `watering`, `sunlight`, `careLevel`, `sort`, `page`) via `useExploreParams` | The view survives navigation and refresh and can be shared as a link | -| `sessionStorage` | The sort order on My Matches (`myMatches.sort`) and the cards left on Plant Match (`plantMatch.deck`) | The value is kept for the current browser session, also when the user goes to another page and back. The page on My Matches always starts at 1, so new matches are seen first | -| Apollo in-memory cache | Query results (plants and the current user) | Avoids asking the backend again for data the app already has, and keeps all pages in sync | -| React state | Short-lived UI state, such as the current plant on the match page and unsaved profile text | Only matters while the component is shown | +| Where | What | Why | +| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| MongoDB `users` | Profile (name, description, picture), preferences and matched plants | Persistent user data that should survive closing the browser | +| `localStorage` | The user id (`userId`), the theme (`theme`), the language (`language`) and whether the walkthrough has been seen (`walkthroughSeen`) | Lets the browser find its user again on the next visit without a login, keeps the chosen theme and language between visits, and only opens the walkthrough by itself on the first visit | +| URL parameters | Explore search, filters, sort and page (`search`, `watering`, `sunlight`, `careLevel`, `sort`, `page`) via `useExploreParams` | The view survives navigation and refresh and can be shared as a link | +| `sessionStorage` | The search, filters and sort order on My Matches (`myMatches.search`, `myMatches.watering`, `myMatches.sunlight`, `myMatches.careLevel`, `myMatches.sort`) via `useMyMatchesParams`, and the cards left on Plant Match (`plantMatch.deck`) | The value is kept for the current browser session, also when the user goes to another page and back. The page on My Matches always starts at 1, so new matches are seen first | +| Apollo in-memory cache | Query results (plants and the current user) | Avoids asking the backend again for data the app already has, and keeps all pages in sync | +| React state | Short-lived UI state, such as the current plant on the match page and unsaved profile text | Only matters while the component is shown | User data used to be stored in `localStorage`. `UserProvider` now removes the old keys (`plantPreferences`, `matchedPlants`, `profileName`, `description`, `profileAvatar`) on start-up, so old data does not lie around in the browser. @@ -312,7 +311,7 @@ T03-Project-2/ │ │ ├── components/ # Reusable UI components, each in its own folder with a matching .css file (walkthrough/ has the guide and its steps) │ │ ├── context/ # UserProvider and useUser() for the current user, ErrorMessageProvider and useErrorMessage() for error messages │ │ ├── graphql/ # All GraphQL queries, mutations and fragments, grouped by domain (fragments/, plants/, user/) -│ │ ├── hooks/ # Reusable logic without UI (useDebounce, useUrlParams, useExploreParams, useSessionState, useProfile, useMatchedPlants, usePlantDeck, useDismissibleTooltip) +│ │ ├── hooks/ # Reusable logic without UI (useDebounce, useUrlParams, useExploreParams, useMyMatchesParams, useSessionState, useProfile, useMatchedPlants, usePlantDeck, useDismissibleTooltip) │ │ ├── i18n/ # Translation setup and locale files (no, en) │ │ ├── pages/ # One folder per page/route, each with a Page.tsx and a matching .css file │ │ │ ├── explorePlants/ # ExplorePlantsPage diff --git a/docs/quality.md b/docs/quality.md index cfb210b2..6b08bd55 100644 --- a/docs/quality.md +++ b/docs/quality.md @@ -107,7 +107,7 @@ We considered sustainability through both our design choices and our approach to - **Color palette and contrast:** We used a limited color palette to maintain a consistent visual identity across the application. We also checked the contrast between our chosen colors to help ensure that text and other interface elements remain distinguishable and in line with accessibility requirements. See [Accessibility](#accessibility). -- **Reusable components:** Shared UI is kept in reusable components, so the pages look and work the same way and changes only need to be made in one place. This makes the application easier to maintain. The Header, Sidebar and plant cards are used across pages, `Pagination`, `SortMenu` and `MatchButton` are shared by Explore Plants and My Matches, and `ErrorMessage` shows error messages on every page. The filters on Explore Plants are defined in one list of `FilterSelect` components, so a new filter only needs one new line. +- **Reusable components:** Shared UI is kept in reusable components, so the pages look and work the same way and changes only need to be made in one place. This makes the application easier to maintain. The Header, Sidebar and plant cards are used across pages, `PlantSearchForm` (search, filters, sort menu and reset), `Pagination` and `MatchButton` are shared by Explore Plants and My Matches, so the two pages look and work the same, and `ErrorMessage` shows error messages on every page. The filters are defined in one list (`plantFilters.ts`), so a new filter only needs one new line in the frontend. - **Keeping the previous results while loading:** On Explore Plants, the previous results and the number of results stay on screen, slightly dimmed, while new ones load (with Apollo's `previousData`). The page does not flicker or jump when the search, a filter or the page changes, and the loading text is only shown the first time. diff --git a/docs/tests.md b/docs/tests.md index d5f8b3a5..62bb19f5 100644 --- a/docs/tests.md +++ b/docs/tests.md @@ -122,7 +122,7 @@ The tests are in `frontend/src/tests`. Snapshot tests are only used for small co - The message is shown in an `alert` region, hidden after six seconds, replaced by a new message with the time started again, and nothing happens without a provider. - `ExplorePlantsPage.test.tsx` - Loading, error and empty results: a loading message, an error message when the query fails, and a message without page navigation when nothing matches. - - Search, filters and sorting: the search text is only sent after the debounce delay, the chosen filters and sort order are sent in the query, the selected sort is visible and included in the sort button's accessible name, and the sort menu closes with Escape and with a click outside. + - Search, filters and sorting: the search text is only sent after the debounce delay, the chosen filters and sort order are sent in the query, the selected sort is visible and included in the sort button's accessible name, and the sort menu closes with Escape and with a click outside, and "Best match first" is only offered when the user has preferences, sends them with the query, and falls back to A–Z when the URL asks for it without preferences. - Number of results: the total number for the whole result is shown, not only the plants on the page, it updates when a filter changes, it is in an `aria-live` region together with "No results found", and it is hidden while loading. Each filter value shows its number of matches, values with no matches are disabled except the chosen one, and the previous results stay on screen while new ones load. - Pagination: moving between pages, disabled buttons at the ends, and going back to page 1 when a filter or the search text changes. - Matches: the button adds a plant that is not matched (✿), and removes a plant that is already matched (✖). @@ -144,6 +144,8 @@ The tests are in `frontend/src/tests`. Snapshot tests are only used for small co - Loading and empty state: a message when there are no matches (without the count, sorting or pages), and the loading state while the user or the matches are fetched. - Fetching: the first page with the newest first by default, fetched again each time the page is opened, the sort order saved earlier in the session used while the page starts at 1, and saved matches shown and removed. - Sorting and pages: the number of matches next to the sort menu in an `aria-live` region that stays on the page, so "no matches" is also announced, moving between pages, a new sort order saved in `sessionStorage` and going back to page 1, and going to the last page when the current page no longer exists. + - Search and filters: a chosen filter is sent, saved in `sessionStorage` and goes back to page 1, the search is sent after the debounce delay, search and filters saved earlier in the session are restored, the number of matches for each filter value with empty values disabled, a message in an `aria-live` region under the filters when no matches fit, like on Explore Plants (with the search and filters still on screen), a separate count when the list is filtered, and reset clearing the search, the filters and the sort order. The search and filters are hidden when the user has no matches at all. + - Best match first: only offered when the user has preferences, saved for the session, and newest first when it was saved but the user has no preferences any more. - `NotFoundPage.test.tsx` - An unknown path shows the 404 page, with a link back to Plant Match. - `PlantCard.test.tsx` @@ -192,9 +194,9 @@ The tests are in `backend/tests`. They use a real MongoDB in memory, started in - Connecting to the database in `MONGODB_URI` and `DB_NAME`, using `iloveplants` when `DB_NAME` is not set, and the error messages when `MONGODB_URI` is missing or empty, is not a MongoDB address, or MongoDB cannot be reached (for example when the SSH tunnel is down). - `server.test.ts` - Starting the server: the default port 3001, the port in `PORT`, and stopping with the error when the port is in use. - - Plants: `getPlants` returns the plants that match the most of the user's preferences first, also when they are fetched in batches ("Low" counts as easy care), random plants when there are no preferences or only unknown ones, and leaves out the plants in `excludeIds` (returning none when all are excluded). Also stored image data before the image URL, and in `explorePlants` the default sorting, case-insensitive search across common and scientific names with special characters read as text, the watering, care level and sunlight filters ("Medium" and "Moderate" count as the same care level), pagination with the total count, that `limit` and `offset` are kept within valid bounds (at most 50 plants per request), and all sort orders, and the match counts for every filter value (with the search and the other filters, but not the filter's own choice). + - Plants: `getPlants` returns the plants that match the most of the user's preferences first, also when they are fetched in batches ("Low" counts as easy care), random plants when there are no preferences or only unknown ones, and leaves out the plants in `excludeIds` (returning none when all are excluded). Also stored image data before the image URL, and in `explorePlants` the default sorting, case-insensitive search across common and scientific names with special characters read as text, the watering, care level and sunlight filters ("Medium" and "Moderate" count as the same care level), pagination with the total count, that `limit` and `offset` are kept within valid bounds (at most 50 plants per request), and all sort orders including best match first (by the preferences sent, by name when plants match equally well, and by name without preferences), and the match counts for every filter value (with the search and the other filters, but not the filter's own choice). - Users: creating and fetching users, updating the profile (trimming text, storing empty text and `null` as `null`, and only changing the sent fields), the plant owner test results as profile pictures, preferences without duplicates, and adding and removing matches in order. - - My matches: `myMatches` sorts by newest (the default), oldest, A–Z and Z–A, returns one page at a time with the total count, leaves out and does not count matched plants that were deleted, and returns an empty page for a user without matches and for an unknown or malformed user id. + - My matches: `myMatches` sorts by newest (the default), oldest, A–Z, Z–A and best match first (by the user's saved preferences), returns one page at a time with the total count, leaves out and does not count matched plants that were deleted, and returns an empty page for a user without matches and for an unknown or malformed user id. Filtering and searching only among the user's matches, with the filter counts also counted only among them, and zero counts for a user without matches. - Error messages: invalid input gives the right message and the code `BAD_USER_INPUT` and saves nothing (too long name or description, unknown profile picture, unknown preferences, unknown or malformed plant ids), invalid GraphQL requests give the right error, and the server passes on a database error and keeps running. - `indexes.test.ts` - The index for sorting by name is created, and creating it again on the next start does not fail. @@ -253,6 +255,7 @@ The UI tests find elements the way a user or a screen reader would: by role, lab - Liking a plant on PlantMatch adds it to MyMatches, where it can be removed. - Adding a plant from ExplorePlants adds it to MyMatches and turns its ✿ button into ✖. Clicking the button again on ExplorePlants removes the plant from MyMatches. +- Searching and filtering MyMatches: the search only looks among the user's matches, a filter disables the values that would give no matches, the choices are remembered when going to another page and back, a search that finds nothing says so under the filters, and reset shows all the matches again. - Matching 13 plants from ExplorePlants gives two pages in MyMatches: the count, the newest first on page 1 and the oldest on page 2, sorting A–Z going back to page 1, and the sort order remembered when going to another page and back, and after a reload. The test user has no preferences, so PlantMatch shows the plants in random order. The test therefore remembers the name of the liked plant and checks that it is the same plant that ends up in MyMatches. diff --git a/e2e/helpers/names.ts b/e2e/helpers/names.ts index e3af2041..8422e081 100644 --- a/e2e/helpers/names.ts +++ b/e2e/helpers/names.ts @@ -28,6 +28,7 @@ export const names = { // Explore Plants and My Matches // A select's name also has the chosen option, e.g. "Care level All (20)" + watering: /^(watering needs|vanningsbehov)\b/i, careLevel: /^(care level|stell)\b/i, // The sort button's name also has the chosen order, e.g. "Sort: Name (A-Z)" sortButton: /^(sort|sorter):/i, @@ -38,6 +39,15 @@ export const names = { next: /^(next|neste)$/i, previous: /^(previous|forrige)$/i, noMatches: /no matches|ingen matcher/i, + // On My Matches, when the search or a filter gives no matches + noneFit: /none of your matches fit|ingen av matchene dine passer/i, + + // Walkthrough + openGuide: /^(open guide|åpne guide)$/i, + // The step counter, e.g. "Step 2 of 7" + guideStep: /^(step|steg) \d+ (of|av) \d+$/i, + // "Go to " + goTo: /^(go to|gå til) /i, // Profile profile: /^(profile|profil)$/i, diff --git a/e2e/uiMatchAndRemovePlant.spec.ts b/e2e/uiMatchAndRemovePlant.spec.ts index 85c1a994..fe7f5aaf 100644 --- a/e2e/uiMatchAndRemovePlant.spec.ts +++ b/e2e/uiMatchAndRemovePlant.spec.ts @@ -182,3 +182,68 @@ test("a plant matched on ExplorePlants never shows up in PlantMatch", async ({ expect(shown.length).toBeGreaterThan(0); expect(shown).not.toContain(matchedName); }); + +test("user can search and filter the matches in MyMatches, and the choices are remembered", async ({ + page, +}) => { + const cards = plantItems(page); + const searchField = page.getByRole("searchbox"); + const wateringSelect = page.getByRole("combobox", { name: names.watering }); + const careLevelSelect = page.getByRole("combobox", { + name: names.careLevel, + }); + + // Matches the first three plants sorted a–z in the fixtures: + // Aloe Vera (minimum watering, low care), Boston Fern (frequent, medium) + // and Calathea (average, high) + await page.goto("#/explorePlants"); + for (let i = 0; i < 3; i++) { + const button = matchButtonIn(cards.nth(i)); + await button.click(); + await expect(button).toHaveAccessibleName(names.removeMatch); + } + await goToPage(page, names.myMatches); + await expect(cards).toHaveCount(3); + + await test.step("the search only looks among the user's matches", async () => { + // Maidenhair Fern is also a fern, but not a match + await searchField.fill("fern"); + await expect(cards).toHaveCount(1); + await expect(cards.first()).toContainText("Boston Fern"); + await searchField.fill(""); + await expect(cards).toHaveCount(3); + }); + + await test.step("a filter shows the counts and can't empty the list", async () => { + await careLevelSelect.selectOption("high"); + await expect(cards).toHaveCount(1); + await expect(cards.first()).toContainText("Calathea"); + // Among the matches with high care, only average watering gives plants, + // so the two other watering values are disabled + await expect( + wateringSelect.getByRole("option", { disabled: true }), + ).toHaveCount(2); + }); + + await test.step("the choices are remembered on another page and back", async () => { + await goToPage(page, names.explorePlants); + await goToPage(page, names.myMatches); + await expect(careLevelSelect).toHaveValue("high"); + await expect(cards).toHaveCount(1); + }); + + await test.step("a search that finds nothing says so under the filters", async () => { + await searchField.fill("cactus"); + await expect(page.getByText(names.noneFit)).toBeVisible(); + await expect(cards).toHaveCount(0); + // The search and the filters stay, so they can be changed + await expect(searchField).toBeVisible(); + }); + + await test.step("reset shows all the matches again", async () => { + await page.getByRole("button", { name: names.reset }).click(); + await expect(searchField).toHaveValue(""); + await expect(careLevelSelect).toHaveValue(""); + await expect(cards).toHaveCount(3); + }); +}); diff --git a/e2e/uiWalkthrough.spec.ts b/e2e/uiWalkthrough.spec.ts index 984a257e..69ce39cd 100644 --- a/e2e/uiWalkthrough.spec.ts +++ b/e2e/uiWalkthrough.spec.ts @@ -1,24 +1,30 @@ -import { test, expect } from "@playwright/test"; +import { test, expect, type Page } from "@playwright/test"; +import { names } from "./helpers/names"; +import { plantMatchCardName } from "./helpers/locators"; // The other UI tests start as users who have seen the walkthrough // (playwright.config.ts). These start as new users, with empty storage. +// Elements are found by role and accessible name in both languages (see +// helpers/names.ts), not by CSS classes. test.use({ storageState: { cookies: [], origins: [] } }); +// The step counter in the walkthrough, e.g. "Step 2 of 7" +const stepCounter = (page: Page) => + page.getByRole("dialog").getByText(names.guideStep); + test("the walkthrough opens for new users and not after it is closed", async ({ page, }) => { await page.goto(""); const dialog = page.getByRole("dialog"); await expect(dialog).toBeVisible(); - await expect(page.locator(".walkthrough__progress")).toHaveText( - /1 (of|av) 7/, - ); + await expect(stepCounter(page)).toHaveText(/1 (of|av) 7/); await page.keyboard.press("Escape"); await expect(dialog).toBeHidden(); await page.reload(); - await expect(page.locator(".plant-card-front")).toBeVisible(); + await expect(plantMatchCardName(page)).toBeVisible(); await expect(dialog).toBeHidden(); }); @@ -29,7 +35,7 @@ test("the page behind is grayed out and can't be used while the walkthrough is o await expect(page.getByRole("dialog")).toBeVisible(); const backdrop = await page - .locator(".walkthrough") + .getByRole("dialog") .evaluate((el) => getComputedStyle(el, "::backdrop").backgroundColor); expect(backdrop).not.toBe("rgba(0, 0, 0, 0)"); @@ -39,7 +45,7 @@ test("the page behind is grayed out and can't be used while the walkthrough is o await page.keyboard.press("Tab"); const focusOnPageBehind = await page.evaluate(() => { const el = document.activeElement; - return !!el && el !== document.body && !el.closest(".walkthrough"); + return !!el && el !== document.body && !el.closest("dialog"); }); expect(focusOnPageBehind).toBe(false); } @@ -52,13 +58,14 @@ test("the help button opens the walkthrough at the current page, and Go to chang await page.keyboard.press("Escape"); await page.goto("#/explorePlants"); - await page.locator(".help-button").click(); - await expect(page.locator(".walkthrough__progress")).toHaveText( - /3 (of|av) 7/, - ); + await page.getByRole("button", { name: names.openGuide }).click(); + await expect(stepCounter(page)).toHaveText(/3 (of|av) 7/); await page.keyboard.press("ArrowRight"); - await page.locator(".walkthrough__go-to").click(); + await page + .getByRole("dialog") + .getByRole("link", { name: names.goTo }) + .click(); await expect(page.getByRole("dialog")).toBeHidden(); await expect(page).toHaveURL(/#\/myMatches$/); @@ -70,16 +77,16 @@ test("the language button in the walkthrough changes the language and keeps the await page.goto(""); const dialog = page.getByRole("dialog"); await page.keyboard.press("ArrowRight"); - await expect(page.locator(".walkthrough__progress")).toHaveText(/2 av 7/); + await expect(stepCounter(page)).toHaveText(/2 av 7/); await dialog.getByRole("button", { name: "EN - Switch to English" }).click(); await expect(dialog).toBeVisible(); - await expect(page.locator(".walkthrough__progress")).toHaveText(/2 of 7/); + await expect(stepCounter(page)).toHaveText(/2 of 7/); await expect(page.locator("html")).toHaveAttribute("lang", "en"); await dialog.getByRole("button", { name: "NO - Bytt til norsk" }).click(); - await expect(page.locator(".walkthrough__progress")).toHaveText(/2 av 7/); + await expect(stepCounter(page)).toHaveText(/2 av 7/); }); test("the hint about the menu button is only shown on small screens", async ({ @@ -89,7 +96,7 @@ test("the hint about the menu button is only shown on small screens", async ({ await page.goto(""); // The last step is about language and theme, in the menu for (let i = 0; i < 6; i++) await page.keyboard.press("ArrowRight"); - await expect(page.locator(".walkthrough__progress")).toHaveText(/7 av 7/); + await expect(stepCounter(page)).toHaveText(/7 av 7/); const hint = page.getByText("På små skjermer åpner du menyen med ☰."); if (isMobile) await expect(hint).toBeVisible(); diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 38cad29d..3a751727 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -36,16 +36,20 @@ function App() { const mainContentRef = useRef(null); const pageStartRef = useRef(null); - // When the user goes to another page, move focus to the start of the page, - // like when a normal web page loads. The next Tab then shows the skip link, - // so keyboard users can choose to jump to the content or go through the - // sidebar. Only the path counts: changing a filter or the page number - // changes the URL parameters, but should not move focus away from the filter. + // When the user goes to another page, scroll to the top and move focus to + // the start of the page, like when a normal web page loads. Without the + // scroll, the new page opens as far down as the previous one was scrolled, + // so the top of it (like the number of matches) is hidden. The next Tab + // shows the skip link, so keyboard users can choose to jump to the content + // or go through the sidebar. Only the path counts: changing a filter or the + // page number changes the URL parameters, but should not move the user away + // from the filter. const { pathname } = useLocation(); const previousPathname = useRef(pathname); useEffect(() => { if (previousPathname.current === pathname) return; previousPathname.current = pathname; + window.scrollTo(0, 0); pageStartRef.current?.focus({ preventScroll: true }); }, [pathname]); diff --git a/frontend/src/components/plantSearchForm/PlantSearchForm.css b/frontend/src/components/plantSearchForm/PlantSearchForm.css new file mode 100644 index 00000000..c5e1cb85 --- /dev/null +++ b/frontend/src/components/plantSearchForm/PlantSearchForm.css @@ -0,0 +1,72 @@ +/* The search field, filters, sort menu and reset button on Explore Plants + and My Matches */ +.plant-search-form { + width: 100%; +} + +.plant-search { + position: relative; + display: block; +} + +.plant-search-icon { + position: absolute; + top: 50%; + left: 1rem; + font-size: 1.25rem; + transform: translateY(-50%); + color: var(--pink-text); + pointer-events: none; +} + +.plant-search input { + width: 100%; + padding: 0.75rem 1rem 0.75rem 2.75rem; + font-size: 1.25rem; + color: var(--text-dark); + background-color: var(--light-pink); + border: 1px solid var(--dark-pink); + border-radius: 8px; + box-sizing: border-box; +} + +.plant-search input:focus { + outline: none; + box-shadow: 0 0 0 2px var(--dark-pink); +} + +.plant-search input::placeholder { + color: var(--text-dark); +} + +.plant-filters { + display: flex; + flex-wrap: wrap; + gap: 1rem; + margin: 1rem 0 0; + padding: 0; + border: 0; +} + +/* At the end of the filter row, at the same height as the sort button */ +.reset-button { + align-self: flex-end; + height: 40px; + padding: 0 1rem; + border: 1px solid var(--dark-pink); + border-radius: 8px; + background-color: var(--dark-pink); + color: var(--text-light); + font-size: 15px; + cursor: pointer; +} + +.reset-button:hover { + background-color: var(--light-pink); + color: var(--text-dark); +} + +.reset-button.reset-button:focus-visible { + outline: none; + box-shadow: 0 0 0 2px var(--dark-pink); +} diff --git a/frontend/src/components/plantSearchForm/PlantSearchForm.tsx b/frontend/src/components/plantSearchForm/PlantSearchForm.tsx new file mode 100644 index 00000000..7772bcd9 --- /dev/null +++ b/frontend/src/components/plantSearchForm/PlantSearchForm.tsx @@ -0,0 +1,103 @@ +import { useTranslation } from "react-i18next"; +import { SearchIcon } from "../icons/Icons"; +import FilterSelect from "../filterSelect/FilterSelect"; +import SortMenu from "../sortMenu/SortMenu"; +import type { FilterCounts } from "../../graphql/plants/queries"; +import { + PLANT_FILTERS, + type FilterParam, + type PlantFilters, +} from "./plantFilters"; +import "./PlantSearchForm.css"; + +type SortOption = { value: string; label: string }; + +type PlantSearchFormProps = { + search: string; + onSearchChange: (value: string) => void; + filters: PlantFilters; + // How many plants each filter value would give. Undefined until the first + // result has come, and then nothing is disabled. + filterCounts?: FilterCounts; + onFilterChange: (param: FilterParam, value: string) => void; + sortLabel: string; + sort: string; + sortOptions: SortOption[]; + onSortChange: (value: string) => void; + onReset: () => void; +}; + +// The search field, the filters, the sort menu and the reset button above a +// list of plants. Used on both Explore Plants and My Matches, so the two pages +// look and work the same. The page decides where the choices are kept. +export default function PlantSearchForm({ + search, + onSearchChange, + filters, + filterCounts, + onFilterChange, + sortLabel, + sort, + sortOptions, + onSortChange, + onReset, +}: PlantSearchFormProps) { + const { t } = useTranslation(); + + // The number of plants a value would give, or undefined before the counts have come + const countFor = (param: FilterParam, value: string) => + filterCounts?.[param].find((c) => c.value === value)?.count; + + return ( +
e.preventDefault()} + > + + +
+ + {t("explorePlantsPage.filters")} + + + {PLANT_FILTERS.map((filter) => ( + ({ + value: option, + label: t(`explorePlantsPage.${option}`), + count: countFor(filter.param, option), + }))} + onChange={(value) => onFilterChange(filter.param, value)} + /> + ))} + + + + +
+
+ ); +} diff --git a/frontend/src/components/plantSearchForm/plantFilters.ts b/frontend/src/components/plantSearchForm/plantFilters.ts new file mode 100644 index 00000000..9530c92d --- /dev/null +++ b/frontend/src/components/plantSearchForm/plantFilters.ts @@ -0,0 +1,24 @@ +// The filters on Explore Plants and My Matches: the name of the filter, the +// translation key for the label, and the values to choose from. Must match +// FILTER_OPTIONS in backend/src/queryBuilders.ts. A new filter only needs a +// new line here (and in the backend). +export const PLANT_FILTERS = [ + { + param: "watering", + label: "explorePlantsPage.watering", + options: ["minimum", "average", "frequent"], + }, + { + param: "sunlight", + label: "explorePlantsPage.sunlight", + options: ["full_sun", "part_shade", "filtered_shade"], + }, + { + param: "careLevel", + label: "explorePlantsPage.careLevel", + options: ["low", "medium", "high"], + }, +] as const; + +export type FilterParam = (typeof PLANT_FILTERS)[number]["param"]; +export type PlantFilters = Record; diff --git a/frontend/src/graphql/fragments/plantFragments.ts b/frontend/src/graphql/fragments/plantFragments.ts index 90ea20c8..a5425a10 100644 --- a/frontend/src/graphql/fragments/plantFragments.ts +++ b/frontend/src/graphql/fragments/plantFragments.ts @@ -14,3 +14,22 @@ export const PLANT_FIELDS = gql` careLevel } `; + +// How many plants each filter value would give, with the current search and +// the other filters. Explore Plants and My Matches ask for the same counts. +export const FILTER_COUNT_FIELDS = gql` + fragment FilterCountFields on FilterCounts { + watering { + value + count + } + sunlight { + value + count + } + careLevel { + value + count + } + } +`; diff --git a/frontend/src/graphql/plants/queries.ts b/frontend/src/graphql/plants/queries.ts index ef222210..46bfaf1d 100644 --- a/frontend/src/graphql/plants/queries.ts +++ b/frontend/src/graphql/plants/queries.ts @@ -1,6 +1,6 @@ import { gql } from "@apollo/client"; import type { Plant } from "../../types/Plant"; -import { PLANT_FIELDS } from "../fragments/plantFragments"; +import { FILTER_COUNT_FIELDS, PLANT_FIELDS } from "../fragments/plantFragments"; // Used by the Plant Match deck (usePlantDeck). Plants already in the deck are // excluded, and plants matching the most preferences come first. @@ -26,6 +26,7 @@ export const EXPLORE_PLANTS = gql` $watering: String $careLevel: String $sort: String + $preferences: [String!] $limit: Int $offset: Int ) { @@ -35,6 +36,7 @@ export const EXPLORE_PLANTS = gql` watering: $watering careLevel: $careLevel sort: $sort + preferences: $preferences limit: $limit offset: $offset ) { @@ -43,22 +45,12 @@ export const EXPLORE_PLANTS = gql` ...PlantFields } filterCounts { - watering { - value - count - } - sunlight { - value - count - } - careLevel { - value - count - } + ...FilterCountFields } } } ${PLANT_FIELDS} + ${FILTER_COUNT_FIELDS} `; export type GetPlantsData = { getPlants: Plant[] }; diff --git a/frontend/src/graphql/user/queries.ts b/frontend/src/graphql/user/queries.ts index c4c28d49..0b1d6089 100644 --- a/frontend/src/graphql/user/queries.ts +++ b/frontend/src/graphql/user/queries.ts @@ -1,7 +1,8 @@ import { gql } from "@apollo/client"; import type { Plant } from "../../types/Plant"; import type { User } from "../../types/User"; -import { PLANT_FIELDS } from "../fragments/plantFragments"; +import { FILTER_COUNT_FIELDS, PLANT_FIELDS } from "../fragments/plantFragments"; +import type { FilterCounts } from "../plants/queries"; import { USER_FIELDS } from "../fragments/userFragments"; export const GET_USER = gql` @@ -13,21 +14,48 @@ export const GET_USER = gql` ${USER_FIELDS} `; -// One page of the user's matched plants, sorted. Only My Matches uses this, -// so the other pages don't have to fetch the whole plants with images. +// One page of the user's matched plants, searched, filtered and sorted, with +// the same filter counts as on Explore Plants. Only My Matches uses this, so +// the other pages don't have to fetch the whole plants with images. export const MY_MATCHES = gql` - query MyMatches($userId: ID!, $sort: String, $limit: Int, $offset: Int) { - myMatches(userId: $userId, sort: $sort, limit: $limit, offset: $offset) { + query MyMatches( + $userId: ID! + $search: String + $sunlight: String + $watering: String + $careLevel: String + $sort: String + $limit: Int + $offset: Int + ) { + myMatches( + userId: $userId + search: $search + sunlight: $sunlight + watering: $watering + careLevel: $careLevel + sort: $sort + limit: $limit + offset: $offset + ) { totalCount plants { ...PlantFields } + filterCounts { + ...FilterCountFields + } } } ${PLANT_FIELDS} + ${FILTER_COUNT_FIELDS} `; export type GetUserData = { getUser: User | null }; export type MyMatchesData = { - myMatches: { totalCount: number; plants: Plant[] }; + myMatches: { + totalCount: number; + plants: Plant[]; + filterCounts: FilterCounts; + }; }; diff --git a/frontend/src/hooks/useExploreParams.ts b/frontend/src/hooks/useExploreParams.ts index 2b804940..ff9c6e87 100644 --- a/frontend/src/hooks/useExploreParams.ts +++ b/frontend/src/hooks/useExploreParams.ts @@ -1,7 +1,5 @@ import { useUrlParams } from "./useUrlParams"; - -// The filters on Explore Plants, as they are named in the URL -type FilterParam = "watering" | "sunlight" | "careLevel"; +import type { FilterParam } from "../components/plantSearchForm/plantFilters"; const DEFAULT_SORT = "name_asc"; diff --git a/frontend/src/hooks/useMyMatchesParams.ts b/frontend/src/hooks/useMyMatchesParams.ts new file mode 100644 index 00000000..c6f57f1f --- /dev/null +++ b/frontend/src/hooks/useMyMatchesParams.ts @@ -0,0 +1,60 @@ +import { useState } from "react"; +import { useSessionState } from "./useSessionState"; +import type { + FilterParam, + PlantFilters, +} from "../components/plantSearchForm/plantFilters"; + +const DEFAULT_SORT = "newest"; + +// Keeps the My Matches state (search, filters, sorting and page). The same +// choices as on Explore Plants, but kept in sessionStorage instead of the URL: +// the matches belong to the user in this browser, so a link to them could not +// be shared anyway. The choices are remembered when the user goes to another +// page and back, and after a reload. The page always starts at 1, so new +// matches, which come first with the newest first, are seen right away. +export function useMyMatchesParams() { + const [search, setSearchState] = useSessionState("myMatches.search"); + const [watering, setWatering] = useSessionState("myMatches.watering"); + const [sunlight, setSunlight] = useSessionState("myMatches.sunlight"); + const [careLevel, setCareLevel] = useSessionState("myMatches.careLevel"); + const [sort, setSortState] = useSessionState("myMatches.sort", DEFAULT_SORT); + const [page, setPage] = useState(1); + + const filters: PlantFilters = { watering, sunlight, careLevel }; + const setters: Record void> = { + watering: setWatering, + sunlight: setSunlight, + careLevel: setCareLevel, + }; + + return { + search, + filters, + sort, + page, + // A new search, filter or sort order goes back to page 1, + // so the user never ends up on a page that no longer exists + setSearch: (value: string) => { + setSearchState(value); + setPage(1); + }, + setFilter: (param: FilterParam, value: string) => { + setters[param](value); + setPage(1); + }, + setSort: (value: string) => { + setSortState(value); + setPage(1); + }, + setPage, + reset: () => { + setSearchState(""); + setWatering(""); + setSunlight(""); + setCareLevel(""); + setSortState(DEFAULT_SORT); + setPage(1); + }, + }; +} diff --git a/frontend/src/i18n/locales/en/translation.json b/frontend/src/i18n/locales/en/translation.json index db7f21ed..00cccafe 100644 --- a/frontend/src/i18n/locales/en/translation.json +++ b/frontend/src/i18n/locales/en/translation.json @@ -52,6 +52,7 @@ "sort": "Sort", "name_asc": "Name (A-Z)", "name_desc": "Name (Z-A)", + "preferences": "Best match first", "watering_asc": "Watering (low-high)", "careLevel_asc": "Care (easy-hard)", "reset": "Reset", @@ -87,11 +88,15 @@ "removeMatch": "Remove from My Matches", "matchCount_one": "You have {{count}} match", "matchCount_other": "You have {{count}} matches", + "filteredCount_one": "{{count}} match fits your search", + "filteredCount_other": "{{count}} matches fit your search", + "noResults": "None of your matches fit your search and filters.", "sort": "Sort", "newest": "Newest first", "oldest": "Oldest first", "name_asc": "Name (A-Z)", - "name_desc": "Name (Z-A)" + "name_desc": "Name (Z-A)", + "preferences": "Best match first" }, "matches": { "addFailed": "Could not add the plant to My Matches. Please try again.", diff --git a/frontend/src/i18n/locales/no/translation.json b/frontend/src/i18n/locales/no/translation.json index a9e7c6e7..a8aab803 100644 --- a/frontend/src/i18n/locales/no/translation.json +++ b/frontend/src/i18n/locales/no/translation.json @@ -52,6 +52,7 @@ "sort": "Sorter", "name_asc": "Navn (A-Z)", "name_desc": "Navn (Z-A)", + "preferences": "Beste match først", "watering_asc": "Vanning (lite-mye)", "careLevel_asc": "Stell (lett-krevende)", "reset": "Nullstill", @@ -87,11 +88,15 @@ "removeMatch": "Fjern fra Mine Matches", "matchCount_one": "Du har {{count}} match", "matchCount_other": "Du har {{count}} matches", + "filteredCount_one": "{{count}} match passer søket", + "filteredCount_other": "{{count}} matcher passer søket", + "noResults": "Ingen av matchene dine passer søket og filtrene.", "sort": "Sorter", "newest": "Nyeste først", "oldest": "Eldste først", "name_asc": "Navn (A-Z)", - "name_desc": "Navn (Z-A)" + "name_desc": "Navn (Z-A)", + "preferences": "Best match først" }, "matches": { "addFailed": "Kunne ikke legge planten til i Mine Matches. Prøv igjen.", diff --git a/frontend/src/pages/explorePlants/ExplorePlantsPage.css b/frontend/src/pages/explorePlants/ExplorePlantsPage.css index e3a7e09a..642087d9 100644 --- a/frontend/src/pages/explorePlants/ExplorePlantsPage.css +++ b/frontend/src/pages/explorePlants/ExplorePlantsPage.css @@ -11,78 +11,10 @@ gap: 30px; } -.explore-form, .plant-grid { width: 100%; } -.explore-search { - position: relative; - display: block; -} - -.explore-search-icon { - position: absolute; - top: 50%; - left: 1rem; - font-size: 1.25rem; - transform: translateY(-50%); - color: var(--pink-text); - pointer-events: none; -} - -.explore-search input { - width: 100%; - padding: 0.75rem 1rem 0.75rem 2.75rem; - font-size: 1.25rem; - color: var(--text-dark); - background-color: var(--light-pink); - border: 1px solid var(--dark-pink); - border-radius: 8px; - box-sizing: border-box; -} - -.explore-search input:focus { - outline: none; - box-shadow: 0 0 0 2px var(--dark-pink); -} - -.explore-search input::placeholder { - color: var(--text-dark); -} - -.explore-filters { - display: flex; - flex-wrap: wrap; - gap: 1rem; - margin: 1rem 0 0; - padding: 0; - border: 0; -} - -/* At the end of the filter row, at the same height as the sort button */ -.reset-button { - align-self: flex-end; - height: 40px; - padding: 0 1rem; - border: 1px solid var(--dark-pink); - border-radius: 8px; - background-color: var(--dark-pink); - color: var(--text-light); - font-size: 15px; - cursor: pointer; -} - -.reset-button:hover { - background-color: var(--light-pink); - color: var(--text-dark); -} - -.reset-button.reset-button:focus-visible { - outline: none; - box-shadow: 0 0 0 2px var(--dark-pink); -} - .explore-results { width: 100%; box-sizing: border-box; diff --git a/frontend/src/pages/explorePlants/ExplorePlantsPage.tsx b/frontend/src/pages/explorePlants/ExplorePlantsPage.tsx index a33ce140..2e06c828 100644 --- a/frontend/src/pages/explorePlants/ExplorePlantsPage.tsx +++ b/frontend/src/pages/explorePlants/ExplorePlantsPage.tsx @@ -1,4 +1,3 @@ -import { SearchIcon } from "../../components/icons/Icons"; import { useTranslation } from "react-i18next"; import { useQuery } from "@apollo/client/react"; import { useDebounce } from "../../hooks/useDebounce"; @@ -9,35 +8,19 @@ import { } from "../../graphql/plants/queries.ts"; import PlantCard from "../../components/plantCard/PlantCard.tsx"; import Pagination from "../../components/pagination/Pagination.tsx"; -import FilterSelect from "../../components/filterSelect/FilterSelect.tsx"; -import SortMenu from "../../components/sortMenu/SortMenu.tsx"; +import PlantSearchForm from "../../components/plantSearchForm/PlantSearchForm.tsx"; import MatchButton from "../../components/matchButton/MatchButton.tsx"; import { useMatchedPlants } from "../../hooks/useMatchedPlants.ts"; +import { useUser } from "../../context/UserContext"; import "./ExplorePlantsPage.css"; const PAGE_SIZE = 12; const SORT_OPTIONS = ["name_asc", "name_desc", "watering_asc", "careLevel_asc"]; -// The filters on the page: the URL parameter, the translation key for the label, -// and the values to choose from. A new filter only needs a new line here. -const FILTERS = [ - { - param: "watering", - label: "explorePlantsPage.watering", - options: ["minimum", "average", "frequent"], - }, - { - param: "sunlight", - label: "explorePlantsPage.sunlight", - options: ["full_sun", "part_shade", "filtered_shade"], - }, - { - param: "careLevel", - label: "explorePlantsPage.careLevel", - options: ["low", "medium", "high"], - }, -] as const; +// Plants matching the most of the user's preferences first. Only offered when +// the user has chosen preferences, since it would be the same as A–Z otherwise. +const PREFERENCES_SORT = "preferences"; export default function ExplorePlantsPage() { const { t } = useTranslation(); @@ -56,6 +39,16 @@ export default function ExplorePlantsPage() { } = useExploreParams(); const debouncedSearch = useDebounce(search, 300); + // The user's saved preferences, for sorting by the best match. Explore has + // no user of its own in the backend, so they are sent with the query. + const { user } = useUser(); + const preferences = user?.preferences ?? []; + const hasPreferences = preferences.length > 0; + // A sort by preferences in the URL (e.g. a shared link) when the user has + // none falls back to the default order, A–Z + const activeSort = + sort === PREFERENCES_SORT && !hasPreferences ? "name_asc" : sort; + // Matches come from the user in the database, so every page sees the same list const { matchedPlantIds, addMatch, removeMatch } = useMatchedPlants(); @@ -70,7 +63,8 @@ export default function ExplorePlantsPage() { watering: filters.watering || null, sunlight: filters.sunlight || null, careLevel: filters.careLevel || null, - sort, + sort: activeSort, + preferences: activeSort === PREFERENCES_SORT ? preferences : null, limit: PAGE_SIZE, offset: (page - 1) * PAGE_SIZE, }, @@ -86,70 +80,28 @@ export default function ExplorePlantsPage() { const plants = data?.explorePlants.plants ?? []; const totalCount = data?.explorePlants.totalCount ?? 0; const totalPages = Math.max(1, Math.ceil(totalCount / PAGE_SIZE)); - const filterCounts = data?.explorePlants.filterCounts; return (
{/* The page heading (h1) is in the Header, like on every page */} -
e.preventDefault()} - > - - -
- - {t("explorePlantsPage.filters")} - - - {FILTERS.map((filter) => ( - c.value === "")?.count - } - options={filter.options.map((option) => ({ - value: option, - label: t(`explorePlantsPage.${option}`), - // No counts until the first result has come, then nothing is disabled - count: filterCounts?.[filter.param].find( - (c) => c.value === option, - )?.count, - }))} - onChange={(value) => setFilter(filter.param, value)} - /> - ))} - - ({ - value: option, - label: t(`explorePlantsPage.${option}`), - }))} - onChange={setSort} - /> - - -
-
+ ({ + value: option, + label: t(`explorePlantsPage.${option}`), + }))} + onSortChange={setSort} + onReset={reset} + />