Skip to content

feat(dynamodb): item CRUD, batch write, and JSON editor UI (#69)#107

Closed
saurabhkhadsangTV wants to merge 3 commits intoDaviReisVieira:mainfrom
saurabhkhadsangTV:feat/#69/dynamodb-item-crud-with-json-editor
Closed

feat(dynamodb): item CRUD, batch write, and JSON editor UI (#69)#107
saurabhkhadsangTV wants to merge 3 commits intoDaviReisVieira:mainfrom
saurabhkhadsangTV:feat/#69/dynamodb-item-crud-with-json-editor

Conversation

@saurabhkhadsangTV
Copy link
Copy Markdown
Contributor

@saurabhkhadsangTV saurabhkhadsangTV commented Apr 26, 2026

Summary

Closes DaviReisVieira/stackport#69.

Implements create / update / delete for DynamoDB items, batch import and bulk delete, a JSON-based editor with plain vs DynamoDB attribute-value modes, and tightens the read-only middleware so item write POST routes are not mistaken for the existing POST .../query read path.

What changed

Backend

  • POST / PUT /api/dynamodb/tables/{name}/itemsput_item (item + item_format: dynamodb | plain)
  • DELETE /api/dynamodb/tables/{name}/itemsdelete_item (JSON key + item_format)
  • POST /api/dynamodb/tables/{name}/items/batchbatch_write_item (≤25 ops, put/delete)
  • Plain objects marshalled with boto3.dynamodb.types.TypeSerializer; key attributes validated against describe_table
  • Item count cache invalidated after successful writes
  • ReadOnlyMiddleware: allow read-only POST only for paths ending in /query (DynamoDB) and /invoke (Lambda), not for all /api/dynamodb/tables/... prefixes

Frontend

  • Toolbar: New item, Import (JSON array, chunked by 25)
  • Table: row selection, edit/delete actions, item detail sheet with edit/delete when writes are enabled
  • Modals: JSON Textarea, Plain ↔ DynamoDB toggle (dynamodb-marshal helpers), JSON.parse validation, Sonner toasts
  • useHealth to hide write actions when writes_enabled is false
  • Resource browser: custom service view wrapped in full-height rounded-lg border bg-card … panel; tab panels use data-[state=inactive]:hidden to avoid flex layout glitches
  • ui/dist rebuilt

Tests

  • tests/test_dynamodb_routes.pyTestItemWrites (put typed/plain, missing key, delete, batch)
  • tests/test_readonly_middleware.pyPOST to /items and /items/batch return 403 when writes disabled
  • uidynamodb-api, dynamodb-marshal, existing suites green

How to verify

  1. Run MiniStack/LocalStack (or real AWS with care), start StackPort, open Resources → DynamoDB → a table.
  2. New item → save with plain JSON; scan to confirm; Edit / Delete; Import a small JSON array; select rows → Delete (n).
  3. STACKPORT_ALLOW_WRITES=false: write actions hidden / API returns 403 for writes.
  4. cd ui && npx tsc -b && npm run build && npx vitest run and python -m pytest — all pass.

Checklist

  • Issue acceptance criteria addressed (see DynamoDB — Item CRUD with JSON editor #69)
  • CI-style checks: UI build + vitest; backend pytest (incl. new tests)
  • Pydantic models in backend/schemas/dynamodb.py (not inline in routes)

DaviReisVieira

This comment was marked as outdated.

@DaviReisVieira DaviReisVieira dismissed their stale review April 26, 2026 19:53

Rewriting review

Copy link
Copy Markdown
Owner

@DaviReisVieira DaviReisVieira left a comment

Choose a reason for hiding this comment

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

Hey @saurabhkhadsangTV, thanks for the PR! Really nice work here — the DynamoDB CRUD implementation is solid and covers all the acceptance criteria from #69. The ReadOnlyMiddleware fix alone is an important catch. 👏

I went through the code, ran the full test suite (backend + frontend + typecheck + lint), and everything looks good overall. Just two things I'd like us to fix before merging:


1. Cache not invalidated on partial batch success

In backend/routes/dynamodb.py (lines 353-363), when batch_write_item returns UnprocessedItems, we skip cache invalidation — but some items were written, so the item count goes stale until TTL expires.

# Currently:
uproc = resp.get("UnprocessedItems", {})
if uproc:
    return { ... }  # <-- returns early, skips invalidation

_invalidate_table_item_count(name, endpoint_url)  # never reached on partial success

Easy fix — just move _invalidate_table_item_count before the if uproc check.

2. Frontend silently swallows partial batch failures

The frontend calls batchWriteDynamoDBItems and only checks res.ok, but doesn't inspect the unprocessed field in the response. If some items fail in a batch, the user gets a green success toast with no hint that anything went wrong. Could we add a warning toast like "Imported X items, but Y were not processed — retry needed" when unprocessed is non-empty?


Everything else looks great — the Pydantic schemas, the marshal library with round-trip tests, the plain/DynamoDB JSON toggle, the useHealth-gated write actions. Nice attention to detail on the whole thing. 🙌

@saurabhkhadsangTV saurabhkhadsangTV force-pushed the feat/#69/dynamodb-item-crud-with-json-editor branch from 7cd6cb2 to 1839b88 Compare April 27, 2026 05:45
…to feat/#69/dynamodb-item-crud-with-json-editor

Resolve ui/dist conflicts by rebuilding the UI bundle; index.html now matches
the current Vite output.#
@saurabhkhadsangTV saurabhkhadsangTV force-pushed the feat/#69/dynamodb-item-crud-with-json-editor branch from 1d28301 to 5d28980 Compare April 27, 2026 05:52
@saurabhkhadsangTV saurabhkhadsangTV closed this by deleting the head repository Apr 27, 2026
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.

DynamoDB — Item CRUD with JSON editor

2 participants