mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-26 20:08:19 +00:00
* feat: add dynamic table based on query * fix: group by repeating * fix: change view when groupBy exist in the list * fix: table scroll * feat: add the pagination and update options menu * feat: trace explorer is updated --------- Co-authored-by: Yevhen Shevchenko <y.shevchenko@seedium.io> Co-authored-by: Nazarenko19 <danil.nazarenko2000@gmail.com> Co-authored-by: Palash Gupta <palashgdev@gmail.com>
45 lines
1020 B
TypeScript
45 lines
1020 B
TypeScript
import useUrlQuery from 'hooks/useUrlQuery';
|
|
import { useCallback, useMemo } from 'react';
|
|
import { useHistory, useLocation } from 'react-router-dom';
|
|
|
|
const useUrlQueryData = <T>(
|
|
queryKey: string,
|
|
defaultData?: T,
|
|
): UseUrlQueryData<T> => {
|
|
const history = useHistory();
|
|
const location = useLocation();
|
|
const urlQuery = useUrlQuery();
|
|
|
|
const query = urlQuery.get(queryKey);
|
|
|
|
const queryData: T = useMemo(() => (query ? JSON.parse(query) : defaultData), [
|
|
query,
|
|
defaultData,
|
|
]);
|
|
|
|
const redirectWithQuery = useCallback(
|
|
(newQueryData: T): void => {
|
|
const newQuery = JSON.stringify(newQueryData);
|
|
|
|
urlQuery.set(queryKey, newQuery);
|
|
const generatedUrl = `${location.pathname}?${urlQuery.toString()}`;
|
|
history.push(generatedUrl);
|
|
},
|
|
[history, location, urlQuery, queryKey],
|
|
);
|
|
|
|
return {
|
|
query,
|
|
queryData,
|
|
redirectWithQuery,
|
|
};
|
|
};
|
|
|
|
interface UseUrlQueryData<T> {
|
|
query: string | null;
|
|
queryData: T;
|
|
redirectWithQuery: (newQueryData: T) => void;
|
|
}
|
|
|
|
export default useUrlQueryData;
|