UNPKG

@prefecthq/prefect-ui-library

Version:

This library is the Vue and Typescript component library for [Prefect 2](https://github.com/PrefectHQ/prefect) and [Prefect Cloud 2](https://www.prefect.io/cloud/). _The components and utilities in this project are not meant to be used independently_.

37 lines (29 loc) 1.23 kB
import { SubscriptionOptions, useSubscriptionWithDependencies } from '@prefecthq/vue-compositions' import { computed, MaybeRefOrGetter, toRef, toValue } from 'vue' import { useCan } from '@/compositions/useCan' import { useWorkspaceApi } from '@/compositions/useWorkspaceApi' import { WorkspaceDeploymentsApi } from '@/services/WorkspaceDeploymentsApi' import { Getter } from '@/types/reactivity' import { UseEntitySubscription } from '@/types/useEntitySubscription' export type UseDeployment = UseEntitySubscription<WorkspaceDeploymentsApi['getDeployment'], 'deployment'> export function useDeployment(deploymentId: MaybeRefOrGetter<string | null | undefined>, options?: SubscriptionOptions): UseDeployment { const api = useWorkspaceApi() const can = useCan() const getter: Getter<[string] | null> = () => { if (!can.read.deployment) { return null } const id = toValue(deploymentId) if (!id) { return null } return [id] } const parameters = toRef(getter) const subscription = useSubscriptionWithDependencies(api.deployments.getDeployment, parameters, options) const deployment = computed(() => subscription.response) return { subscription, deployment, } }