Skip to content

Commit

Permalink
Fixed an issue with identifier null values
Browse files Browse the repository at this point in the history
  • Loading branch information
nwalker2398 committed Feb 19, 2024
1 parent ebccb97 commit 4b2afb0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions app/controllers/api/v1/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/components/resources/ResourceList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit 4b2afb0

Please sign in to comment.