Skip to content

Commit

Permalink
onboarding status, service command fixes, and ux fixes (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap authored Apr 25, 2023
1 parent d8b1a2d commit 0e5f6ec
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 113 deletions.
6 changes: 2 additions & 4 deletions src/app/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ export function setupStore({ initState }: Props): AppStore<AppState> {
const middleware: Middleware[] = [];

if (import.meta.env.VITE_DEBUG === "true") {
const logger = (store: any) => (next: any) => (action: any) => {
const logger = (_: any) => (next: any) => (action: any) => {
if (action.type === BATCH) {
log("== BATCH ==");
action.payload.forEach(log);
log("== END BATCH ==");
action.payload.forEach((act: any) => log("ACTION", act));
} else {
log("ACTION", action);
}
Expand Down
44 changes: 11 additions & 33 deletions src/deploy/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PaginateProps, api, cacheTimer, combinePages, thunks } from "@app/api";
import { PaginateProps, api, combinePages, thunks } from "@app/api";
import { defaultEntity, extractIdFromLink } from "@app/hal";
import {
createReducerMap,
Expand All @@ -13,13 +13,9 @@ import type {
ProvisionableStatus,
} from "@app/types";
import { createAction, createSelector } from "@reduxjs/toolkit";
import { call, fork, poll, select } from "saga-query";
import { call, poll, select } from "saga-query";

import {
findEnvById,
selectEnvironments,
updateDeployEnvironmentStatus,
} from "../environment";
import { findEnvById, selectEnvironments } from "../environment";
import { deserializeImage } from "../image";
import { deserializeDeployOperation, waitForOperation } from "../operation";
import { selectDeploy } from "../slice";
Expand Down Expand Up @@ -170,13 +166,17 @@ export const selectAppsForTableSearch = createSelector(
},
);

export const fetchApps = api.get<PaginateProps>("/apps?page=:page", {
saga: cacheTimer(),
});
export const fetchApps = api.get<PaginateProps>("/apps?page=:page");

export const fetchAllApps = thunks.create(
"fetch-all-apps",
{ saga: cacheTimer() },
combinePages(fetchApps),
);

export const cancelAppsPoll = createAction("cancel-apps-poll");
export const pollApps = thunks.create(
"poll-apps",
{ saga: poll(60 * 1000, `${cancelAppsPoll}`) },
combinePages(fetchApps),
);

Expand Down Expand Up @@ -277,28 +277,6 @@ export const createAppOperation = api.post<AppOpProps, DeployOperationResponse>(
const body = getBody();
ctx.request = ctx.req({ body: JSON.stringify(body) });
yield next();

if (!ctx.json.ok) {
return;
}

yield* fork(function* () {
if (type !== "scan_code" && type !== "deploy") {
return;
}
const op = yield* call(waitForOperation, { id: `${ctx.json.data.id}` });
if (op.status !== "succeeded") {
return;
}

yield call(
updateDeployEnvironmentStatus.run,
updateDeployEnvironmentStatus({
id: ctx.payload.envId,
status: type === "scan_code" ? "scanned" : "app_provisioned",
}),
);
});
},
);

Expand Down
29 changes: 1 addition & 28 deletions src/deploy/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
FetchJson,
Payload,
call,
fork,
put,
select,
setLoaderError,
Expand Down Expand Up @@ -35,11 +34,7 @@ import type {
} from "@app/types";

import { deserializeDisk } from "../disk";
import {
findEnvById,
selectEnvironments,
updateDeployEnvironmentStatus,
} from "../environment";
import { findEnvById, selectEnvironments } from "../environment";
import { deserializeDeployOperation, waitForOperation } from "../operation";
import { selectDeploy } from "../slice";
import { createSelector } from "@reduxjs/toolkit";
Expand Down Expand Up @@ -367,28 +362,6 @@ export const createDatabaseOperation = api.post<
const body = getBody();
ctx.request = ctx.req({ body: JSON.stringify(body) });
yield next();

if (!ctx.json.ok) {
return;
}

yield* fork(function* () {
if (type !== "provision") {
return;
}
const op = yield* call(waitForOperation, { id: `${ctx.json.data.id}` });
if (op.status !== "succeeded") {
return;
}

yield call(
updateDeployEnvironmentStatus.run,
updateDeployEnvironmentStatus({
id: ctx.payload.envId,
status: "db_provisioned",
}),
);
});
});

export const fetchDatabaseOperations = api.get<{ id: string }>(
Expand Down
22 changes: 13 additions & 9 deletions src/deploy/environment/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createSelector } from "@reduxjs/toolkit";
import { latest, put, select } from "saga-query";
import { createAction, createSelector } from "@reduxjs/toolkit";
import { latest, poll, put, select } from "saga-query";

import { PaginateProps, api, combinePages, thunks } from "@app/api";
import { defaultEntity, extractIdFromLink } from "@app/hal";
Expand All @@ -17,9 +17,8 @@ import type {
} from "@app/types";

import {
findLatestDbProvisionOp,
findLatestDeployOp,
findLatestSuccessDeployOp,
findLatestSuccessProvisionDbOp,
findLatestSuccessScanOp,
} from "../operation";
import { selectDeploy } from "../slice";
Expand Down Expand Up @@ -147,6 +146,13 @@ export const fetchAllEnvironments = thunks.create(
combinePages(fetchEnvironments),
);

export const cancelEnvPoll = createAction("cancel-env-poll");
export const pollEnvs = thunks.create(
"poll-envs",
{ saga: poll(60 * 1000, `${cancelEnvPoll}`) },
combinePages(fetchEnvironments),
);

interface CreateEnvProps {
name: string;
stackId: string;
Expand All @@ -171,15 +177,13 @@ export const selectEnvironmentsForTableSearch = createSelector(
);

export function deriveAccountStatus(ops: DeployOperation[]): OnboardingStatus {
const app = findLatestSuccessDeployOp(ops);
const appDeploy = findLatestDeployOp(ops);
const db = findLatestSuccessProvisionDbOp(ops);
const app = findLatestDeployOp(ops);
const db = findLatestDbProvisionOp(ops);
const scan = findLatestSuccessScanOp(ops);
if (app && db && scan) {
return "completed";
}
// app was provisioned but failed
if (!app && appDeploy && db && scan) {
if (app && !db && scan) {
return "app_provisioned";
}
if (!app && db && scan) {
Expand Down
3 changes: 3 additions & 0 deletions src/deploy/operation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ export const selectLatestConfigureOp = createSelector(
export const findLatestDeployOp = (ops: DeployOperation[]) =>
ops.find((op) => op.type === "deploy");

export const findLatestDbProvisionOp = (ops: DeployOperation[]) =>
ops.find((op) => op.resourceType === "database" && op.type === "provision");

export const selectLatestDeployOp = createSelector(
selectOperationsByAppId,
(ops) => ops.find((op) => op.type === "deploy") || initOp,
Expand Down
2 changes: 0 additions & 2 deletions src/projects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,6 @@ export const deployProject = thunks.create<CreateProjectSettingsProps>(
return;
}

yield* call(waitForOperation, { id: `${deployCtx.json.data.id}` });

yield next();
yield put(setLoaderSuccess({ id }));
},
Expand Down
Loading

0 comments on commit 0e5f6ec

Please sign in to comment.