-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from canvas/jsb/react-input-fix
Cache initial filter options from backend, BigNumber date aggregation fix, selected styling
- Loading branch information
Showing
32 changed files
with
149 additions
and
208 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,51 @@ | ||
import React from 'react'; | ||
import { ComponentEmbedElement } from '../types'; | ||
import { parseNumber } from '../Spreadsheet'; | ||
import { DownToTheRightIcon, UpToTheRightIcon } from '../icons'; | ||
|
||
export const BigNumber = ({ element }: { element: ComponentEmbedElement }) => { | ||
const formattedValue = element.elementType.formattedValues?.[1]; | ||
export const BigNumber = ({ element, title }: { element: ComponentEmbedElement; title: string }) => { | ||
const data = element.elementType.data; | ||
|
||
return <> {formattedValue != null && <div className="text-3xl">{formattedValue}</div>}</>; | ||
const currentNumber = data && data[0] && data[0][0] ? data[0][0] : null; | ||
const lastNumber = data && data[0] && data[0][1] ? data[0][1] : null; | ||
|
||
let change: string | null = null; | ||
let changeIcon: any = null; | ||
if (currentNumber !== null && lastNumber !== null) { | ||
const last = parseNumber(lastNumber); | ||
const current = parseNumber(currentNumber); | ||
if (last != 0) { | ||
const over = (current - last) / last; | ||
change = (Math.abs(over) * 100.0).toLocaleString(undefined, { | ||
maximumFractionDigits: 1, | ||
}); | ||
|
||
if (over > 0) { | ||
changeIcon = <UpToTheRightIcon className="h-3" />; | ||
} else if (over < 0) { | ||
changeIcon = <DownToTheRightIcon className="h-3" />; | ||
} else { | ||
changeIcon = null; | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<div> | ||
{title && ( | ||
<div className="flex gap-x-4 items-center mb-1"> | ||
<div className="text-[15px] font-medium text-default/80">{title}</div> | ||
{change ? ( | ||
<div className="flex items-center gap-1"> | ||
{changeIcon} {change}% | ||
</div> | ||
) : ( | ||
<></> | ||
)} | ||
</div> | ||
)} | ||
<span className="font-big-number text-3xl">{currentNumber} </span> | ||
{lastNumber ? <span className="text-[15px] text-faded">from {lastNumber}</span> : null} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import isEmpty from 'lodash/isEmpty'; | ||
import MultiSelectInput from '../components/MultiSelectInput'; | ||
import useCanvasState from '../state/useCanvasState'; | ||
import { GetCanvasEmbedResponse } from '@/src/rust_types/GetCanvasEmbedResponse'; | ||
import { FilterConfig } from '../rust_types/FilterConfig'; | ||
|
||
const Filter = ({ canvasData, filter }: { canvasData: GetCanvasEmbedResponse; filter: FilterConfig }) => { | ||
const updateFilter = useCanvasState((state) => state.updateFilter); | ||
const selectedFilters = useCanvasState((state) => state.filters); | ||
const valueIsSelected = !isEmpty(selectedFilters); | ||
// Cache mapping filterId to its filterOptions | ||
// We are exclusively using the initial filter options from the initial API response | ||
const [filterOptionsCache, setFilterOptionsCache] = React.useState<Record<string, string[][]>>({}); | ||
|
||
// currently only Select filters are supported, but remove this as we support more filter types | ||
if (filter.filterType.type !== 'select' || filter.filterType.storeId == null) { | ||
return null; | ||
} | ||
|
||
let filterOptions; | ||
|
||
if (filter.filterId in filterOptionsCache) { | ||
filterOptions = filterOptionsCache[filter.filterId]; | ||
} else { | ||
filterOptions = canvasData.filters.uniqueValues[filter.filterType.storeId]; | ||
setFilterOptionsCache((prev) => ({ ...prev, [filter.filterId]: filterOptions })); | ||
} | ||
|
||
return ( | ||
<div key={filter.filterId} className="flex gap-3"> | ||
<MultiSelectInput | ||
value={selectedFilters[filter.variable]} | ||
onChange={(item: string) => { | ||
if (item === '' || item == null) { | ||
updateFilter({}); | ||
return; | ||
} | ||
const variable = filter.variable; | ||
updateFilter({ [variable]: item }); | ||
}} | ||
defaultOption="Select Filter" | ||
options={filterOptions} | ||
/> | ||
{valueIsSelected && ( | ||
<button onClick={() => updateFilter({})} className="text-xs text-blue-700"> | ||
Clear Filter | ||
</button> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Filter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,16 @@ | ||
import React from 'react'; | ||
import isEmpty from 'lodash/isEmpty'; | ||
import MultiSelectInput from '../components/MultiSelectInput'; | ||
import useCanvasState from '../state/useCanvasState'; | ||
import { GetCanvasEmbedResponse } from '@/src/rust_types/GetCanvasEmbedResponse'; | ||
import Filter from './Filter'; | ||
|
||
export function Filters({ canvasData }: { canvasData: GetCanvasEmbedResponse }) { | ||
const filters = canvasData?.filters?.filters; | ||
const filtersVisible = filters?.filter((filter) => filter?.filterType?.type === 'select'); | ||
const updateFilter = useCanvasState((state) => state.updateFilter); | ||
const selectedFilters = useCanvasState((state) => state.filters); | ||
const valueIsSelected = !isEmpty(selectedFilters); | ||
const filtersVisible = filters?.filter( | ||
(filter) => filter?.filterType?.type === 'select' && filter.filterType.storeId != null, | ||
); | ||
|
||
return ( | ||
<section> | ||
{filtersVisible?.map((filter) => ( | ||
<div key={filter.filterId} className="flex gap-3"> | ||
<MultiSelectInput | ||
value={selectedFilters[filter.variable]} | ||
onChange={(item: string) => { | ||
if (item === '' || item == null) { | ||
updateFilter({}); | ||
return; | ||
} | ||
const variable = filter.variable; | ||
updateFilter({ [variable]: item }); | ||
}} | ||
defaultOption="Select Filter" | ||
// @ts-ignore | ||
options={canvasData.filters.uniqueValues[filter.filterType.storeId]} | ||
/> | ||
{valueIsSelected && ( | ||
<button onClick={() => updateFilter({})} className="text-xs text-blue-700"> | ||
Clear Filter | ||
</button> | ||
)} | ||
</div> | ||
))} | ||
{filtersVisible?.map((filter) => <Filter key={filter.filterId} canvasData={canvasData} filter={filter} />)} | ||
</section> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
import type { TextValue } from './TextValue'; | ||
|
||
export interface Field { | ||
id: string; | ||
label: string; | ||
isDate: boolean; | ||
export interface Cell { | ||
value: TextValue; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
6 changes: 5 additions & 1 deletion
6
react/src/rust_types/ActionKind.ts → react/src/rust_types/Grid.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. | ||
|
||
export type ActionKind = 'Append' | 'Set' | 'SetMeta'; | ||
export interface Grid<T> { | ||
data: Array<T>; | ||
row_count: number; | ||
column_count: number; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.