Aiven-Open / Aiven-Open/klaw

refactor(coral): Remove type casting in useSearchParams

Đang mở
#695 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Frontend
Ngôn ngữ chính
Java
Star
195
Fork
77
Merge trung bình
8 ngày 9 giờ
Pull request đã merge (30 ngày)
1

Mô tả

# What is currently missing?

Currently, we do `as Type` type casting in some of our use of `searchParmas.get`: https://github.com/Aiven-Open/klaw/blob/main/coral/src/app/features/components/filters/useFiltersContext.tsx#L71-L89

This is actually a potential source of bugs for people entering search params directly in the URL: if they enter a value that is incorrect, we won't know about it, and will send wrong values as part of our API requests, which would result in an error:

![Screenshot 2023-02-24 at 09 45 20](https://user-images.githubusercontent.com/20607294/221134396-51978005-2183-41b3-ba9b-8fa344ef56f9.png)

# How could this be improved?

- remove type casting
- add typeguards to ascertain the type of the search params we get, for example:

```ts
const isRequestStatus = (param: string | null): param is RequestStatus => {
return param !== null && statusList.includes(param)
}

```

# Is this a feature you would work on yourself?

* [ ] I plan to open a pull request for this feature

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.