Skip to content

Auto refresh

The Dashboard refreshes a List after you make changes from it. You can also configure a List to refresh when its database tables change.

After you successfully create, edit, or delete a record from a List, the Dashboard reruns that List’s query with your current filters and sort order. For example, if you change an order’s quantity and it no longer matches your filter, it disappears from the results. This refresh is automatic.

The Dashboard also refreshes the List when you submit a process start form opened from it.

Use watchTables to refresh a List after Process Focus detects a committed write to one of its watched tables.

This example assumes webOrders already exists and makeDatabase() opens the project’s Process Focus-managed Drizzle client.

import { Effect, Schema } from "effect"
import { List, Organisation, Role } from "@pf/process"
import { makeDatabase } from "./schema/database"
import { webOrders } from "./schema/schema"
export const org = new Organisation({ name: "Demo Store" })
const sales = new Role(org, "Sales")
new List(org, "web-orders", {
name: "Web orders",
roles: [sales],
watchTables: [webOrders],
output: {
id: Schema.String.annotate({ title: "Order ID" }),
sku: Schema.String.annotate({ title: "SKU" }),
quantity: Schema.Number.annotate({ title: "Quantity" }),
},
query: ({ page, limit }) =>
Effect.gen(function* () {
const db = yield* makeDatabase()
const orders = yield* db.select().from(webOrders).orderBy(webOrders.id)
const offset = (page - 1) * limit
return {
items: orders.slice(offset, offset + limit),
totalCount: orders.length,
}
}).pipe(Effect.orDie),
})

If new orders come in, this list will refresh due to its use of watchTables.

Assume we have an order process, that is called from the website.

import { NumberField, TextField } from "@pf/form-schema"
import { Form, NodeStep, Process } from "@pf/process"
const enterOrder = new Process(org, "enter-order", {
name: "Enter web order",
purpose: "Record a new web order",
})
const orderForm = new Form(enterOrder, "Order details", {
role: sales,
form: Schema.Struct({
sku: TextField({ label: "SKU" }),
quantity: NumberField({ label: "Quantity" }),
}),
})
const submitted = enterOrder.start(orderForm)
const saveOrder = new NodeStep(submitted, "Save order", {
input: ({ sku, quantity }, { process }) =>
Effect.succeed({ id: process.executionId, sku: sku.trim(), quantity }),
output: {},
execute: ({ id, sku, quantity }) =>
Effect.gen(function* () {
const db = yield* makeDatabase()
yield* db.insert(webOrders).values({ id, sku, quantity })
return {}
}),
})
submitted.next(saveOrder).end()

After saveOrder runs, any user who has the web order list open, will see the update almost immediately.

The Web orders List watches webOrders, the same table that Save order writes to. Process Focus tracks the insert through its managed Drizzle client and refreshes the List after the write commits.

Pass the table definitions used by the List’s query to watchTables, including any joined tables whose changes affect the results.

Writes must be made through our Drizzle client. Writes made outside the runtime will not trigger a refresh.