mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-24 17:51:14 +02:00
add sort buttons
This commit is contained in:
parent
8d44925eca
commit
4d9b400eea
@ -10,7 +10,9 @@ import { HighlightCell } from 'component/common/Table/cells/HighlightCell/Highli
|
|||||||
import { GlobalChangeRequestTitleCell } from './GlobalChangeRequestTitleCell.js';
|
import { GlobalChangeRequestTitleCell } from './GlobalChangeRequestTitleCell.js';
|
||||||
import { FeaturesCell } from '../ProjectChangeRequests/ChangeRequestsTabs/FeaturesCell.js';
|
import { FeaturesCell } from '../ProjectChangeRequests/ChangeRequestsTabs/FeaturesCell.js';
|
||||||
import { useUiFlag } from 'hooks/useUiFlag.js';
|
import { useUiFlag } from 'hooks/useUiFlag.js';
|
||||||
|
import { ChangeRequestFilters } from './ChangeRequestFilters.tsx';
|
||||||
import { withTableState } from 'utils/withTableState';
|
import { withTableState } from 'utils/withTableState';
|
||||||
|
import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser';
|
||||||
import {
|
import {
|
||||||
useChangeRequestsWithMockData as useChangeRequests,
|
useChangeRequestsWithMockData as useChangeRequests,
|
||||||
type ChangeRequestItem
|
type ChangeRequestItem
|
||||||
@ -25,30 +27,55 @@ import {
|
|||||||
import mapValues from 'lodash.mapvalues';
|
import mapValues from 'lodash.mapvalues';
|
||||||
import useLoading from 'hooks/useLoading';
|
import useLoading from 'hooks/useLoading';
|
||||||
import { styles as themeStyles } from 'component/common';
|
import { styles as themeStyles } from 'component/common';
|
||||||
|
import { FilterItemParam } from 'utils/serializeQueryParams';
|
||||||
|
|
||||||
const DEFAULT_PAGE_LIMIT = 25;
|
const DEFAULT_PAGE_LIMIT = 25;
|
||||||
const columnHelper = createColumnHelper<ChangeRequestItem>();
|
const columnHelper = createColumnHelper<ChangeRequestItem>();
|
||||||
|
|
||||||
const ChangeRequestsInner = () => {
|
const ChangeRequestsInner = () => {
|
||||||
|
const { user } = useAuthUser();
|
||||||
|
|
||||||
|
// Check URL parameters directly to avoid double fetching
|
||||||
|
const shouldApplyDefaults = useMemo(() => {
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
return !urlParams.has('createdBy') && !urlParams.has('requestedApprovalBy') && user;
|
||||||
|
}, [user]);
|
||||||
|
|
||||||
const stateConfig = {
|
const stateConfig = {
|
||||||
offset: withDefault(NumberParam, 0),
|
offset: withDefault(NumberParam, 0),
|
||||||
limit: withDefault(NumberParam, DEFAULT_PAGE_LIMIT),
|
limit: withDefault(NumberParam, DEFAULT_PAGE_LIMIT),
|
||||||
sortBy: withDefault(StringParam, 'createdAt'),
|
sortBy: withDefault(StringParam, 'createdAt'),
|
||||||
sortOrder: withDefault(StringParam, 'desc'),
|
sortOrder: withDefault(StringParam, 'desc'),
|
||||||
|
createdBy: FilterItemParam,
|
||||||
|
requestedApprovalBy: FilterItemParam,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Apply initial defaults if needed
|
||||||
|
const initialState = shouldApplyDefaults ? {
|
||||||
|
createdBy: {
|
||||||
|
operator: 'IS' as const,
|
||||||
|
values: [user.id.toString()],
|
||||||
|
}
|
||||||
|
} : {};
|
||||||
|
|
||||||
const [tableState, setTableState] = useQueryParams(
|
const [tableState, setTableState] = useQueryParams(
|
||||||
stateConfig,
|
stateConfig,
|
||||||
{ updateType: 'replaceIn' },
|
{ updateType: 'replaceIn' },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Merge with initial state on first load only
|
||||||
|
const effectiveTableState = useMemo(() => ({
|
||||||
|
...initialState,
|
||||||
|
...tableState
|
||||||
|
}), [initialState, tableState]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
changeRequests: data,
|
changeRequests: data,
|
||||||
total,
|
total,
|
||||||
loading,
|
loading,
|
||||||
initialLoad,
|
initialLoad,
|
||||||
} = useChangeRequests(
|
} = useChangeRequests(
|
||||||
mapValues(encodeQueryParams(stateConfig, tableState), (value) =>
|
mapValues(encodeQueryParams(stateConfig, effectiveTableState), (value) =>
|
||||||
value ? `${value}` : undefined,
|
value ? `${value}` : undefined,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -126,7 +153,7 @@ const ChangeRequestsInner = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const table = useReactTable(
|
const table = useReactTable(
|
||||||
withTableState(tableState, setTableState, {
|
withTableState(effectiveTableState, setTableState, {
|
||||||
columns,
|
columns,
|
||||||
data,
|
data,
|
||||||
}),
|
}),
|
||||||
@ -139,6 +166,10 @@ const ChangeRequestsInner = () => {
|
|||||||
bodyClass='no-padding'
|
bodyClass='no-padding'
|
||||||
header={<PageHeader title='Change requests' />}
|
header={<PageHeader title='Change requests' />}
|
||||||
>
|
>
|
||||||
|
<ChangeRequestFilters
|
||||||
|
tableState={effectiveTableState}
|
||||||
|
setTableState={setTableState}
|
||||||
|
/>
|
||||||
<div className={themeStyles.fullwidth}>
|
<div className={themeStyles.fullwidth}>
|
||||||
<div ref={bodyLoadingRef}>
|
<div ref={bodyLoadingRef}>
|
||||||
<PaginatedTable tableInstance={table} totalItems={total} />
|
<PaginatedTable tableInstance={table} totalItems={total} />
|
||||||
|
Loading…
Reference in New Issue
Block a user