Skip to content

[WC-3448]: Add datamatrix option for Barcode Generation - #2319

Open
samuelreichert wants to merge 16 commits into
mainfrom
WC-3448/add-datamatrix-generation
Open

[WC-3448]: Add datamatrix option for Barcode Generation#2319
samuelreichert wants to merge 16 commits into
mainfrom
WC-3448/add-datamatrix-generation

Conversation

@samuelreichert

Copy link
Copy Markdown
Contributor

Pull request type

New feature (non-breaking change which adds functionality)


Description

@samuelreichert
samuelreichert force-pushed the WC-3448/add-datamatrix-generation branch from 431b188 to d9b57b4 Compare July 10, 2026 15:26
@samuelreichert
samuelreichert marked this pull request as ready for review July 16, 2026 07:40
@samuelreichert
samuelreichert requested a review from a team as a code owner July 16, 2026 07:40
@github-actions

This comment has been minimized.

@samuelreichert
samuelreichert force-pushed the WC-3448/add-datamatrix-generation branch from 312ba29 to f568c62 Compare July 20, 2026 08:01
@github-actions

This comment has been minimized.

Comment thread packages/pluggableWidgets/barcode-generator-web/src/config/validation.ts Outdated
gjulivan
gjulivan previously approved these changes Jul 27, 2026
@github-actions

This comment has been minimized.

@samuelreichert
samuelreichert force-pushed the WC-3448/add-datamatrix-generation branch from 9cc45a5 to db1c6ac Compare August 13, 2026 07:45
@github-actions

This comment has been minimized.

@samuelreichert
samuelreichert force-pushed the WC-3448/add-datamatrix-generation branch from db1c6ac to 8086499 Compare August 13, 2026 08:29
@github-actions

This comment has been minimized.

gjulivan
gjulivan previously approved these changes Aug 14, 2026
iobuhov
iobuhov previously approved these changes Aug 14, 2026

@iobuhov iobuhov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

samuelreichert and others added 13 commits August 18, 2026 11:16
Adds the tree-shakeable bwip-js browser entry, the only maintained
library with native GS1 Data Matrix support, for upcoming Data Matrix
generation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds "Data Matrix" to the top-level barcode format and a new
"Advanced Data Matrix Settings" group (GS1 mode toggle, square/rectangle
shape, size). Regenerates the widget prop typings to match.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds DataMatrixTypeConfig to the BarcodeConfig union with a
format === "DataMatrix" branch in barcodeConfig(), plus a DataMatrix
value check and a loose GS1 Application Identifier syntax validator.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds DataMatrixRenderer as a third render path. Selects the bwip-js
encoder by GS1 mode and shape (datamatrix / gs1datamatrix /
*rectangular), renders inline SVG, and reuses the existing SVG->PNG
download pipeline. Wires the dispatch in BarcodeGenerator and the
download filename prefix for the datamatrix type.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Renders a representative Data Matrix glyph in the Studio Pro page
editor when the Data Matrix format is selected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds config-mapping and validation unit tests plus render tests
asserting encoder selection (plain vs GS1, rectangular) and the
malformed-GS1 error path. Mocks bwip-js and adds the new required
Data Matrix props to the shared test props builder.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Proposal, design, specs, and task checklist for adding Data Matrix
and GS1 Data Matrix generation to the barcode generator widget.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Move the add-datamatrix-generation change folder under
packages/pluggableWidgets/barcode-generator-web/openspec/ instead of the
repo-root openspec/ folder, per AGENTS.md.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
bwip-js SVGs carry only a viewBox, no width/height attributes, so the
rendered element defaulted to intrinsic sizing instead of the
configured size. Derive pixel dimensions from the viewBox and apply
them via inline style.
…class, tighten memo deps

Data Matrix code value comes from a Mendix DynamicValue and reaches the
DOM via dangerouslySetInnerHTML; sanitize the bwip-js SVG output with
DOMPurify before injecting it. Also prefix the preview image class per
widget style convention and destructure encodeDataMatrix's params so the
useMemo dependency list stays exhaustive without a lint suppression.
Data Matrix reused codeMargin, which is documented in pixels, but bwip-js
multiplies paddingwidth/paddingheight by scale — so the Data Matrix margin
is in module units, like qrMargin. A codeMargin of 0 chosen for a 1D barcode
therefore stripped the Data Matrix quiet zone and made the symbol unscannable.

Add dmMargin (module units, default 2) and branch the margin per format.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
samuelreichert and others added 3 commits August 18, 2026 11:26
… format

The Advanced Data Matrix Settings group was never hidden, so it showed for
Barcode, QR Code and Custom. The reverse leaked too: because the existing
conditions enumerated QRCode/CODE128/Custom, selecting Data Matrix still
showed bar width, code height, display value, EAN-128, Mod43 and the EAN
addon properties.

Replace the enumerated format checks with intent-named booleans so adding a
format cannot silently reopen these, and gate check() to validate only the
sizing properties that are visible. Also report QR size problems on qrSize
instead of codeHeight, and validate static GS1 values at design time.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Replace the placeholder body assertion with plain render, GS1 render,
rectangular shape, value re-render and PNG download tests.

These stay dormant: mendix/testProjects has no barcode-generator-web branch
yet, so the e2e script remains stubbed. The spec header lists the page route
and mx-names the test project needs before the runner can be enabled.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Add requirements for the dedicated Data Matrix sizing/quiet zone and for
format-scoped property visibility, resolve the design doc's open question on
sizing props with the bwip-js scaling evidence, and update the task list:
the build now succeeds (~228 KB minified / ~73 KB gzipped for the tree-shaken
Data Matrix encoders) and e2e is written but dormant.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@samuelreichert
samuelreichert dismissed stale reviews from iobuhov and gjulivan via 5607a47 August 18, 2026 09:26
@samuelreichert
samuelreichert force-pushed the WC-3448/add-datamatrix-generation branch from 8086499 to 5607a47 Compare August 18, 2026 09:26
@github-actions

Copy link
Copy Markdown
Contributor

AI Code Review

🔶 Changes requested — one or more medium-severity items must be addressed


What was reviewed

File Change
src/components/DataMatrix.tsx New DataMatrix renderer component using bwip-js
src/components/preview/DataMatrixPreview.tsx Studio Pro editor preview for Data Matrix
src/BarcodeGenerator.tsx Dispatch to DataMatrixRenderer
src/BarcodeGenerator.xml New DataMatrix enum value + DM property group
src/BarcodeGenerator.editorConfig.ts Format-scoped visibility, DM size/margin validation
src/BarcodeGenerator.editorPreview.tsx Preview routing for DataMatrix
src/config/Barcode.config.ts DataMatrixTypeConfig + barcodeConfig() branch
src/config/validation.ts validateBarcodeValue("DataMatrix") + validateGs1DataMatrixValue
src/utils/download-code.ts DataMatrix filename prefix
src/ui/BarcodeGenerator.scss .datamatrix-svg and preview image styles
typings/BarcodeGeneratorProps.d.ts DataMatrix added to CodeFormatEnum, DmShapeEnum, new DM props
src/__tests__/BarcodeGenerator.spec.tsx Unit tests: encoder dispatch, GS1/plain/shape/error
src/__tests__/BarcodeGenerator.editorConfig.spec.ts New: visibility and check() tests for DM format
src/config/__tests__/Barcode.config.spec.ts New: config-mapping tests
src/config/__tests__/validation.spec.ts New: GS1 and plain DM validation tests
e2e/BarcodeGenerator.spec.js Dormant E2E tests covering render/GS1/shape/download
CHANGELOG.md Added Data Matrix + GS1 Data Matrix entry
package.json Added @bwip-js/browser and dompurify

Skipped (out of scope): pnpm-lock.yaml, openspec/changes/ (design artefacts)


Findings

🔶 Medium — E2E beforeEach drops waitForMendixApp without a replacement

File: e2e/BarcodeGenerator.spec.js line 42
Problem: The previous beforeEach called waitForMendixApp(page) after page.goto. The new code removes it and navigates to /p/datamatrix bare. When the tests are activated (the dormant-notice swap from echo to run-e2e ci), Mendix widget rendering will race against the assertions — expect(symbol).toBeVisible() may time out before the runtime has bootstrapped. The E2E guidelines require waitForMendixApp in beforeEach.
Fix:

import { waitForMendixApp } from "@mendix/run-e2e/mendix-helpers";

test.beforeEach(async ({ page }) => {
    await page.goto("/p/datamatrix");
    await waitForMendixApp(page);
});

⚠️ Low — dmMargin is split from the "Advanced Data Matrix Settings" XML group

File: src/BarcodeGenerator.xml lines 195–198
Note: dmGs1Mode, dmShape, and dmSize are all under the <propertyGroup caption="Advanced Data Matrix Settings"> group, but dmMargin lives in the separate Display group. A developer configuring Data Matrix has to hunt across two property panels for related settings. Moving dmMargin inside "Advanced Data Matrix Settings" alongside dmSize would be consistent and match how qrMargin is now hidden when DM is active anyway.


⚠️ Low — QR Code hint text is stale after MAX_2D_BARCODE_STATIC_VALUE_LENGTH change

File: src/BarcodeGenerator.editorConfig.ts line 217
Note: getFormatHint still says "QR Code: any text (max 1200 chars recommended)" but the actual validation threshold for both QR and DataMatrix was unified at MAX_2D_BARCODE_STATIC_VALUE_LENGTH = 2000. The hint text shown to Studio Pro developers should reflect the real limit:

QRCode: "QR Code: any text (max 2000 chars recommended)",

⚠️ Low — DataMatrix SVG has no accessibility label

File: src/components/DataMatrix.tsx lines 115–127
Note: QR codes expose a qrTitle property (rendered as a <title> inside the SVG) so screen readers can announce the content. The Data Matrix renderer injects raw SVG markup via dangerouslySetInnerHTML with no equivalent title or aria-label. This isn't a blocker for this PR (the spec doesn't mention it), but a follow-up issue to add an accessible label would bring DataMatrix to parity with the QR path.


Positives

  • dangerouslySetInnerHTML is correctly guarded with DOMPurify.sanitize using the SVG profile on both the runtime renderer and the editor preview — exactly the right approach for injecting bwip-js output.
  • bwip-js is imported tree-shakeably (datamatrix, drawingSVG named exports; no toSVG() call) as the design doc required; the bundle delta note in tasks.md is a nice transparency touch.
  • The DataMatrixTypeConfig discriminated union slots cleanly into the existing BarcodeConfig type without touching BarcodeTypeConfig or QRCodeTypeConfig.
  • check() correctly scopes sizing validation to the active format — the old bug where QR size errors were reported on codeHeight is also fixed here (property was previously "codeHeight", now correctly "qrSize").
  • Validation is layered sensibly: validateBarcodeValue handles length/charset, validateGs1DataMatrixValue handles AI-structure, and bwip-js is the final encoding authority — the two-stage approach is a good balance of early feedback vs not duplicating encoder logic.
  • Unit test coverage is thorough: config mapping, GS1/plain encoder dispatch, rectangular shape, error-alert visibility, design-time property visibility, and GS1 AI syntax — each tested independently with a clean beforeEach(jest.clearAllMocks).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants