@snapdragonsnursery/react-components 1.17.9 → 1.17.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
// - onSearchChange?: (query: string) => void // callback for search query changes
|
|
38
38
|
// - searchResults?: Array<employee> // search results from server
|
|
39
39
|
// - isSearching?: boolean // loading state for server search
|
|
40
|
+
// - requireSearch?: boolean // hide results until user types (default: false)
|
|
40
41
|
|
|
41
42
|
import React from "react";
|
|
42
43
|
import { Users, Search } from "lucide-react";
|
|
@@ -72,6 +73,7 @@ export const EmployeeSelect = ({
|
|
|
72
73
|
onSearchChange = null,
|
|
73
74
|
searchResults = [],
|
|
74
75
|
isSearching = false,
|
|
76
|
+
requireSearch = false,
|
|
75
77
|
}) => {
|
|
76
78
|
const [searchTerm, setSearchTerm] = React.useState("");
|
|
77
79
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
@@ -178,8 +180,14 @@ export const EmployeeSelect = ({
|
|
|
178
180
|
return a.fullName.localeCompare(b.fullName);
|
|
179
181
|
});
|
|
180
182
|
|
|
183
|
+
// If requireSearch is true and no search term, show only selected item (if any)
|
|
184
|
+
if (requireSearch && !searchTerm) {
|
|
185
|
+
// Return only the currently selected item, or empty array if nothing selected
|
|
186
|
+
return searchFiltered.filter((e) => e.entraId === value);
|
|
187
|
+
}
|
|
188
|
+
|
|
181
189
|
return searchFiltered;
|
|
182
|
-
}, [items, filter, groupBy, searchTerm, enableServerSearch, searchResults]);
|
|
190
|
+
}, [items, filter, groupBy, searchTerm, enableServerSearch, searchResults, requireSearch, value]);
|
|
183
191
|
|
|
184
192
|
const selectedEmployee = processedItems.find((e) => e.entraId === value);
|
|
185
193
|
|
|
@@ -272,7 +280,13 @@ export const EmployeeSelect = ({
|
|
|
272
280
|
</div>
|
|
273
281
|
</div>
|
|
274
282
|
{allowAll && <SelectItem value="__all__">{allLabel}</SelectItem>}
|
|
275
|
-
{
|
|
283
|
+
{requireSearch && !searchTerm && processedItems.length === 0 && (
|
|
284
|
+
<div className="px-2 py-6 text-center text-sm text-muted-foreground">
|
|
285
|
+
Start typing to search for employees...
|
|
286
|
+
</div>
|
|
287
|
+
)}
|
|
288
|
+
{(!requireSearch || searchTerm || processedItems.length > 0) && (
|
|
289
|
+
groupBy === "site"
|
|
276
290
|
? // Group by site
|
|
277
291
|
Object.entries(
|
|
278
292
|
processedItems.reduce((groups, employee) => {
|
|
@@ -328,7 +342,8 @@ export const EmployeeSelect = ({
|
|
|
328
342
|
{renderEmployeeItem(employee, isSelected)}
|
|
329
343
|
</SelectItem>
|
|
330
344
|
);
|
|
331
|
-
})
|
|
345
|
+
})
|
|
346
|
+
)}
|
|
332
347
|
</SelectContent>
|
|
333
348
|
</Select>
|
|
334
349
|
);
|