Skip to content

Commit 98b1496

Browse files
committed
fix: lint errors
1 parent 0eedeb9 commit 98b1496

File tree

8 files changed

+303
-90
lines changed

8 files changed

+303
-90
lines changed

packages/pluggableWidgets/barcode-generator-web/src/BarcodeGenerator.editorConfig.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { hidePropertiesIn, hidePropertyIn, Properties } from "@mendix/pluggable-widgets-tools";
22
import { BarcodeGeneratorPreviewProps } from "../typings/BarcodeGeneratorProps";
3+
import { validateAddonValue, validateBarcodeValue } from "./config/validation";
34

45
export type Problem = {
56
property?: string; // key of the property, at which the problem exists
@@ -114,5 +115,42 @@ export function check(_values: BarcodeGeneratorPreviewProps): Problem[] {
114115
});
115116
}
116117

117-
return errors;
118+
// Design-time validation for static barcode value(s)
119+
const valueProblems = validateCodeValues(_values);
120+
return errors.concat(valueProblems);
121+
}
122+
123+
function getActiveFormat(values: BarcodeGeneratorPreviewProps): string {
124+
if (values.codeFormat === "Custom") {
125+
return values.customCodeFormat || "CODE128";
126+
}
127+
128+
return values.codeFormat;
129+
}
130+
131+
function validateCodeValues(values: BarcodeGeneratorPreviewProps): Problem[] {
132+
const problems: Problem[] = [];
133+
const val = values.codeValue ?? "";
134+
const addon = values.addonValue ?? "";
135+
const format = getActiveFormat(values);
136+
137+
// Only validate static (design-time) values — if empty, skip (user may bind dynamically)
138+
if (!val) {
139+
// still validate addon if present
140+
} else {
141+
const result = validateBarcodeValue(format, val);
142+
if (!result.valid) {
143+
const msg = result.message || "Invalid barcode value for selected format.";
144+
problems.push({ property: "codeValue", severity: "warning", message: msg });
145+
}
146+
}
147+
148+
// Validate addon value if visible
149+
const addonResult = validateAddonValue(values.addonFormat, addon);
150+
if (!addonResult.valid) {
151+
const msg = addonResult.message || "Invalid addon value.";
152+
problems.push({ property: "addonValue", severity: "warning", message: msg });
153+
}
154+
155+
return problems;
118156
}

packages/pluggableWidgets/barcode-generator-web/src/BarcodeGenerator.xml

Lines changed: 88 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@
2424
<enumerationValue key="Custom">Custom</enumerationValue>
2525
</enumerationValues>
2626
</property>
27+
<property key="allowDownload" type="boolean" defaultValue="false">
28+
<caption>Allow download</caption>
29+
<description>Adds a download button</description>
30+
</property>
31+
<property key="downloadAriaLabel" type="string" required="false">
32+
<caption>Button aria-label</caption>
33+
<description />
34+
</property>
35+
</propertyGroup>
36+
</propertyGroup>
37+
<propertyGroup caption="Advanced">
38+
<propertyGroup caption="Advanced Barcode Settings">
2739
<property key="customCodeFormat" type="enumeration" required="true" defaultValue="CODE128">
2840
<caption>Custom Format</caption>
2941
<description>Choose between barcode types format</description>
@@ -56,10 +68,6 @@
5668
<caption>Mod43</caption>
5769
<description>For code 39 if used with modulo 43 check digit</description>
5870
</property>
59-
<property key="allowDownload" type="boolean" defaultValue="false">
60-
<caption>Allow download</caption>
61-
<description>Adds a download button</description>
62-
</property>
6371
</propertyGroup>
6472
<propertyGroup caption="EAN Addons">
6573
<property key="addonFormat" type="enumeration" required="true" defaultValue="None">
@@ -83,82 +91,82 @@
8391
<description>Space between main barcode and addon (in pixels)</description>
8492
</property>
8593
</propertyGroup>
86-
<propertyGroup caption="Display">
87-
<property key="displayValue" type="boolean" defaultValue="false">
88-
<caption>Display value</caption>
89-
<description>Display the value below the code</description>
90-
</property>
91-
<property key="codeWidth" type="integer" required="true" defaultValue="2">
92-
<caption>Bar width</caption>
93-
<description>Width of a single bar</description>
94-
</property>
95-
<property key="codeHeight" type="integer" required="true" defaultValue="200">
96-
<caption>Code height</caption>
97-
<description>Height of the barcode</description>
98-
</property>
99-
<property key="codeMargin" type="integer" required="true" defaultValue="2">
100-
<caption>Margin size</caption>
101-
<description>In pixels</description>
102-
</property>
103-
<property key="qrSize" type="integer" required="true" defaultValue="128">
104-
<caption>QR Size</caption>
105-
<description>The size of the QR box</description>
106-
</property>
107-
<property key="qrMargin" type="integer" required="true" defaultValue="2">
108-
<caption>Margin size</caption>
109-
<description />
110-
</property>
111-
<property key="qrTitle" type="string" required="true">
112-
<caption>Title</caption>
113-
<description>Used for accessibility reasons</description>
114-
</property>
115-
<property key="qrLevel" type="enumeration" required="true" defaultValue="L">
116-
<caption>Level</caption>
117-
<description>The Error Correction Level to use</description>
118-
<enumerationValues>
119-
<enumerationValue key="L">L</enumerationValue>
120-
<enumerationValue key="M">M</enumerationValue>
121-
<enumerationValue key="Q">Q</enumerationValue>
122-
<enumerationValue key="H">H</enumerationValue>
123-
</enumerationValues>
124-
</property>
125-
<property key="qrImage" type="boolean" required="true" defaultValue="false">
126-
<caption>Image</caption>
127-
<description>Include an image on top the QR code</description>
128-
</property>
129-
<property key="qrImageSrc" type="image" required="true">
130-
<caption>Image source</caption>
131-
<description>URL or path to the image to display on the QR code</description>
132-
</property>
133-
<property key="qrImageCenter" type="boolean" required="true" defaultValue="true">
134-
<caption>Center image</caption>
135-
<description>Center the image in the QR code</description>
136-
</property>
137-
<property key="qrImageX" type="integer" required="true" defaultValue="0">
138-
<caption>Image X position</caption>
139-
<description>Horizontal position of the image</description>
140-
</property>
141-
<property key="qrImageY" type="integer" required="true" defaultValue="0">
142-
<caption>Image Y position</caption>
143-
<description>Vertical position of the image</description>
144-
</property>
145-
<property key="qrImageHeight" type="integer" required="true" defaultValue="24">
146-
<caption>Image height</caption>
147-
<description>Height of the image in pixels</description>
148-
</property>
149-
<property key="qrImageWidth" type="integer" required="true" defaultValue="24">
150-
<caption>Image width</caption>
151-
<description>Width of the image in pixels</description>
152-
</property>
153-
<property key="qrImageOpacity" type="decimal" required="true" defaultValue="1">
154-
<caption>Image opacity</caption>
155-
<description>Opacity of the image (0.0 to 1.0)</description>
156-
</property>
157-
<property key="qrImageExcavate" type="boolean" required="true" defaultValue="true">
158-
<caption>Excavate background</caption>
159-
<description>Remove QR code dots behind the image</description>
160-
</property>
161-
</propertyGroup>
94+
</propertyGroup>
95+
<propertyGroup caption="Display">
96+
<property key="displayValue" type="boolean" defaultValue="false">
97+
<caption>Display value</caption>
98+
<description>Display the value below the code</description>
99+
</property>
100+
<property key="codeWidth" type="integer" required="true" defaultValue="2">
101+
<caption>Bar width</caption>
102+
<description>Width of a single bar</description>
103+
</property>
104+
<property key="codeHeight" type="integer" required="true" defaultValue="200">
105+
<caption>Code height</caption>
106+
<description>Height of the barcode</description>
107+
</property>
108+
<property key="codeMargin" type="integer" required="true" defaultValue="2">
109+
<caption>Margin size</caption>
110+
<description>In pixels</description>
111+
</property>
112+
<property key="qrSize" type="integer" required="true" defaultValue="128">
113+
<caption>QR Size</caption>
114+
<description>The size of the QR box</description>
115+
</property>
116+
<property key="qrMargin" type="integer" required="true" defaultValue="2">
117+
<caption>Margin size</caption>
118+
<description />
119+
</property>
120+
<property key="qrTitle" type="string" required="true">
121+
<caption>Title</caption>
122+
<description>Used for accessibility reasons</description>
123+
</property>
124+
<property key="qrLevel" type="enumeration" required="true" defaultValue="L">
125+
<caption>Level</caption>
126+
<description>The Error Correction Level to use</description>
127+
<enumerationValues>
128+
<enumerationValue key="L">L</enumerationValue>
129+
<enumerationValue key="M">M</enumerationValue>
130+
<enumerationValue key="Q">Q</enumerationValue>
131+
<enumerationValue key="H">H</enumerationValue>
132+
</enumerationValues>
133+
</property>
134+
<property key="qrImage" type="boolean" required="true" defaultValue="false">
135+
<caption>Image</caption>
136+
<description>Include an image on top the QR code</description>
137+
</property>
138+
<property key="qrImageSrc" type="image" required="true">
139+
<caption>Image source</caption>
140+
<description>URL or path to the image to display on the QR code</description>
141+
</property>
142+
<property key="qrImageCenter" type="boolean" required="true" defaultValue="true">
143+
<caption>Center image</caption>
144+
<description>Center the image in the QR code</description>
145+
</property>
146+
<property key="qrImageX" type="integer" required="true" defaultValue="0">
147+
<caption>Image X position</caption>
148+
<description>Horizontal position of the image</description>
149+
</property>
150+
<property key="qrImageY" type="integer" required="true" defaultValue="0">
151+
<caption>Image Y position</caption>
152+
<description>Vertical position of the image</description>
153+
</property>
154+
<property key="qrImageHeight" type="integer" required="true" defaultValue="24">
155+
<caption>Image height</caption>
156+
<description>Height of the image in pixels</description>
157+
</property>
158+
<property key="qrImageWidth" type="integer" required="true" defaultValue="24">
159+
<caption>Image width</caption>
160+
<description>Width of the image in pixels</description>
161+
</property>
162+
<property key="qrImageOpacity" type="decimal" required="true" defaultValue="1">
163+
<caption>Image opacity</caption>
164+
<description>Opacity of the image (0.0 to 1.0)</description>
165+
</property>
166+
<property key="qrImageExcavate" type="boolean" required="true" defaultValue="true">
167+
<caption>Excavate background</caption>
168+
<description>Remove QR code dots behind the image</description>
169+
</property>
162170
</propertyGroup>
163171
</properties>
164172
</widget>

packages/pluggableWidgets/barcode-generator-web/src/components/Barcode.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import { Fragment } from "react";
66

77
export const BarcodeRenderer = () => {
88
const ref = useRenderBarcode();
9-
const { allowDownload } = useBarcodeConfig();
9+
const { allowDownload, downloadAriaLabel } = useBarcodeConfig();
1010
const { downloadBarcode } = useDownloadBarcode({ ref });
1111

1212
return (
1313
<Fragment>
1414
<svg ref={ref} />
1515
{allowDownload && (
16-
<button className="btn btn-default" onClick={downloadBarcode}>
16+
<button className="btn btn-default" aria-label={downloadAriaLabel} onClick={downloadBarcode}>
1717
Download barcode
1818
</button>
1919
)}

packages/pluggableWidgets/barcode-generator-web/src/components/QRCode.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export const QRCodeRenderer = () => {
2020
qrImageHeight: imageHeight,
2121
qrImageWidth: imageWidth,
2222
qrImageOpacity: imageOpacity,
23-
qrImageExcavate: imageExcavate
23+
qrImageExcavate: imageExcavate,
24+
downloadAriaLabel: downloadAriaLabel
2425
} = useBarcodeConfig();
2526
const imageSettings = imageSrc
2627
? {
@@ -46,7 +47,12 @@ export const QRCodeRenderer = () => {
4647
imageSettings={imageSettings}
4748
/>
4849
{allowDownload && (
49-
<button type="button" onClick={downloadQrCode} className="btn btn-default">
50+
<button
51+
type="button"
52+
aria-label={downloadAriaLabel}
53+
onClick={downloadQrCode}
54+
className="btn btn-default"
55+
>
5056
Download QR Code
5157
</button>
5258
)}

packages/pluggableWidgets/barcode-generator-web/src/config/Barcode.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface BarcodeConfig {
1111
margin: number;
1212
displayValue: boolean;
1313
allowDownload: boolean;
14+
downloadAriaLabel?: string;
1415

1516
// Advanced barcode options
1617
enableEan128: boolean;
@@ -51,6 +52,7 @@ export function barcodeConfig(props: BarcodeGeneratorContainerProps): BarcodeCon
5152
margin: props.codeMargin ?? 2,
5253
displayValue: props.displayValue ?? false,
5354
allowDownload: props.allowDownload ?? false,
55+
downloadAriaLabel: props.downloadAriaLabel,
5456

5557
// Advanced barcode options
5658
enableEan128: props.enableEan128 ?? false,

0 commit comments

Comments
 (0)