♻️ refactor

This commit is contained in:
Fred KISSIE
2026-03-20 04:02:51 +01:00
parent ce58e71c44
commit 02697e27a4
4 changed files with 15 additions and 13 deletions

View File

@@ -41,21 +41,21 @@ export function MachineSelector({
orgQueries.machineClients({ orgId, perPage: 10, query: debouncedValue }) orgQueries.machineClients({ orgId, perPage: 10, query: debouncedValue })
); );
// always include the selected site in the list of sites shown // always include the selected machines in the list of machines shown (if the user isn't searching)
const machinesShown = useMemo(() => { const machinesShown = useMemo(() => {
const allMachines: Array<SelectedMachine> = [...machines]; const allMachines: Array<SelectedMachine> = [...machines];
for (const machine of selectedMachines) { if (debouncedValue.trim().length === 0) {
if ( for (const machine of selectedMachines) {
!allMachines.find( if (
(machine) => machine.clientId === machine.clientId !allMachines.find((mc) => mc.clientId === machine.clientId)
) ) {
) { allMachines.unshift(machine);
allMachines.unshift(machine); }
} }
} }
return allMachines; return allMachines;
}, [machines, selectedMachines]); }, [machines, selectedMachines, debouncedValue]);
const selectedMachinesIds = new Set( const selectedMachinesIds = new Set(
selectedMachines.map((m) => m.clientId) selectedMachines.map((m) => m.clientId)

View File

@@ -44,10 +44,11 @@ export function ResourceSelector({
}) })
); );
// always include the selected site in the list of sites shown // always include the selected resource in the list of resources shown
const resourcesShown = useMemo(() => { const resourcesShown = useMemo(() => {
const allResources: Array<SelectedResource> = [...resources]; const allResources: Array<SelectedResource> = [...resources];
if ( if (
debouncedSearchQuery.trim().length === 0 &&
selectedResource && selectedResource &&
!allResources.find( !allResources.find(
(resource) => (resource) =>
@@ -57,7 +58,7 @@ export function ResourceSelector({
allResources.unshift(selectedResource); allResources.unshift(selectedResource);
} }
return allResources; return allResources;
}, [resources, selectedResource]); }, [debouncedSearchQuery, resources, selectedResource]);
return ( return (
<Command shouldFilter={false}> <Command shouldFilter={false}>

View File

@@ -47,13 +47,14 @@ export function SitesSelector({
const sitesShown = useMemo(() => { const sitesShown = useMemo(() => {
const allSites: Array<Selectedsite> = [...sites]; const allSites: Array<Selectedsite> = [...sites];
if ( if (
debouncedQuery.trim().length === 0 &&
selectedSite && selectedSite &&
!allSites.find((site) => site.siteId === selectedSite?.siteId) !allSites.find((site) => site.siteId === selectedSite?.siteId)
) { ) {
allSites.unshift(selectedSite); allSites.unshift(selectedSite);
} }
return allSites; return allSites;
}, [sites, selectedSite]); }, [debouncedQuery, sites, selectedSite]);
return ( return (
<Command shouldFilter={false}> <Command shouldFilter={false}>

View File

@@ -102,7 +102,7 @@ export const orgQueries = {
perPage?: number; perPage?: number;
}) => }) =>
queryOptions({ queryOptions({
queryKey: ["ORG", orgId, "CLIENTS"] as const, queryKey: ["ORG", orgId, "CLIENTS", { query, perPage }] as const,
queryFn: async ({ signal, meta }) => { queryFn: async ({ signal, meta }) => {
const sp = new URLSearchParams({ const sp = new URLSearchParams({
pageSize: perPage.toString() pageSize: perPage.toString()