Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support orderBy as array #5681

Merged
merged 17 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export const fetchAllThreadMessagesOperationSignatureFactory: RecordGqlOperation
eq: messageThreadId || '',
},
},
orderBy: {
receivedAt: 'AscNullsLast',
},
orderBy: [
{
receivedAt: 'AscNullsLast',
},
],
limit: 10,
},
fields: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export const useAttachments = (targetableObject: ActivityTargetableObject) => {
eq: targetableObject.id,
},
},
orderBy: {
createdAt: 'DescNullsFirst',
},
orderBy: [
{
createdAt: 'DescNullsFirst',
},
],
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const mocks: MockedResponse[] = [
query: gql`
query FindManyActivityTargets(
$filter: ActivityTargetFilterInput
$orderBy: ActivityTargetOrderByInput
$orderBy: [ActivityTargetOrderByInput]
$lastCursor: String
$limit: Int
) {
Expand Down Expand Up @@ -103,7 +103,7 @@ const mocks: MockedResponse[] = [
query: gql`
query FindManyActivities(
$filter: ActivityFilterInput
$orderBy: ActivityOrderByInput
$orderBy: [ActivityOrderByInput]
$lastCursor: String
$limit: Int
) {
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('useActivities', () => {
useActivities({
targetableObjects: [],
activitiesFilters: {},
activitiesOrderByVariables: {},
activitiesOrderByVariables: [{}],
skip: false,
}),
{ wrapper: Wrapper },
Expand All @@ -202,7 +202,7 @@ describe('useActivities', () => {
{ targetObjectNameSingular: 'company', id: '123' },
],
activitiesFilters: {},
activitiesOrderByVariables: {},
activitiesOrderByVariables: [{}],
skip: false,
});
return { activities, setCurrentWorkspaceMember };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const mocks: MockedResponse[] = [
query: gql`
query FindManyActivityTargets(
$filter: ActivityTargetFilterInput
$orderBy: ActivityTargetOrderByInput
$orderBy: [ActivityTargetOrderByInput]
$lastCursor: String
$limit: Int
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const usePrepareFindManyActivitiesQuery = () => {
objectRecordsToOverwrite: filteredActivities,
queryVariables: {
...nextFindManyActivitiesQueryFilter,
orderBy: { createdAt: 'DescNullsFirst' },
orderBy: [{ createdAt: 'DescNullsFirst' }],
},
recordGqlFields: FIND_ACTIVITIES_OPERATION_SIGNATURE.fields,
computeReferences: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useNotes = (targetableObject: ActivityTargetableObject) => {

const { activities, loading } = useActivities({
activitiesFilters: notesQueryVariables.filter ?? {},
activitiesOrderByVariables: notesQueryVariables.orderBy ?? {},
activitiesOrderByVariables: notesQueryVariables.orderBy ?? [{}],
targetableObjects: [targetableObject],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ export const useTasks = ({
const { activities: completeTasksData } = useActivities({
targetableObjects,
activitiesFilters: completedQueryVariables.filter ?? {},
activitiesOrderByVariables: completedQueryVariables.orderBy ?? {},
activitiesOrderByVariables: completedQueryVariables.orderBy ?? [{}],
});

const { activities: incompleteTaskData } = useActivities({
targetableObjects,
activitiesFilters: incompleteQueryVariables.filter ?? {},
activitiesOrderByVariables: incompleteQueryVariables.orderBy ?? {},
activitiesOrderByVariables: incompleteQueryVariables.orderBy ?? [{}],
});

const todayOrPreviousTasks = incompleteTaskData?.filter((task) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { RecordGqlOperationOrderBy } from '@/object-record/graphql/types/RecordGqlOperationOrderBy';

export const FIND_MANY_TIMELINE_ACTIVITIES_ORDER_BY: RecordGqlOperationOrderBy =
{
createdAt: 'DescNullsFirst',
};
[
{
createdAt: 'DescNullsFirst',
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export const makeTimelineActivitiesQueryVariables = ({
in: [...activityIds].sort(sortByAscString),
},
},
orderBy: {
createdAt: 'DescNullsFirst',
},
orderBy: [
{
createdAt: 'DescNullsFirst',
},
],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ export const useTimelineActivities = (
eq: targetableObject.id,
},
},
orderBy: {
createdAt: 'DescNullsFirst',
},
orderBy: [
{
createdAt: 'DescNullsFirst',
},
],
fetchPolicy: 'network-only',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const sortCachedObjectEdges = ({
orderBy: RecordGqlOperationOrderBy;
readCacheField: ReadFieldFunction;
}) => {
const [orderByFieldName, orderByFieldValue] = Object.entries(orderBy)[0];
const [orderByFieldName, orderByFieldValue] = Object.entries(orderBy[0])[0];
const [orderBySubFieldName, orderBySubFieldValue] =
typeof orderByFieldValue === 'string'
? []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const query = gql`
export const findManyViewsQuery = gql`
query FindManyViews(
$filter: ViewFilterInput
$orderBy: ViewOrderByInput
$orderBy: [ViewOrderByInput]
$lastCursor: String
$limit: Int
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@ export const getOrderByFieldForObjectMetadataItem = (
if (isDefined(labelIdentifierFieldMetadata)) {
switch (labelIdentifierFieldMetadata.type) {
case FieldMetadataType.FullName:
return {
[labelIdentifierFieldMetadata.name]: {
firstName: orderBy ?? 'AscNullsLast',
lastName: orderBy ?? 'AscNullsLast',
return [
{
[labelIdentifierFieldMetadata.name]: {
firstName: orderBy ?? 'AscNullsLast',
lastName: orderBy ?? 'AscNullsLast',
},
},
};
];
default:
return {
[labelIdentifierFieldMetadata.name]: orderBy ?? 'AscNullsLast',
};
return [
{
[labelIdentifierFieldMetadata.name]: orderBy ?? 'AscNullsLast',
},
];
}
} else {
return {
createdAt: orderBy ?? 'DescNullsLast',
};
return [
{
createdAt: orderBy ?? 'DescNullsLast',
},
];
}
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { OrderBy } from '@/object-metadata/types/OrderBy';

export type RecordGqlOperationOrderBy = {
export type RecordGqlOperationOrderBy = Array<{
[fieldName: string]: OrderBy | { [subFieldName: string]: OrderBy };
};
}>;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RecoilRoot } from 'recoil';
import { useFindManyRecordsQuery } from '@/object-record/hooks/useFindManyRecordsQuery';

const expectedQueryTemplate = `
query FindManyPeople($filter: PersonFilterInput, $orderBy: PersonOrderByInput, $lastCursor: String, $limit: Int) {
query FindManyPeople($filter: PersonFilterInput, $orderBy: [PersonOrderByInput], $lastCursor: String, $limit: Int) {
people(filter: $filter, orderBy: $orderBy, first: $limit, after: $lastCursor) {
edges {
node {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export const useGenerateCombinedFindManyRecordsQuery = ({
const orderByPerMetadataItemArray = operationSignatures
.map(
({ objectNameSingular }) =>
`$orderBy${capitalize(objectNameSingular)}: ${capitalize(
`$orderBy${capitalize(objectNameSingular)}: [${capitalize(
objectNameSingular,
)}OrderByInput`,
)}OrderByInput]`,
)
.join(', ');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,23 @@ export const turnSortsIntoOrderBy = (
): RecordGqlOperationOrderBy => {
const fields: Pick<Field, 'id' | 'name'>[] = objectMetadataItem?.fields ?? [];
const fieldsById = mapArrayToObject(fields, ({ id }) => id);
const sortsOrderBy = Object.fromEntries(
sorts
.map((sort) => {
const correspondingField = fieldsById[sort.fieldMetadataId];
const sortsOrderBy = sorts
.map((sort) => {
const correspondingField = fieldsById[sort.fieldMetadataId];

if (isUndefinedOrNull(correspondingField)) {
return undefined;
}
if (isUndefinedOrNull(correspondingField)) {
return undefined;
}

const direction: OrderBy =
sort.direction === 'asc' ? 'AscNullsFirst' : 'DescNullsLast';
const direction: OrderBy =
sort.direction === 'asc' ? 'AscNullsFirst' : 'DescNullsLast';

return [correspondingField.name, direction];
})
.filter(isDefined),
);
return { [correspondingField.name]: direction };
})
.filter(isDefined);

if (hasPositionField(objectMetadataItem)) {
return {
...sortsOrderBy,
position: 'AscNullsFirst',
};
return [...sortsOrderBy, { position: 'AscNullsFirst' }];
}

return sortsOrderBy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FieldMetadataType } from '~/generated/graphql';
const query = gql`
query CombinedFindManyRecords(
$filterNameSingular: NameSingularFilterInput
$orderByNameSingular: NameSingularOrderByInput
$orderByNameSingular: [NameSingularOrderByInput]
$lastCursorNameSingular: String
$limitNameSingular: Int
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ query FindMany${capitalize(
objectMetadataItem.namePlural,
)}($filter: ${capitalize(
objectMetadataItem.nameSingular,
)}FilterInput, $orderBy: ${capitalize(
)}FilterInput, $orderBy: [${capitalize(
objectMetadataItem.nameSingular,
)}OrderByInput, $lastCursor: String, $limit: Int) {
)}OrderByInput], $lastCursor: String, $limit: Int) {
${
objectMetadataItem.namePlural
}(filter: $filter, orderBy: $orderBy, first: $limit, after: $lastCursor){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { gql } from '@apollo/client';
export const query = gql`
query FindManyPeople(
$filter: PersonFilterInput
$orderBy: PersonOrderByInput
$orderBy: [PersonOrderByInput]
$lastCursor: String
$limit: Int = 60
) {
Expand Down Expand Up @@ -166,7 +166,7 @@ export const variables = {
{ not: { id: { in: ['1', '2'] } } },
],
},
orderBy: { name: 'AscNullsLast' },
orderBy: [{ name: 'AscNullsLast' }],
},
filteredSelectedEntities: {
limit: 60,
Expand All @@ -176,12 +176,12 @@ export const variables = {
{ id: { in: ['1'] } },
],
},
orderBy: { name: 'AscNullsLast' },
orderBy: [{ name: 'AscNullsLast' }],
},
selectedEntities: {
limit: 60,
filter: { id: { in: ['1'] } },
orderBy: { name: 'AscNullsLast' },
orderBy: [{ name: 'AscNullsLast' }],
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const useFilteredSearchEntityQuery = ({
useFindManyRecords({
objectNameSingular,
filter: selectedIdsFilter,
orderBy: { [orderByField]: sortOrder },
orderBy: [{ [orderByField]: sortOrder }],
skip: !selectedIds.length,
});

Expand Down Expand Up @@ -93,7 +93,7 @@ export const useFilteredSearchEntityQuery = ({
} = useFindManyRecords({
objectNameSingular,
filter: makeAndFilterVariables([...searchFilters, selectedIdsFilter]),
orderBy: { [orderByField]: sortOrder },
orderBy: [{ [orderByField]: sortOrder }],
skip: !selectedIds.length,
});

Expand All @@ -106,7 +106,7 @@ export const useFilteredSearchEntityQuery = ({
objectNameSingular,
filter: makeAndFilterVariables([...searchFilters, notFilter]),
limit: limit ?? DEFAULT_SEARCH_REQUEST_LIMIT,
orderBy: { [orderByField]: sortOrder },
orderBy: [{ [orderByField]: sortOrder }],
});

return {
Expand Down
Loading
Loading