Skip to content

Commit

Permalink
fix(automate): redirect github auth flow to workspace if possible (#3632
Browse files Browse the repository at this point in the history
)

* fix(automate): redirect to workspace after auth if possible

* fix(automate): include session in github auth flow

* chore(automate): update props after merge

* fix(automate): pick => fragment

* fix(automate): use fragments correctly
  • Loading branch information
cdriesler authored Dec 6, 2024
1 parent 4e6f199 commit 02be49f
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 46 deletions.
27 changes: 21 additions & 6 deletions packages/frontend-2/components/automate/function/CreateDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ import {
useUpdateAutomateFunction
} from '~/lib/automate/composables/management'
import { useMutationLoading } from '@vue/apollo-composable'
import type { AutomateFunctionCreateDialogDoneStep_AutomateFunctionFragment } from '~~/lib/common/generated/gql/graphql'
import type {
AutomateFunctionCreateDialogDoneStep_AutomateFunctionFragment,
AutomateFunctionCreateDialog_WorkspaceFragment
} from '~~/lib/common/generated/gql/graphql'
import { useMixpanel } from '~/lib/core/composables/mp'
import { graphql } from '~/lib/common/generated/gql'
enum FunctionCreateSteps {
Authorize,
Expand All @@ -73,11 +77,19 @@ enum FunctionCreateSteps {
type DetailsFormValues = FunctionDetailsFormValues
graphql(`
fragment AutomateFunctionCreateDialog_Workspace on Workspace {
id
name
slug
}
`)
const props = defineProps<{
isAuthorized: boolean
templates: CreatableFunctionTemplate[]
githubOrgs: string[]
workspaceId?: string
workspace?: AutomateFunctionCreateDialog_WorkspaceFragment
}>()
const open = defineModel<boolean>('open', { required: true })
Expand Down Expand Up @@ -114,19 +126,19 @@ const onDetailsSubmit = handleDetailsSubmit(async (values) => {
templateId: selectedTemplate.value.id,
name: values.name,
/* eslint-disable-next-line camelcase */
workspace_id: props.workspaceId
workspace_id: props.workspace?.id
})
createdFunction.value = res
step.value++
if (!props.workspaceId) {
if (!props.workspace?.id) {
return
}
await updateFunction({
input: {
id: res.id,
workspaceIds: [props.workspaceId]
workspaceIds: [props.workspace.id]
}
})
})
Expand Down Expand Up @@ -184,7 +196,10 @@ const title = computed(() => {
})
const authorizeGithubUrl = computed(() => {
const redirectUrl = new URL(automateGithubAppAuthorizationRoute, apiBaseUrl)
const redirectUrl = new URL(
automateGithubAppAuthorizationRoute(props.workspace?.slug),
apiBaseUrl
)
return redirectUrl.toString()
})
Expand Down
12 changes: 10 additions & 2 deletions packages/frontend-2/components/automate/function/EditDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ import { difference, differenceBy } from 'lodash-es'
import { useForm } from 'vee-validate'
import { useUpdateAutomateFunction } from '~/lib/automate/composables/management'
import type { FunctionDetailsFormValues } from '~/lib/automate/helpers/functions'
import type { Workspace } from '~/lib/common/generated/gql/graphql'
import { graphql } from '~/lib/common/generated/gql'
import type { AutomateFunctionEditDialog_WorkspaceFragment } from '~/lib/common/generated/gql/graphql'
graphql(`
fragment AutomateFunctionEditDialog_Workspace on Workspace {
id
name
}
`)
const props = defineProps<{
model: FunctionDetailsFormValues
fnId: string
workspaces?: Pick<Workspace, 'id' | 'name'>[]
workspaces?: AutomateFunctionEditDialog_WorkspaceFragment[]
}>()
const open = defineModel<boolean>('open', { required: true })
const { handleSubmit, setValues } = useForm<FunctionDetailsFormValues>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,11 @@
<script setup lang="ts">
import { ValidationHelpers } from '@speckle/ui-components'
import { isArray } from 'lodash-es'
import { graphql } from '~/lib/common/generated/gql'
import type { Workspace } from '~/lib/common/generated/gql/graphql'
graphql(`
fragment AutomateFunctionCreateDialog_Workspace on Workspace {
id
name
}
`)
import type { AutomateFunctionCreateDialog_WorkspaceFragment } from '~/lib/common/generated/gql/graphql'
defineProps<{
githubOrgs?: string[]
workspaces?: Pick<Workspace, 'id' | 'name'>[]
workspaces?: AutomateFunctionCreateDialog_WorkspaceFragment[]
}>()
const avatarEditMode = ref(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
:is-authorized="!!activeUser?.automateInfo.hasAutomateGithubApp"
:github-orgs="activeUser?.automateInfo.availableGithubOrgs || []"
:templates="availableTemplates"
:workspace-id="workspace?.id"
:workspace="workspace"
/>
</div>
</template>
Expand All @@ -45,8 +45,8 @@ import { Roles, type Nullable, type Optional } from '@speckle/shared'
import { useDebouncedTextInput } from '@speckle/ui-components'
import { graphql } from '~/lib/common/generated/gql'
import type {
AutomateFunctionsPageHeader_QueryFragment,
Workspace
AutomateFunctionCreateDialog_WorkspaceFragment,
AutomateFunctionsPageHeader_QueryFragment
} from '~/lib/common/generated/gql/graphql'
import { workspaceFunctionsRoute, workspaceRoute } from '~/lib/common/helpers/route'
import { useMixpanel } from '~/lib/core/composables/mp'
Expand Down Expand Up @@ -74,7 +74,7 @@ graphql(`
const props = defineProps<{
activeUser: Optional<AutomateFunctionsPageHeader_QueryFragment['activeUser']>
serverInfo: Optional<AutomateFunctionsPageHeader_QueryFragment['serverInfo']>
workspace?: Pick<Workspace, 'id' | 'slug' | 'name'>
workspace?: AutomateFunctionCreateDialog_WorkspaceFragment
}>()
const search = defineModel<string>('search')
Expand Down
13 changes: 6 additions & 7 deletions packages/frontend-2/components/project/page/automations/Tab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="flex flex-col gap-y-4 md:gap-y-6">
<ProjectPageAutomationsHeader
v-model:search="search"
:workspace-slug="workspaceSlug"
:workspace-slug="workspace?.slug"
:show-empty-state="shouldShowEmptyState"
:creation-disabled-message="disableCreateAutomationMessage"
@new-automation="onNewAutomation"
Expand All @@ -13,7 +13,7 @@
<template v-else>
<ProjectPageAutomationsEmptyState
v-if="shouldShowEmptyState"
:workspace-slug="workspaceSlug"
:workspace-slug="workspace?.slug"
:hidden-actions="hiddenActions"
:disabled-actions="disabledActions"
@new-automation="onNewAutomation"
Expand All @@ -37,15 +37,15 @@
</template>
</template>
<AutomateAutomationCreateDialog
v-if="workspaceId"
v-if="workspace?.id"
v-model:open="showNewAutomationDialog"
:workspace-id="workspaceId"
:workspace-id="workspace?.id"
:preselected-project="project"
:preselected-function="newAutomationTargetFn"
/>
<AutomateFunctionCreateDialog
v-model:open="showNewFunctionDialog"
:workspace-id="workspaceId"
:workspace="workspace"
:is-authorized="isGithubAppConfigured"
:github-orgs="githubOrgs"
:templates="availableFunctionTemplates"
Expand Down Expand Up @@ -83,8 +83,7 @@ const { result, loading } = useQuery(
})
)
const workspaceId = computed(() => result.value?.project?.workspace?.id)
const workspaceSlug = computed(() => result.value?.project?.workspace?.slug)
const workspace = computed(() => result.value?.project?.workspace ?? undefined)
const workspaceFunctionCount = computed(
() => result.value?.project.workspace?.automateFunctions.totalCount ?? 0
Expand Down
Loading

0 comments on commit 02be49f

Please sign in to comment.