Skip to content

Commit

Permalink
Merge pull request #1453 from PrefectHQ/disable-cancel
Browse files Browse the repository at this point in the history
Enhancement: Show disabled cancel button for runs not created by a deployment
  • Loading branch information
zhen0 authored May 26, 2023
2 parents fb9f1b4 + 012a4ca commit 310eec7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
50 changes: 20 additions & 30 deletions src/components/FlowRunCancelButton.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<template>
<p-tooltip v-if="disableCancel" :text="localization.info.disableFlowRunCancel">
<p-button
disabled
secondary
danger
>
Cancel
</p-button>
</p-tooltip>
<p-button
v-if="canCancel"
v-else-if="canCancel"
secondary
danger
@click="open"
Expand All @@ -15,12 +24,11 @@
</template>

<script lang="ts" setup>
import { useSubscriptionWithDependencies } from '@prefecthq/vue-compositions'
import { computed } from 'vue'
import FlowRunCancelModal from '@/components/FlowRunCancelModal.vue'
import { useWorkspaceApi } from '@/compositions'
import { useCan } from '@/compositions/useCan'
import { useShowModal } from '@/compositions/useShowModal'
import { localization } from '@/localization'
import { FlowRun, isStuckStateType } from '@/models'
const props = defineProps<{
Expand All @@ -30,35 +38,17 @@
const can = useCan()
const { showModal, open } = useShowModal()
const api = useWorkspaceApi()
const flowRunFilter = computed<Parameters<typeof api.flowRuns.getFlowRuns> | null>(() => {
if (props.flowRun.parentTaskRunId) {
return [
{
taskRuns: {
id: [props.flowRun.parentTaskRunId],
},
},
]
}
return null
})
const parentFlowRunListSubscription = useSubscriptionWithDependencies(api.flowRuns.getFlowRuns, flowRunFilter)
const parentFlowRunList = computed(() => parentFlowRunListSubscription.response ?? [])
const parentFlowRunId = computed(() => {
if (!parentFlowRunList.value.length) {
return
}
const [value] = parentFlowRunList.value
return value.id
})
const canCancel = computed(() => {
if (!can.update.flow_run || !props.flowRun.stateType || parentFlowRunId.value || !props.flowRun.deploymentId) {
if (!can.update.flow_run || !props.flowRun.stateType) {
return false
}
return isStuckStateType(props.flowRun.stateType)
})
</script>
const disableCancel = computed(() => {
if (!props.flowRun.deploymentId && canCancel.value) {
return true
}
return false
})
</script>
1 change: 1 addition & 0 deletions src/localization/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,6 @@ export const en = {
taskInput: 'Task inputs show parameter keys and can also show task run relationships.',
workPoolInfrastructureConfigurationInstructions: 'Below you can configure workers\' behavior when executing flow runs from this work pool. You can use the editor in the **Advanced** section to modify the existing configuration options if you need additional configuration options.\nIf you don\'t need to change the default behavior, hit **Create** to create your work pool!',
workPoolInfrastructureConfigurationAgent: 'Prefect Agents handle infrastructure configuration via infrastructure blocks attached to deployments. You can hit **Create** to create this work pool and then head over to the **Blocks** tab to create an infrastructure block for your deployments.\nTo learn more about how to configure infrastructure for Prefect Agents, check out the [docs](https://docs.prefect.io/latest/concepts/infrastructure/).',
disableFlowRunCancel: 'Only runs created from a deployment can be cancelled',
},
}

0 comments on commit 310eec7

Please sign in to comment.