diff --git a/src/pages/Hosts/Hosts.tsx b/src/pages/Hosts/Hosts.tsx index 4552887d..1847829e 100644 --- a/src/pages/Hosts/Hosts.tsx +++ b/src/pages/Hosts/Hosts.tsx @@ -130,7 +130,7 @@ const Hosts = () => { // Derived states - what we get from API const hostDataResponse = useGettingHostQuery({ searchValue: "", - sizeLimit: 0, + sizelimit: 0, apiVersion: apiVersion || API_VERSION_BACKUP, } as HostsPayload); @@ -162,12 +162,10 @@ const Hosts = () => { hostDataResponse.data && batchResponse !== undefined ) { - const hostsListResult = batchResponse.result.results; - const hostsListSize = batchResponse.result.count; + const hostsListSize = batchResponse.length; const hostsList: Host[] = []; - for (let i = 0; i < hostsListSize; i++) { - hostsList.push(hostsListResult[i].result); + hostsList.push(batchResponse[i]); } // Update 'Hosts' slice data diff --git a/src/services/rpc.ts b/src/services/rpc.ts index 2888f8ac..6782fffd 100644 --- a/src/services/rpc.ts +++ b/src/services/rpc.ts @@ -19,6 +19,7 @@ import { PwPolicy, KrbPolicy, CertProfile, + Host, } from "src/utils/datatypes/globalDataTypes"; import { apiToUser } from "src/utils/userUtils"; import { apiToPwPolicy } from "src/utils/pwPolicyUtils"; @@ -129,7 +130,7 @@ export interface UsersPayload { export interface HostsPayload { searchValue: string; - sizeLimit: number; + sizelimit: number; apiVersion: string; } @@ -588,70 +589,21 @@ export const api = createApi({ providesTags: ["ActiveUsers"], }), // Hosts - gettingHost: build.query({ - async queryFn(payloadData, _queryApi, _extraOptions, fetchWithBQ) { - const { searchValue, sizeLimit, apiVersion } = payloadData; - - if (apiVersion === undefined) { - return { - error: { - status: "CUSTOM_ERROR", - data: "", - error: "API version not available", - } as FetchBaseQueryError, - }; - } - + gettingHost: build.query({ + query: (payload) => { // Prepare search parameters const params = { - pkey_only: true, - sizelimit: sizeLimit, - version: apiVersion, + version: payload.apiVersion, + sizelimit: payload.sizelimit, + all: true, }; - - // Prepare payload - const payloadDataIds: Command = { + return getCommand({ method: "host_find", - params: [[searchValue], params], - }; - - // Make call using 'fetchWithBQ' - const getGroupIDsResult = await fetchWithBQ(getCommand(payloadDataIds)); - // Return possible errors - if (getGroupIDsResult.error) { - return { error: getGroupIDsResult.error as FetchBaseQueryError }; - } - // If no error: cast and assign 'uids' - const hostIdResponseData = getGroupIDsResult.data as FindRPCResponse; - - const fqdns: string[] = []; - const itemsCount = hostIdResponseData.result.result.length as number; - for (let i = 0; i < itemsCount; i++) { - const hostId = hostIdResponseData.result.result[i] as fqdnType; - const { fqdn } = hostId; - fqdns.push(fqdn[0] as string); - } - - // 2ND CALL - GET PARTIAL HOSTS INFO - // Prepare payload - const payloadHostDataBatch: Command[] = fqdns.map((fqdn) => ({ - method: "host_show", - params: [[fqdn], {}], - })); - - // Make call using 'fetchWithBQ' - const partialHostsInfoResult = await fetchWithBQ( - getBatchCommand(payloadHostDataBatch as Command[], apiVersion) - ); - - // Return results - return partialHostsInfoResult.data - ? { data: partialHostsInfoResult.data as BatchRPCResponse } - : { - error: - partialHostsInfoResult.error as unknown as FetchBaseQueryError, - }; + params: [[payload.searchValue], params], + }); }, + transformResponse: (response: FindRPCResponse): Host[] => + response.result.result as unknown as Host[], }), // Autommeber Users autoMemberRebuildUsers: build.mutation({