Skip to content

Commit

Permalink
fix(@leav/ui): apply correct behavior (sort create_at->limit 20->sort…
Browse files Browse the repository at this point in the history
… whoAmI.label)
  • Loading branch information
P0ppoff authored and philippechevieux committed Apr 22, 2024
1 parent 8e5f6dc commit 0ca188a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('<MonoValueSelect />', () => {
{
request: {
query: getRecordsFromLibraryQuery(),
variables: {library: 'test_lib', limit: 20, sort: {field: 'label', order: SortOrder.asc}}
variables: {library: 'test_lib', limit: 20, sort: {field: 'created_at', order: SortOrder.desc}}
},
result: {data: {records}}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('useGetOptionsQuery', () => {
{
request: {
query: getRecordsFromLibraryQuery(),
variables: {library: linkedLibraryId, limit: 20, sort: {field: 'label', order: SortOrder.asc}}
variables: {library: linkedLibraryId, limit: 20, sort: {field: 'created_at', order: SortOrder.desc}}
},
result: {data}
}
Expand Down Expand Up @@ -98,18 +98,18 @@ describe('useGetOptionsQuery', () => {
{
idCard: {
avatar: expect.anything(),
title: 'Danette pistache'
title: 'Danette chocolat'
},
label: 'Danette pistache',
value: '28121951'
label: 'Danette chocolat',
value: '15061943'
},
{
idCard: {
avatar: expect.anything(),
title: 'Danette chocolat'
title: 'Danette pistache'
},
label: 'Danette chocolat',
value: '15061943'
label: 'Danette pistache',
value: '28121951'
}
])
);
Expand Down Expand Up @@ -157,18 +157,18 @@ describe('useGetOptionsQuery', () => {
{
idCard: {
avatar: expect.anything(),
title: 'Danette pistache'
title: 'Danette chocolat'
},
label: 'Danette pistache',
value: '28121951'
label: 'Danette chocolat',
value: '15061943'
},
{
idCard: {
avatar: expect.anything(),
title: 'Danette chocolat'
title: 'Danette pistache'
},
label: 'Danette chocolat',
value: '15061943'
label: 'Danette pistache',
value: '28121951'
},
{
idCard: {
Expand All @@ -183,11 +183,6 @@ describe('useGetOptionsQuery', () => {
});

describe('updateLeavField', () => {
const attribute = {
id: '12'
} as any;
const idValue = '12';

test('Should call onSelectChange with linkValue if record not in list', async () => {
const mock = mockFactory({records});
const activeValue = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {KitAvatar, KitSelect} from 'aristid-ds';
import {ComponentProps, useMemo} from 'react';
import {RecordFormElementsValueLinkValue} from '_ui/hooks/useGetRecordForm';
import {IRecordIdentity} from '_ui/types';
import sortBy from 'lodash/sortBy';

export const useGetOptionsQuery = ({
activeValue,
Expand All @@ -25,16 +26,17 @@ export const useGetOptionsQuery = ({
fetchPolicy: 'network-only',
variables: {
library: linkedLibraryId,
limit: 20,
limit: 20, // TODO: should be a xStream configuration
sort: {
field: 'label',
order: SortOrder.asc
field: 'created_at',
order: SortOrder.desc
}
}
}
);

const recordList = useMemo(() => data?.records?.list ?? [], [data]);
// const recordList = useMemo(() => data?.records?.list.toSorted() ?? [], [data]); // TODO: when toSorted method available (ie. TS >= 5.2.0)
const recordList = useMemo(() => sortBy(data?.records?.list, 'whoAmI.label'), [data]);

const selectOptions = useMemo<ComponentProps<typeof KitSelect>['options']>(
() =>
Expand Down

0 comments on commit 0ca188a

Please sign in to comment.