Skip to content

Commit 9923a44

Browse files
authored
Merge pull request #81 from cloudadoption/ue-support
hero & form UE fix and updated pre hook to check for lint issues
2 parents 19cee70 + a7f69d2 commit 9923a44

File tree

7 files changed

+94
-34
lines changed

7 files changed

+94
-34
lines changed

.husky/pre-commit.mjs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,46 @@ import { exec } from 'node:child_process';
22

33
const run = (cmd) => new Promise((resolve, reject) => exec(
44
cmd,
5-
(error, stdout, stderr) => {
5+
(error, stdout) => {
66
if (error) reject(error);
7-
if (stderr) reject(new Error(stderr));
8-
resolve(stdout);
7+
else resolve(stdout);
98
},
109
));
1110

1211
const changeset = await run('git diff --cached --name-only --diff-filter=ACMR');
1312
const modifiedFiles = changeset.split('\n').filter(Boolean);
1413

15-
// Check if there are any model files staged
14+
// Auto-fix and lint staged JS files
15+
const jsFiles = modifiedFiles.filter((f) => f.endsWith('.js'));
16+
if (jsFiles.length > 0) {
17+
const fileList = jsFiles.join(' ');
18+
try {
19+
await run(`npx eslint --fix ${fileList}`);
20+
} catch {
21+
// fix ran; lint check below will surface unfixable errors
22+
}
23+
await run(`git add ${fileList}`);
24+
// Fail the commit if unfixable lint errors remain
25+
const output = await run(`npx eslint ${fileList}`);
26+
if (output) console.log(output);
27+
}
28+
29+
// Auto-fix and lint staged CSS files
30+
const cssFiles = modifiedFiles.filter((f) => f.endsWith('.css'));
31+
if (cssFiles.length > 0) {
32+
const fileList = cssFiles.join(' ');
33+
try {
34+
await run(`npx stylelint --fix ${fileList}`);
35+
} catch {
36+
// fix ran; lint check below will surface unfixable errors
37+
}
38+
await run(`git add ${fileList}`);
39+
// Fail the commit if unfixable lint errors remain
40+
const output = await run(`npx stylelint ${fileList}`);
41+
if (output) console.log(output);
42+
}
43+
44+
// Rebuild UE JSON bundles when model files are staged
1645
const modifiedPartials = modifiedFiles.filter((file) => file.match(/^ue\/models\/.*\.json/));
1746
if (modifiedPartials.length > 0) {
1847
const output = await run('npm run build:json --silent');

blocks/form/form.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -746,12 +746,7 @@ export default function decorate(block) {
746746
const data = Array.isArray(raw) ? raw : (raw?.fields && Array.isArray(raw.fields) ? raw.fields : null);
747747
if (!data || !Array.isArray(data)) throw new Error(`No form fields at ${source}`);
748748
const form = buildForm(data, submit);
749-
const configRow = block.querySelector(':scope > div');
750-
if (configRow) {
751-
block.replaceChildren(configRow, form);
752-
} else {
753-
block.replaceChildren(form);
754-
}
749+
block.replaceChildren(form);
755750
block.removeAttribute('style');
756751
} catch (error) {
757752

component-definition.json

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,23 @@
168168
"model": "form",
169169
"plugins": {
170170
"da": {
171-
"name": "form",
172-
"rows": 2,
173-
"columns": 1,
171+
"unsafeHTML": "<div class=\"form\"><div><div><p><a href=\"\"></a></p></div></div><div><div><p><a href=\"\"></a></p></div></div></div>",
174172
"fields": [
175173
{
176-
"name": "source",
177-
"selector": "div:nth-child(1)>div>p"
174+
"name": "url",
175+
"selector": "div:nth-child(1)>div>p>a[href]"
176+
},
177+
{
178+
"name": "urlText",
179+
"selector": "div:nth-child(1)>div>p>a"
178180
},
179181
{
180182
"name": "actionUrl",
181-
"selector": "div:nth-child(2)>div>p"
183+
"selector": "div:nth-child(2)>div>p>a[href]"
184+
},
185+
{
186+
"name": "actionUrlText",
187+
"selector": "div:nth-child(2)>div>p>a"
182188
}
183189
]
184190
}
@@ -216,15 +222,15 @@
216222
"fields": [
217223
{
218224
"name": "image",
219-
"selector": "div:nth-child(1)>div>p>picture>img[src]"
225+
"selector": "div:nth-child(1)>div>picture>img[src]"
220226
},
221227
{
222228
"name": "imageAlt",
223-
"selector": "div:nth-child(1)>div>p>picture>img[alt]"
229+
"selector": "div:nth-child(1)>div>picture>img[alt]"
224230
},
225231
{
226232
"name": "heading",
227-
"selector": "div:nth-child(2)>div>p>h1"
233+
"selector": "div:nth-child(2)>div>h1"
228234
}
229235
]
230236
}

component-models.json

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,30 @@
257257
"id": "form",
258258
"fields": [
259259
{
260-
"component": "richtext",
261-
"name": "source",
260+
"component": "text",
261+
"name": "urlText",
262+
"label": "Form Source URL Text",
263+
"valueType": "string",
264+
"required": true,
265+
"description": "Text to display for the Form Source URL"
266+
},
267+
{
268+
"component": "text",
269+
"name": "url",
262270
"label": "Form Source URL",
263271
"valueType": "string",
264272
"required": true,
265273
"description": "URL to the JSON form definition"
266274
},
267275
{
268-
"component": "richtext",
276+
"component": "text",
277+
"name": "actionUrlText",
278+
"label": "Submit Endpoint Text",
279+
"valueType": "string",
280+
"description": "Text to display for the Submit Endpoint"
281+
},
282+
{
283+
"component": "text",
269284
"name": "actionUrl",
270285
"label": "Submit Endpoint",
271286
"valueType": "string",

ue/models/blocks/form.json

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"model": "form",
77
"plugins": {
88
"da": {
9-
"name": "form",
10-
"rows": 2,
11-
"columns": 1,
9+
"unsafeHTML": "<div class=\"form\"><div><div><p><a href=\"\"></a></p></div></div><div><div><p><a href=\"\"></a></p></div></div></div>",
1210
"fields": [
13-
{ "name": "source", "selector": "div:nth-child(1)>div>p" },
14-
{ "name": "actionUrl", "selector": "div:nth-child(2)>div>p" }
11+
{ "name": "url", "selector": "div:nth-child(1)>div>p>a[href]"},
12+
{ "name": "urlText", "selector": "div:nth-child(1)>div>p>a"},
13+
{ "name": "actionUrl", "selector": "div:nth-child(2)>div>p>a[href]"},
14+
{ "name": "actionUrlText", "selector": "div:nth-child(2)>div>p>a"}
1515
]
1616
}
1717
}
@@ -22,15 +22,30 @@
2222
"id": "form",
2323
"fields": [
2424
{
25-
"component": "richtext",
26-
"name": "source",
25+
"component": "text",
26+
"name": "urlText",
27+
"label": "Form Source URL Text",
28+
"valueType": "string",
29+
"required": true,
30+
"description": "Text to display for the Form Source URL"
31+
},
32+
{
33+
"component": "text",
34+
"name": "url",
2735
"label": "Form Source URL",
2836
"valueType": "string",
2937
"required": true,
3038
"description": "URL to the JSON form definition"
3139
},
3240
{
33-
"component": "richtext",
41+
"component": "text",
42+
"name": "actionUrlText",
43+
"label": "Submit Endpoint Text",
44+
"valueType": "string",
45+
"description": "Text to display for the Submit Endpoint"
46+
},
47+
{
48+
"component": "text",
3449
"name": "actionUrl",
3550
"label": "Submit Endpoint",
3651
"valueType": "string",

ue/models/blocks/hero.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"rows": 2,
1111
"columns": 1,
1212
"fields": [
13-
{ "name": "image", "selector": "div:nth-child(1)>div>p>picture>img[src]" },
14-
{ "name": "imageAlt", "selector": "div:nth-child(1)>div>p>picture>img[alt]" },
15-
{ "name": "heading", "selector": "div:nth-child(2)>div>p>h1" }
13+
{ "name": "image", "selector": "div:nth-child(1)>div>picture>img[src]" },
14+
{ "name": "imageAlt", "selector": "div:nth-child(1)>div>picture>img[alt]" },
15+
{ "name": "heading", "selector": "div:nth-child(2)>div>h1" }
1616
]
1717
}
1818
}

ue/scripts/ue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,4 @@ const setupUEEventHandlers = () => {
116116
export default () => {
117117
setupObservers();
118118
setupUEEventHandlers();
119-
};
119+
};

0 commit comments

Comments
 (0)