Skip to content

Commit

Permalink
fix not refreshing df columns at visualization v2 block
Browse files Browse the repository at this point in the history
  • Loading branch information
vieiralucas committed Jan 30, 2025
1 parent c8a20bd commit b0f67c3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,24 +236,24 @@ const getCurrColumns = (currDataframe: DataFrame | null) => {

const DynamicInput = (props: DynamicInputProps) => {
const attrs = useYMemo(
props.blocks,
(blocks) => getDropdownInputAttributes(props.block, blocks),
[props.blocks],
() => getDropdownInputAttributes(props.block, props.blocks),
[props.block]
)

const dataframes = useYMemo(
props.dataframes,
(dataframes) =>
Array.from(dataframes.values()).map((df) => ({
[props.dataframes],
() =>
Array.from(props.dataframes.values()).map((df) => ({
label: df.name,
value: df.name,
})),
[]
)
const currDataframe = useYMemo(
props.dataframes,
(dataframes) => getCurrDataframe(attrs.dataframeName, dataframes),
[attrs.dataframeName, props.dataframes]
[props.dataframes],
() => getCurrDataframe(attrs.dataframeName, props.dataframes),
[attrs.dataframeName]
)
const columns = getCurrColumns(currDataframe)

Expand All @@ -276,7 +276,7 @@ const DynamicInput = (props: DynamicInputProps) => {
(col) => col.name === attrs.columnName
)
const categories =
currCol && 'categories' in currCol ? (currCol.categories ?? []) : []
currCol && 'categories' in currCol ? currCol.categories ?? [] : []
appendDropdownInputOptions(
props.block,
props.blocks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,21 @@ interface Props {
}
function VisualizationBlockV2(props: Props) {
const attrs = useYMemo(
props.block,
(block) => getVisualizationV2Attributes(block),
[props.block],
() => getVisualizationV2Attributes(props.block),
[]
)

const dataframe = useYMemo(
props.block,
(block) => getDataframeFromVisualizationV2(block, props.dataframes),
[props.dataframes]
[props.block, props.dataframes],
() => getDataframeFromVisualizationV2(props.block, props.dataframes),
[]
)

const dataframeOptions = useYMemo(
props.dataframes,
(dataframes) =>
Array.from(dataframes.values()).map((df) => ({
[props.dataframes],
() =>
Array.from(props.dataframes.values()).map((df) => ({
value: df.name,
label: df.name,
})),
Expand Down
18 changes: 11 additions & 7 deletions apps/web/src/hooks/useYMemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,27 @@ interface YObservable {
unobserveDeep: (fn: () => void) => void
}
export function useYMemo<O extends YObservable, T>(
observable: O,
fn: (observable: O) => T,
observables: O[],
fn: () => T,
deps: DependencyList
) {
const [value, setValue] = useResettableState<T>(() => fn(observable), deps)
const [value, setValue] = useResettableState<T>(() => fn(), deps)

useEffect(() => {
const onUpdate = () => {
setValue(fn(observable))
setValue(fn())
}

observable.observeDeep(onUpdate)
for (const observable of observables) {
observable.observeDeep(onUpdate)
}

return () => {
observable.unobserveDeep(onUpdate)
for (const observable of observables) {
observable.unobserveDeep(onUpdate)
}
}
}, [observable, ...deps])
}, [observables, ...deps])

return value
}

0 comments on commit b0f67c3

Please sign in to comment.