Skip to content

Refactor and harden standalone Apps Script inventory app: config, column mapping, UI, and save flow#3

Open
sunnydesigntech wants to merge 1 commit intomainfrom
codex/complete-dt-qr-inventory-system-tx2g90
Open

Refactor and harden standalone Apps Script inventory app: config, column mapping, UI, and save flow#3
sunnydesigntech wants to merge 1 commit intomainfrom
codex/complete-dt-qr-inventory-system-tx2g90

Conversation

@sunnydesigntech
Copy link
Copy Markdown
Owner

Motivation

  • Convert the script into a single-file, production-ready Apps Script web app with clearer public entry points and diagnostics.
  • Make sheet/column handling and configuration more robust against missing or renamed headers and optional columns.
  • Improve the technician save flow and client/server bridging with stronger validation and nicer UI rendering.

Description

  • Introduced centralized constants and canonical maps (STATUS_OPTIONS, REQUIRED_FIELDS, OPTIONAL_FIELDS, STATUS_CANONICAL_MAP) and replaced ad-hoc aliases with a soft column-mapping system implemented in computeColumnMapSoft_ and getColumnMap_.
  • Reworked configuration helpers and exposure: setAppConfig, getConfigStatus_, getSpreadsheet_, getInventorySheet_, getWebAppBaseUrl_, plus optional admin helpers onOpen and logConfigStatus_ for sheet owners.
  • Rewrote data flows and validations: validateSavePayload_, saveInventoryUpdates now accepts updates with per-row validation and atomic writes, getInventoryRowsForLocation_ and getAllLocations_ read ranges more efficiently and return normalized objects, and refreshQrLinks now bulk-writes link values and validates config first.
  • Rebuilt server-side rendering and client interaction: buildShellHtml_, renderLanding_, renderLocationPage_, renderItemCardsHtml_, clientScript_, CSS (css_) and HTML escaping (escapeHtml_, safeString_) to produce a responsive UI and in-page save handling that updates the DOM with server-rendered item HTML on success.
  • Utility improvements include header normalization (normalizeHeader_), status/quantity normalization (normalizeStatus_, normalizeQty_), optional value handling (getOptionalValue_), and improved statusClass_ mapping.

Testing

  • No automated tests were added or executed for this change.

Codex Task

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 917c307e94

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread code.gs
mainContent,
debugPanel,
' </main>',
' <script>window.__APP_DATA__=' + JSON.stringify(clientData) + ';</script>',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Escape bootstrap JSON before embedding script tag

The page bootstrap currently injects JSON.stringify(clientData) directly into a <script> tag, so a crafted room/loc value containing </script> can break out of the assignment and run arbitrary JavaScript in the viewer’s browser. The previous implementation explicitly escaped < before embedding JSON; this needs to be restored here to prevent script injection via URL parameters or sheet data reflected into clientData.

Useful? React with 👍 / 👎.

Comment thread code.gs
Comment on lines +84 to +85
sheet.getRange(rowNumber, colMap.qty).setValue(qtyValue);
sheet.getRange(rowNumber, colMap.status).setValue(statusValue);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Validate all row updates before mutating sheet

This loop writes each row immediately after validating that one row, which means a later invalid update causes the function to return an error after earlier rows have already been modified. For payloads with multiple updates, this creates partial saves and data inconsistency despite a failed response. Keep validation and mutation in separate passes so no cell writes happen unless the entire payload is valid.

Useful? React with 👍 / 👎.

Comment thread code.gs
Comment on lines +947 to +950
const normalized = normalizeStatus_(status) || safeString_(status).toLowerCase();
if (normalized === 'good') return 'status-good';
if (normalized === 'low stock') return 'status-low';
if (normalized === 'missing') return 'status-missing';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Compare normalized status values consistently

statusClass_ can receive canonical values like Good from normalizeStatus_, but the subsequent checks compare against lowercase literals (good, low stock, etc.), so recognized statuses fall through to status-default and lose their intended visual severity styling. Normalize to one case before the comparisons (or compare against canonical strings) so status pills render correctly.

Useful? React with 👍 / 👎.

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.

1 participant