From 4b2afb0528b63a609d7920aed3416265ec795090 Mon Sep 17 00:00:00 2001 From: Nathan Alexander Walker Date: Mon, 19 Feb 2024 17:18:11 -0500 Subject: [PATCH] Fixed an issue with identifier null values --- app/controllers/api/v1/resources_controller.rb | 9 +++++---- app/javascript/components/resources/ResourceList.jsx | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/resources_controller.rb b/app/controllers/api/v1/resources_controller.rb index f23bee2..1e276ab 100644 --- a/app/controllers/api/v1/resources_controller.rb +++ b/app/controllers/api/v1/resources_controller.rb @@ -48,10 +48,10 @@ def destroy # GET /resources def index - per_page, status, page = get_index_query_params(index_params[:per_page], index_params[:status], index_params[:page]) + per_page, status, page, identifier = get_index_query_params(index_params[:per_page], index_params[:status], index_params[:page], index_params[:identifier]) resources = Resource - index_params[:identifier] && resources = resources.where(identifier: index_params[:identifier]) + identifier && identifier != 'any' && resources = resources.where(identifier: identifier) status && status != 'any' && resources = resources.where(status: status) resources, last_page = find_page(resources, page, per_page) @@ -69,15 +69,16 @@ def find_page(resources, page, per_page) [resources, last_page] end - def get_index_query_params(per_page_p, status_p, page_p) + def get_index_query_params(per_page_p, status_p, page_p, identifier_p) statuses = ['pending', 'processing', 'failure', 'ready'] per_page = per_page_p ? Integer(per_page_p) : 50 param_status = status_p.is_a?(String) ? status_p.downcase : status_p + identifier = identifier_p.is_a?(String) ? identifier_p.downcase : identifier_p status = statuses.include?(param_status) ? statuses.index(param_status) : param_status page = page_p ? Integer(page_p) : 1 - [per_page, status, page] + [per_page, status, page, identifier] end def set_resource diff --git a/app/javascript/components/resources/ResourceList.jsx b/app/javascript/components/resources/ResourceList.jsx index 54f3f07..28835f6 100644 --- a/app/javascript/components/resources/ResourceList.jsx +++ b/app/javascript/components/resources/ResourceList.jsx @@ -9,7 +9,7 @@ export default function ResourceList() { const [searchParams] = useSearchParams(); const navigate = useNavigate(); const [filteredResources, setFilteredResources] = useState([]); - const [pageState, setPageState] = useState({ identifier: '', status: 'Any', pageNumber: 1, per_page: 50 }); + const [pageState, setPageState] = useState({ identifier: 'Any', status: 'Any', pageNumber: 1, per_page: 50 }); const [lastPage, setLastPage] = useState(true); useEffect(() => {