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

feat: add facility search bar component #925

Merged
merged 6 commits into from
Jan 13, 2025

Conversation

gminetoma
Copy link
Contributor

@gminetoma gminetoma commented Nov 30, 2024

Resolves #924

🔧 What changed

Introduces a new search component to search for existing facilities.
Handles input changes, searches through facilitiesStore.facilityData,
and displays the best matches. Users can select a facility using
the mouse or arrow keys + Enter. Pressing the Esc key or blurring
the search input clears the input field.

Uses a store to keep the results, accessible via
useFacilitySearchbarStore().selectedFacilities.

Adds a .gitignore rule for VS Code settings: .vscode.

📸 Screenshots

  • Before

  • N/A

  • After

Recording.2024-12-17.210203.mp4

@gminetoma gminetoma linked an issue Nov 30, 2024 that may be closed by this pull request
3 tasks
@gminetoma gminetoma self-assigned this Nov 30, 2024
Copy link

netlify bot commented Nov 30, 2024

Deploy Preview for findadoc ready!

Name Link
🔨 Latest commit 3a7c080
🔍 Latest deploy log https://app.netlify.com/sites/findadoc/deploys/6784f7a6b1a18900083af8f7
😎 Deploy Preview https://deploy-preview-925--findadoc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@gminetoma gminetoma force-pushed the feat/facility-search-bar-existing-facilities branch 2 times, most recently from c162923 to 6876e77 Compare November 30, 2024 15:34
@gminetoma gminetoma closed this Dec 1, 2024
@gminetoma gminetoma reopened this Dec 1, 2024
@gminetoma gminetoma force-pushed the feat/facility-search-bar-existing-facilities branch 2 times, most recently from caf7037 to 76868b7 Compare December 1, 2024 02:07
@gminetoma gminetoma changed the title WIP feat: add facility search bar component Dec 1, 2024
@gminetoma gminetoma force-pushed the feat/facility-search-bar-existing-facilities branch 2 times, most recently from 4f9af4d to e079011 Compare December 2, 2024 00:30
@gminetoma gminetoma force-pushed the feat/facility-search-bar-existing-facilities branch 2 times, most recently from a7229f2 to 7dd87cd Compare December 17, 2024 11:25
@gminetoma gminetoma marked this pull request as ready for review December 17, 2024 11:38
@gminetoma gminetoma force-pushed the feat/facility-search-bar-existing-facilities branch 2 times, most recently from 1c09d77 to 1d8f78a Compare December 17, 2024 11:59
Copy link
Contributor

@ermish ermish left a comment

Choose a reason for hiding this comment

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

lots of great work in here! Complex dropdowns have a lot of UX and logic. Great work on making one for findadoc 🚀

components/ModFacilitySearchbar.vue Outdated Show resolved Hide resolved
components/ModFacilitySearchbar.vue Outdated Show resolved Hide resolved
components/ModFacilitySearchbar.vue Outdated Show resolved Hide resolved
components/ModFacilitySearchbar.vue Outdated Show resolved Hide resolved
components/ModFacilitySearchbar.vue Outdated Show resolved Hide resolved
components/ModFacilitySearchbar.vue Outdated Show resolved Hide resolved
components/ModFacilitySearchbar.vue Outdated Show resolved Hide resolved
components/ModFacilitySearchbar.vue Outdated Show resolved Hide resolved
components/ModFacilitySearchbar.vue Outdated Show resolved Hide resolved
stores/facilitySearchbarStore.ts Outdated Show resolved Hide resolved
Introduces a new search component to search for existing facilities.
Handles input changes, searches through `facilitiesStore.facilityData`,
and displays the best matches. Users can select a facility using
the mouse or arrow keys + Enter. Pressing the Esc key or blurring
the search input clears the input field.

Uses a store to keep the results, accessible via
`useFacilitySearchbarStore().selectedFacilities`.

Adds a `.gitignore` rule for VS Code settings: `.vscode`.
@gminetoma gminetoma force-pushed the feat/facility-search-bar-existing-facilities branch from 1d8f78a to 28da14d Compare December 20, 2024 13:48
@gminetoma
Copy link
Contributor Author

gminetoma commented Dec 21, 2024

@ermish

Requested changes:

  • Remove the extra "-" from line 9.
  • Extract the search input component.
  • Replace specific class colors like "bg-white" with theme colors.
  • Improve the display of search results.
  • Replace "mousemove" with "mouseover".
  • Change the active item color to a better one.
  • Remove unnecessary comments.
  • Improve div identification.
  • Place all "event.preventDefault()" calls inside their respective handlers.
  • Set the index limit for the arrow-up key to 0.
  • Use a responsive alternative for '-translate-y-full -top-14'.
  • Remove the store and use local state for search results.

After changes:

Recording.2024-12-22.003601.mp4

This commit introduces the following changes:
- Extracts a new component `ModSearchBar` from `ModFacilitySearchBar`.
- Replaces specific class colors with theme colors for consistency.
- Displays the search results count directly in the search bar.
- Improves the search results display with a scrollbar and removes the results limit.
- Replaces the "mousemove" event with the "mouseover" event for better performance.
- Updates the active item color to `bg-primary/90` for improved visibility.
- Removes unnecessary comments for cleaner code.
- Adds proper identifiers (IDs and classes) to relevant `<div>` elements.
- Ensures all `event.preventDefault()` calls are placed inside their respective handlers.
- Limits the arrow-up key index to 0 for better navigation control.
- Introduces an `isNearPageBottom` conditional to dynamically adjust the layout:
  - Near the page bottom, the main container uses `flex-col-reverse`.
  - Results now use `-translate-y-full` instead of `-top-14`.
- Removes the `facilitySearchBarStore.ts` file and integrates its logic directly into the component.

How to use this component now?
- Easy Peasy!
  1. Import `ModFacilitySearchBar`.
  2. Create a ref like this:
     ```typescript
     const selectedFacilities = ref(new Set<Facility>());
     ```
  3. Pass the ref to the component like this:
     ```html
     <ModFacilitySearchBar v-model="selectedFacilities" />
     ```
  4. Done! 🎉

But, what about the new component (`ModSearchBar`)?
- No problema!
  1. Import `ModSearchBar`.
  2. Create a `HTMLInputElement` ref like this:
     ```typescript
     const searchInputElement = ref<HTMLInputElement | null>(null);
     ```
  3. Pass the ref to the component like this for better control of the search results input:
     ```html
     <ModSearchBar
         v-model="searchInputElement"
         :items-count="filteredItems.length"
     />
     ```
  4. Pass additional props like `place-holder-text`, `items-count`, and listen to events such as `search-input-arrow-up`, `search-input-arrow-down`, `search-input-change`, `search-input-enter`, and `search-input-blur`.
  5. Done! 🎉

Additional Notes:
- Updated the i18n key to use the correct snake_case format.
- Added a visible index to the search results for better navigation control.
@gminetoma gminetoma force-pushed the feat/facility-search-bar-existing-facilities branch from ab5d830 to bfcbadc Compare December 21, 2024 16:18
@gminetoma gminetoma requested a review from ermish December 21, 2024 16:23
@ermish
Copy link
Contributor

ermish commented Dec 31, 2024

nice updates @gminetoma ! Added 3 new comments and the rest look fixed!

`ModSearchBar` is now a generic component with a search input and a results list.

Type inference is implemented using 'Generics'. Learn more here:
https://vuejs.org/api/sfc-script-setup.html#generics

Changed i18n keys to `modHealthcareProfessionalSection`.

Removed old i18n keys.

Added a new prop called `fields-to-display-callback`. This callback
receives the item to be displayed and returns an array of strings,
allowing us to display the desired properties to the user.

Fixed a bug where 'currentFacilities' was empty after a page reload.

Moved 'handleSearchInputChange' to 'ModEditHealthcareProfessionalSection'.
@gminetoma
Copy link
Contributor Author

@ermish -> commit

After changes:

Health Care Professionals:

Screen.Recording.2025-01-08.011429.mp4

Facilities:

Screen.Recording.2025-01-08.012534.mp4

@gminetoma gminetoma requested a review from ermish January 7, 2025 16:49
Copy link
Contributor

@ermish ermish left a comment

Choose a reason for hiding this comment

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

looks solid! nice work with the changes @gminetoma ! 🤜 🤛

@ermish ermish merged commit 6f2f2ef into main Jan 13, 2025
11 checks passed
@ermish
Copy link
Contributor

ermish commented Jan 13, 2025

@gminetoma FYI I added missing Vietnamese locale keys that were added from another PR merge so this one can be merged too 🚀

@ermish ermish deleted the feat/facility-search-bar-existing-facilities branch January 13, 2025 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a facility search bar for existing facilities
2 participants