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

feat(frontend): Add an onRecompute callback to handle recompute side … #3493

Merged
merged 9 commits into from
Apr 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import InitializeComponent from '../../helpers/InitializeComponent.svelte'
import { getSelectInput } from './queries/select'
import DebouncedInput from '../../helpers/DebouncedInput.svelte'
import { CancelablePromise } from '$lib/gen'

export let id: string
export let configuration: RichConfigurations
Expand Down Expand Up @@ -108,7 +109,7 @@
}, 1000)
}

const { app, worldStore, mode, selectedComponent } =
const { app, worldStore, mode, selectedComponent, runnableComponents } =
getContext<AppViewerContext>('AppViewerContext')
const editorContext = getContext<AppEditorContext>('AppEditorContext')

Expand Down Expand Up @@ -201,6 +202,24 @@
})
}

let isCallbackAdded = false

function addOnRecomputeCallback() {
$runnableComponents[id].cb = [
...$runnableComponents[id].cb,
() =>
new CancelablePromise(async (resolve) => {
await dbExplorerCount?.computeCount(true)

aggrid?.clearRows()
resolve()
})
]
isCallbackAdded = true
}

$: $runnableComponents[id]?.cb && !isCallbackAdded && addOnRecomputeCallback()

async function listTables() {
let resource = resolvedConfig.type.configuration?.[resolvedConfig.type.selected]?.resource

Expand Down Expand Up @@ -528,6 +547,7 @@
let state: any = undefined
let insertRowRunnable: InsertRowRunnable
let deleteRow: DeleteRow
let dbExplorerCount: DbExplorerCount | undefined = undefined

function onDelete(e) {
const data = { ...e.detail }
Expand Down Expand Up @@ -581,6 +601,7 @@
<UpdateCell {id} bind:this={updateCell} />
{#if render}
<DbExplorerCount
bind:this={dbExplorerCount}
renderCount={refreshCount}
{id}
{quicksearch}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@

$: table && renderCount != undefined && quicksearch != undefined && computeCount()

async function computeCount() {
if (
lastTableCount === table &&
renderCount == renderCountLast &&
quicksearch == quicksearchLast
)
return
export async function computeCount(forceCompute?: boolean | undefined) {
if (!forceCompute) {
if (
lastTableCount === table &&
renderCount == renderCountLast &&
quicksearch == quicksearchLast
) {
return
}
}

if (table != undefined && resource !== undefined) {
renderCountLast = renderCount
lastTableCount = table
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/lib/components/apps/components/helpers/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,6 @@ export async function eval_like(
controlComponents[id]?.setTab?.(index)
},
(id) => {
// Check for the existence of sub-runnables:
// For example a_count for Database Studio

if (runnableComponents[`${id}_count`]?.cb) {
runnableComponents[`${id}_count`]?.cb?.forEach((f) => f())
}

runnableComponents[id]?.cb?.forEach((f) => f())
},
(id) => {
Expand Down
Loading