Frontend School

Reorderable Dashboard Widgets

Machine Coding
medium

Reorderable Dashboard Widgets

Medium
Drag and Drop
React
Frontend
UI/UX

Overview

Oracle Cloud Infrastructure (OCI) provides powerful dashboards for users to monitor their resources. A key user experience feature is the ability to customize these dashboards. This problem focuses on enabling users to reorder their configured widgets seamlessly using drag-and-drop functionality, enhancing personalization and usability.

What you need to do / Task

Your task is to implement a reorderable list of dashboard widgets. You will be provided with a starter React application that renders a static list of WidgetCard components. Your goal is to add drag-and-drop capabilities to allow users to change the vertical order of these widgets.

  1. Enable Dragging: Make each WidgetCard draggable.
  2. Handle Drag Events: Implement the necessary event handlers (onDragStart, onDragEnter, onDragLeave, onDragOver, onDrop, onDragEnd) to manage the drag-and-drop interaction.
  3. Reorder List: When a widget is dropped, update the internal state (widgets array) to reflect the new order.
  4. Render Updated List: Ensure the UI re-renders to display the widgets in their new sequence.

UI/UX expectations

  • Widget Representation: Each widget should be displayed as a distinct card with a title and description, as provided in the starter code.
  • Drag Visual Feedback: When a user drags a widget, the dragged item should have a clear visual indication (e.g., reduced opacity, a border). The starter CSS includes a .dragging class you can use.
  • Drop Target Visual Feedback: As a dragged item hovers over potential drop locations, provide visual feedback (e.g., a border highlight on the target, or an insertion line) to indicate where the item will be placed if dropped. The starter CSS includes .drag-over and .drop-indicator classes.
  • Smooth Reordering: The list should update smoothly upon drop, reflecting the new order without jarring jumps or flickers.

Acceptance criteria

  • The initial list of widgets is rendered correctly based on the initialWidgets data.
  • Any WidgetCard can be picked up and dragged by the user.
  • While dragging, the dragged item's appearance changes (e.g., opacity reduces).
  • As a dragged item moves over other widgets, visual cues indicate the potential drop position.
  • Dropping a widget at a new position successfully reorders the list of widgets both visually and in the application's state.
  • The reordered list persists until another drag-and-drop operation changes it again.

Constraints

Constraints & assumptions

  • You must use React for the implementation.
  • Focus on implementing the solution using native HTML Drag and Drop APIs (e.g., draggable attribute, drag events). Avoid external drag-and-drop libraries unless absolutely necessary and justified.
  • The widget data is static and provided in the starter code. No dynamic loading or API calls are required.
  • The solution should be entirely client-side; no backend integration is needed.
  • The problem focuses solely on reordering items within a single list.

Out of scope

  • Adding new widgets or deleting existing ones.
  • Saving the widget order to local storage or a backend.
  • Complex animations beyond basic visual feedback for drag and drop.
  • Keyboard accessibility for drag and drop operations.
  • Cross-list drag and drop (e.g., moving widgets between two separate lists).

What interviewers evaluate

  • Correct and idiomatic use of React for component structure and state management.
  • Proper implementation of the native HTML Drag and Drop API (draggable, ondragstart, ondragover, ondrop, ondragend).
  • Effective state update logic to reorder the list items efficiently.
  • Clear and helpful visual feedback during the drag-and-drop interaction.
  • Code clarity, maintainability, and adherence to best practices.

Loading editor...