Skip to content

Comments

Wire up delete entity.#36

Merged
izakfilmalter merged 7 commits intomasterfrom
delete-action
Oct 21, 2025
Merged

Wire up delete entity.#36
izakfilmalter merged 7 commits intomasterfrom
delete-action

Conversation

@izakfilmalter
Copy link
Contributor

No description provided.

@izakfilmalter izakfilmalter changed the title Wire up delete entitie. Wire up delete entity. Oct 21, 2025
@claude
Copy link

claude bot commented Oct 21, 2025

Claude finished @izakfilmalter's task —— View job


Code Review for PR #36: Wire up delete entity

Todo List:

  • Read key changed files to understand delete entity implementation
  • Analyze code quality and best practices
  • Check for potential bugs or issues
  • Evaluate performance considerations
  • Review security concerns
  • Assess test coverage
  • Provide comprehensive feedback

Review Summary

This PR implements delete functionality across the application stack with solid architecture and proper security controls. The implementation follows good patterns but has a few areas that could be improved.

Strengths

Security & Authorization

  • Excellent auth controls: packages/zero/mutators.ts:50-61 implements proper user/org validation before mutations
  • Admin bypass: Lines 52-53 correctly allow admin users to bypass ownership checks
  • Soft deletes: Line 64 implements soft deletes (update operation instead of hard delete) which is a security best practice

Architecture & Design

  • Consistent patterns: Delete functionality follows same patterns as insert/update operations
  • Effect-TS integration: Proper use of Effect for error handling and functional composition
  • Schema validation: packages/schema/shared/introspection.ts:498-521 shows robust validation logic for delete operations

UI/UX

  • Contextual controls: packages/ui/table/universalDropdownMenu.tsx:97-106 properly checks config.meta.disableDelete
  • Visual consistency: Trash icon with destructive styling (text-destructive) follows design system

🔧 Areas for Improvement

1. Missing User Confirmation

Issue: packages/ui/table/universalDropdownMenu.tsx:98-106 - Delete action triggers immediately without confirmation

onClick={() => {
  deleteEntity([{ id: x.row.id }])  // ❌ No confirmation dialog
}}

Risk: Accidental deletions due to misclicks
Recommendation: Add confirmation dialog before delete action

2. Error Handling & User Feedback

Issue: packages/ui/shared/hooks/schemaMutations.ts:80-86 - Limited error context in toast messages

Effect.tapError((error) =>
  Effect.sync(() => toast.error(`Failed to ${operation}: ${error.message}`))
)

Issue: Generic error messages may not help users understand what went wrong
Recommendation: Provide more specific error messages based on error type

3. Potential Performance Impact

Issue: packages/zero/baseQueries.ts:46-47 - Queries filter soft-deleted items at query level

const baseQuery = z.query[entityName].where('deletedAt', 'IS', null)

Consideration: This adds a filter to every query. Ensure database has proper indexes on deletedAt column for performance.

4. Schema Consistency

Issue: packages/schema/directory/ofAddressSchema.ts:113-115 shows all CRUD operations disabled for Address entity:

meta: {
  disableCreate: true,
  disableDelete: true,  // ❌ Delete disabled
  disableEdit: true,
}

Question: If addresses can't be deleted via UI, should the delete mutator logic still apply to them?

🚨 Potential Bugs

1. Race Condition Risk

Location: packages/ui/table/universalDataGrid.tsx:306-311

if (column?.id === 'actions') {
  setShowMenu({
    bounds: event.bounds,
    row: dataRow,  // ❌ Could be stale if data updates
  })
}

Risk: If data updates between click and menu render, row might reference outdated entity data

2. Missing Null Checks

Location: packages/ui/table/universalDropdownMenu.tsx:100

deleteEntity([{ id: x.row.id }])  // ❌ No validation x.row.id exists

Risk: Runtime error if id is missing

📋 Test Coverage Assessment

Missing Test Coverage (recommended additions):

  1. Unit tests for delete mutation validation logic
  2. Integration tests for delete operation with auth scenarios
  3. UI tests for dropdown menu delete action
  4. Error handling tests for various failure modes

🎯 Recommendations

High Priority

  1. Add confirmation dialog for delete actions
  2. Validate entity ID exists before mutation
  3. Add more specific error messages

Medium Priority

  1. Review Address entity delete permissions consistency
  2. Add database indexes for deletedAt if not present
  3. Add comprehensive test coverage

Low Priority

  1. Consider caching delete permissions to reduce re-computation
  2. Add audit logging for delete operations

🏆 Overall Assessment

Score: 8.5/10 - Solid implementation with good security practices and consistent architecture. The main concerns are around user experience (lack of confirmation) and some edge case handling, but the core functionality is well-designed and secure.


@izakfilmalter izakfilmalter merged commit 47892d4 into master Oct 21, 2025
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.

1 participant