Skip to content

Commit

Permalink
fix: round custom filters to ensure correct file size comparison, use…
Browse files Browse the repository at this point in the history
… base 10 (SI) file sizes
  • Loading branch information
robinpyon committed Jan 3, 2021
1 parent 63403e3 commit b3c2cfc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/components/AssetMetadata/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const AssetMetadata: FC<Props> = (props: Props) => {
<Flex justify="space-between">
<Text size={1}>Size</Text>
<Text muted size={1}>
{filesize(asset?.size, {round: 0})}
{filesize(asset?.size, {base: 10, round: 0})}
</Text>
</Flex>
{/* MIME type */}
Expand Down
2 changes: 1 addition & 1 deletion src/components/TableRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const TableRow = (props: Props) => {
}}
>
<TextEllipsis muted size={1}>
{filesize(asset.size, {round: 0})}
{filesize(asset.size, {base: 10, round: 0})}
</TextEllipsis>
</LegacyBox>

Expand Down
4 changes: 2 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ export const FACETS: (SearchFacetProps | null)[] = [
{
name: 'kb',
title: 'KB',
fn: val => val * 1000
fieldModifier: fieldName => `round(${fieldName} / 1000)`
},
{
name: 'mb',
title: 'MB',
fn: val => val * 1000000
fieldModifier: fieldName => `round(${fieldName} / 1000000)`
}
]
},
Expand Down
8 changes: 5 additions & 3 deletions src/modules/assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,12 @@ const constructFilter = (searchFacets: SearchFacetProps[], searchQuery?: string)
// Get current modifier
const currentModifier = options?.modifiers.find(m => m.name === modifier)

// Apply modifier fn (if present)
const modifiedValue = currentModifier ? currentModifier?.fn(value) : value
// Apply field modifier fn (if present)
const fieldValue = currentModifier?.fieldModifier
? currentModifier.fieldModifier(field)
: field

return `${field} ${COMPARISON_OPERATOR_MAPPING[operators.comparison].value} ${modifiedValue}`
return `${fieldValue} ${COMPARISON_OPERATOR_MAPPING[operators.comparison].value} ${value}`
}

if (facet.type === 'select') {
Expand Down
3 changes: 1 addition & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ export type Order = {
}

export type SearchFacetNumberModifier = {
// TODO: use correct type
fn: (val: any) => any
fieldModifier?: (fieldName: string) => string
name: string
title: string
}
Expand Down

0 comments on commit b3c2cfc

Please sign in to comment.