-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #384 from projectNEWM/bugfix/minor-bug-fixes-impro…
…vements Update regex for inputs and sort dropdown options and other misc updates
- Loading branch information
Showing
13 changed files
with
78 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
import { useMemo } from "react"; | ||
|
||
/** | ||
* Extracts the specified property from an array of items. | ||
* This hook extracts the specified property from an array of items. | ||
* Each item is expected to have the specified property of type string. | ||
* | ||
* @param {T[]} items - An array of items to extract property from. | ||
* @param {K} property - The name of the property to extract. | ||
* @param {boolean} shouldSort - Whether the result should be sorted. | ||
* @return {string[]} An array of extracted property values. | ||
* | ||
* @template T | ||
* @typedef {object} T | ||
* @property {string} K | ||
*/ | ||
export const extractProperty = <T, K extends keyof T>( | ||
export const useExtractProperty = < | ||
T extends Record<K, string>, | ||
K extends keyof T | ||
>( | ||
items: T[], | ||
property: K | ||
): T[K][] => items.map((item) => item[property]); | ||
|
||
export const useExtractProperty = <T, K extends keyof T>( | ||
items: T[], | ||
property: K | ||
property: K, | ||
shouldSort = true | ||
): T[K][] => { | ||
const memoized = useMemo( | ||
() => extractProperty(items, property), | ||
[items, property] | ||
); | ||
|
||
return memoized; | ||
return useMemo(() => { | ||
const extracted = items.map((item) => item[property]); | ||
return shouldSort | ||
? extracted.sort((a, b) => a.localeCompare(b)) | ||
: extracted; | ||
}, [items, property, shouldSort]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters