Skip to content

feat(tree,collections,firestore): tree field add/delete and admin timestamp fix - #22

Merged
flowdeskadmin merged 11 commits into
Flowdesktech:masterfrom
EMTumariscal:develop
Sep 23, 2026
Merged

flowdeskadmin merged 11 commits into
Flowdesktech:masterfrom
EMTumariscal:develop

Conversation

@EMTumariscal

Copy link
Copy Markdown
Contributor

Description

Consolidated PR from develop to upstream/master that supersedes #19, #20 and #21 (to be closed). It bundles the three already-reviewed changes into a single integration branch, plus the build-fix commit needed to merge them together.

1/3 — fix(firestore): convert app-shaped timestamps and geopoints on admin writes (was #19)

Fixes a data-corruption bug on the firebase-admin (service-account) write path: updating any document containing Firestore Timestamp (or GeoPoint) fields rewrote those fields as plain maps instead of native values.

  • Adds toFirestoreAdminValue(value, { Timestamp, GeoPoint, FieldValue }) to electron/utils/firestoreHelpers.js: recursive, non-mutating converter (Date → Timestamp, { _seconds, _nanoseconds } / { seconds, nanoseconds|nanos } → Timestamp, { _latitude, _longitude } / { latitude, longitude } → GeoPoint, recursion through arrays/maps, FieldValue sentinels preserved, no firebase-admin import).
  • Applies it in the four Admin SDK write handlers in electron/controllers/firestoreController.js: firestore:createDocument, firestore:setDocument, firestore:updateDocument, firestore:importDocuments.
  • REST/Google path and all read paths unchanged.

2/3 — feat(collections): allow deleting fields from documents in Tree view (was #20)

  • documentService.prepareDeleteData(doc, fieldPath): dot-notation removal, returns a new object (never mutates), no-op on missing/non-Map intermediates, never throws.
  • Tree view affordance: document-relative fieldPath through TreeNodeRow/TreeContext, hover delete icon (fixed 20px slot, no row shift), confirmation dialog with document id + field path, handleDeleteField in CollectionTab reusing the existing updateDocument thunk.
  • Array indices excluded (splice ≠ field removal); a Map/Array node itself remains deletable as one field.

3/3 — feat(tree): add type-aware field creation in Tree view (was #21)

  • Type-aware Add Field dialog (name + type + value input per type: String, Integer, Number, Boolean, Null, Timestamp, GeoPoint, Array, Map, Reference) opened from a hover Add (+) button on documents and nested Maps.
  • Plumbing: documentService.prepareAddData (dot-path set, duplicate/empty/dots/Array rejection, structuredClone with JSON fallback) → TreeContext.onAddField → CollectionTab → updateDocument thunk.
  • Hardening included: nested parentPath derivation fix, invalid-date (NaN) guard in AddFieldDialog, JSON-clone lossiness fix.

Integration — fix(tree): resolve parse errors blocking vite build

Merges the two Tree features without breaking the build: closes prepareDeleteData before prepareAddData in documentService, merges duplicated TableRow openers in TreeNodeRow, drops the unused documentService import in CollectionTab.

Type of Change

  • Feature (field creation + field deletion in Tree view)
  • Bug fix (admin timestamp/geopoint writes + build parse errors)
  • Docs
  • Refactor

AI Code Generation

This consolidated PR was assembled by an AI coding agent (OpenCode) under human direction. The human requested closing #19/#20/#21 and opening this single PR from develop, reviewed the diff, and authorized the push. The underlying changes were AI-assisted as disclosed in each superseded PR; no Co-Authored-By or AI attribution was added to any commit.

Related Issue

Supersedes #19, #20, #21. No other open/closed upstream issue covers these changes (as documented in each original PR).

Technical Context

  • Renderer shape: Firestore Timestamp is { _seconds, _nanoseconds }, GeoPoint is { _latitude, _longitude } (electron/utils/firestoreHelpers.js); Admin SDK v14 serializes unrecognized plain objects as mapValue — hence the converter (1/3).
  • Persistence for (2/3) and (3/3) reuses updateDocument (src/features/collections/store/collectionSlice.ts) which writes the whole document object, so omitting/adding a key works on both google and service-account auth without FieldValue.delete plumbing.
  • Deletion/editing live in src/features/collections/services/documentService.ts (prepareDeleteData, prepareAddData); UI in TreeNodeRow.tsx, TreeContext.ts, AddFieldDialog.tsx, CollectionTab.tsx, TreeView.tsx.
  • Firebase data types: https://firebase.google.com/docs/firestore/manage-data/data-types

Test Environment

  • Hardware/OS: x86_64 Linux dev machine.
  • Toolchain: Node.js + pnpm (repo-pinned), Electron app Firestudio.
  • Channels used: local pnpm suite (same commands .github/workflows/ci.yml runs on pull_request).

Evidence

The 3 functionalities were tested together on the consolidated develop branch and all work correctly:

$ pnpm run test
Test Files  14 passed (14)
     Tests  111 passed (111)

$ pnpm run typecheck   # tsc -p tsconfig.json --noEmit → clean
$ pnpm run format:check  # All matched files use Prettier code style!

Breakdown of coverage (union of the three PRs):

  • electron/utils/firestoreHelpers.test.js: Date, both timestamp shapes, both geopoint shapes, nested array/map, primitive passthrough, FieldValue sentinel preservation, non-mutation.
  • electron/controllers/firestoreController.test.js: createDocument, setDocument, updateDocument, importDocuments convert app-shaped values before writing; payload not mutated.
  • src/features/collections/services/documentService.test.ts: 7 delete cases (top-level, whole-map, nested, deeply nested, missing parent no-op, non-Map intermediate no-op, non-mutation) + add cases (nested set, duplicate/empty/dots/Array rejection).

Checklist

  • Ran checks locally (test / typecheck / format:check) — green (111/111 tests)
  • The 3 functionalities verified working on the consolidated branch
  • PR is focused: only the three superseded changes + the integration build fix
  • AI involvement disclosed above
  • No Co-Authored-By or AI attribution added to commits
  • No unrelated changes bundled

Size

13 files, +1284 / -17 (upstream/master..develop), of which ~247 lines are the ODD feature records (odd/tasks/tree-add-fields.md, odd/tasks/tree-delete-fields.md). Requesting size:exception for a single consolidated PR (same exception already granted on #20/#21 individually); happy to split into a chain if the maintainer prefers.

@flowdeskadmin flowdeskadmin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@flowdeskadmin
flowdeskadmin merged commit 64dc87e into Flowdesktech:master Sep 23, 2026
1 check passed
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.

2 participants