Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Introduce RowStatus to environment model to support Archive

天舟438f1dbe781d
diff --git a/frontend/src/components/Breadcrumb.vue b/frontend/src/components/Breadcrumb.vue
index 5b9b55fc93..3950bea4c0 100644
--- a/frontend/src/components/Breadcrumb.vue
+++ b/frontend/src/components/Breadcrumb.vue
@@ -124,12 +124,18 @@ export default {
const routeSlug: RouterSlug = store.getters["router/routeSlug"](
currentRoute.value
);
+ const environmentSlug = routeSlug.environmentSlug;
const instanceSlug = routeSlug.instanceSlug;
const databaseSlug = routeSlug.databaseSlug;
const dataSourceSlug = routeSlug.dataSourceSlug;
const list: Array<BreadcrumbItem> = [];
- if (instanceSlug) {
+ if (environmentSlug) {
+ list.push({
+ name: "Environment",
+ path: "/environment",
+ });
+ } else if (instanceSlug) {
list.push({
name: "Instance",
path: "/instance",
diff --git a/frontend/src/components/EnvironmentForm.vue b/frontend/src/components/EnvironmentForm.vue
index 0899985f09..cd8795d3e1 100644
--- a/frontend/src/components/EnvironmentForm.vue
+++ b/frontend/src/components/EnvironmentForm.vue
@@ -14,60 +14,78 @@
/>
</div>
</div>
- <template v-if="allowEdit">
- <!-- Create button group -->
- <div v-if="create" class="flex justify-end pt-5">
+ <!-- Create button group -->
+ <div v-if="create" class="flex justify-end pt-5">
+ <button
+ type="button"
+ class="btn-normal py-2 px-4"
+ @click.prevent="$emit('cancel')"
+ >
+ Cancel
+ </button>
+ <button
+ type="submit"
+ class="btn-primary ml-3 inline-flex justify-center py-2 px-4"
+ :disabled="!allowCreate"
+ @click.prevent="createEnvironment"
+ >
+ Create
+ </button>
+ </div>
+ <!-- Update button group -->
+ <div v-else class="flex justify-between items-center pt-5">
+ <div v-if="state.environment.rowStatus == 'NORMAL'">
+ <BBButtonTrash
+ v-if="allowArchive"
+ :buttonText="'Archive this environment'"
+ :okText="'Archive'"
+ :confirmTitle="
+ 'Archive environment \'' + state.environment.name + '\' ?'
+ "
+ :confirmDescription="'Archived environment will not be shown on the normal interface. You can still restore later from the Archive page.'"
+ :requireConfirm="true"
+ @confirm="archiveEnvironment"
+ />
+ </div>
+ <div v-else-if="state.environment.rowStatus == 'ARCHIVED'">
+ <BBButtonTrash
+ :buttonText="'Restore this environment'"
+ :okText="'Restore'"
+ :confirmTitle="
+ 'Restore environment \'' +
+ state.environment.name +
+ '\' to normal state?'
+ "
+ :confirmDescription="''"
+ :requireConfirm="true"
+ @confirm="restoreEnvironment"
+ />
+ </div>
+ <div v-else></div>
+ <div v-if="allowEdit">
<button
type="button"
class="btn-normal py-2 px-4"
- @click.prevent="$emit('cancel')"
+ :disabled="!valueChanged"
+ @click.prevent="revertEnvironment"
>
- Cancel
+ Revert
</button>
<button
type="submit"
class="btn-primary ml-3 inline-flex justify-center py-2 px-4"
- :disabled="!allowCreate"
- @click.prevent="createEnvironment"
+ :disabled="!valueChanged"
+ @click.prevent="updateEnvironment"
>
- Create
+ Update
</button>
</div>
- <!-- Update button group -->
- <div v-else class="flex justify-between items-center pt-5">
- <div>
- <BBButtonTrash
- v-if="allowDelete"
- :buttonText="'Delete this environment'"
- :requireConfirm="false"
- @confirm="$emit('delete')"
- />
- </div>
- <div>
- <button
- type="button"
- class="btn-normal py-2 px-4"
- :disabled="!valueChanged"
- @click.prevent="revertEnvironment"
- >
- Revert
- </button>
- <button
- type="submit"
- class="btn-primary ml-3 inline-flex justify-center py-2 px-4"
- :disabled="!valueChanged"
- @click.prevent="updateEnvironment"
- >
- Update
- </button>
- </div>
- </div>
- </template>
+ </div>
</div>
</template>
<script lang="ts">
-import { computed, reactive, PropType } from "vue";
+import { computed, reactive, PropType, watch } from "vue";
import { useStore } from "vuex";
import cloneDeep from "lodash-es/cloneDeep";
import isEqual from "lodash-es/isEqual";
@@ -81,36 +99,45 @@ interface LocalState {
export default {
name: "EnvironmentForm",
- emits: ["create", "update", "cancel", "delete"],
+ emits: ["create", "update", "cancel", "archive", "restore"],
props: {
create: {
type: Boolean,
default: false,
},
- allowDelete: {
- type: Boolean,
- default: true,
- },
environment: {
- // Can be false when create is true
- required: false,
- type: Object as PropType<Environment>,
+ required: true,
+ type: Object as PropType<Environment | EnvironmentNew>,
},
},
setup(props, { emit }) {
const store = useStore();
const state = reactive<LocalState>({
- environment: props.environment
- ? cloneDeep(props.environment)
- : {
- name: "New Env",
- },
+ environment: cloneDeep(props.environment),
});
+ watch(
+ () => props.environment,
+ (cur: Environment | EnvironmentNew) => {
+ state.environment = cloneDeep(cur);
+ }
+ );
+
const currentUser = computed(() => store.getters["auth/currentUser"]());
+ const environmentList = computed(() => {
+ return store.getters["environment/environmentList"]("NORMAL");
+ });
+
+ const allowArchive = computed(() => {
+ return environmentList.value.length > 1;
+ });
+
const allowEdit = computed(() => {
- return isDBA(currentUser.value.role);
+ return (
+ (state.environment as Environment).rowStatus == "NORMAL" &&
+ isDBA(currentUser.value.role)
+ );
});
const valueChanged = computed(() => {
@@ -135,17 +162,32 @@ export default {
if (state.environment.name != props.environment!.name) {
patchedEnvironment.name = state.environment.name;
}
- emit("update", patchedEnvironment);
+ emit(
+ "update",
+ (props.environment as Environment)!.id,
+ patchedEnvironment
+ );
+ };
+
+ const archiveEnvironment = () => {
+ emit("archive", state.environment);
+ };
+
+ const restoreEnvironment = () => {
+ emit("restore", state.environment);
};
return {
state,
+ allowArchive,
allowEdit,
valueChanged,
allowCreate,
revertEnvironment,
createEnvironment,
updateEnvironment,
+ archiveEnvironment,
+ restoreEnvironment,
};
},
};
diff --git a/frontend/src/components/EnvironmentTable.vue b/frontend/src/components/EnvironmentTable.vue
index 566ed26c74..f1105338c6 100644
--- a/frontend/src/components/EnvironmentTable.vue
+++ b/frontend/src/components/EnvironmentTable.vue
@@ -28,6 +28,7 @@
import { PropType } from "vue";
import { useRouter } from "vue-router";
import { Environment } from "../types";
+import { environmentSlug } from "../utils";
const COLUMN_LIST = [
{
@@ -58,7 +59,7 @@ export default {
const clickEnvironment = function (section: number, row: number) {
const environment = props.environmentList[row];
- router.push(`/environment#${environment.id}`);
+ router.push(`/environment/${environmentSlug(environment)}`);
};
return {
diff --git a/frontend/src/main.js b/frontend/src/main.js
index 752c806e21..c0303b3fc1 100644
--- a/frontend/src/main.js
+++ b/frontend/src/main.js
@@ -39,6 +39,7 @@ import {
humanizeTs,
sizeToFit,
urlfy,
+ environmentSlug,
instanceSlug,
databaseSlug,
dataSourceSlug,
@@ -61,6 +62,7 @@ app.config.globalProperties.isDemo = isDemo();
app.config.globalProperties.isDevOrDemo = isDevOrDemo();
app.config.globalProperties.sizeToFit = sizeToFit;
app.config.globalProperties.urlfy = urlfy;
+app.config.globalProperties.environmentSlug = environmentSlug;
app.config.globalProperties.instanceSlug = instanceSlug;
app.config.globalProperties.databaseSlug = databaseSlug;
app.config.globalProperties.dataSourceSlug = dataSourceSlug;
diff --git a/frontend/src/miragejs/factories/environment.js b/frontend/src/miragejs/factories/environment.js
index c519c4726e..9cb1d9375a 100644
--- a/frontend/src/miragejs/factories/environment.js
+++ b/frontend/src/miragejs/factories/environment.js
@@ -2,6 +2,9 @@ import { Factory } from "miragejs";
export default {
environment: Factory.extend({
+ rowStatus(i) {
+ return i > 3 ? "ARCHIVED" : "NORMAL";
+ },
name(i) {
if (i == 0) {
return "Sandbox A";
@@ -9,11 +12,10 @@ export default {
return "Integration";
} else if (i == 2) {
return "Staging";
+ } else if (i == 3) {
+ return "Prod";
} else {
- if (i == 3) {
- return "Prod";
- }
- return "Prod " + (i - 2);
+ return "Archived Env " + (i - 3);
}
},
order(i) {
diff --git a/frontend/src/miragejs/routes/environment.js b/frontend/src/miragejs/routes/environment.js
index 02d951368d..d0eb5a74b0 100644
--- a/frontend/src/miragejs/routes/environment.js
+++ b/frontend/src/miragejs/routes/environment.js
@@ -4,11 +4,26 @@ import { WORKSPACE_ID, OWNER_ID } from "./index";
export default function configureEnvironment(route) {
route.get("/environment", function (schema, request) {
- return schema.environments
- .where((environment) => {
- return environment.workspaceId == WORKSPACE_ID;
- })
- .sort((a, b) => a.order - b.order);
+ const {
+ queryParams: { rowstatus: rowStatus },
+ } = request;
+ return schema.environments.where((environment) => {
+ if (environment.workspaceId != WORKSPACE_ID) {
+ return false;
+ }
+
+ if (!rowStatus) {
+ if (environment.rowStatus != "NORMAL") {
+ return false;
+ }
+ } else if (
+ environment.rowStatus.toLowerCase() != rowStatus.toLowerCase()
+ ) {
+ return false;
+ }
+
+ return true;
+ });
});
route.post("/environment", function (schema, request) {
@@ -59,11 +74,9 @@ export default function configureEnvironment(route) {
env.update(batch);
}
}
- return schema.environments
- .where((environment) => {
- return environment.workspaceId == WORKSPACE_ID;
- })
- .sort((a, b) => a.order - b.order);
+ return schema.environments.where((environment) => {
+ return environment.workspaceId == WORKSPACE_ID;
+ });
});
route.patch("/environment/:environmentId", function (schema, request) {
diff --git a/frontend/src/miragejs/seeds/index.ts b/frontend/src/miragejs/seeds/index.ts
index dc170644cf..807fa35353 100644
--- a/frontend/src/miragejs/seeds/index.ts
+++ b/frontend/src/miragejs/seeds/index.ts
@@ -26,7 +26,7 @@ const workspacesSeeder = (server: any) => {
// Environment
const environmentList1 = [];
- for (let i = 0; i < 4; i++) {
+ for (let i = 0; i < 5; i++) {
environmentList1.push(
server.create("environment", {
workspace: workspace1,
@@ -36,7 +36,7 @@ const workspacesSeeder = (server: any) => {
workspace1.update({ environment: environmentList1 });
const environmentList2 = [];
- for (let i = 0; i < 4; i++) {
+ for (let i = 0; i < 5; i++) {
environmentList2.push(
server.create("environment", {
workspace: workspace2,
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 6c392e52c0..ee1619bee2 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -293,6 +293,24 @@ const routes: Array<RouteRecordRaw> = [
},
props: { content: true, leftSidebar: true },
},
+ {
+ path: "environment/:environmentSlug",
+ name: "workspace.environment.detail",
+ meta: {
+ title: (route: RouteLocationNormalized) => {
+ const slug = route.params.environmentSlug as string;
+ return store.getters["environment/environmentById"](
+ idFromSlug(slug)
+ ).name;
+ },
+ allowBookmark: true,
+ },
+ components: {
+ content: () => import("../views/EnvironmentDetail.vue"),
+ leftSidebar: DashboardSidebar,
+ },
+ props: { content: true },
+ },
{
path: "instance",
name: "workspace.instance",
@@ -562,6 +580,7 @@ router.beforeEach((to, from, next) => {
}
const routerSlug = store.getters["router/routeSlug"](to);
+ const environmentSlug = routerSlug.environmentSlug;
const taskSlug = routerSlug.taskSlug;
const instanceSlug = routerSlug.instanceSlug;
const databaseSlug = routerSlug.databaseSlug;
@@ -570,6 +589,19 @@ router.beforeEach((to, from, next) => {
console.log("RouterSlug:", routerSlug);
+ if (environmentSlug) {
+ if (
+ store.getters["environment/environmentById"](idFromSlug(environmentSlug))
+ ) {
+ next();
+ return;
+ }
+ next({
+ name: "error.404",
+ replace: false,
+ });
+ }
+
if (taskSlug) {
if (taskSlug.toLowerCase() == "new") {
next();
diff --git a/frontend/src/store/modules/environment.ts b/frontend/src/store/modules/environment.ts
index b1e739d606..ce423a20a1 100644
--- a/frontend/src/store/modules/environment.ts
+++ b/frontend/src/store/modules/environment.ts
@@ -6,6 +6,7 @@ import {
EnvironmentState,
ResourceObject,
unknown,
+ RowStatus,
EnvironmentPatch,
} from "../../types";
@@ -21,7 +22,14 @@ const state: () => EnvironmentState = () => ({
});
const getters = {
- environmentList: (state: EnvironmentState) => (): Environment[] => {
+ environmentList: (state: EnvironmentState) => (
+ rowStatus?: RowStatus
+ ): Environment[] => {
+ if (rowStatus) {
+ return state.environmentList.filter((environment: Environment) => {
+ return environment.rowStatus == rowStatus;
+ });
+ }
return state.environmentList;
},
@@ -38,14 +46,17 @@ const getters = {
};
const actions = {
- async fetchEnvironmentList({ commit }: any) {
- const environmentList = (await axios.get(`/api/environment`)).data.data.map(
+ async fetchEnvironmentList({ commit }: any, rowStatus?: RowStatus) {
+ const path =
+ "/api/environment" +
+ (rowStatus ? "?rowstatus=" + rowStatus.toLowerCase() : "");
+ const environmentList = (await axios.get(path)).data.data.map(
(env: ResourceObject) => {
return convert(env);
}
);
- commit("setEnvironmentList", environmentList);
+ commit("upsertEnvironmentList", environmentList);
return environmentList;
},
@@ -62,7 +73,7 @@ const actions = {
).data.data
);
- commit("appendEnvironment", createdEnvironment);
+ commit("upsertEnvironmentList", [createdEnvironment]);
return createdEnvironment;
},
@@ -86,7 +97,7 @@ const actions = {
return convert(env);
});
- commit("setEnvironmentList", environmentList);
+ commit("upsertEnvironmentList", environmentList);
return environmentList;
},
@@ -112,7 +123,7 @@ const actions = {
).data.data
);
- commit("replaceEnvironmentInList", updatedEnvironment);
+ commit("upsertEnvironmentList", [updatedEnvironment]);
return updatedEnvironment;
},
@@ -127,28 +138,36 @@ const actions = {
return item.id != id;
});
- commit("setEnvironmentList", newList);
+ commit("deleteEnvironmentById", id);
},
};
const mutations = {
- setEnvironmentList(state: EnvironmentState, environmentList: Environment[]) {
- state.environmentList = environmentList;
- },
+ upsertEnvironmentList(
+ state: EnvironmentState,
+ environmentList: Environment[]
+ ) {
+ for (const environment of environmentList) {
+ const i = state.environmentList.findIndex(
+ (item: Environment) => item.id == environment.id
+ );
+ if (i != -1) {
+ state.environmentList[i] = environment;
+ } else {
+ state.environmentList.push(environment);
+ }
- appendEnvironment(state: EnvironmentState, newEnvironment: Environment) {
- state.environmentList.push(newEnvironment);
+ state.environmentList.sort((a, b) => a.order - b.order);
+ }
},
- replaceEnvironmentInList(
- state: EnvironmentState,
- updatedEnvironment: Environment
- ) {
+ deleteEnvironmentById(state: EnvironmentState, environmentId: EnvironmentId) {
const i = state.environmentList.findIndex(
- (item: Environment) => item.id == updatedEnvironment.id
+ (item: Environment) => item.id == environmentId
);
- if (i != -1) {
- state.environmentList[i] = updatedEnvironment;
+
+ if (i >= 0) {
+ state.environmentList.splice(i, 1);
}
},
};
diff --git a/frontend/src/store/modules/router.ts b/frontend/src/store/modules/router.ts
index 779a0d26f1..17e52b359e 100644
--- a/frontend/src/store/modules/router.ts
+++ b/frontend/src/store/modules/router.ts
@@ -11,6 +11,19 @@ const getters = {
routeSlug: (state: RouterState) => (
currentRoute: RouteLocationNormalized
): RouterSlug => {
+ {
+ // /environment/:environmentSlug
+ // Total 2 elements, 2nd element is the task slug
+ const environmentComponents = currentRoute.path.match(
+ "/environment/([0-9a-zA-Z_-]+)"
+ ) || ["/", undefined];
+ if (environmentComponents[1]) {
+ return {
+ environmentSlug: environmentComponents[1],
+ };
+ }
+ }
+
{
// /task/:taskSlug
// Total 2 elements, 2nd element is the task slug
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 130d4b6c69..c175ddc243 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -64,6 +64,7 @@ export const unknown = (
const UNKNOWN_ENVIRONMENT: Environment = {
id: UNKNOWN_ID,
+ rowStatus: "NORMAL",
name: "<<Unknown environment>>",
order: 0,
};
@@ -218,6 +219,10 @@ export type ContainerId = TaskId;
// Persistent State Models
+// RowStatus
+export type RowStatus = "NORMAL" | "ARCHIVED" | "PENDING_DELETE";
+
+// Execution
export type ExecutionStatus = "PENDING" | "RUNNING" | "DONE" | "FAILED";
export type Execution = {
@@ -586,6 +591,7 @@ export type MessagePatch = {
// Environment
export type Environment = {
id: EnvironmentId;
+ rowStatus: RowStatus;
name: string;
order: number;
};
@@ -595,6 +601,7 @@ export type EnvironmentNew = {
};
export type EnvironmentPatch = {
+ rowStatus?: RowStatus;
name?: string;
};
@@ -726,6 +733,7 @@ export enum PlanType {
// UI State Models
export type RouterSlug = {
+ environmentSlug?: string;
taskSlug?: string;
instanceSlug?: string;
databaseSlug?: string;
diff --git a/frontend/src/utils/slug.ts b/frontend/src/utils/slug.ts
index a1b6dcb180..5a80c1216a 100644
--- a/frontend/src/utils/slug.ts
+++ b/frontend/src/utils/slug.ts
@@ -1,4 +1,4 @@
-import { Database, DataSource, Instance, TaskId } from "../types";
+import { Database, DataSource, Environment, Instance, TaskId } from "../types";
import slug from "slug";
export function taskSlug(taskName: string, taskId: TaskId) {
@@ -6,6 +6,10 @@ export function taskSlug(taskName: string, taskId: TaskId) {
}
// On the other hand, it's not possible to de-slug due to slug's one-way algorithm
+export function environmentSlug(environment: Environment): string {
+ return [slug(environment.name), environment.id].join("-");
+}
+
export function instanceSlug(instance: Instance): string {
return [
slug(instance.environment.name),
diff --git a/frontend/src/views/Archive.vue b/frontend/src/views/Archive.vue
index 570e9f0e6f..025e4325ea 100644
--- a/frontend/src/views/Archive.vue
+++ b/frontend/src/views/Archive.vue
@@ -59,6 +59,12 @@ export default {
store.dispatch("instance/fetchInstanceList").catch((error) => {
console.error(error);
});
+
+ store
+ .dispatch("environment/fetchEnvironmentList", "ARCHIVED")
+ .catch((error) => {
+ console.error(error);
+ });
};
watchEffect(prepareInstanceList);
@@ -68,7 +74,7 @@ export default {
});
const environmentList = computed(() => {
- return store.getters["environment/environmentList"]();
+ return store.getters["environment/environmentList"]("ARCHIVED");
});
const filteredInstanceList = (list: Instance[]) => {
diff --git a/frontend/src/views/EnvironmentDashboard.vue b/frontend/src/views/EnvironmentDashboard.vue
index f31d9ab29d..6bde7df9e0 100644
--- a/frontend/src/views/EnvironmentDashboard.vue
+++ b/frontend/src/views/EnvironmentDashboard.vue
@@ -31,9 +31,8 @@
</div>
<EnvironmentDetail
v-else
- :allowDelete="environmentList.length > 1"
- :environment="item"
- @delete="doDelete"
+ :environmentSlug="environmentSlug(item)"
+ @archive="doArchive"
/>
</BBTabPanel>
</BBTab>
@@ -45,6 +44,9 @@
>
<EnvironmentForm
:create="true"
+ :environment="{
+ name: 'New Env',
+ }"
@create="doCreate"
@cancel="state.showCreateModal = false"
/>
@@ -72,8 +74,8 @@ import { onMounted, onUnmounted, computed, reactive, watch } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { array_swap } from "../utils";
-import EnvironmentForm from "../components/EnvironmentForm.vue";
import EnvironmentDetail from "../views/EnvironmentDetail.vue";
+import EnvironmentForm from "../components/EnvironmentForm.vue";
import { Environment, EnvironmentNew } from "../types";
import { BBTabItem } from "../bbkit/types";
@@ -158,7 +160,7 @@ export default {
);
const environmentList = computed(() => {
- return store.getters["environment/environmentList"]();
+ return store.getters["environment/environmentList"]("NORMAL");
});
const tabItemList = computed((): BBTabItem[] => {
@@ -250,17 +252,10 @@ export default {
});
};
- const doDelete = (environment: Environment) => {
- store
- .dispatch("environment/deleteEnvironmentById", environment.id)
- .then(() => {
- if (environmentList.value.length > 0) {
- selectEnvironment(0);
- }
- })
- .catch((error) => {
- console.log(error);
- });
+ const doArchive = (environment: Environment) => {
+ if (environmentList.value.length > 0) {
+ selectEnvironment(0);
+ }
};
const selectEnvironment = (index: number) => {
@@ -279,12 +274,12 @@ export default {
tabItemList,
createEnvironment,
doCreate,
+ doArchive,
doDismissGuide,
reorderEnvironment,
orderChanged,
discardReorder,
doReorder,
- doDelete,
selectEnvironment,
tabClass,
};
diff --git a/frontend/src/views/EnvironmentDetail.vue b/frontend/src/views/EnvironmentDetail.vue
index ef537eb6be..25a97d9ebd 100644
--- a/frontend/src/views/EnvironmentDetail.vue
+++ b/frontend/src/views/EnvironmentDetail.vue
@@ -1,61 +1,48 @@
<template>
+ <div
+ v-if="state.environment.rowStatus == 'ARCHIVED'"
+ class="h-10 w-full text-2xl font-bold bg-gray-700 text-white flex justify-center items-center"
+ >
+ Archived
+ </div>
<EnvironmentForm
v-if="state.environment"
- :allowDelete="allowDelete"
:environment="state.environment"
@update="doUpdate"
- @delete="state.showDeleteModal = true"
+ @archive="doArchive"
+ @restore="doRestore"
/>
- <BBAlert
- v-if="state.showDeleteModal"
- :style="'CRITICAL'"
- :okText="'Delete'"
- :title="'Delete environment \'' + state.environment.name + '\' ?'"
- :description="'You cannot undo this action.'"
- @ok="
- () => {
- state.showDeleteModal = false;
- doDelete();
- }
- "
- @cancel="state.showDeleteModal = false"
- >
- </BBAlert>
</template>
<script lang="ts">
-import { reactive, PropType } from "vue";
+import { reactive } from "vue";
import { useStore } from "vuex";
-import { useRouter } from "vue-router";
import EnvironmentForm from "../components/EnvironmentForm.vue";
import { Environment, EnvironmentPatch } from "../types";
+import { idFromSlug } from "../utils";
export default {
name: "EnvironmentDetail",
- emits: ["delete"],
+ emits: ["archive"],
components: {
EnvironmentForm,
},
props: {
- environment: {
+ environmentSlug: {
required: true,
- type: Object as PropType<Environment>,
- },
- allowDelete: {
- type: Boolean,
- default: true,
+ type: String,
},
},
setup(props, { emit }) {
const store = useStore();
const state = reactive({
- environment: props.environment,
- showDeleteModal: false,
+ environment: store.getters["environment/environmentById"](
+ idFromSlug(props.environmentSlug)
+ ),
+ showArchiveModal: false,
});
- const router = useRouter();
-
const assignEnvironment = (environment: Environment) => {
state.environment = environment;
};
@@ -63,7 +50,7 @@ export default {
const doUpdate = (environmentPatch: EnvironmentPatch) => {
store
.dispatch("environment/patchEnvironment", {
- environmentId: props.environment.id,
+ environmentId: idFromSlug(props.environmentSlug),
environmentPatch,
})
.then((environment) => {
@@ -74,14 +61,44 @@ export default {
});
};
- const doDelete = () => {
- emit("delete", props.environment);
+ const doArchive = (environment: Environment) => {
+ store
+ .dispatch("environment/patchEnvironment", {
+ environmentId: environment.id,
+ environmentPatch: {
+ rowStatus: "ARCHIVED",
+ },
+ })
+ .then((environment) => {
+ emit("archive", environment);
+ assignEnvironment(environment);
+ })
+ .catch((error) => {
+ console.log(error);
+ });
+ };
+
+ const doRestore = (environment: Environment) => {
+ store
+ .dispatch("environment/patchEnvironment", {
+ environmentId: environment.id,
+ environmentPatch: {
+ rowStatus: "NORMAL",
+ },
+ })
+ .then((environment) => {
+ assignEnvironment(environment);
+ })
+ .catch((error) => {
+ console.log(error);
+ });
};
return {
state,
doUpdate,
- doDelete,
+ doArchive,
+ doRestore,
};
},
};