Skip to content

Commit 219bd12

Browse files
committed
feat(barcode): adding log level details
1 parent 5c47b3b commit 219bd12

7 files changed

Lines changed: 77 additions & 36 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ export function getProperties(values: BarcodeGeneratorPreviewProps, defaultPrope
9494
hidePropertiesIn(defaultProperties, values, ["customCodeFormat"]);
9595
}
9696

97+
if (!values.allowDownload) {
98+
hidePropertiesIn(defaultProperties, values, [
99+
"downloadButtonCaption",
100+
"downloadButtonAriaLabel",
101+
"downloadFileName",
102+
"buttonPosition"
103+
]);
104+
}
105+
97106
return defaultProperties;
98107
}
99108

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function BarcodeGenerator(props: BarcodeGeneratorContainerProps):
1111
const config = barcodeConfig(props);
1212

1313
if (!config.codeValue) {
14-
return <span>No barcode value provided</span>;
14+
return <span>{props.emptyMessage?.value || "No barcode value provided"}</span>;
1515
}
1616

1717
return (

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
<enumerationValue key="Custom">Custom</enumerationValue>
2323
</enumerationValues>
2424
</property>
25+
<property key="emptyMessage" type="textTemplate" required="false">
26+
<caption>Empty message</caption>
27+
<description />
28+
<translations>
29+
<translation lang="en_US">No barcode value provided</translation>
30+
<translation lang="nl_NL">Geen barcodewaarde opgegeven</translation>
31+
</translations>
32+
</property>
2533
<property key="allowDownload" type="boolean" defaultValue="false">
2634
<caption>Allow download</caption>
2735
<description>Adds a download button</description>
@@ -111,6 +119,17 @@
111119
<description>Space between main barcode and addon (in pixels)</description>
112120
</property>
113121
</propertyGroup>
122+
<propertyGroup caption="Development">
123+
<property key="logLevel" type="enumeration" required="true" defaultValue="None">
124+
<caption>Log Level</caption>
125+
<description>Choose the log level for in the case of failure for generating the barcode. Info will display generic error message on the UI and Debug will gives detailed information on the developer console.</description>
126+
<enumerationValues>
127+
<enumerationValue key="None">None</enumerationValue>
128+
<enumerationValue key="Info">Info</enumerationValue>
129+
<enumerationValue key="Debug">Debug</enumerationValue>
130+
</enumerationValues>
131+
</property>
132+
</propertyGroup>
114133
</propertyGroup>
115134
<propertyGroup caption="Display">
116135
<property key="displayValue" type="boolean" defaultValue="false">

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ export function BarcodeRenderer({ config }: BarcodeRendererProps): ReactElement
1717
if (error) {
1818
return (
1919
<div className="barcode-renderer">
20-
<div className="alert alert-danger" role="alert">
21-
<strong>Unable to generate barcode.</strong> Please check the barcode value and format
22-
configuration.
23-
</div>
20+
{config.logLevel !== "None" && (
21+
<div className="alert alert-danger" role="alert">
22+
<strong>Unable to generate barcode.</strong> Please check the barcode value and format
23+
configuration.
24+
</div>
25+
)}
2426
</div>
2527
);
2628
}

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ interface DownloadButtonConfig {
77
buttonPosition: "top" | "bottom";
88
}
99

10-
/** Configuration for barcode (non-QR) rendering */
11-
export interface BarcodeTypeConfig {
12-
type: "barcode";
10+
type codeType = "barcode" | "qrcode";
11+
12+
export interface CodeBaseTypeConfig<T = codeType> extends Pick<BarcodeGeneratorContainerProps, "logLevel"> {
13+
type: T;
1314
codeValue: string;
15+
margin: number;
16+
downloadButton?: DownloadButtonConfig;
17+
}
18+
19+
/** Configuration for barcode (non-QR) rendering */
20+
export interface BarcodeTypeConfig extends CodeBaseTypeConfig<"barcode"> {
1421
width: number;
1522
height: number;
1623
format: string;
17-
margin: number;
1824
displayValue: boolean;
19-
downloadButton?: DownloadButtonConfig;
2025

2126
// Advanced barcode options
2227
enableEan128: boolean;
@@ -29,14 +34,10 @@ export interface BarcodeTypeConfig {
2934
}
3035

3136
/** Configuration for QR code rendering */
32-
export interface QRCodeTypeConfig {
33-
type: "qrcode";
34-
codeValue: string;
37+
export interface QRCodeTypeConfig extends CodeBaseTypeConfig<"qrcode"> {
3538
size: number;
36-
margin: number;
3739
title: string;
3840
level: QrLevelEnum;
39-
downloadButton?: DownloadButtonConfig;
4041
image?: {
4142
src: string;
4243
x: number | undefined;
@@ -63,15 +64,21 @@ export function barcodeConfig(props: BarcodeGeneratorContainerProps): BarcodeCon
6364
}
6465
: undefined;
6566

67+
const baseConfig: CodeBaseTypeConfig = {
68+
type: format === "QRCode" ? "qrcode" : "barcode",
69+
codeValue,
70+
margin: props.codeMargin ?? 2,
71+
logLevel: props.logLevel,
72+
downloadButton: downloadButtonConfig
73+
};
74+
6675
if (format === "QRCode") {
6776
return {
77+
...baseConfig,
6878
type: "qrcode",
69-
codeValue,
7079
size: props.qrSize ?? 128,
71-
margin: props.qrMargin ?? 2,
7280
title: props.qrTitle ?? "",
7381
level: props.qrLevel ?? "L",
74-
downloadButton: downloadButtonConfig,
7582
image:
7683
props.qrOverlaySrc?.status === "available"
7784
? {
@@ -88,14 +95,12 @@ export function barcodeConfig(props: BarcodeGeneratorContainerProps): BarcodeCon
8895
}
8996

9097
return {
98+
...baseConfig,
9199
type: "barcode",
92-
codeValue,
93100
width: props.codeWidth ?? 128,
94101
height: props.codeHeight ?? 128,
95102
format,
96-
margin: props.codeMargin ?? 2,
97103
displayValue: props.displayValue ?? false,
98-
downloadButton: downloadButtonConfig,
99104

100105
// Advanced barcode options
101106
enableEan128: props.enableEan128 ?? false,

packages/pluggableWidgets/barcode-generator-web/src/hooks/useRenderBarcode.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { BarcodeTypeConfig } from "../config/Barcode.config";
22
import { RefObject, useEffect, useRef, useState } from "react";
33
import { type BarcodeRenderOptions, renderBarcode } from "../utils/barcodeRenderer-utils";
44
import { validateAddonValue, validateBarcodeValue } from "../config/validation";
5+
import { LogLevelEnum } from "../../typings/BarcodeGeneratorProps";
6+
7+
function printError(message: string, logLevel: LogLevelEnum) {
8+
if (logLevel === "Debug") {
9+
console.error(`[Barcode Generator] ${message}`);
10+
}
11+
}
512

613
export const useRenderBarcode = (
714
config: BarcodeTypeConfig
@@ -35,10 +42,10 @@ export const useRenderBarcode = (
3542
if (!validationResult.valid) {
3643
const errorMsg = validationResult.message || "Invalid barcode value";
3744
// Log detailed error for developers
38-
console.error(
39-
`[Barcode Generator] Validation failed for format "${format}":`,
40-
errorMsg,
41-
`\nProvided value: "${value}"`
45+
46+
printError(
47+
`Validation failed for format "${format}": ${errorMsg} \nProvided value: "${value}"`,
48+
config.logLevel
4249
);
4350
setError(true);
4451
return;
@@ -50,10 +57,9 @@ export const useRenderBarcode = (
5057
if (!addonResult.valid) {
5158
const errorMsg = addonResult.message || "Invalid addon value";
5259
// Log detailed error for developers
53-
console.error(
54-
`[Barcode Generator] Addon validation failed for format "${addonFormat}":`,
55-
errorMsg,
56-
`\nProvided addon value: "${addonValue}"`
60+
printError(
61+
`Addon validation failed for format "${addonFormat}": ${errorMsg} \nProvided addon value: "${addonValue}"`,
62+
config.logLevel
5763
);
5864
setError(true);
5965
return;
@@ -82,13 +88,7 @@ export const useRenderBarcode = (
8288
} catch (error) {
8389
const errorMsg = error instanceof Error ? error.message : "Error generating barcode";
8490
// Log detailed error for developers
85-
console.error(
86-
`[Barcode Generator] Rendering failed:`,
87-
errorMsg,
88-
`\nFormat: "${format}"`,
89-
`\nValue: "${value}"`,
90-
error
91-
);
91+
printError(`Rendering failed: ${errorMsg} \nFormat: "${format}" \nValue: "${value}"`, config.logLevel);
9292
setError(true);
9393
}
9494
} else if (!value) {

packages/pluggableWidgets/barcode-generator-web/typings/BarcodeGeneratorProps.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export type CustomCodeFormatEnum = "CODE128" | "EAN13" | "EAN8" | "UPC" | "CODE3
1515

1616
export type AddonFormatEnum = "None" | "EAN5" | "EAN2";
1717

18+
export type LogLevelEnum = "None" | "Info" | "Debug";
19+
1820
export type QrLevelEnum = "L" | "M" | "Q" | "H";
1921

2022
export interface BarcodeGeneratorContainerProps {
@@ -24,6 +26,7 @@ export interface BarcodeGeneratorContainerProps {
2426
tabIndex?: number;
2527
codeValue: DynamicValue<string>;
2628
codeFormat: CodeFormatEnum;
29+
emptyMessage?: DynamicValue<string>;
2730
allowDownload: boolean;
2831
downloadButtonCaption?: DynamicValue<string>;
2932
downloadButtonAriaLabel?: DynamicValue<string>;
@@ -37,6 +40,7 @@ export interface BarcodeGeneratorContainerProps {
3740
addonFormat: AddonFormatEnum;
3841
addonValue: DynamicValue<string>;
3942
addonSpacing: number;
43+
logLevel: LogLevelEnum;
4044
displayValue: boolean;
4145
showAsCard: boolean;
4246
codeWidth: number;
@@ -70,6 +74,7 @@ export interface BarcodeGeneratorPreviewProps {
7074
translate: (text: string) => string;
7175
codeValue: string;
7276
codeFormat: CodeFormatEnum;
77+
emptyMessage: string;
7378
allowDownload: boolean;
7479
downloadButtonCaption: string;
7580
downloadButtonAriaLabel: string;
@@ -83,6 +88,7 @@ export interface BarcodeGeneratorPreviewProps {
8388
addonFormat: AddonFormatEnum;
8489
addonValue: string;
8590
addonSpacing: number | null;
91+
logLevel: LogLevelEnum;
8692
displayValue: boolean;
8793
showAsCard: boolean;
8894
codeWidth: number | null;

0 commit comments

Comments
 (0)