From 2347971ea966debab5919ec1c48383824fe06f29 Mon Sep 17 00:00:00 2001 From: Pyry Koivisto Date: Fri, 20 Oct 2023 15:14:47 +0300 Subject: [PATCH 1/2] SHARED(Frontend): More intuitive autocomplete behaviour. --- frontend/packages/shared/CHANGELOG.MD | 6 ++++++ frontend/packages/shared/package.json | 2 +- .../src/components/ComboBox/ComboBox.tsx | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/frontend/packages/shared/CHANGELOG.MD b/frontend/packages/shared/CHANGELOG.MD index 8d99bd504..05cc75a30 100644 --- a/frontend/packages/shared/CHANGELOG.MD +++ b/frontend/packages/shared/CHANGELOG.MD @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Released] +## [1.9.29] - 2023-10-20 + +### Changed + +- Changed behaviour of ComboBox autocomplete: spaces are trimmed from search input and matching is only performed against the start of option labels + ## [1.9.28] - 2023-10-05 ### Changed diff --git a/frontend/packages/shared/package.json b/frontend/packages/shared/package.json index 067e8c392..68b689422 100644 --- a/frontend/packages/shared/package.json +++ b/frontend/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@opetushallitus/kieli-ja-kaantajatutkinnot.shared", - "version": "1.9.28", + "version": "1.9.29", "description": "Shared Frontend Package", "exports": { "./components": "./src/components/index.tsx", diff --git a/frontend/packages/shared/src/components/ComboBox/ComboBox.tsx b/frontend/packages/shared/src/components/ComboBox/ComboBox.tsx index cd9afe3b5..a51ecd2c7 100644 --- a/frontend/packages/shared/src/components/ComboBox/ComboBox.tsx +++ b/frontend/packages/shared/src/components/ComboBox/ComboBox.tsx @@ -1,6 +1,8 @@ import { Autocomplete, AutocompleteProps, + createFilterOptions, + FilterOptionsState, FormControl, FormHelperText, TextField, @@ -23,7 +25,11 @@ interface ComboBoxProps { type AutoCompleteComboBox = Omit< AutocompleteProps, - 'options' | 'renderInput' + | 'options' + | 'renderInput' + | 'getOptionLabel' + | 'isOptionEqualToValue' + | 'filterOptions' >; const compareOptionLabels = (a: ComboBoxOption, b: ComboBoxOption) => { @@ -47,6 +53,14 @@ const isOptionEqualToValue = ( } }; +const filterOptions: ( + options: Array, + state: FilterOptionsState +) => Array = createFilterOptions({ + matchFrom: 'start', + trim: true, +}); + export const valueAsOption = (value: string) => ({ value: value, label: value, @@ -74,6 +88,7 @@ export const ComboBox = ({ getOptionLabel={getOptionLabel} isOptionEqualToValue={isOptionEqualToValue} options={values} + filterOptions={filterOptions} renderInput={(params) => ( ( Date: Fri, 20 Oct 2023 15:16:11 +0300 Subject: [PATCH 2/2] AKR:OTR:VKT:YKI(Frontend): Take new shared package into use [deploy] --- frontend/packages/akr/package.json | 2 +- frontend/packages/otr/package.json | 2 +- frontend/packages/vkt/package.json | 2 +- frontend/packages/yki/package.json | 2 +- frontend/yarn.lock | 10 +++++----- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/frontend/packages/akr/package.json b/frontend/packages/akr/package.json index f8bd791d8..3df468226 100644 --- a/frontend/packages/akr/package.json +++ b/frontend/packages/akr/package.json @@ -22,6 +22,6 @@ "akr:tslint": "yarn g:tsc --pretty --noEmit" }, "dependencies": { - "shared": "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.28" + "shared": "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.29" } } diff --git a/frontend/packages/otr/package.json b/frontend/packages/otr/package.json index 17013064a..18aca046b 100644 --- a/frontend/packages/otr/package.json +++ b/frontend/packages/otr/package.json @@ -25,6 +25,6 @@ "otr:tslint": "yarn g:tsc --pretty --noEmit" }, "dependencies": { - "shared": "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.28" + "shared": "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.29" } } diff --git a/frontend/packages/vkt/package.json b/frontend/packages/vkt/package.json index 2f4bb7a3b..2309a3829 100644 --- a/frontend/packages/vkt/package.json +++ b/frontend/packages/vkt/package.json @@ -26,6 +26,6 @@ }, "dependencies": { "reduxjs-toolkit-persist": "^7.2.1", - "shared": "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.28" + "shared": "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.29" } } diff --git a/frontend/packages/yki/package.json b/frontend/packages/yki/package.json index d24981a2b..0fe93352d 100644 --- a/frontend/packages/yki/package.json +++ b/frontend/packages/yki/package.json @@ -26,7 +26,7 @@ "yki:tslint": "yarn g:tsc --pretty --noEmit" }, "dependencies": { - "shared": "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.28" + "shared": "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.29" }, "devDependencies": { "multer": "^1.4.5-lts.1" diff --git a/frontend/yarn.lock b/frontend/yarn.lock index c03d045e5..fc6c6a173 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -2890,7 +2890,7 @@ __metadata: version: 0.0.0-use.local resolution: "@opetushallitus/kieli-ja-kaantajatutkinnot.akr@workspace:packages/akr" dependencies: - shared: "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.28" + shared: "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.29" languageName: unknown linkType: soft @@ -2898,7 +2898,7 @@ __metadata: version: 0.0.0-use.local resolution: "@opetushallitus/kieli-ja-kaantajatutkinnot.otr@workspace:packages/otr" dependencies: - shared: "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.28" + shared: "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.29" languageName: unknown linkType: soft @@ -2990,7 +2990,7 @@ __metadata: languageName: unknown linkType: soft -"@opetushallitus/kieli-ja-kaantajatutkinnot.shared@workspace:packages/shared, shared@npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.28": +"@opetushallitus/kieli-ja-kaantajatutkinnot.shared@workspace:packages/shared, shared@npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.29": version: 0.0.0-use.local resolution: "@opetushallitus/kieli-ja-kaantajatutkinnot.shared@workspace:packages/shared" languageName: unknown @@ -3001,7 +3001,7 @@ __metadata: resolution: "@opetushallitus/kieli-ja-kaantajatutkinnot.vkt@workspace:packages/vkt" dependencies: reduxjs-toolkit-persist: ^7.2.1 - shared: "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.28" + shared: "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.29" languageName: unknown linkType: soft @@ -3010,7 +3010,7 @@ __metadata: resolution: "@opetushallitus/kieli-ja-kaantajatutkinnot.yki@workspace:packages/yki" dependencies: multer: ^1.4.5-lts.1 - shared: "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.28" + shared: "npm:@opetushallitus/kieli-ja-kaantajatutkinnot.shared@1.9.29" languageName: unknown linkType: soft