Skip to content

Commit a123f3c

Browse files
committed
Merge remote-tracking branch 'origin/master' into tech/typescript-i-bygger
2 parents a5274bb + d7aced0 commit a123f3c

31 files changed

+1072
-24217
lines changed

.eslintignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
src/template/*
1+
**/src/template/**
2+
**/dist/**
3+
**/node_modules/**

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ og disse dataene vil så deployes sammen med fyllut.
1616
| yarn build | bygger react-applikasjonene, ikke nødvendig for lokal utvikling (bruk start og watch) |
1717
| yarn test | kjører alle tester |
1818
| yarn clean | sletter node_modules / dist / build / coverage for alle pakker i monorepoet |
19+
| yarn lint | se etter problemer i koden |
1920

2021
## Bygge docker-image for testing av produksjonsbygg lokalt
2122

package.json

+14-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,22 @@
1717
"start:bygger": "lerna run --scope @navikt/bygger --scope @navikt/bygger-backend start",
1818
"start:fyllut": "lerna run --scope @navikt/fyllut-frontend --scope @navikt/fyllut-backend start",
1919
"test": "cross-env-shell CI=true lerna run --stream test",
20-
"test:coverage": "cross-env-shell CI=true lerna run --stream test:coverage"
20+
"test:coverage": "cross-env-shell CI=true lerna run --stream test:coverage",
21+
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs"
2122
},
2223
"devDependencies": {
2324
"@material-ui/styles": "4.10.0",
25+
"@typescript-eslint/eslint-plugin": "^4.0.0",
26+
"@typescript-eslint/parser": "^4.0.0",
27+
"babel-eslint": "^10.0.0",
2428
"cross-env": "^7.0.2",
29+
"eslint": "^6.6.0",
30+
"eslint-config-react-app": "^6.0.0",
31+
"eslint-plugin-flowtype": "^5.2.0",
32+
"eslint-plugin-import": "^2.22.0",
33+
"eslint-plugin-jsx-a11y": "^6.3.1",
34+
"eslint-plugin-react": "^7.20.3",
35+
"eslint-plugin-react-hooks": "^4.0.8",
2536
"formiojs": "4.14.0-rc.18",
2637
"husky": "^3.1.0",
2738
"lerna": "^4.0.0",
@@ -32,7 +43,8 @@
3243
"react": "^16.13.1",
3344
"react-dom": "^16.13.1",
3445
"react-router-dom": "^5.2.0",
35-
"rimraf": "^3.0.2"
46+
"rimraf": "^3.0.2",
47+
"typescript": "^4.4.2"
3648
},
3749
"engines": {
3850
"node": ">=14.15.0 <=14.17.0"

packages/bygger/package-lock.json

-23,704
This file was deleted.

packages/bygger/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@
6969
"test:coverage": "craco test --coverage --env=jest-environment-jsdom-sixteen --transformIgnorePatterns \"node_modules/(?!@navikt/ds-icons)/\"",
7070
"eject": "craco eject"
7171
},
72-
"eslintConfig": {
73-
"extends": "react-app"
74-
},
7572
"engines": {
7673
"node": ">= 14"
7774
},

packages/bygger/src/Forms/EditFormPage.jsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SkjemaVisningSelect } from "../components/FormMetadataEditor";
22
import NavFormBuilder from "../components/NavFormBuilder";
33
import React, { useContext } from "react";
4-
import { FormBuilderOptions } from "@navikt/skjemadigitalisering-shared-components";
4+
import { FormBuilderOptions, useAppConfig } from "@navikt/skjemadigitalisering-shared-components";
55
import { Hovedknapp, Knapp } from "nav-frontend-knapper";
66
import { AppLayoutWithContext } from "../components/AppLayout";
77
import ConfirmPublishModal from "./ConfirmPublishModal";
@@ -12,7 +12,6 @@ import Column from "../components/layout/Column";
1212
import makeStyles from "@material-ui/styles/makeStyles/makeStyles";
1313
import { Normaltekst, Undertittel } from "nav-frontend-typografi";
1414
import { Link } from "react-router-dom";
15-
import { useAppConfig } from "@navikt/skjemadigitalisering-shared-components";
1615
import ActionRow from "../components/layout/ActionRow";
1716
import { UserAlerterContext } from "../userAlerting";
1817

packages/bygger/src/Forms/FormSettingsPage.jsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ import { Link } from "react-router-dom";
1111
import Row from "../components/layout/Row";
1212
import Column from "../components/layout/Column";
1313
import { UserAlerterContext } from "../userAlerting";
14+
import { Undertittel } from "nav-frontend-typografi";
1415

1516
const useStyles = makeStyles({
1617
mainCol: {
1718
gridColumn: "2 / 3",
1819
},
20+
titleRow: {
21+
height: "79px",
22+
},
1923
});
2024

2125
export function FormSettingsPage({ editFormUrl, testFormUrl, form, onSave, onChange, onLogout, onPublish }) {
@@ -27,7 +31,7 @@ export function FormSettingsPage({ editFormUrl, testFormUrl, form, onSave, onCha
2731
const styles = useStyles();
2832

2933
return (
30-
<AppLayoutWithContext navBarProps={{ title: title, visSkjemaliste: true, logout: onLogout }}>
34+
<AppLayoutWithContext navBarProps={{ title: "Skjemainnstillinger", visSkjemaliste: true, logout: onLogout }}>
3135
<AmplitudeProvider form={form} shouldUseAmplitude={true}>
3236
<ActionRow>
3337
<Link className="knapp" to={editFormUrl}>
@@ -37,9 +41,13 @@ export function FormSettingsPage({ editFormUrl, testFormUrl, form, onSave, onCha
3741
Forhåndsvis
3842
</Link>
3943
</ActionRow>
44+
<Row className={styles.titleRow}>
45+
<Column className={styles.mainCol}>
46+
<Undertittel tag="h1">{title}</Undertittel>
47+
</Column>
48+
</Row>
4049
<Row>
4150
<Column className={styles.mainCol}>
42-
<h1 className="typo-sidetittel">{title}</h1>
4351
<FormMetadataEditor form={form} onChange={onChange} />
4452
</Column>
4553
<Column>

packages/bygger/src/Forms/learnFormio.test.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import React from "react";
21
import * as formiojs from "formiojs";
32
import waitForExpect from "wait-for-expect";
43
import columnsForm from "../../example_data/columnsForm.json";
5-
import { render, screen } from "@testing-library/react";
6-
import NavFormBuilder from "../components/NavFormBuilder";
7-
import {FakeBackend} from "../fakeBackend/FakeBackend";
8-
// import { queryBySelector } from "@testing-library/dom"
9-
10-
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
114

125
describe("Formio.js replica", () => {
136
let builderElement;
@@ -68,10 +61,10 @@ describe("Formio.js replica", () => {
6861
};
6962

7063
const saveComponent = () => {
71-
const click = new MouseEvent('click', {
64+
const click = new MouseEvent("click", {
7265
view: window,
7366
bubbles: true,
74-
cancelable: true
67+
cancelable: true,
7568
});
7669

7770
const saveBtn = builder.instance.componentEdit.querySelector('[ref="saveButton"]');

packages/bygger/src/components/NavBar.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const useStyles = makeStyles({
1010
navBar: {
1111
backgroundColor: navCssVariables.navDypBlaLighten40,
1212
color: "#fff",
13-
padding: "1.5rem 0",
13+
padding: "1.5rem 2rem",
1414
},
1515
title: {
1616
textAlign: "center",

packages/bygger/src/components/NavFormBuilder.test.jsx

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ describe("NavFormBuilder", () => {
5656
});
5757

5858
describe("Formio.js focused tests", () => {
59-
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
6059
const buildComponent = (builder, type, container) => {
6160
// Get the builder sidebar component.
6261
const webformBuilder = builder.instance;
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1-
import connect from 'connect';
2-
import quip from './ourQuip.js';
3-
import bodyParser from 'body-parser';
4-
import {dispatcherWithBackend} from "./fakeWebApp.js";
5-
import {FakeBackend} from "./FakeBackend.js";
6-
7-
const rewriteUrl = (req, res, next) => {
8-
req.url = req.url.replace('/backend/api', '');
9-
next();
10-
};
1+
import connect from "connect";
2+
import quip from "./ourQuip.js";
3+
import bodyParser from "body-parser";
4+
import { dispatcherWithBackend } from "./fakeWebApp.js";
5+
import { FakeBackend } from "./FakeBackend.js";
116

127
const fallback = (req, res) => {
13-
console.log('slem request', `${req.method} ${req.url}`);
14-
res.notFound('Not found');
8+
console.log("slem request", `${req.method} ${req.url}`);
9+
res.notFound("Not found");
1510
};
1611

1712
const backend = new FakeBackend();
1813
const dispatcher = dispatcherWithBackend(backend);
1914

2015
const server = connect();
21-
server.use(bodyParser.text({limit: '5mb', type: '*/*'}));
16+
server.use(bodyParser.text({ limit: "5mb", type: "*/*" }));
2217
server.use(quip);
23-
// server.use(rewriteUrl);
2418
server.use(dispatcher);
2519
server.use(fallback);
26-
console.log('about to listen to 4000');
20+
console.log("about to listen to 4000");
2721
server.listen(4000);

packages/bygger/src/fakeBackend/ourQuip.js

+58-50
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* See README for examples.
44
*/
55

6-
export default function (req, res, next) {
6+
function ourQuip(req, res, next) {
77
if (arguments.length === 1) {
88
res = req;
99
req = null;
@@ -16,33 +16,43 @@ export default function (req, res, next) {
1616
///// private helper methods /////
1717
var withStatus = function (code) {
1818
return function (data) {
19-
return data ? res.status(code).send(data):
20-
res.status(code);
19+
return data ? res.status(code).send(data) : res.status(code);
2120
};
2221
};
2322
var redirection = function (code, message) {
2423
return function (loc) {
2524
res._quip_headers.Location = loc;
26-
return res.status(code).send(
27-
'<html>' +
28-
'<head>' +
29-
'<title>' + code + ' ' + message + '</title>' +
30-
'</head>' +
31-
'<body>' +
32-
'<p>' +
33-
message + ': ' +
34-
'<a href="' + loc + '">' + loc + '</a>' +
35-
'</p>' +
36-
'</body>' +
37-
'</html>'
38-
);
25+
return res
26+
.status(code)
27+
.send(
28+
"<html>" +
29+
"<head>" +
30+
"<title>" +
31+
code +
32+
" " +
33+
message +
34+
"</title>" +
35+
"</head>" +
36+
"<body>" +
37+
"<p>" +
38+
message +
39+
": " +
40+
'<a href="' +
41+
loc +
42+
'">' +
43+
loc +
44+
"</a>" +
45+
"</p>" +
46+
"</body>" +
47+
"</html>"
48+
);
3949
};
40-
}
50+
};
4151
var withType = function (type) {
4252
return function (data) {
43-
res.headers({'Content-Type': type});
44-
return data ? res.send(data): res;
45-
}
53+
res.headers({ "Content-Type": type });
54+
return data ? res.send(data) : res;
55+
};
4656
};
4757

4858
///// exported methods /////
@@ -64,8 +74,8 @@ export default function (req, res, next) {
6474
res.noContent = withStatus(204);
6575

6676
// redirection
67-
res.moved = redirection(301, 'Moved Permanently');
68-
res.redirect = redirection(302, 'Found');
77+
res.moved = redirection(301, "Moved Permanently");
78+
res.redirect = redirection(302, "Found");
6979
res.found = res.redirect;
7080
res.notModified = function () {
7181
res.status(304).send();
@@ -81,32 +91,32 @@ export default function (req, res, next) {
8191
res.gone = withStatus(410);
8292

8393
// server error
84-
res.error = withStatus(500, 'error');
94+
res.error = withStatus(500, "error");
8595

8696
// mime types
87-
res.text = withType('text/plain');
97+
res.text = withType("text/plain");
8898
res.plain = res.text;
89-
res.html = withType('text/html');
90-
res.xhtml = withType('application/xhtml+xml');
91-
res.css = withType('text/css');
92-
res.xml = withType('text/xml');
93-
res.atom = withType('application/atom+xml');
94-
res.rss = withType('application/rss+xml');
95-
res.javascript = withType('application/javascript');
96-
res.json = withType('application/json');
99+
res.html = withType("text/html");
100+
res.xhtml = withType("application/xhtml+xml");
101+
res.css = withType("text/css");
102+
res.xml = withType("text/xml");
103+
res.atom = withType("application/atom+xml");
104+
res.rss = withType("application/rss+xml");
105+
res.javascript = withType("application/javascript");
106+
res.json = withType("application/json");
97107

98108
// custom mime type
99109
res.mime = function (type, data) {
100-
res.headers({'Content-Type': type});
101-
return data ? res.send(data): res;
110+
res.headers({ "Content-Type": type });
111+
return data ? res.send(data) : res;
102112
};
103113

104114
// JSONP is a special case that should always respond with a 200,
105115
// there is no reliable way to receive a JSONP result on the
106116
// client-side if the HTTP status-code is not 200!
107117
res.jsonp = function (callback, data) {
108-
if(typeof data == 'object') data = JSON.stringify(data);
109-
data = callback + '(' + data + ');';
118+
if (typeof data == "object") data = JSON.stringify(data);
119+
data = callback + "(" + data + ");";
110120
return res.ok().javascript(data);
111121
};
112122

@@ -122,28 +132,26 @@ export default function (req, res, next) {
122132
res.send = function (data) {
123133
if (data) {
124134
if (Buffer.isBuffer(data)) {
125-
res._quip_headers['Content-Length'] = data.length
126-
}
127-
else {
128-
if (typeof data === 'object') {
135+
res._quip_headers["Content-Length"] = data.length;
136+
} else {
137+
if (typeof data === "object") {
129138
// assume data is JSON if passed an object (not a buffer)
130-
if (!res._quip_headers['Content-Type']) {
131-
res._quip_headers['Content-Type'] = 'application/json';
139+
if (!res._quip_headers["Content-Type"]) {
140+
res._quip_headers["Content-Type"] = "application/json";
132141
}
133142
data = JSON.stringify(data);
134143
}
135-
res._quip_headers['Content-Length'] = Buffer.byteLength(data);
144+
res._quip_headers["Content-Length"] = Buffer.byteLength(data);
136145
}
137146
}
138-
if (!res._quip_headers['Content-Type']) {
147+
if (!res._quip_headers["Content-Type"]) {
139148
// assume HTML if data is a string and content type not set
140-
res._quip_headers['Content-Type'] = 'text/html';
149+
res._quip_headers["Content-Type"] = "text/html";
141150
}
142151

143152
if (data) {
144153
res.write(data);
145-
}
146-
else {
154+
} else {
147155
res.writeHead(res._quip_status, res._quip_headers);
148156
}
149157
res.end();
@@ -153,10 +161,10 @@ export default function (req, res, next) {
153161
if (next) {
154162
// pass updated response object onto next connect middleware
155163
next(null, res);
156-
}
157-
else {
164+
} else {
158165
// called directly, return updated response object
159166
return res;
160167
}
168+
}
161169

162-
};
170+
export default ourQuip;

packages/bygger/src/featureToggles.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
export default {
1+
const featureToggles = {
22
enableTranslations: false,
33
};
4+
export default featureToggles;

0 commit comments

Comments
 (0)