Skip to content

Commit bb72d95

Browse files
authored
Merge pull request #999 from navikt/bugfix/norwegian-alerttype
Add support for Norwegian alertType
2 parents 96e2ae4 + 5b34da5 commit bb72d95

File tree

3 files changed

+98
-15
lines changed

3 files changed

+98
-15
lines changed

Diff for: mocks/mocks/data/formio-api/custom-components-alert.json

+83-13
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
"allowMultipleMasks": false,
161161
"addons": [],
162162
"alerttype": "info",
163-
"id": "eubi385"
163+
"id": "egjh8ds"
164164
},
165165
{
166166
"content": "New alert 2",
@@ -230,10 +230,10 @@
230230
"properties": {},
231231
"allowMultipleMasks": false,
232232
"addons": [],
233-
"id": "eqnggid"
233+
"id": "e2l94q"
234234
}
235235
],
236-
"id": "e6986x8",
236+
"id": "edyw9u",
237237
"navId": "eoxwudf6"
238238
},
239239
{
@@ -377,7 +377,7 @@
377377
"addons": [],
378378
"tag": "p",
379379
"attrs": [],
380-
"id": "en8bkmr",
380+
"id": "exek0h9",
381381
"navId": "ews0he"
382382
},
383383
{
@@ -450,10 +450,10 @@
450450
"properties": {},
451451
"allowMultipleMasks": false,
452452
"addons": [],
453-
"id": "eq707rc"
453+
"id": "ez8k1r"
454454
}
455455
],
456-
"id": "ef9f9yi",
456+
"id": "ezzl3t2",
457457
"navId": "ek4trcc"
458458
},
459459
{
@@ -469,6 +469,10 @@
469469
"contentForPdf": "",
470470
"key": "alertstripehtml",
471471
"input": false,
472+
"tableView": false,
473+
"label": "",
474+
"type": "alertstripe",
475+
"navId": "ewfphrw",
472476
"placeholder": "",
473477
"prefix": "",
474478
"customClass": "",
@@ -482,9 +486,7 @@
482486
"clearOnHide": true,
483487
"refreshOn": "",
484488
"redrawOn": "",
485-
"tableView": false,
486489
"modalEdit": false,
487-
"label": "",
488490
"dataGridLabel": false,
489491
"labelPosition": "top",
490492
"description": "",
@@ -523,9 +525,77 @@
523525
"properties": {},
524526
"allowMultipleMasks": false,
525527
"addons": [],
528+
"id": "euxgq6"
529+
},
530+
{
531+
"content": "<p>Norwegian alertType</p>",
532+
"isInline": false,
533+
"textDisplay": "form",
534+
"key": "alertstripenorwegian",
535+
"alerttype": "suksess",
536+
"input": false,
537+
"tableView": false,
538+
"label": "",
526539
"type": "alertstripe",
527-
"id": "ew998zs",
528-
"navId": "ewfphrw"
540+
"navId": "ennccwmj",
541+
"id": "e0ju1e3w",
542+
"placeholder": "",
543+
"prefix": "",
544+
"customClass": "",
545+
"suffix": "",
546+
"multiple": false,
547+
"defaultValue": null,
548+
"protected": false,
549+
"unique": false,
550+
"persistent": true,
551+
"hidden": false,
552+
"clearOnHide": true,
553+
"refreshOn": "",
554+
"redrawOn": "",
555+
"modalEdit": false,
556+
"dataGridLabel": false,
557+
"labelPosition": "top",
558+
"description": "",
559+
"errorLabel": "",
560+
"tooltip": "",
561+
"hideLabel": true,
562+
"tabindex": "",
563+
"disabled": false,
564+
"autofocus": false,
565+
"dbIndex": false,
566+
"customDefaultValue": "",
567+
"calculateValue": "",
568+
"calculateServer": false,
569+
"widget": null,
570+
"attributes": {},
571+
"validateOn": "change",
572+
"validate": {
573+
"required": false,
574+
"custom": "",
575+
"customPrivate": false,
576+
"strictDateValidation": false,
577+
"multiple": false,
578+
"unique": false
579+
},
580+
"conditional": {
581+
"show": null,
582+
"when": null,
583+
"eq": ""
584+
},
585+
"overlay": {
586+
"style": "",
587+
"left": "",
588+
"top": "",
589+
"width": "",
590+
"height": ""
591+
},
592+
"allowCalculateOverride": false,
593+
"encrypted": false,
594+
"showCharCount": false,
595+
"showWordCount": false,
596+
"properties": {},
597+
"allowMultipleMasks": false,
598+
"addons": []
529599
}
530600
],
531601
"input": false,
@@ -591,7 +661,7 @@
591661
"lazyLoad": false,
592662
"theme": "default",
593663
"breadcrumb": "default",
594-
"id": "e5ufkb",
664+
"id": "eb7tjff",
595665
"navId": "eccby0b"
596666
}
597667
],
@@ -607,7 +677,7 @@
607677
"key": "9c9b610d-fe35-45e0-bc13-b57f3598d3ee"
608678
}
609679
],
610-
"modified": "2024-01-17T11:52:59.914Z",
680+
"modified": "2024-02-01T12:24:27.728Z",
611681
"modifiedBy": "[email protected]"
612682
},
613683
"project": "628ca77305690db58c974cfd",
@@ -616,6 +686,6 @@
616686
"_vid": 0,
617687
"submissionAccess": [],
618688
"created": "2024-01-15T14:22:34.405Z",
619-
"modified": "2024-01-17T11:53:00.594Z",
689+
"modified": "2024-02-01T12:24:28.223Z",
620690
"machineName": "jvcemxwcpghcqjn:testingalert"
621691
}

Diff for: packages/fyllut/cypress/e2e/custom-react-components.cy.ts

+4
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ describe('Custom react components', () => {
483483
cy.get('.formio-component-alertstripehtml').find('a').should('have.attr', 'href', 'https://www.nav.no/');
484484
});
485485

486+
it('should display alert with norwegian alerttype (suksess instead of success)', () => {
487+
cy.get('.formio-component-alertstripenorwegian').find('.navds-alert--success').contains('Norwegian alertType');
488+
});
489+
486490
// Old alerts (components have input=true on component and label defined)
487491
it('should have marginBottom from input=true of var(--a-spacing-10) which is 2.5rem = 40px', () => {
488492
cy.contains('.formio-component-alertstripe', 'Old alert 1').should('have.css', 'marginBottom', '40px');

Diff for: packages/shared-components/src/formio/components/core/alert/Alert.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@ class Alert extends BaseComponent {
2323
return alertBuilder();
2424
}
2525

26-
getAlertType() {
27-
return (this.component?.alerttype ?? 'info') as AlertProps['variant'];
26+
getAlertType(): AlertProps['variant'] {
27+
const alertTypeMap = {
28+
info: 'info',
29+
suksess: 'success',
30+
advarsel: 'warning',
31+
feil: 'error',
32+
};
33+
34+
if (!this.component?.alerttype) return 'info';
35+
36+
return alertTypeMap[this.component?.alerttype] ?? this.component?.alerttype;
2837
}
2938

3039
getIsinline() {

0 commit comments

Comments
 (0)