Fix order by (#2646)
* Order by createdAt desc if no sort provided * Fix '0' currency amounts * Code review returns
This commit is contained in:
@ -123,7 +123,7 @@ export const HooksCompanyBoardEffect = () => {
|
|||||||
objectNamePlural: 'companies',
|
objectNamePlural: 'companies',
|
||||||
filter: {
|
filter: {
|
||||||
id: {
|
id: {
|
||||||
in: opportunities.map((opportuntiy) => opportuntiy.companyId || ''),
|
in: opportunities.map((opportunity) => opportunity.companyId || ''),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
onCompleted: useCallback((data: PaginatedObjectTypeResults<Company>) => {
|
onCompleted: useCallback((data: PaginatedObjectTypeResults<Company>) => {
|
||||||
|
|||||||
@ -35,7 +35,6 @@ export const useObjectRecordTable = () => {
|
|||||||
tableFilters,
|
tableFilters,
|
||||||
foundObjectMetadataItem?.fields ?? [],
|
foundObjectMetadataItem?.fields ?? [],
|
||||||
);
|
);
|
||||||
|
|
||||||
const orderBy = turnSortsIntoOrderByV2(
|
const orderBy = turnSortsIntoOrderByV2(
|
||||||
tableSorts,
|
tableSorts,
|
||||||
foundObjectMetadataItem?.fields ?? [],
|
foundObjectMetadataItem?.fields ?? [],
|
||||||
|
|||||||
@ -7,6 +7,11 @@ export const turnSortsIntoOrderByV2 = (
|
|||||||
fields: Pick<Field, 'id' | 'name'>[],
|
fields: Pick<Field, 'id' | 'name'>[],
|
||||||
) => {
|
) => {
|
||||||
const sortsObject: Record<string, 'AscNullsFirst' | 'DescNullsLast'> = {};
|
const sortsObject: Record<string, 'AscNullsFirst' | 'DescNullsLast'> = {};
|
||||||
|
if (!sorts.length) {
|
||||||
|
return {
|
||||||
|
createdAt: 'DescNullsFirst',
|
||||||
|
};
|
||||||
|
}
|
||||||
sorts.forEach((sort) => {
|
sorts.forEach((sort) => {
|
||||||
const correspondingField = fields.find(
|
const correspondingField = fields.find(
|
||||||
(field) => field.id === sort.fieldMetadataId,
|
(field) => field.id === sort.fieldMetadataId,
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import { isUndefined } from '@sniptt/guards';
|
||||||
|
|
||||||
export const convertCurrencyToCurrencyMicros = (
|
export const convertCurrencyToCurrencyMicros = (
|
||||||
currencyAmount: number | undefined,
|
currencyAmount: number | undefined,
|
||||||
) => {
|
) => {
|
||||||
@ -18,13 +20,12 @@ export const convertCurrencyToCurrencyMicros = (
|
|||||||
export const convertCurrencyMicrosToCurrency = (
|
export const convertCurrencyMicrosToCurrency = (
|
||||||
currencyAmountMicros: number | undefined,
|
currencyAmountMicros: number | undefined,
|
||||||
) => {
|
) => {
|
||||||
if (!currencyAmountMicros) {
|
if (isUndefined(currencyAmountMicros)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
const currencyAmountMicrosAsNumber = +currencyAmountMicros;
|
const currencyAmountMicrosAsNumber = +currencyAmountMicros;
|
||||||
if (isNaN(currencyAmountMicrosAsNumber)) {
|
if (isNaN(currencyAmountMicrosAsNumber)) {
|
||||||
throw new Error(`Cannot convert ${currencyAmountMicros} to currency`);
|
throw new Error(`Cannot convert ${currencyAmountMicros} to currency`);
|
||||||
}
|
}
|
||||||
const currencyAmount = currencyAmountMicrosAsNumber / 1000000;
|
return currencyAmountMicrosAsNumber / 1000000;
|
||||||
return currencyAmount;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user