Overview
In ServiceNow, managing Configuration Items (CIs) within the Configuration Management Database (CMDB) is fundamental. Users frequently need to locate specific CIs quickly by searching their names or attributes. For large CMDBs, performing a search API call on every keystroke can lead to excessive backend load and a poor user experience due to slow responses or rate limiting. This problem focuses on building a robust and performant search component that addresses these challenges through a debounced search mechanism.
What you need to do / Task
Your task is to implement a React component that allows users to search for Configuration Items (CIs) with a debounced input. The component should display search results, provide feedback during loading, and handle various edge cases.
- Search Input Field: Render an accessible input field where users can type their search query.
- Debounced Search Logic: Implement a debounced mechanism such that the
mockFetchCIs function is called only after the user has stopped typing for a specified delay (e.g., 300ms).
- Display Search Results: Show a list of matching CIs below the search input. Each CI should display its
name and className.
- Loading State Feedback: Display a visible loading indicator (e.g., a spinner or text) while the search operation is in progress.
- Empty State Handling: Clearly communicate to the user when:
- No search term has been entered (e.g., "Start typing to search for CIs...").
- The search returns no results (e.g., "No CIs found matching your query.").
- Error Handling: If the
mockFetchCIs function encounters an error (simulated), display an appropriate error message to the user.
- Accessibility: Ensure the search input and results display meet basic accessibility standards (e.g., ARIA attributes, keyboard navigation considerations).
UI/UX expectations
- The search input field should be clearly visible at the top of the component.
- Below the input, display a dedicated area for search results, loading indicators, or status messages.
- Results should be presented in a simple, readable list format.
- Loading feedback should be intuitive and temporary.
- Status messages (empty state, no results, error) should be distinct and informative.
- The component should be responsive to user input without feeling sluggish.
Acceptance criteria
- Typing into the input field triggers a search only after the debounce delay has passed.
- The
mockFetchCIs function is not called on every keystroke.
- A loading indicator is displayed immediately after the debounce delay and before results are shown.
- Search results (CI name and class) are correctly rendered for matching CIs.
- An appropriate message is displayed when the search input is empty.
- An appropriate message is displayed when the search yields no results.
- An error message is displayed when
mockFetchCIs simulates a failure.
- The search input has an associated label or
aria-label.
- The search results area uses appropriate ARIA roles (e.g.,
aria-live for status messages).