Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mohandast52 committed Apr 10, 2024
1 parent 555f06b commit ffb02ce
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const getAgentsBySearchQuery = (searchValue, ownerAddress = null) => {
and: [
{ packageType: "agent" }
${getSearchFilterSubQueryForAgentsAndComponents(searchValue)}
${ownerAddress ? `owner_contains_nocase: "${ownerAddress}"` : ''}
${
ownerAddress ? `{ owner_contains_nocase: "${ownerAddress}" }` : ''
}
]
}
orderBy: tokenId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,42 @@ import {
import { TOTAL_VIEW_COUNT } from '../../util/constants';

const componentPackageType =
'packageType_in: [connection,skill,protocol,contract,custom]';
'packageType_in: [connection,skill,protocol,contract,custom,unknown]';

const getAllAndMyComponentsQuery = (currentPage, ownerAddress = null) => {
return gql`
{
units(
first: ${TOTAL_VIEW_COUNT},
skip: ${TOTAL_VIEW_COUNT * (currentPage - 1)},
where: {
${componentPackageType}
${ownerAddress ? `owner_contains_nocase: "${ownerAddress}"` : ''}
},
orderBy: tokenId
) ${UNIT_FIELDS}
}
`;
};

const getComponentsBySearchQuery = (searchValue, ownerAddress = null) => {
return gql`
{
units(
where: {
and: [
{ ${componentPackageType} }
${getSearchFilterSubQueryForAgentsAndComponents(searchValue)}
${
ownerAddress ? `{ owner_contains_nocase: "${ownerAddress}" }` : ''
}
]
}
orderBy: tokenId
) ${UNIT_FIELDS}
}
`;
};

/**
* Hook to get ALL components
Expand All @@ -23,17 +58,7 @@ const componentPackageType =
*/
export const useAllComponents = () => {
return useCallback(async (currentPage) => {
const query = gql`
{
units(
first: ${TOTAL_VIEW_COUNT},
skip: ${TOTAL_VIEW_COUNT * (currentPage - 1)},
where: { ${componentPackageType} },
orderBy: tokenId
) ${UNIT_FIELDS}
}
`;

const query = getAllAndMyComponentsQuery(currentPage);
const response = await GRAPHQL_CLIENT.request(query);
return response?.units;
}, []);
Expand All @@ -45,20 +70,7 @@ export const useAllComponents = () => {
*/
export const useMyComponents = () => {
return useCallback(async (ownerAddress, currentPage) => {
const query = gql`
{
units(
first: ${TOTAL_VIEW_COUNT},
skip: ${TOTAL_VIEW_COUNT * (currentPage - 1)},
where: {
${componentPackageType}
owner_contains_nocase: "${ownerAddress}",
},
orderBy: tokenId,
) ${UNIT_FIELDS}
}
`;

const query = getAllAndMyComponentsQuery(currentPage, ownerAddress);
const response = await GRAPHQL_CLIENT.request(query);
return response?.units;
}, []);
Expand All @@ -70,20 +82,7 @@ export const useMyComponents = () => {
*/
const useAllComponentsBySearch = () => {
return useCallback(async (searchValue) => {
const query = gql`
{
units(
where: {
and: [
{ ${componentPackageType} }
${getSearchFilterSubQueryForAgentsAndComponents(searchValue)}
]
}
orderBy: tokenId
) ${UNIT_FIELDS}
}
`;

const query = getComponentsBySearchQuery(searchValue);
const response = await GRAPHQL_CLIENT.request(query);
return response?.units;
}, []);
Expand All @@ -95,21 +94,7 @@ const useAllComponentsBySearch = () => {
*/
const useMyComponentsBySearch = () => {
return useCallback(async (ownerAddress, searchValue) => {
const query = gql`
{
units(
where: {
and: [
{ ${componentPackageType} }
{ owner_contains_nocase: "${ownerAddress}" }
${getSearchFilterSubQueryForAgentsAndComponents(searchValue)}
]
}
orderBy: tokenId
) ${UNIT_FIELDS}
}
`;

const query = getComponentsBySearchQuery(searchValue, ownerAddress);
const response = await GRAPHQL_CLIENT.request(query);
return response?.units;
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,26 @@ const SERVICE_FIELDS = `{
packageHash
metadataHash
state
description
}`;

const getAllAndMyServicesQuery = (currentPage, ownerAddress = null) => {
return gql`
{
services(
first: ${TOTAL_VIEW_COUNT},
skip: ${TOTAL_VIEW_COUNT * (currentPage - 1)},
orderBy: serviceId
${
ownerAddress
? `where: { owner_contains_nocase: "${ownerAddress}" }`
: ''
}
) ${SERVICE_FIELDS}
}
`;
};

/**
* Searches by
* - publicId (package name)
Expand All @@ -36,12 +54,34 @@ export const getSearchFilterSubQueryForServices = (searchValue) => {
{ packageHash_contains_nocase: "${searchValue}" }
{ owner_contains_nocase: "${searchValue}" }
{ metadataHash_contains_nocase: "${completeMetadataHash}" }
{ description_contains_nocase: "${searchValue}" }
]
}`;
};

// TODO: description needs to be added
// { description_contains_nocase: "${searchValue}" }
const getServicesBySearchQuery = (
searchValue,
currentPage,
ownerAddress = null,
) => {
return gql`
{
services (
first: ${TOTAL_VIEW_COUNT},
skip: ${TOTAL_VIEW_COUNT * (currentPage - 1)},
where: {
and: [
${
ownerAddress ? `{ owner_contains_nocase: "${ownerAddress}" }` : ''
}
${getSearchFilterSubQueryForServices(searchValue)},
]
}
orderBy: serviceId
) ${SERVICE_FIELDS}
}
`;
};

/**
* Hook to get ALL units
Expand All @@ -50,16 +90,7 @@ export const getSearchFilterSubQueryForServices = (searchValue) => {
*/
export const useAllServices = () => {
return useCallback(async (currentPage) => {
const query = gql`
{
services(
first: ${TOTAL_VIEW_COUNT},
skip: ${TOTAL_VIEW_COUNT * (currentPage - 1)},
orderBy: serviceId
) ${SERVICE_FIELDS}
}
`;

const query = getAllAndMyServicesQuery(currentPage);
const response = await GRAPHQL_CLIENT.request(query);
return response?.services || [];
}, []);
Expand All @@ -71,19 +102,7 @@ export const useAllServices = () => {
*/
export const useMyServices = () => {
return useCallback(async (ownerAddress, currentPage) => {
const query = gql`
{
services (
first: ${TOTAL_VIEW_COUNT},
skip: ${TOTAL_VIEW_COUNT * (currentPage - 1)},
where: {
owner_contains_nocase: "${ownerAddress}"
},
orderBy: serviceId,
) ${SERVICE_FIELDS}
}
`;

const query = getAllAndMyServicesQuery(currentPage, ownerAddress);
const response = await GRAPHQL_CLIENT.request(query);
return response?.services || [];
}, []);
Expand All @@ -95,21 +114,7 @@ export const useMyServices = () => {
*/
export const useAllServicesBySearch = () => {
return useCallback(async (searchValue, currentPage) => {
const query = gql`
{
services (
first: ${TOTAL_VIEW_COUNT},
skip: ${TOTAL_VIEW_COUNT * (currentPage - 1)},
where: {
and: [
${getSearchFilterSubQueryForServices(searchValue)},
]
}
orderBy: serviceId
) ${SERVICE_FIELDS}
}
`;

const query = getServicesBySearchQuery(searchValue, currentPage);
const response = await GRAPHQL_CLIENT.request(query);
return response?.services || [];
}, []);
Expand All @@ -121,22 +126,11 @@ export const useAllServicesBySearch = () => {
*/
export const useMyServicesBySearch = () => {
return useCallback(async (ownerAddress, searchValue, currentPage) => {
const query = gql`
{
services (
first: ${TOTAL_VIEW_COUNT},
skip: ${TOTAL_VIEW_COUNT * (currentPage - 1)},
where: {
and: [
{ owner_contains_nocase: "${ownerAddress}" }
${getSearchFilterSubQueryForServices(searchValue)}
]
}
orderBy: serviceId,
) ${SERVICE_FIELDS}
}
`;

const query = getServicesBySearchQuery(
searchValue,
currentPage,
ownerAddress,
);
const response = await GRAPHQL_CLIENT.request(query);
return response?.services || [];
}, []);
Expand Down

0 comments on commit ffb02ce

Please sign in to comment.