@arbetsformedlingen/yrkesvaljaren 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -2
- package/dist/cjs/digi-service-job-selector.cjs.entry.js +85 -35
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/cjs/{types-DdzCbiye.js → types-B3W1Y40Q.js} +5 -4
- package/dist/collection/components/job-selector/job-selector-controller.js +20 -6
- package/dist/collection/components/job-selector/job-selector.js +66 -30
- package/dist/collection/components/job-selector/logic/adapter.utils.js +5 -4
- package/dist/components/digi-service-job-selector.js +1 -1
- package/dist/components/types.js +1 -1
- package/dist/esm/digi-service-job-selector.entry.js +85 -35
- package/dist/esm/index.js +2 -2
- package/dist/esm/{types-DVos4HHS.js → types-D9zmn-JR.js} +5 -4
- package/dist/types/components/job-selector/job-selector-controller.d.ts +10 -1
- package/dist/types/components/job-selector/job-selector.d.ts +3 -0
- package/dist/types/components/job-selector/logic/adapter.utils.d.ts +1 -1
- package/dist/types/components/job-selector/types.d.ts +17 -2
- package/dist/types/components.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/yrkesvaljaren/index.esm.js +1 -1
- package/dist/yrkesvaljaren/{p-DVos4HHS.js → p-D9zmn-JR.js} +1 -1
- package/dist/yrkesvaljaren/p-c2eb633a.entry.js +1 -0
- package/dist/yrkesvaljaren/yrkesvaljaren.esm.js +1 -1
- package/package.json +1 -1
- package/dist/yrkesvaljaren/p-0f19a308.entry.js +0 -1
package/README.md
CHANGED
|
@@ -275,7 +275,7 @@ Programmatisk input går endast genom `setSelection()`. Metoden accepterar:
|
|
|
275
275
|
|
|
276
276
|
* en sträng
|
|
277
277
|
* en array där alla värden är strängar
|
|
278
|
-
*
|
|
278
|
+
* en array med `JobSelectionItem` från `afJobSelected`, sparade referenser (`JobSelectionReferenceInput`) eller båda
|
|
279
279
|
|
|
280
280
|
Output är alltid en rik `JobSelectionItem[]`, både från metodens returvärde och från `afJobSelected.detail`.
|
|
281
281
|
|
|
@@ -317,9 +317,27 @@ yrkesvaljaren.addEventListener("afJobSelected", async (event) => {
|
|
|
317
317
|
|
|
318
318
|
En sträng som matchar Concept ID-formatet tolkas alltid som ett taxonomi-id och verifieras mot det laddade YV-datasetet. Övriga strängar tolkas som fritext. Fritext kräver `af-manual-input="true"`.
|
|
319
319
|
|
|
320
|
-
Komponenten
|
|
320
|
+
Komponenten slår upp valen i den laddade yrkesdatan och returnerar aktuella etiketter. En jobbtitel kan ha samma `id` för flera yrkesbenämningar. Då skiljer `related.id` varianterna åt.
|
|
321
321
|
`ssyk_code_2012` är SSYK 2012-koden när den finns i YV-datat. Komponenten returnerar inget fält som heter `ssyk` och returnerar inte SSYK-nivåns taxonomi-id.
|
|
322
322
|
|
|
323
|
+
#### Återställ sparade id:n
|
|
324
|
+
|
|
325
|
+
För taxonomival, spara `item.id` som `conceptId` och `item.related?.id` som `occupationNameId` från `afJobSelected.detail`. När användaren öppnar Redigera kan appen skicka tillbaka id:n utan att spara etiketterna.
|
|
326
|
+
|
|
327
|
+
```javascript
|
|
328
|
+
await yrkesvaljaren.setSelection(
|
|
329
|
+
savedSelection.map(({ conceptId, occupationNameId }) =>
|
|
330
|
+
occupationNameId
|
|
331
|
+
? { id: conceptId, related: { id: occupationNameId } }
|
|
332
|
+
: { id: conceptId }
|
|
333
|
+
)
|
|
334
|
+
);
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
En yrkesbenämning eller en jobbtitel med en enda variant kan skickas som `{ id }`. För en jobbtitel med flera varianter måste referensen också ha `related.id`. Saknas det eller matchar paret ingen variant får appen `InvalidSelectionError` med koden `invalid-input`. Då kan appen låta användaren välja på nytt. Stränganrop med bara titelns id fortsätter att välja första varianten.
|
|
338
|
+
|
|
339
|
+
Två val med samma titel-id och olika yrkesbenämningar är giltiga. En dubblett är samma titel och yrkesbenämning två gånger.
|
|
340
|
+
|
|
323
341
|
Samma input-array får inte blanda strängar och objekt. Flera värden kräver `af-enable-multiple="true"`; metoden aktiverar aldrig flervalsläge automatiskt.
|
|
324
342
|
|
|
325
343
|
```javascript
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var index = require('./index-DMQDFAL7.js');
|
|
4
|
-
var types = require('./types-
|
|
4
|
+
var types = require('./types-B3W1Y40Q.js');
|
|
5
5
|
var afValidationMessage = require('./af-validation-message-BdR9X_qh.js');
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -813,6 +813,7 @@ class JobSelectorController {
|
|
|
813
813
|
}
|
|
814
814
|
setSelection(selection) {
|
|
815
815
|
const invalidIds = [];
|
|
816
|
+
let invalidReference;
|
|
816
817
|
const selectedItems = selection.map((item) => {
|
|
817
818
|
if (item.id !== null) {
|
|
818
819
|
const matchingItems = this.taxonomyData.filter((taxonomy) => taxonomy.id === item.id);
|
|
@@ -820,18 +821,22 @@ class JobSelectorController {
|
|
|
820
821
|
invalidIds.push(item.id);
|
|
821
822
|
return undefined;
|
|
822
823
|
}
|
|
824
|
+
const relatedId = item.related?.id;
|
|
823
825
|
let taxonomyItem;
|
|
824
|
-
if (
|
|
825
|
-
taxonomyItem = matchingItems.find((taxonomy) => taxonomy.occupation_name_id ===
|
|
826
|
-
if (!taxonomyItem && matchingItems.length === 1) {
|
|
826
|
+
if (relatedId) {
|
|
827
|
+
taxonomyItem = matchingItems.find((taxonomy) => taxonomy.occupation_name_id === relatedId);
|
|
828
|
+
if (!taxonomyItem && !item.exact && matchingItems.length === 1) {
|
|
827
829
|
taxonomyItem = matchingItems[0];
|
|
828
830
|
}
|
|
829
831
|
}
|
|
830
|
-
else {
|
|
832
|
+
else if (!item.exact || matchingItems.length === 1) {
|
|
831
833
|
taxonomyItem = matchingItems[0];
|
|
832
834
|
}
|
|
833
835
|
if (!taxonomyItem) {
|
|
834
836
|
invalidIds.push(item.id);
|
|
837
|
+
if (item.exact) {
|
|
838
|
+
invalidReference ??= item;
|
|
839
|
+
}
|
|
835
840
|
return undefined;
|
|
836
841
|
}
|
|
837
842
|
return this.toSearchResult(taxonomyItem);
|
|
@@ -839,9 +844,18 @@ class JobSelectorController {
|
|
|
839
844
|
return this.createManualInputItem(item.preferred_label);
|
|
840
845
|
});
|
|
841
846
|
if (invalidIds.length > 0) {
|
|
842
|
-
return
|
|
847
|
+
return invalidReference
|
|
848
|
+
? { ok: false, invalidIds, reference: invalidReference }
|
|
849
|
+
: { ok: false, invalidIds };
|
|
843
850
|
}
|
|
844
851
|
const resolvedItems = selectedItems;
|
|
852
|
+
// Kontrollera taxonomival efter uppslagning så att två referenser till samma rad avvisas.
|
|
853
|
+
// Fritext valideras separat och får ha samma text som ett taxonomival.
|
|
854
|
+
const taxonomyItems = resolvedItems.filter((item) => item.id);
|
|
855
|
+
const hasDuplicate = taxonomyItems.some((item, index) => taxonomyItems.findIndex((other) => types.isSameSearchResult(other, item)) !== index);
|
|
856
|
+
if (hasDuplicate) {
|
|
857
|
+
return { ok: false, invalidIds: [], duplicate: true };
|
|
858
|
+
}
|
|
845
859
|
const commonState = this.getCommonState();
|
|
846
860
|
if (this.config.enableMultiple) {
|
|
847
861
|
this.updateState({
|
|
@@ -957,7 +971,7 @@ class JobSelectorController {
|
|
|
957
971
|
};
|
|
958
972
|
}
|
|
959
973
|
toPublicSelection(item) {
|
|
960
|
-
return types.TaxonomyAdapter.toPublicSelection(item);
|
|
974
|
+
return types.TaxonomyAdapter.toPublicSelection(item, (id) => this.taxonomyData.find((row) => row.id === id && row.type === 'occupation-name')?.preferred_label?.trim());
|
|
961
975
|
}
|
|
962
976
|
createManualInputItem(value) {
|
|
963
977
|
return {
|
|
@@ -1047,6 +1061,9 @@ const jobSelectorCss = () => `:host{--digi--grayscale-0:#ffffff;--digi--grayscal
|
|
|
1047
1061
|
types.log.setLevel(types.log.levels.SILENT);
|
|
1048
1062
|
}
|
|
1049
1063
|
const CONCEPT_ID_PATTERN = /^[123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]{4}_[123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]{3}_[123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]{3}$/;
|
|
1064
|
+
function taxonomySelectionKey(id, relatedId) {
|
|
1065
|
+
return JSON.stringify([id, relatedId ?? null]);
|
|
1066
|
+
}
|
|
1050
1067
|
const JobSelector = class {
|
|
1051
1068
|
get hostElement() { return index.getElement(this); }
|
|
1052
1069
|
internals;
|
|
@@ -1167,6 +1184,10 @@ const JobSelector = class {
|
|
|
1167
1184
|
}
|
|
1168
1185
|
const selection = [];
|
|
1169
1186
|
const taxonomyIds = [];
|
|
1187
|
+
// Unikhet avgörs av taxonomi-id + related.id, samma regel som vid manuellt val.
|
|
1188
|
+
// En jobbtitel kan höra till flera yrkesbenämningar, t.ex. Butiksmedarbetare
|
|
1189
|
+
// (Kassapersonal) och Butiksmedarbetare (Butikssäljare), och båda är giltiga val.
|
|
1190
|
+
const selectionKeys = [];
|
|
1170
1191
|
const manualLabels = [];
|
|
1171
1192
|
for (const item of values) {
|
|
1172
1193
|
if (typeof item === 'string') {
|
|
@@ -1176,6 +1197,7 @@ const JobSelector = class {
|
|
|
1176
1197
|
}
|
|
1177
1198
|
if (CONCEPT_ID_PATTERN.test(value)) {
|
|
1178
1199
|
taxonomyIds.push(value);
|
|
1200
|
+
selectionKeys.push(taxonomySelectionKey(value));
|
|
1179
1201
|
selection.push({ id: value });
|
|
1180
1202
|
}
|
|
1181
1203
|
else {
|
|
@@ -1193,32 +1215,29 @@ const JobSelector = class {
|
|
|
1193
1215
|
const candidateItem = item;
|
|
1194
1216
|
if (typeof candidateItem.id === 'string') {
|
|
1195
1217
|
const id = candidateItem.id.trim();
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
&& candidateItem.type !== 'occupation-name')
|
|
1218
|
+
const exact = candidateItem.type === undefined && candidateItem.preferred_label === undefined;
|
|
1219
|
+
if (!id || (!exact && ((candidateItem.type !== 'job-title' && candidateItem.type !== 'occupation-name')
|
|
1199
1220
|
|| typeof candidateItem.preferred_label !== 'string'
|
|
1200
|
-
|| !candidateItem.preferred_label.trim()) {
|
|
1221
|
+
|| !candidateItem.preferred_label.trim()))) {
|
|
1201
1222
|
return { ok: false, reason: 'invalid-input' };
|
|
1202
1223
|
}
|
|
1203
|
-
let
|
|
1224
|
+
let relatedId;
|
|
1204
1225
|
if (candidateItem.related !== undefined) {
|
|
1205
1226
|
const related = candidateItem.related;
|
|
1206
1227
|
if (!related
|
|
1207
|
-
|| related
|
|
1228
|
+
|| typeof related !== 'object'
|
|
1208
1229
|
|| typeof related.id !== 'string'
|
|
1209
1230
|
|| !related.id.trim()
|
|
1210
|
-
||
|
|
1211
|
-
|
|
1231
|
+
|| (!exact && (related.type !== 'occupation-name'
|
|
1232
|
+
|| typeof related.preferred_label !== 'string'
|
|
1233
|
+
|| !related.preferred_label.trim()))) {
|
|
1212
1234
|
return { ok: false, reason: 'invalid-input' };
|
|
1213
1235
|
}
|
|
1214
|
-
|
|
1215
|
-
type: 'occupation-name',
|
|
1216
|
-
id: related.id.trim(),
|
|
1217
|
-
preferred_label: related.preferred_label.trim(),
|
|
1218
|
-
};
|
|
1236
|
+
relatedId = related.id.trim();
|
|
1219
1237
|
}
|
|
1220
1238
|
taxonomyIds.push(id);
|
|
1221
|
-
|
|
1239
|
+
selectionKeys.push(taxonomySelectionKey(id, relatedId));
|
|
1240
|
+
selection.push({ id, related: relatedId ? { id: relatedId } : undefined, exact });
|
|
1222
1241
|
}
|
|
1223
1242
|
else if (candidateItem.id === null && candidateItem.type === 'manual-input') {
|
|
1224
1243
|
if (typeof candidateItem.preferred_label !== 'string' || !candidateItem.preferred_label.trim()) {
|
|
@@ -1238,7 +1257,7 @@ const JobSelector = class {
|
|
|
1238
1257
|
if (!this.enableMultiple && selection.length > 1) {
|
|
1239
1258
|
return { ok: false, reason: 'multiple-disabled' };
|
|
1240
1259
|
}
|
|
1241
|
-
if (new Set(
|
|
1260
|
+
if (new Set(selectionKeys).size !== selectionKeys.length) {
|
|
1242
1261
|
return { ok: false, reason: 'duplicate-taxonomy-id' };
|
|
1243
1262
|
}
|
|
1244
1263
|
if (new Set(manualLabels).size !== manualLabels.length) {
|
|
@@ -1253,11 +1272,17 @@ const JobSelector = class {
|
|
|
1253
1272
|
describeSelectionRejection(rejection) {
|
|
1254
1273
|
switch (rejection.reason) {
|
|
1255
1274
|
case 'invalid-input':
|
|
1256
|
-
return 'setSelection accepterar en sträng, en
|
|
1275
|
+
return 'setSelection accepterar en sträng, en array med strängar eller en array med valobjekt eller referenser som { id, related: { id } }.';
|
|
1276
|
+
case 'invalid-reference': {
|
|
1277
|
+
const { id, related } = rejection.reference;
|
|
1278
|
+
return related
|
|
1279
|
+
? `Yrkesbenämningen ${related.id} hör inte till valet ${id} i den laddade yrkesdatan.`
|
|
1280
|
+
: `Jobbtiteln ${id} hör till flera yrkesbenämningar. Ange yrkesbenämningens id i related.id.`;
|
|
1281
|
+
}
|
|
1257
1282
|
case 'data-unavailable':
|
|
1258
1283
|
return 'setSelection kan inte användas eftersom yrkesdata inte kunde laddas.';
|
|
1259
1284
|
case 'duplicate-taxonomy-id':
|
|
1260
|
-
return 'selection får inte innehålla
|
|
1285
|
+
return 'selection får inte innehålla samma yrke två gånger (samma taxonomi-id och related.id).';
|
|
1261
1286
|
case 'duplicate-manual-label':
|
|
1262
1287
|
return 'selection får inte innehålla dubbla manuella labels.';
|
|
1263
1288
|
case 'multiple-disabled':
|
|
@@ -1288,8 +1313,19 @@ const JobSelector = class {
|
|
|
1288
1313
|
this.updateValidity(false);
|
|
1289
1314
|
return new types.InvalidSelectionError(message, this.errorCodeForRejection(rejection.reason), rejection.invalidIds);
|
|
1290
1315
|
}
|
|
1291
|
-
syncAcceptedSelection(selection) {
|
|
1316
|
+
syncAcceptedSelection(selection, references) {
|
|
1292
1317
|
const nextSelection = this.cloneSelection(selection);
|
|
1318
|
+
// Behåll exakt matchning även när användaren ändrar andra val i listan.
|
|
1319
|
+
this.exactSelectionKeys = new Set(nextSelection.flatMap((item, index) => {
|
|
1320
|
+
if (item.id === null)
|
|
1321
|
+
return [];
|
|
1322
|
+
const key = taxonomySelectionKey(item.id, item.related?.id);
|
|
1323
|
+
const reference = references?.[index];
|
|
1324
|
+
const exact = reference
|
|
1325
|
+
? reference.id !== null && reference.exact
|
|
1326
|
+
: this.exactSelectionKeys.has(key);
|
|
1327
|
+
return exact ? [key] : [];
|
|
1328
|
+
}));
|
|
1293
1329
|
this.lastAcceptedSelection = nextSelection;
|
|
1294
1330
|
if (this.activeErrorType === 'invalidInput') {
|
|
1295
1331
|
const hasAcceptedSelection = nextSelection.length > 0;
|
|
@@ -1310,11 +1346,20 @@ const JobSelector = class {
|
|
|
1310
1346
|
}
|
|
1311
1347
|
const result = this.controller.setSelection(validation.selection);
|
|
1312
1348
|
if (!result.ok) {
|
|
1313
|
-
throw this.
|
|
1349
|
+
throw this.rejectSelectionResolution(candidate, result);
|
|
1314
1350
|
}
|
|
1315
|
-
this.syncAcceptedSelection(result.selection);
|
|
1351
|
+
this.syncAcceptedSelection(result.selection, validation.selection);
|
|
1316
1352
|
return this.cloneSelection(result.selection);
|
|
1317
1353
|
}
|
|
1354
|
+
rejectSelectionResolution(candidate, result) {
|
|
1355
|
+
if (result.duplicate) {
|
|
1356
|
+
return this.rejectSelection(candidate, { ok: false, reason: 'duplicate-taxonomy-id' });
|
|
1357
|
+
}
|
|
1358
|
+
if (result.reference) {
|
|
1359
|
+
return this.rejectSelection(candidate, { ok: false, reason: 'invalid-reference', reference: result.reference });
|
|
1360
|
+
}
|
|
1361
|
+
return this.rejectSelection(candidate, { ok: false, reason: 'unknown-id', invalidIds: result.invalidIds });
|
|
1362
|
+
}
|
|
1318
1363
|
watchRequired(newValue) {
|
|
1319
1364
|
this.controller.updateConfig({ required: newValue });
|
|
1320
1365
|
}
|
|
@@ -1383,20 +1428,24 @@ const JobSelector = class {
|
|
|
1383
1428
|
controller;
|
|
1384
1429
|
validJobIds = new Set();
|
|
1385
1430
|
lastAcceptedSelection = [];
|
|
1431
|
+
exactSelectionKeys = new Set();
|
|
1386
1432
|
restoreAcceptedSelectionAfterDataUpdate() {
|
|
1387
1433
|
if (this.lastAcceptedSelection.length === 0) {
|
|
1388
1434
|
return;
|
|
1389
1435
|
}
|
|
1390
|
-
const
|
|
1436
|
+
const references = this.lastAcceptedSelection.map((item) => item.id === null
|
|
1437
|
+
? item
|
|
1438
|
+
: {
|
|
1439
|
+
id: item.id,
|
|
1440
|
+
related: item.related,
|
|
1441
|
+
exact: this.exactSelectionKeys.has(taxonomySelectionKey(item.id, item.related?.id)),
|
|
1442
|
+
});
|
|
1443
|
+
const result = this.controller.setSelection(references);
|
|
1391
1444
|
if (result.ok) {
|
|
1392
|
-
this.syncAcceptedSelection(result.selection);
|
|
1445
|
+
this.syncAcceptedSelection(result.selection, references);
|
|
1393
1446
|
return;
|
|
1394
1447
|
}
|
|
1395
|
-
this.
|
|
1396
|
-
ok: false,
|
|
1397
|
-
reason: 'unknown-id',
|
|
1398
|
-
invalidIds: result.invalidIds,
|
|
1399
|
-
});
|
|
1448
|
+
this.rejectSelectionResolution(this.lastAcceptedSelection, result);
|
|
1400
1449
|
}
|
|
1401
1450
|
// --- LIVSCYKEL-METODER ---
|
|
1402
1451
|
async componentWillLoad() {
|
|
@@ -1659,6 +1708,7 @@ const JobSelector = class {
|
|
|
1659
1708
|
/**
|
|
1660
1709
|
* Sätter ett programatiskt val och returnerar YV:s normaliserade, rika selection.
|
|
1661
1710
|
* Strängar som matchar Concept ID-formatet tolkas som taxonomi-id:n; övriga som fritext.
|
|
1711
|
+
* Sparade referenser som { id, related: { id } } slås upp i den laddade yrkesdatan.
|
|
1662
1712
|
*/
|
|
1663
1713
|
async setSelection(input) {
|
|
1664
1714
|
return this.applySelection(input);
|
|
@@ -1885,7 +1935,7 @@ const JobSelector = class {
|
|
|
1885
1935
|
};
|
|
1886
1936
|
// Pass external error message if present and we are not in loading/error state
|
|
1887
1937
|
// (This logic is now moved to _mapStateToSelectorState to respect validation state)
|
|
1888
|
-
return (index.h("div", { key: '
|
|
1938
|
+
return (index.h("div", { key: 'd2042c1c0e5e76d8dfeedd2691de20d6fcf49c27', class: "job-selector-wrapper" }, this.state.status === 'error' ? (index.h("div", { class: "error-message" }, index.h(afValidationMessage.AfValidationMessage, { variant: "error", role: "alert" }, this.state.message || 'Ett fel uppstod.'))) : (index.h(index.Fragment, null, index.h("core-selector", { id: this.componentId, componentId: this.componentId, state: selectorState, config: config, label: this.label, labelDescription: this.labelDescription, size: this.size, afFocused: this.afFocused }), this.suggestionState && this.suggestionState.status !== 'pii-blocked' && (index.h("div", { key: "yv-suggestion-box", class: "yv-suggestion-box", role: "region", "aria-label": "F\u00F6resl\u00E5 saknat yrke" }, this.suggestionState.status === 'form' ? (index.h("div", { class: "yv-suggestion-form" }, index.h("div", { class: "yv-suggestion-title", id: `${this.componentId}-suggestion-title` }, "Motivera varf\u00F6r \"", index.h("strong", null, this.suggestionState.term), "\" b\u00F6r l\u00E4ggas till som yrke (frivilligt):"), index.h("div", { class: "yv-motivation-container" }, index.h("div", { class: "yv-motivation-field-wrapper" }, index.h("textarea", { id: `${this.componentId}-suggestion-motivation-input`, "aria-labelledby": `${this.componentId}-suggestion-title`, "aria-describedby": this.suggestionState.piiError
|
|
1889
1939
|
? `${this.componentId}-motivation-pii-error ${this.componentId}-motivation-counter`
|
|
1890
1940
|
: `${this.componentId}-motivation-counter`, "aria-invalid": this.suggestionState.piiError ? 'true' : 'false', class: "yv-motivation-input", value: this.suggestionState.motivation, maxLength: 160, rows: 2, ref: (el) => {
|
|
1891
1941
|
if (el) {
|
package/dist/cjs/index.cjs.js
CHANGED
|
@@ -2484,7 +2484,7 @@ const TaxonomyAdapter = {
|
|
|
2484
2484
|
};
|
|
2485
2485
|
},
|
|
2486
2486
|
/** Maps an internal item to the public event format */
|
|
2487
|
-
toPublicSelection(item) {
|
|
2487
|
+
toPublicSelection(item, findOccupationLabel) {
|
|
2488
2488
|
const id = item.id || '';
|
|
2489
2489
|
const preferredLabel = item.preferred_label || item.rawLabel || '';
|
|
2490
2490
|
if (!id) {
|
|
@@ -2506,12 +2506,13 @@ const TaxonomyAdapter = {
|
|
|
2506
2506
|
selection.ssyk_code_2012 = item.ssyk_code_2012;
|
|
2507
2507
|
}
|
|
2508
2508
|
const occupationId = item.occupation_name_id || item.occupationId;
|
|
2509
|
-
|
|
2510
|
-
|
|
2509
|
+
if (item.type === 'job-title' && occupationId) {
|
|
2510
|
+
const occupationLabel = item.occupation_name_preferred_label?.trim()
|
|
2511
|
+
|| item.occupationLabel?.trim();
|
|
2511
2512
|
selection.related = {
|
|
2512
2513
|
type: 'occupation-name',
|
|
2513
2514
|
id: occupationId,
|
|
2514
|
-
preferred_label: occupationLabel,
|
|
2515
|
+
preferred_label: occupationLabel || findOccupationLabel?.(occupationId) || occupationId,
|
|
2515
2516
|
};
|
|
2516
2517
|
}
|
|
2517
2518
|
return selection;
|
|
@@ -641,6 +641,7 @@ export class JobSelectorController {
|
|
|
641
641
|
}
|
|
642
642
|
setSelection(selection) {
|
|
643
643
|
const invalidIds = [];
|
|
644
|
+
let invalidReference;
|
|
644
645
|
const selectedItems = selection.map((item) => {
|
|
645
646
|
if (item.id !== null) {
|
|
646
647
|
const matchingItems = this.taxonomyData.filter((taxonomy) => taxonomy.id === item.id);
|
|
@@ -648,18 +649,22 @@ export class JobSelectorController {
|
|
|
648
649
|
invalidIds.push(item.id);
|
|
649
650
|
return undefined;
|
|
650
651
|
}
|
|
652
|
+
const relatedId = item.related?.id;
|
|
651
653
|
let taxonomyItem;
|
|
652
|
-
if (
|
|
653
|
-
taxonomyItem = matchingItems.find((taxonomy) => taxonomy.occupation_name_id ===
|
|
654
|
-
if (!taxonomyItem && matchingItems.length === 1) {
|
|
654
|
+
if (relatedId) {
|
|
655
|
+
taxonomyItem = matchingItems.find((taxonomy) => taxonomy.occupation_name_id === relatedId);
|
|
656
|
+
if (!taxonomyItem && !item.exact && matchingItems.length === 1) {
|
|
655
657
|
taxonomyItem = matchingItems[0];
|
|
656
658
|
}
|
|
657
659
|
}
|
|
658
|
-
else {
|
|
660
|
+
else if (!item.exact || matchingItems.length === 1) {
|
|
659
661
|
taxonomyItem = matchingItems[0];
|
|
660
662
|
}
|
|
661
663
|
if (!taxonomyItem) {
|
|
662
664
|
invalidIds.push(item.id);
|
|
665
|
+
if (item.exact) {
|
|
666
|
+
invalidReference ??= item;
|
|
667
|
+
}
|
|
663
668
|
return undefined;
|
|
664
669
|
}
|
|
665
670
|
return this.toSearchResult(taxonomyItem);
|
|
@@ -667,9 +672,18 @@ export class JobSelectorController {
|
|
|
667
672
|
return this.createManualInputItem(item.preferred_label);
|
|
668
673
|
});
|
|
669
674
|
if (invalidIds.length > 0) {
|
|
670
|
-
return
|
|
675
|
+
return invalidReference
|
|
676
|
+
? { ok: false, invalidIds, reference: invalidReference }
|
|
677
|
+
: { ok: false, invalidIds };
|
|
671
678
|
}
|
|
672
679
|
const resolvedItems = selectedItems;
|
|
680
|
+
// Kontrollera taxonomival efter uppslagning så att två referenser till samma rad avvisas.
|
|
681
|
+
// Fritext valideras separat och får ha samma text som ett taxonomival.
|
|
682
|
+
const taxonomyItems = resolvedItems.filter((item) => item.id);
|
|
683
|
+
const hasDuplicate = taxonomyItems.some((item, index) => taxonomyItems.findIndex((other) => isSameSearchResult(other, item)) !== index);
|
|
684
|
+
if (hasDuplicate) {
|
|
685
|
+
return { ok: false, invalidIds: [], duplicate: true };
|
|
686
|
+
}
|
|
673
687
|
const commonState = this.getCommonState();
|
|
674
688
|
if (this.config.enableMultiple) {
|
|
675
689
|
this.updateState({
|
|
@@ -785,7 +799,7 @@ export class JobSelectorController {
|
|
|
785
799
|
};
|
|
786
800
|
}
|
|
787
801
|
toPublicSelection(item) {
|
|
788
|
-
return TaxonomyAdapter.toPublicSelection(item);
|
|
802
|
+
return TaxonomyAdapter.toPublicSelection(item, (id) => this.taxonomyData.find((row) => row.id === id && row.type === 'occupation-name')?.preferred_label?.trim());
|
|
789
803
|
}
|
|
790
804
|
createManualInputItem(value) {
|
|
791
805
|
return {
|
|
@@ -15,6 +15,9 @@ else {
|
|
|
15
15
|
log.setLevel(log.levels.DEBUG);
|
|
16
16
|
}
|
|
17
17
|
const CONCEPT_ID_PATTERN = /^[123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]{4}_[123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]{3}_[123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]{3}$/;
|
|
18
|
+
function taxonomySelectionKey(id, relatedId) {
|
|
19
|
+
return JSON.stringify([id, relatedId ?? null]);
|
|
20
|
+
}
|
|
18
21
|
export class JobSelector {
|
|
19
22
|
hostElement;
|
|
20
23
|
internals;
|
|
@@ -123,6 +126,10 @@ export class JobSelector {
|
|
|
123
126
|
}
|
|
124
127
|
const selection = [];
|
|
125
128
|
const taxonomyIds = [];
|
|
129
|
+
// Unikhet avgörs av taxonomi-id + related.id, samma regel som vid manuellt val.
|
|
130
|
+
// En jobbtitel kan höra till flera yrkesbenämningar, t.ex. Butiksmedarbetare
|
|
131
|
+
// (Kassapersonal) och Butiksmedarbetare (Butikssäljare), och båda är giltiga val.
|
|
132
|
+
const selectionKeys = [];
|
|
126
133
|
const manualLabels = [];
|
|
127
134
|
for (const item of values) {
|
|
128
135
|
if (typeof item === 'string') {
|
|
@@ -132,6 +139,7 @@ export class JobSelector {
|
|
|
132
139
|
}
|
|
133
140
|
if (CONCEPT_ID_PATTERN.test(value)) {
|
|
134
141
|
taxonomyIds.push(value);
|
|
142
|
+
selectionKeys.push(taxonomySelectionKey(value));
|
|
135
143
|
selection.push({ id: value });
|
|
136
144
|
}
|
|
137
145
|
else {
|
|
@@ -149,32 +157,29 @@ export class JobSelector {
|
|
|
149
157
|
const candidateItem = item;
|
|
150
158
|
if (typeof candidateItem.id === 'string') {
|
|
151
159
|
const id = candidateItem.id.trim();
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
&& candidateItem.type !== 'occupation-name')
|
|
160
|
+
const exact = candidateItem.type === undefined && candidateItem.preferred_label === undefined;
|
|
161
|
+
if (!id || (!exact && ((candidateItem.type !== 'job-title' && candidateItem.type !== 'occupation-name')
|
|
155
162
|
|| typeof candidateItem.preferred_label !== 'string'
|
|
156
|
-
|| !candidateItem.preferred_label.trim()) {
|
|
163
|
+
|| !candidateItem.preferred_label.trim()))) {
|
|
157
164
|
return { ok: false, reason: 'invalid-input' };
|
|
158
165
|
}
|
|
159
|
-
let
|
|
166
|
+
let relatedId;
|
|
160
167
|
if (candidateItem.related !== undefined) {
|
|
161
168
|
const related = candidateItem.related;
|
|
162
169
|
if (!related
|
|
163
|
-
|| related
|
|
170
|
+
|| typeof related !== 'object'
|
|
164
171
|
|| typeof related.id !== 'string'
|
|
165
172
|
|| !related.id.trim()
|
|
166
|
-
||
|
|
167
|
-
|
|
173
|
+
|| (!exact && (related.type !== 'occupation-name'
|
|
174
|
+
|| typeof related.preferred_label !== 'string'
|
|
175
|
+
|| !related.preferred_label.trim()))) {
|
|
168
176
|
return { ok: false, reason: 'invalid-input' };
|
|
169
177
|
}
|
|
170
|
-
|
|
171
|
-
type: 'occupation-name',
|
|
172
|
-
id: related.id.trim(),
|
|
173
|
-
preferred_label: related.preferred_label.trim(),
|
|
174
|
-
};
|
|
178
|
+
relatedId = related.id.trim();
|
|
175
179
|
}
|
|
176
180
|
taxonomyIds.push(id);
|
|
177
|
-
|
|
181
|
+
selectionKeys.push(taxonomySelectionKey(id, relatedId));
|
|
182
|
+
selection.push({ id, related: relatedId ? { id: relatedId } : undefined, exact });
|
|
178
183
|
}
|
|
179
184
|
else if (candidateItem.id === null && candidateItem.type === 'manual-input') {
|
|
180
185
|
if (typeof candidateItem.preferred_label !== 'string' || !candidateItem.preferred_label.trim()) {
|
|
@@ -194,7 +199,7 @@ export class JobSelector {
|
|
|
194
199
|
if (!this.enableMultiple && selection.length > 1) {
|
|
195
200
|
return { ok: false, reason: 'multiple-disabled' };
|
|
196
201
|
}
|
|
197
|
-
if (new Set(
|
|
202
|
+
if (new Set(selectionKeys).size !== selectionKeys.length) {
|
|
198
203
|
return { ok: false, reason: 'duplicate-taxonomy-id' };
|
|
199
204
|
}
|
|
200
205
|
if (new Set(manualLabels).size !== manualLabels.length) {
|
|
@@ -209,11 +214,17 @@ export class JobSelector {
|
|
|
209
214
|
describeSelectionRejection(rejection) {
|
|
210
215
|
switch (rejection.reason) {
|
|
211
216
|
case 'invalid-input':
|
|
212
|
-
return 'setSelection accepterar en sträng, en
|
|
217
|
+
return 'setSelection accepterar en sträng, en array med strängar eller en array med valobjekt eller referenser som { id, related: { id } }.';
|
|
218
|
+
case 'invalid-reference': {
|
|
219
|
+
const { id, related } = rejection.reference;
|
|
220
|
+
return related
|
|
221
|
+
? `Yrkesbenämningen ${related.id} hör inte till valet ${id} i den laddade yrkesdatan.`
|
|
222
|
+
: `Jobbtiteln ${id} hör till flera yrkesbenämningar. Ange yrkesbenämningens id i related.id.`;
|
|
223
|
+
}
|
|
213
224
|
case 'data-unavailable':
|
|
214
225
|
return 'setSelection kan inte användas eftersom yrkesdata inte kunde laddas.';
|
|
215
226
|
case 'duplicate-taxonomy-id':
|
|
216
|
-
return 'selection får inte innehålla
|
|
227
|
+
return 'selection får inte innehålla samma yrke två gånger (samma taxonomi-id och related.id).';
|
|
217
228
|
case 'duplicate-manual-label':
|
|
218
229
|
return 'selection får inte innehålla dubbla manuella labels.';
|
|
219
230
|
case 'multiple-disabled':
|
|
@@ -244,8 +255,19 @@ export class JobSelector {
|
|
|
244
255
|
this.updateValidity(false);
|
|
245
256
|
return new InvalidSelectionError(message, this.errorCodeForRejection(rejection.reason), rejection.invalidIds);
|
|
246
257
|
}
|
|
247
|
-
syncAcceptedSelection(selection) {
|
|
258
|
+
syncAcceptedSelection(selection, references) {
|
|
248
259
|
const nextSelection = this.cloneSelection(selection);
|
|
260
|
+
// Behåll exakt matchning även när användaren ändrar andra val i listan.
|
|
261
|
+
this.exactSelectionKeys = new Set(nextSelection.flatMap((item, index) => {
|
|
262
|
+
if (item.id === null)
|
|
263
|
+
return [];
|
|
264
|
+
const key = taxonomySelectionKey(item.id, item.related?.id);
|
|
265
|
+
const reference = references?.[index];
|
|
266
|
+
const exact = reference
|
|
267
|
+
? reference.id !== null && reference.exact
|
|
268
|
+
: this.exactSelectionKeys.has(key);
|
|
269
|
+
return exact ? [key] : [];
|
|
270
|
+
}));
|
|
249
271
|
this.lastAcceptedSelection = nextSelection;
|
|
250
272
|
if (this.activeErrorType === 'invalidInput') {
|
|
251
273
|
const hasAcceptedSelection = nextSelection.length > 0;
|
|
@@ -266,11 +288,20 @@ export class JobSelector {
|
|
|
266
288
|
}
|
|
267
289
|
const result = this.controller.setSelection(validation.selection);
|
|
268
290
|
if (!result.ok) {
|
|
269
|
-
throw this.
|
|
291
|
+
throw this.rejectSelectionResolution(candidate, result);
|
|
270
292
|
}
|
|
271
|
-
this.syncAcceptedSelection(result.selection);
|
|
293
|
+
this.syncAcceptedSelection(result.selection, validation.selection);
|
|
272
294
|
return this.cloneSelection(result.selection);
|
|
273
295
|
}
|
|
296
|
+
rejectSelectionResolution(candidate, result) {
|
|
297
|
+
if (result.duplicate) {
|
|
298
|
+
return this.rejectSelection(candidate, { ok: false, reason: 'duplicate-taxonomy-id' });
|
|
299
|
+
}
|
|
300
|
+
if (result.reference) {
|
|
301
|
+
return this.rejectSelection(candidate, { ok: false, reason: 'invalid-reference', reference: result.reference });
|
|
302
|
+
}
|
|
303
|
+
return this.rejectSelection(candidate, { ok: false, reason: 'unknown-id', invalidIds: result.invalidIds });
|
|
304
|
+
}
|
|
274
305
|
watchRequired(newValue) {
|
|
275
306
|
this.controller.updateConfig({ required: newValue });
|
|
276
307
|
}
|
|
@@ -339,20 +370,24 @@ export class JobSelector {
|
|
|
339
370
|
controller;
|
|
340
371
|
validJobIds = new Set();
|
|
341
372
|
lastAcceptedSelection = [];
|
|
373
|
+
exactSelectionKeys = new Set();
|
|
342
374
|
restoreAcceptedSelectionAfterDataUpdate() {
|
|
343
375
|
if (this.lastAcceptedSelection.length === 0) {
|
|
344
376
|
return;
|
|
345
377
|
}
|
|
346
|
-
const
|
|
378
|
+
const references = this.lastAcceptedSelection.map((item) => item.id === null
|
|
379
|
+
? item
|
|
380
|
+
: {
|
|
381
|
+
id: item.id,
|
|
382
|
+
related: item.related,
|
|
383
|
+
exact: this.exactSelectionKeys.has(taxonomySelectionKey(item.id, item.related?.id)),
|
|
384
|
+
});
|
|
385
|
+
const result = this.controller.setSelection(references);
|
|
347
386
|
if (result.ok) {
|
|
348
|
-
this.syncAcceptedSelection(result.selection);
|
|
387
|
+
this.syncAcceptedSelection(result.selection, references);
|
|
349
388
|
return;
|
|
350
389
|
}
|
|
351
|
-
this.
|
|
352
|
-
ok: false,
|
|
353
|
-
reason: 'unknown-id',
|
|
354
|
-
invalidIds: result.invalidIds,
|
|
355
|
-
});
|
|
390
|
+
this.rejectSelectionResolution(this.lastAcceptedSelection, result);
|
|
356
391
|
}
|
|
357
392
|
// --- LIVSCYKEL-METODER ---
|
|
358
393
|
async componentWillLoad() {
|
|
@@ -615,6 +650,7 @@ export class JobSelector {
|
|
|
615
650
|
/**
|
|
616
651
|
* Sätter ett programatiskt val och returnerar YV:s normaliserade, rika selection.
|
|
617
652
|
* Strängar som matchar Concept ID-formatet tolkas som taxonomi-id:n; övriga som fritext.
|
|
653
|
+
* Sparade referenser som { id, related: { id } } slås upp i den laddade yrkesdatan.
|
|
618
654
|
*/
|
|
619
655
|
async setSelection(input) {
|
|
620
656
|
return this.applySelection(input);
|
|
@@ -841,7 +877,7 @@ export class JobSelector {
|
|
|
841
877
|
};
|
|
842
878
|
// Pass external error message if present and we are not in loading/error state
|
|
843
879
|
// (This logic is now moved to _mapStateToSelectorState to respect validation state)
|
|
844
|
-
return (h("div", { key: '
|
|
880
|
+
return (h("div", { key: 'd2042c1c0e5e76d8dfeedd2691de20d6fcf49c27', class: "job-selector-wrapper" }, this.state.status === 'error' ? (h("div", { class: "error-message" }, h(AfValidationMessage, { variant: "error", role: "alert" }, this.state.message || 'Ett fel uppstod.'))) : (h(Fragment, null, h("core-selector", { id: this.componentId, componentId: this.componentId, state: selectorState, config: config, label: this.label, labelDescription: this.labelDescription, size: this.size, afFocused: this.afFocused }), this.suggestionState && this.suggestionState.status !== 'pii-blocked' && (h("div", { key: "yv-suggestion-box", class: "yv-suggestion-box", role: "region", "aria-label": "F\u00F6resl\u00E5 saknat yrke" }, this.suggestionState.status === 'form' ? (h("div", { class: "yv-suggestion-form" }, h("div", { class: "yv-suggestion-title", id: `${this.componentId}-suggestion-title` }, "Motivera varf\u00F6r \"", h("strong", null, this.suggestionState.term), "\" b\u00F6r l\u00E4ggas till som yrke (frivilligt):"), h("div", { class: "yv-motivation-container" }, h("div", { class: "yv-motivation-field-wrapper" }, h("textarea", { id: `${this.componentId}-suggestion-motivation-input`, "aria-labelledby": `${this.componentId}-suggestion-title`, "aria-describedby": this.suggestionState.piiError
|
|
845
881
|
? `${this.componentId}-motivation-pii-error ${this.componentId}-motivation-counter`
|
|
846
882
|
: `${this.componentId}-motivation-counter`, "aria-invalid": this.suggestionState.piiError ? 'true' : 'false', class: "yv-motivation-input", value: this.suggestionState.motivation, maxLength: 160, rows: 2, ref: (el) => {
|
|
847
883
|
if (el) {
|
|
@@ -1315,7 +1351,7 @@ export class JobSelector {
|
|
|
1315
1351
|
"signature": "(input: JobSelectionInput) => Promise<JobSelectionItem[]>",
|
|
1316
1352
|
"parameters": [{
|
|
1317
1353
|
"name": "input",
|
|
1318
|
-
"type": "string | string[] | JobSelectionItem[]",
|
|
1354
|
+
"type": "string | string[] | (JobSelectionItem | JobSelectionReferenceInput)[]",
|
|
1319
1355
|
"docs": ""
|
|
1320
1356
|
}],
|
|
1321
1357
|
"references": {
|
|
@@ -1339,7 +1375,7 @@ export class JobSelector {
|
|
|
1339
1375
|
"return": "Promise<JobSelectionItem[]>"
|
|
1340
1376
|
},
|
|
1341
1377
|
"docs": {
|
|
1342
|
-
"text": "S\u00E4tter ett programatiskt val och returnerar YV:s normaliserade, rika selection.\nStr\u00E4ngar som matchar Concept ID-formatet tolkas som taxonomi-id:n; \u00F6vriga som fritext.",
|
|
1378
|
+
"text": "S\u00E4tter ett programatiskt val och returnerar YV:s normaliserade, rika selection.\nStr\u00E4ngar som matchar Concept ID-formatet tolkas som taxonomi-id:n; \u00F6vriga som fritext.\nSparade referenser som { id, related: { id } } sl\u00E5s upp i den laddade yrkesdatan.",
|
|
1343
1379
|
"tags": []
|
|
1344
1380
|
}
|
|
1345
1381
|
},
|
|
@@ -40,7 +40,7 @@ export const TaxonomyAdapter = {
|
|
|
40
40
|
};
|
|
41
41
|
},
|
|
42
42
|
/** Maps an internal item to the public event format */
|
|
43
|
-
toPublicSelection(item) {
|
|
43
|
+
toPublicSelection(item, findOccupationLabel) {
|
|
44
44
|
const id = item.id || '';
|
|
45
45
|
const preferredLabel = item.preferred_label || item.rawLabel || '';
|
|
46
46
|
if (!id) {
|
|
@@ -62,12 +62,13 @@ export const TaxonomyAdapter = {
|
|
|
62
62
|
selection.ssyk_code_2012 = item.ssyk_code_2012;
|
|
63
63
|
}
|
|
64
64
|
const occupationId = item.occupation_name_id || item.occupationId;
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
if (item.type === 'job-title' && occupationId) {
|
|
66
|
+
const occupationLabel = item.occupation_name_preferred_label?.trim()
|
|
67
|
+
|| item.occupationLabel?.trim();
|
|
67
68
|
selection.related = {
|
|
68
69
|
type: 'occupation-name',
|
|
69
70
|
id: occupationId,
|
|
70
|
-
preferred_label: occupationLabel,
|
|
71
|
+
preferred_label: occupationLabel || findOccupationLabel?.(occupationId) || occupationId,
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
74
|
return selection;
|