Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom events for table cell managemnet #5928

Open
lucasbordeau opened this issue Jun 18, 2024 · 1 comment
Open

Remove custom events for table cell managemnet #5928

lucasbordeau opened this issue Jun 18, 2024 · 1 comment
Assignees

Comments

@lucasbordeau
Copy link
Contributor

Scope & Context

Table cells, after performance optimization with custom events for handling soft focus and edit mode.

Current behavior

We use custom event with useEffect to handle soft focus and edit mode toggle in table cells.

The problem is that it's a pattern that opens for potentially many difficult to reproduce and to fix edge cases, like a cell staying open that blocks everything else.

Expected behavior

We want to go back to the previous idea, even if it lowers performances a bit, because it was a simple and predictable pattern.

The idea is to reimplement only one family state for a cell position, that contains everything a cell needs to know : soft focus, edit mode, loading, etc. So that there's only one recoil call being made.

@lucasbordeau lucasbordeau self-assigned this Jun 18, 2024
Copy link

greptile-apps bot commented Jun 18, 2024

Steps to Remove Custom Events for Table Cell Management

  1. Locate Custom Event Handlers: Identify and remove custom event handlers in the relevant components. These are likely found in files managing table cell states, such as TableCell.js or similar.

  2. Remove useEffect Hooks: Remove useEffect hooks that handle custom events for soft focus and edit mode toggling.

  3. Implement Single State Management:

    • Create a single Recoil state to manage cell properties (soft focus, edit mode, loading, etc.).
    import { atom } from 'recoil';
    
    export const cellState = atom({
      key: 'cellState',
      default: {
        softFocus: false,
        editMode: false,
        loading: false,
        // add other properties as needed
      },
    });
  4. Update Components: Update table cell components to use the new Recoil state.

    import { useRecoilState } from 'recoil';
    import { cellState } from './path/to/state';
    
    const TableCell = ({ cellId }) => {
      const [state, setState] = useRecoilState(cellState(cellId));
    
      // Replace custom event logic with direct state updates
      const handleFocus = () => setState(prev => ({ ...prev, softFocus: true }));
      const handleEditMode = () => setState(prev => ({ ...prev, editMode: !prev.editMode }));
    
      return (
        <div onFocus={handleFocus} onClick={handleEditMode}>
          {/* Render cell content */}
        </div>
      );
    };
  5. Remove Custom Event Logic: Ensure all custom event logic is removed and replaced with direct state manipulation using Recoil.

  6. Refactor and Clean Up: Refactor the code to ensure consistency and remove any redundant code related to the old custom event system.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant