fix: order select input options in ascending manner

This commit is contained in:
ValdiANS
2026-05-04 14:19:14 +07:00
parent 4e58f20ba3
commit a5f1a6ea75
5 changed files with 45 additions and 16 deletions
@@ -89,7 +89,10 @@ export function Dashboard() {
options: kandangOptions, options: kandangOptions,
loadMore: loadMoreKandang, loadMore: loadMoreKandang,
isLoadingMore: isLoadingMoreKandang, isLoadingMore: isLoadingMoreKandang,
} = useSelect(DailyChecklistKandangApi.basePath, 'id', 'name'); } = useSelect(DailyChecklistKandangApi.basePath, 'id', 'name', 'search', {
order_by: 'asc',
sort_by: 'name',
});
const handleKandangScroll = (e: React.UIEvent<HTMLDivElement>) => { const handleKandangScroll = (e: React.UIEvent<HTMLDivElement>) => {
const target = e.target as HTMLDivElement; const target = e.target as HTMLDivElement;
@@ -110,7 +110,10 @@ export function ListDailyChecklistContent() {
options: kandangOptions, options: kandangOptions,
isLoadingMore: isLoadingMoreKandang, isLoadingMore: isLoadingMoreKandang,
loadMore: loadMoreKandang, loadMore: loadMoreKandang,
} = useSelect(DailyChecklistKandangApi.basePath, 'id', 'name'); } = useSelect(DailyChecklistKandangApi.basePath, 'id', 'name', 'search', {
order_by: 'asc',
sort_by: 'name',
});
const checklistList = isResponseSuccess(checklistListRes) const checklistList = isResponseSuccess(checklistListRes)
? checklistListRes.data || [] ? checklistListRes.data || []
@@ -96,7 +96,10 @@ export function MasterEmployeeContent() {
options: kandangOptions, options: kandangOptions,
loadMore: loadMoreKandang, loadMore: loadMoreKandang,
isLoadingMore: isLoadingMoreKandang, isLoadingMore: isLoadingMoreKandang,
} = useSelect(DailyChecklistKandangApi.basePath, 'id', 'name'); } = useSelect(DailyChecklistKandangApi.basePath, 'id', 'name', 'search', {
order_by: 'asc',
sort_by: 'name',
});
const handleKandangScroll = (e: React.UIEvent<HTMLDivElement>) => { const handleKandangScroll = (e: React.UIEvent<HTMLDivElement>) => {
const target = e.target as HTMLDivElement; const target = e.target as HTMLDivElement;
@@ -368,7 +368,9 @@ export function MasterKandangContent() {
name='search' name='search'
placeholder='Cari kandang...' placeholder='Cari kandang...'
value={tableFilterState.search} value={tableFilterState.search}
onChange={(e) => updateFilter('search', e.target.value)} onChange={(e) =>
updateFilter('search', e.target.value, true)
}
className={{ className={{
wrapper: 'w-full sm:w-[280px] border-gray-200', wrapper: 'w-full sm:w-[280px] border-gray-200',
inputWrapper: 'px-3 py-2 h-fit rounded-md', inputWrapper: 'px-3 py-2 h-fit rounded-md',
@@ -383,7 +385,11 @@ export function MasterKandangContent() {
<Select <Select
value={tableFilterState.location_id} value={tableFilterState.location_id}
onValueChange={(value) => onValueChange={(value) =>
updateFilter('location_id', value === 'all' ? '' : value) updateFilter(
'location_id',
value === 'all' ? '' : value,
true
)
} }
> >
<SelectTrigger className='w-[180px] border-gray-200'> <SelectTrigger className='w-[180px] border-gray-200'>
@@ -137,6 +137,8 @@ export function DailyChecklistReportsContent() {
} = useSelect(DailyChecklistKandangApi.basePath, 'id', 'name', 'search', { } = useSelect(DailyChecklistKandangApi.basePath, 'id', 'name', 'search', {
area_id: tableFilterState.area_id, area_id: tableFilterState.area_id,
location_id: tableFilterState.location_id, location_id: tableFilterState.location_id,
order_by: 'asc',
sort_by: 'name',
}); });
const handleKandangScroll = (e: React.UIEvent<HTMLDivElement>) => { const handleKandangScroll = (e: React.UIEvent<HTMLDivElement>) => {
@@ -159,17 +161,24 @@ export function DailyChecklistReportsContent() {
} }
); );
const { options: employeeOptions } = useSelect( const {
EmployeeApi.basePath, options: employeeOptions,
'id', loadMore: loadMoreEmployee,
'name', isLoadingMore: isLoadingMoreEmployee,
'search', } = useSelect(EmployeeApi.basePath, 'id', 'name', 'search', {
{ order_by: 'asc',
page: '1', sort_by: 'name',
limit: '500', kandang_id: tableFilterState.kandang_id,
kandang_id: tableFilterState.kandang_id, });
const handleEmployeeScroll = (e: React.UIEvent<HTMLDivElement>) => {
const target = e.target as HTMLDivElement;
if (target.scrollHeight - target.scrollTop <= target.clientHeight + 10) {
if (!isLoadingMoreEmployee) {
loadMoreEmployee();
}
} }
); };
const currentMonthMaxDay = new Date( const currentMonthMaxDay = new Date(
Number(tableFilterState.tahun), Number(tableFilterState.tahun),
@@ -493,7 +502,7 @@ export function DailyChecklistReportsContent() {
> >
<SelectValue placeholder='Semua ABK' /> <SelectValue placeholder='Semua ABK' />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent onScroll={handleEmployeeScroll}>
<SelectItem value='ALL'>Semua ABK</SelectItem> <SelectItem value='ALL'>Semua ABK</SelectItem>
{employeeOptions.map((employee) => ( {employeeOptions.map((employee) => (
<SelectItem <SelectItem
@@ -503,6 +512,11 @@ export function DailyChecklistReportsContent() {
{employee.label} {employee.label}
</SelectItem> </SelectItem>
))} ))}
{isLoadingMoreEmployee && (
<div className='flex justify-center p-2'>
<Loader2 className='h-4 w-4 animate-spin text-gray-500' />
</div>
)}
</SelectContent> </SelectContent>
</Select> </Select>
</div> </div>