Skip to content

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

Support InstanceSelect filter by environmentId

天舟63f047522299
diff --git a/frontend/src/components/InstanceSelect.vue b/frontend/src/components/InstanceSelect.vue
index bd9e4c283d..1c747e3ea3 100644
--- a/frontend/src/components/InstanceSelect.vue
+++ b/frontend/src/components/InstanceSelect.vue
@@ -22,8 +22,9 @@
</template>
<script lang="ts">
-import { computed, reactive } from "vue";
+import { computed, reactive, watch } from "vue";
import { useStore } from "vuex";
+import { Instance } from "../types";
interface LocalState {
selectedId?: string;
@@ -37,6 +38,9 @@ export default {
selectedId: {
type: String,
},
+ environmentId: {
+ type: String,
+ },
},
setup(props, { emit }) {
const store = useStore();
@@ -45,9 +49,37 @@ export default {
});
const instanceList = computed(() => {
+ if (props.environmentId) {
+ return store.getters["instance/instanceListByEnvironmentId"](
+ props.environmentId
+ );
+ }
return store.getters["instance/instanceList"]();
});
+ watch(
+ () => props.selectedId,
+ (cur, _) => {
+ state.selectedId = cur;
+ }
+ );
+
+ // The instance list might change if environmentId changes, and the previous selected id
+ // might not exist in the new list. In such case, we need to invalidate the selection
+ // and emit the event.
+ watch(
+ () => instanceList.value,
+ (curList, _) => {
+ if (
+ state.selectedId &&
+ !curList.find((instance: Instance) => instance.id == state.selectedId)
+ ) {
+ state.selectedId = undefined;
+ emit("select-instance-id", undefined);
+ }
+ }
+ );
+
return {
state,
instanceList,
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
index 8db30987bc..37b7835421 100644
--- a/frontend/src/store/modules/instance.ts
+++ b/frontend/src/store/modules/instance.ts
@@ -6,6 +6,7 @@ import {
InstanceState,
ResourceObject,
Environment,
+ EnvironmentId,
} from "../../types";
function convert(instance: ResourceObject, rootGetters: any): Instance {
@@ -34,6 +35,15 @@ const getters = {
});
},
+ instanceListByEnvironmentId: (state: InstanceState, getters: any) => (
+ environmentId: EnvironmentId
+ ) => {
+ const list = getters["instanceList"]();
+ return list.filter(
+ (item: Instance) => item.environment.id == environmentId
+ );
+ },
+
instanceById: (state: InstanceState) => (instanceId: InstanceId) => {
return state.instanceById.get(instanceId);
},