diff --git a/src/services/useDatastore/useDatastore.jsx b/src/services/useDatastore/useDatastore.jsx index 3e58e8a9..56125195 100644 --- a/src/services/useDatastore/useDatastore.jsx +++ b/src/services/useDatastore/useDatastore.jsx @@ -6,7 +6,7 @@ const useDatastore = ( resourceId, rootAPIUrl, options, - additionalParams = {} + additionalParams = {}, ) => { const keys = options.keys ? options.keys : true; const { prepareColumns } = options; @@ -21,6 +21,7 @@ const useDatastore = ( const [conditions, setConditions] = useState( options.conditions ? options.conditions : undefined ); + const requireConditions = options.requireConditions; const [sort, setSort] = useState(options.sort ? options.sort : undefined); const [groupings, setGroupings] = useState( options.groupings ? options.groupings : undefined @@ -41,8 +42,15 @@ const useDatastore = ( groupings: groupings, ...additionalParams, } - - const additionalParamsString = Object.keys(params).length ? `&${qs.stringify(params)}` : ''; + const additionalParamsString = Object.keys(params).length ? `${qs.stringify(params)}` : ''; + + let enabled = false; + if (id) { + if (!requireConditions) + enabled = true; + if (conditions && conditions.length) + enabled = true; + } const {data, isPending, error} = useQuery({ queryKey: ["datastore" + id + additionalParamsString], @@ -50,7 +58,7 @@ const useDatastore = ( return fetch(`${rootUrl}/datastore/query/${id}?${additionalParamsString}`) .then(res => res.json()) }, - enabled: id != "" + enabled: enabled }) useEffect(() => { @@ -70,7 +78,7 @@ const useDatastore = ( }, [data]) return { - loading: isPending, + loading: enabled ? isPending : false, values, count, columns, diff --git a/src/templates/Dataset/index.tsx b/src/templates/Dataset/index.tsx index 0f3c548d..6e6cbb6a 100644 --- a/src/templates/Dataset/index.tsx +++ b/src/templates/Dataset/index.tsx @@ -70,7 +70,6 @@ const Dataset = ({ { ...options, limit: defaultPageSize, - manual: true, }, additionalParams ) as ResourceType; diff --git a/src/templates/FilteredResource/FilteredResourceBody.jsx b/src/templates/FilteredResource/FilteredResourceBody.jsx index cdff86f8..eac45df8 100644 --- a/src/templates/FilteredResource/FilteredResourceBody.jsx +++ b/src/templates/FilteredResource/FilteredResourceBody.jsx @@ -47,7 +47,6 @@ const FilteredResourceBody = ({ { ...options, limit: 25, - manual: true, }, additionalParams );