Skip to content

Commit

Permalink
fix: SKFP-927 add default sorting based on study_code
Browse files Browse the repository at this point in the history
  • Loading branch information
aperron-ferlab committed Feb 6, 2024
1 parent cf130e3 commit 2aa8ed7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/views/Studies/components/PageContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import { formatQuerySortList } from 'utils/helper';
import { getProTableDictionary } from 'utils/translation';
import { getQueryBuilderDictionary } from 'utils/translation';

import { DEFAULT_PAGE_INDEX, DEFAULT_QUERY_CONFIG, STUDIES_REPO_QB_ID } from '../../utils/constant';
import {
DEFAULT_PAGE_INDEX,
DEFAULT_QUERY_CONFIG,
DEFAULT_STUDY_QUERY_SORT,
STUDIES_REPO_QB_ID,
} from '../../utils/constant';

import styles from './index.module.scss';

Expand All @@ -47,7 +52,10 @@ const PageContent = ({
const dispatch = useDispatch();
const { userInfo } = useUser();
const { queryList, activeQuery } = useQueryBuilderState(STUDIES_REPO_QB_ID);
const [queryConfig, setQueryConfig] = useState(DEFAULT_QUERY_CONFIG);
const [queryConfig, setQueryConfig] = useState({
...DEFAULT_QUERY_CONFIG,
sort: DEFAULT_STUDY_QUERY_SORT,
});
const resolvedSqon = resolveSyntheticSqon(queryList, activeQuery);

const { loading, total, data } = useStudies({
Expand All @@ -56,8 +64,8 @@ const PageContent = ({
sqon: resolvedSqon,
sort: tieBreaker({
sort: queryConfig.sort,
defaultSort: [],
field: 'study_id',
defaultSort: DEFAULT_STUDY_QUERY_SORT,
field: 'study_code',
order: queryConfig.operations?.previous ? SortDirection.Desc : SortDirection.Asc,
}),
});
Expand Down
7 changes: 6 additions & 1 deletion src/views/Studies/utils/constant.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IQueryConfig } from '@ferlab/ui/core/graphql/types';
import { SortDirection } from '@ferlab/ui/core/graphql/constants';
import { IQueryConfig, ISort } from '@ferlab/ui/core/graphql/types';

export const STUDIES_REPO_QB_ID = 'studies-repo-key';

Expand All @@ -14,6 +15,10 @@ export const DEFAULT_PAGING_CONFIG = {
size: DEFAULT_PAGE_SIZE,
};

export const DEFAULT_STUDY_QUERY_SORT = [
{ field: 'study_code', order: SortDirection.Asc },
] as ISort[];

export const DEFAULT_QUERY_CONFIG: IQueryConfig = {
pageIndex: DEFAULT_PAGE_INDEX,
size: DEFAULT_PAGE_SIZE,
Expand Down

0 comments on commit 2aa8ed7

Please sign in to comment.