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

Create settings with defaults when a pool is created #2794

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/domain/pools/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type PoolsOperations = {

"pools.update": (lakeId: string, update: PoolUpdate | PoolUpdate[]) => void
"pools.load": (poolId: string, data: string, opts: Partial<LoadOpts>) => void
"pools.createSettings": (id: string) => void
"pools.updateSettings": (update: Update<PoolSetting>) => void
"pools.getSettings": (id: string) => PoolSetting | null
}
12 changes: 9 additions & 3 deletions src/domain/pools/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {createOperation} from "src/core/operations"
import {CreatePoolOpts, LoadOpts} from "@brimdata/zed-js"
import {lake, pools} from "src/zui"
import PoolSettings from "src/js/state/PoolSettings"
import {getDefaults} from "src/js/state/PoolSettings/selectors"

export const create = createOperation(
"pools.create",
Expand Down Expand Up @@ -39,12 +40,17 @@ export const load = createOperation(
}
)

export const createSettings = createOperation(
"pools.createSettings",
async ({main}, id: string) => {
main.store.dispatch(PoolSettings.create({id, ...getDefaults()}))
}
)

export const updateSettings = createOperation(
"pools.updateSettings",
async ({main}, update) => {
const dispatch = main.store.dispatch
dispatch(PoolSettings.create({id: update.id as string}))
dispatch(PoolSettings.update(update))
main.store.dispatch(PoolSettings.update(update))
}
)

Expand Down
7 changes: 5 additions & 2 deletions src/plugins/core-pool/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import {FieldPath} from "src/core/field-path"
import {createSettings} from "src/domain/pools/operations"
import {pools, PluginContext} from "src/zui"

export function activate(_ctx: PluginContext) {
pools.on("create", ({pool}) => {
const poolKeyAccessor = new FieldPath(pool.layout.keys[0]).toString()
createSettings.run(pool.id)

pools.configure(pool.id).set("timeField", poolKeyAccessor)
pools
.configure(pool.id)
.set("timeField", new FieldPath(pool.layout.keys[0]).toString())
})
}