mirror of
https://github.com/coder/coder.git
synced 2026-09-21 20:51:01 +08:00
* chore: Add timezone param to DAU SQL query * Merge DAUs response * Pass time offsets to metricscache
85 lines
2.1 KiB
TypeScript
85 lines
2.1 KiB
TypeScript
import { DAUsResponse } from "./../../api/typesGenerated"
|
|
import { getDeploymentValues, getDeploymentDAUs } from "api/api"
|
|
import { createMachine, assign } from "xstate"
|
|
import { DeploymentConfig } from "api/types"
|
|
|
|
export const deploymentConfigMachine = createMachine(
|
|
{
|
|
id: "deploymentConfigMachine",
|
|
predictableActionArguments: true,
|
|
|
|
schema: {
|
|
context: {} as {
|
|
deploymentValues?: DeploymentConfig
|
|
getDeploymentValuesError?: unknown
|
|
deploymentDAUs?: DAUsResponse
|
|
getDeploymentDAUsError?: unknown
|
|
},
|
|
events: {} as { type: "LOAD" },
|
|
services: {} as {
|
|
getDeploymentValues: {
|
|
data: DeploymentConfig
|
|
}
|
|
getDeploymentDAUs: {
|
|
data: DAUsResponse
|
|
}
|
|
},
|
|
},
|
|
tsTypes: {} as import("./deploymentConfigMachine.typegen").Typegen0,
|
|
initial: "config",
|
|
states: {
|
|
config: {
|
|
invoke: {
|
|
src: "getDeploymentValues",
|
|
onDone: {
|
|
target: "daus",
|
|
actions: ["assignDeploymentValues"],
|
|
},
|
|
onError: {
|
|
target: "daus",
|
|
actions: ["assignGetDeploymentValuesError"],
|
|
},
|
|
},
|
|
tags: "loading",
|
|
},
|
|
daus: {
|
|
invoke: {
|
|
src: "getDeploymentDAUs",
|
|
onDone: {
|
|
target: "done",
|
|
actions: ["assignDeploymentDAUs"],
|
|
},
|
|
onError: {
|
|
target: "done",
|
|
actions: ["assignGetDeploymentDAUsError"],
|
|
},
|
|
},
|
|
tags: "loading",
|
|
},
|
|
done: {
|
|
type: "final",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
services: {
|
|
getDeploymentValues: getDeploymentValues,
|
|
getDeploymentDAUs: getDeploymentDAUs,
|
|
},
|
|
actions: {
|
|
assignDeploymentValues: assign({
|
|
deploymentValues: (_, { data }) => data,
|
|
}),
|
|
assignGetDeploymentValuesError: assign({
|
|
getDeploymentValuesError: (_, { data }) => data,
|
|
}),
|
|
assignDeploymentDAUs: assign({
|
|
deploymentDAUs: (_, { data }) => data,
|
|
}),
|
|
assignGetDeploymentDAUsError: assign({
|
|
getDeploymentDAUsError: (_, { data }) => data,
|
|
}),
|
|
},
|
|
},
|
|
)
|