Skip to content

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

Pass new from TaskDetail to subcomponents so those components can become reactive after switching from creation view to normal view

Tianzhou Chenbb27170e02c9
diff --git a/frontend/src/views/TaskContent.vue b/frontend/src/views/TaskContent.vue
index 7af1da6b4c..2351df9c6a 100644
--- a/frontend/src/views/TaskContent.vue
+++ b/frontend/src/views/TaskContent.vue
@@ -1,6 +1,6 @@
<template>
<!-- Content Bar -->
- <div class="flex justify-end space-x-2">
+ <div v-if="!$props.new" class="flex justify-end space-x-2">
<button
v-if="!state.edit"
type="button"
@@ -70,7 +70,15 @@
</template>
<script lang="ts">
-import { nextTick, onMounted, onUnmounted, PropType, ref, reactive } from "vue";
+import {
+ nextTick,
+ onMounted,
+ onUnmounted,
+ watch,
+ PropType,
+ ref,
+ reactive,
+} from "vue";
import { Task } from "../types";
import { sizeToFit } from "../utils";
@@ -86,6 +94,10 @@ export default {
required: true,
type: Object as PropType<Task>,
},
+ new: {
+ required: true,
+ type: Boolean,
+ },
},
components: {},
setup(props, { emit }) {
@@ -112,6 +124,10 @@ export default {
document.addEventListener("keydown", keyboardHandler);
nextTick(() => {
sizeToFit(editContentTextArea.value);
+ if (props.new) {
+ state.edit = true;
+ editContentTextArea.value.focus();
+ }
});
});
@@ -119,6 +135,16 @@ export default {
document.removeEventListener("keydown", keyboardHandler);
});
+ // Reset the edit state after creating the task.
+ watch(
+ () => props.new,
+ (curNew, prevNew) => {
+ if (!curNew && prevNew) {
+ state.edit = false;
+ }
+ }
+ );
+
const beginEdit = () => {
editContent.value = props.task.attributes.content;
state.edit = true;
diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vue
index 87880b8fbf..4459703e3b 100644
--- a/frontend/src/views/TaskDetail.vue
+++ b/frontend/src/views/TaskDetail.vue
@@ -6,7 +6,7 @@
>
<!-- Highlight Panel -->
<div class="bg-white px-4 pt-6 lg:border-t lg:border-block-border">
- <TaskHighlightPanel :task="state.task">
+ <TaskHighlightPanel :task="state.task" :new="state.new">
<template v-if="state.new">
<button
type="button"
@@ -66,12 +66,17 @@
<TaskSidebar
class="lg:hidden"
:task="state.task"
+ :new="state.new"
:fieldList="inputFieldList"
@update-task-status="updateTaskStatus"
@update-custom-field="updateCustomField"
/>
<div class="lg:hidden my-4 border-t border-block-border" />
- <TaskContent :task="state.task" @update-content="updateContent" />
+ <TaskContent
+ :task="state.task"
+ :new="state.new"
+ @update-content="updateContent"
+ />
</div>
<section
v-if="!state.new"
@@ -87,6 +92,7 @@
<TaskSidebar
class="hidden lg:block pt-4 lg:w-72 lg:pl-8 xl:w-80"
:task="state.task"
+ :new="state.new"
:fieldList="inputFieldList"
@update-task-status="updateTaskStatus"
@update-custom-field="updateCustomField"
@@ -355,9 +361,11 @@ export default {
value = field.preprocessor(value);
}
state.task.attributes.payload[field.id] = value;
- patchTask({
- payload: state.task.attributes.payload,
- });
+ if (!state.new) {
+ patchTask({
+ payload: state.task.attributes.payload,
+ });
+ }
};
const doCreate = () => {
diff --git a/frontend/src/views/TaskHighlightPanel.vue b/frontend/src/views/TaskHighlightPanel.vue
index 10e0f285c8..aab764ccff 100644
--- a/frontend/src/views/TaskHighlightPanel.vue
+++ b/frontend/src/views/TaskHighlightPanel.vue
@@ -4,14 +4,14 @@
<div class="flex items-center">
<div>
<div class="flex items-center">
- <TaskStatusIcon v-if="!state.new" :task="task" />
+ <TaskStatusIcon v-if="!$props.new" :task="task" />
<p
class="ml-2 text-xl font-bold leading-7 text-main whitespace-nowrap md:w-96 lg:w-160 truncate"
>
{{ task.attributes.name }}
</p>
</div>
- <div v-if="!state.new">
+ <div v-if="!$props.new">
<p class="mt-2 text-sm text-gray-500">
#{{ task.id }} opened by
<span href="#" class="font-medium text-control">{{
@@ -33,15 +33,10 @@
</template>
<script lang="ts">
-import { PropType, watchEffect, reactive } from "vue";
-import isEmpty from "lodash-es/isEmpty";
+import { PropType } from "vue";
import TaskStatusIcon from "../components/TaskStatusIcon.vue";
import { Task } from "../types";
-interface LocalState {
- new: boolean;
-}
-
export default {
name: "TaskHighlightPanel",
props: {
@@ -49,20 +44,12 @@ export default {
required: true,
type: Object as PropType<Task>,
},
+ new: {
+ required: true,
+ type: Boolean,
+ },
},
components: { TaskStatusIcon },
- setup(props, ctx) {
- const state = reactive<LocalState>({
- new: isEmpty(props.task.id),
- });
-
- const refreshState = () => {
- state.new = isEmpty(props.task.id);
- };
-
- watchEffect(refreshState);
-
- return { state };
- },
+ setup(props, ctx) {},
};
</script>
diff --git a/frontend/src/views/TaskSidebar.vue b/frontend/src/views/TaskSidebar.vue
index d37d72a3a7..73b228b8a5 100644
--- a/frontend/src/views/TaskSidebar.vue
+++ b/frontend/src/views/TaskSidebar.vue
@@ -3,7 +3,7 @@
<h2 class="sr-only">Details</h2>
<div class="space-y-3">
<div
- v-if="!state.new"
+ v-if="!$props.new"
class="flex flex-row space-x-2 lg:flex-col lg:space-x-0"
>
<h2 class="flex items-center textlabel w-1/4 lg:w-auto">Status</h2>
@@ -158,7 +158,7 @@
</template>
</div>
<div
- v-if="!state.new"
+ v-if="!$props.new"
class="mt-6 border-t border-block-border py-6 space-y-4"
>
<div>
@@ -186,7 +186,6 @@ import {
nextTick,
reactive,
ref,
- watchEffect,
} from "vue";
import isEmpty from "lodash-es/isEmpty";
import EnvironmentSelect from "../components/EnvironmentSelect.vue";
@@ -196,7 +195,6 @@ import { Task } from "../types";
import { activeStageIsRunning } from "../utils";
interface LocalState {
- new: boolean;
activeCustomFieldIndex: number;
}
@@ -208,6 +206,10 @@ export default {
required: true,
type: Object as PropType<Task>,
},
+ new: {
+ required: true,
+ type: Boolean,
+ },
fieldList: {
required: true,
type: Object as PropType<TaskField[]>,
@@ -216,7 +218,6 @@ export default {
components: { EnvironmentSelect, TaskStatusSelect },
setup(props, { emit }) {
const state = reactive<LocalState>({
- new: isEmpty(props.task.id),
activeCustomFieldIndex: -1,
});
@@ -252,10 +253,6 @@ export default {
document.removeEventListener("keydown", keyboardHandler);
});
- const refreshState = () => {
- state.new = isEmpty(props.task.id);
- };
-
const fieldValue = (field: TaskField): string => {
return field.preprocessor
? field.preprocessor(props.task.attributes.payload[field.id])
@@ -288,8 +285,6 @@ export default {
state.activeCustomFieldIndex = -1;
};
- watchEffect(refreshState);
-
return {
state,
customFieldSaveButton,