From 01bcd4a254d994893e26818120254c2a7118028b Mon Sep 17 00:00:00 2001 From: Sync Fork Date: Thu, 11 Jan 2024 00:04:17 +0000 Subject: [PATCH] Merge upstream changes --- .changeset/lovely-clocks-boil.md | 5 ++ dashboard/CHANGELOG.md | 12 +++++ dashboard/package.json | 2 +- .../features/ai/DevAssistant/DevAssistant.tsx | 14 +++++- .../useAdminApolloClient.ts | 31 +++++++----- .../hooks/useIsGraphiteEnabled/index.ts | 1 + .../useIsGraphiteEnabled.ts | 14 ++++++ .../assistants/getGraphiteSessions.gql | 7 +++ .../[appSlug]/ai/assistants/index.tsx | 46 ++++++------------ .../[appSlug]/ai/auto-embeddings/index.tsx | 46 ++++++------------ dashboard/src/pages/signin.tsx | 12 +++-- .../utils/__generated__/graphite.graphql.ts | 44 +++++++++++++++++ docs/CHANGELOG.md | 6 +++ docs/guides/ai/enabling-service.mdx | 19 ++++++-- docs/guides/ai/local_development.mdx | 45 +++++++++++++++++ .../ai/local_development/git_status.png | Bin 0 -> 123106 bytes .../git_status_functions.png | Bin 0 -> 112273 bytes .../guides/ai/local_development/migration.png | Bin 0 -> 937553 bytes .../guides/ai/local_development/nhost_up.png | Bin 0 -> 402254 bytes docs/mint.json | 19 ++++---- docs/package.json | 8 ++- docs/product/ai.mdx | 8 +-- packages/docgen/src/templates/TypeTemplate.ts | 2 +- 23 files changed, 240 insertions(+), 101 deletions(-) create mode 100644 .changeset/lovely-clocks-boil.md create mode 100644 dashboard/src/features/projects/common/hooks/useIsGraphiteEnabled/index.ts create mode 100644 dashboard/src/features/projects/common/hooks/useIsGraphiteEnabled/useIsGraphiteEnabled.ts create mode 100644 dashboard/src/gql/graphite/assistants/getGraphiteSessions.gql create mode 100644 docs/guides/ai/local_development.mdx create mode 100644 docs/images/guides/ai/local_development/git_status.png create mode 100644 docs/images/guides/ai/local_development/git_status_functions.png create mode 100644 docs/images/guides/ai/local_development/migration.png create mode 100644 docs/images/guides/ai/local_development/nhost_up.png diff --git a/.changeset/lovely-clocks-boil.md b/.changeset/lovely-clocks-boil.md new file mode 100644 index 0000000000..cbbbfcceb7 --- /dev/null +++ b/.changeset/lovely-clocks-boil.md @@ -0,0 +1,5 @@ +--- +'@nhost/docs': minor +--- + +feat: added graphite/cli documentation diff --git a/dashboard/CHANGELOG.md b/dashboard/CHANGELOG.md index da26ba13aa..156f30f6f8 100644 --- a/dashboard/CHANGELOG.md +++ b/dashboard/CHANGELOG.md @@ -1,5 +1,17 @@ # @nhost/dashboard +## 1.4.0 + +### Minor Changes + +- 7883bbcbd: feat: don't show deprecated plans +- 44be6dc0a: feat: set redirectTo during sign-in to support preview environments + +### Patch Changes + +- 3c3594898: fix: allow access to graphite when configured running in local dashboard +- 32c246b7a: chore: update docs icon + ## 1.3.2 ### Patch Changes diff --git a/dashboard/package.json b/dashboard/package.json index 9fde0565a4..a3a537a75c 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -1,6 +1,6 @@ { "name": "@nhost/dashboard", - "version": "1.3.2", + "version": "1.4.0", "private": true, "scripts": { "preinstall": "npx only-allow pnpm", diff --git a/dashboard/src/features/ai/DevAssistant/DevAssistant.tsx b/dashboard/src/features/ai/DevAssistant/DevAssistant.tsx index 85b172f4e9..85ae6a856b 100644 --- a/dashboard/src/features/ai/DevAssistant/DevAssistant.tsx +++ b/dashboard/src/features/ai/DevAssistant/DevAssistant.tsx @@ -15,6 +15,8 @@ import { } from '@/features/ai/DevAssistant/state'; import { useAdminApolloClient } from '@/features/projects/common/hooks/useAdminApolloClient'; import { useCurrentWorkspaceAndProject } from '@/features/projects/common/hooks/useCurrentWorkspaceAndProject'; +import { useIsGraphiteEnabled } from '@/features/projects/common/hooks/useIsGraphiteEnabled'; +import { useIsPlatform } from '@/features/projects/common/hooks/useIsPlatform'; import { getToastStyleProps } from '@/utils/constants/settings'; import { useSendDevMessageMutation, @@ -33,6 +35,7 @@ export type Message = Omit< >; export default function DevAssistant() { + const isPlatform = useIsPlatform(); const { currentProject, currentWorkspace } = useCurrentWorkspaceAndProject(); const [loading, setLoading] = useState(false); @@ -45,6 +48,8 @@ export default function DevAssistant() { const [startDevSession] = useStartDevSessionMutation({ client: adminClient }); const [sendDevMessage] = useSendDevMessageMutation({ client: adminClient }); + const { isGraphiteEnabled } = useIsGraphiteEnabled(); + const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); @@ -141,7 +146,7 @@ export default function DevAssistant() { } }; - if (currentProject.plan.isFree) { + if (isPlatform && currentProject?.plan?.isFree) { return ( diff --git a/dashboard/src/features/projects/common/hooks/useAdminApolloClient/useAdminApolloClient.ts b/dashboard/src/features/projects/common/hooks/useAdminApolloClient/useAdminApolloClient.ts index 127d135f6d..af7f27a06b 100644 --- a/dashboard/src/features/projects/common/hooks/useAdminApolloClient/useAdminApolloClient.ts +++ b/dashboard/src/features/projects/common/hooks/useAdminApolloClient/useAdminApolloClient.ts @@ -2,6 +2,7 @@ import { useCurrentWorkspaceAndProject } from '@/features/projects/common/hooks/ import { generateAppServiceUrl } from '@/features/projects/common/utils/generateAppServiceUrl'; import { getHasuraAdminSecret } from '@/utils/env'; import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'; +import { useMemo } from 'react'; export default function useAdminApolloClient() { const { currentProject } = useCurrentWorkspaceAndProject(); @@ -12,18 +13,24 @@ export default function useAdminApolloClient() { 'graphql', ); - const adminClient = new ApolloClient({ - cache: new InMemoryCache(), - link: new HttpLink({ - uri: serviceUrl, - headers: { - 'x-hasura-admin-secret': - process.env.NEXT_PUBLIC_ENV === 'dev' - ? getHasuraAdminSecret() - : currentProject?.config?.hasura.adminSecret, - }, - }), - }); + const projectAdminSecret = currentProject.config?.hasura?.adminSecret; + + const adminClient = useMemo( + () => + new ApolloClient({ + cache: new InMemoryCache(), + link: new HttpLink({ + uri: serviceUrl, + headers: { + 'x-hasura-admin-secret': + process.env.NEXT_PUBLIC_ENV === 'dev' + ? getHasuraAdminSecret() + : projectAdminSecret, + }, + }), + }), + [serviceUrl, projectAdminSecret], + ); return { adminClient, diff --git a/dashboard/src/features/projects/common/hooks/useIsGraphiteEnabled/index.ts b/dashboard/src/features/projects/common/hooks/useIsGraphiteEnabled/index.ts new file mode 100644 index 0000000000..d92cbfdd06 --- /dev/null +++ b/dashboard/src/features/projects/common/hooks/useIsGraphiteEnabled/index.ts @@ -0,0 +1 @@ +export { default as useIsGraphiteEnabled } from './useIsGraphiteEnabled'; diff --git a/dashboard/src/features/projects/common/hooks/useIsGraphiteEnabled/useIsGraphiteEnabled.ts b/dashboard/src/features/projects/common/hooks/useIsGraphiteEnabled/useIsGraphiteEnabled.ts new file mode 100644 index 0000000000..6342f47dd2 --- /dev/null +++ b/dashboard/src/features/projects/common/hooks/useIsGraphiteEnabled/useIsGraphiteEnabled.ts @@ -0,0 +1,14 @@ +import { useAdminApolloClient } from '@/features/projects/common/hooks/useAdminApolloClient'; +import { useGetGraphiteSessionsQuery } from '@/utils/__generated__/graphite.graphql'; + +export default function useIsGraphiteEnabled() { + const { adminClient } = useAdminApolloClient(); + + const { error } = useGetGraphiteSessionsQuery({ + client: adminClient, + }); + + return { + isGraphiteEnabled: !error, + }; +} diff --git a/dashboard/src/gql/graphite/assistants/getGraphiteSessions.gql b/dashboard/src/gql/graphite/assistants/getGraphiteSessions.gql new file mode 100644 index 0000000000..26e7f2e2ac --- /dev/null +++ b/dashboard/src/gql/graphite/assistants/getGraphiteSessions.gql @@ -0,0 +1,7 @@ +query getGraphiteSessions { + graphite { + sessions { + sessionID + } + } +} diff --git a/dashboard/src/pages/[workspaceSlug]/[appSlug]/ai/assistants/index.tsx b/dashboard/src/pages/[workspaceSlug]/[appSlug]/ai/assistants/index.tsx index 70de883ec2..89640eb268 100644 --- a/dashboard/src/pages/[workspaceSlug]/[appSlug]/ai/assistants/index.tsx +++ b/dashboard/src/pages/[workspaceSlug]/[appSlug]/ai/assistants/index.tsx @@ -9,14 +9,14 @@ import { Link } from '@/components/ui/v2/Link'; import { Text } from '@/components/ui/v2/Text'; import { AssistantForm } from '@/features/ai/AssistantForm'; import { AssistantsList } from '@/features/ai/AssistantsList'; +import { useAdminApolloClient } from '@/features/projects/common/hooks/useAdminApolloClient'; import { useCurrentWorkspaceAndProject } from '@/features/projects/common/hooks/useCurrentWorkspaceAndProject'; -import { generateAppServiceUrl } from '@/features/projects/common/utils/generateAppServiceUrl'; -import { getHasuraAdminSecret } from '@/utils/env'; +import { useIsGraphiteEnabled } from '@/features/projects/common/hooks/useIsGraphiteEnabled'; +import { useIsPlatform } from '@/features/projects/common/hooks/useIsPlatform'; import { useGetAssistantsQuery, type GetAssistantsQuery, } from '@/utils/__generated__/graphite.graphql'; -import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'; import { useMemo, type ReactElement } from 'react'; export type Assistant = Omit< @@ -26,34 +26,15 @@ export type Assistant = Omit< export default function AssistantsPage() { const { openDrawer } = useDialog(); + const isPlatform = useIsPlatform(); const { currentWorkspace, currentProject } = useCurrentWorkspaceAndProject(); - const adminSecret = currentProject?.config?.hasura?.adminSecret; + const { adminClient } = useAdminApolloClient(); + const { isGraphiteEnabled } = useIsGraphiteEnabled(); - const serviceUrl = generateAppServiceUrl( - currentProject?.subdomain, - currentProject?.region, - 'graphql', - ); - - const client = useMemo( - () => - new ApolloClient({ - cache: new InMemoryCache(), - link: new HttpLink({ - uri: serviceUrl, - headers: { - 'x-hasura-admin-secret': - process.env.NEXT_PUBLIC_ENV === 'dev' - ? getHasuraAdminSecret() - : adminSecret, - }, - }), - }), - [serviceUrl, adminSecret], - ); - - const { data, loading, refetch } = useGetAssistantsQuery({ client }); + const { data, loading, refetch } = useGetAssistantsQuery({ + client: adminClient, + }); const assistants = useMemo(() => data?.graphite?.assistants || [], [data]); @@ -64,7 +45,7 @@ export default function AssistantsPage() { }); }; - if (currentProject.plan.isFree) { + if (isPlatform && currentProject?.plan?.isFree) { return ( diff --git a/dashboard/src/pages/[workspaceSlug]/[appSlug]/ai/auto-embeddings/index.tsx b/dashboard/src/pages/[workspaceSlug]/[appSlug]/ai/auto-embeddings/index.tsx index 3ebbf23bd5..25ef1448cc 100644 --- a/dashboard/src/pages/[workspaceSlug]/[appSlug]/ai/auto-embeddings/index.tsx +++ b/dashboard/src/pages/[workspaceSlug]/[appSlug]/ai/auto-embeddings/index.tsx @@ -11,14 +11,14 @@ import { Link } from '@/components/ui/v2/Link'; import { Text } from '@/components/ui/v2/Text'; import { AutoEmbeddingsForm } from '@/features/ai/AutoEmbeddingsForm'; import { AutoEmbeddingsList } from '@/features/ai/AutoEmbeddingsList'; +import { useAdminApolloClient } from '@/features/projects/common/hooks/useAdminApolloClient'; import { useCurrentWorkspaceAndProject } from '@/features/projects/common/hooks/useCurrentWorkspaceAndProject'; -import { generateAppServiceUrl } from '@/features/projects/common/utils/generateAppServiceUrl'; -import { getHasuraAdminSecret } from '@/utils/env'; +import { useIsGraphiteEnabled } from '@/features/projects/common/hooks/useIsGraphiteEnabled'; +import { useIsPlatform } from '@/features/projects/common/hooks/useIsPlatform'; import { useGetGraphiteAutoEmbeddingsConfigurationsQuery, type GetGraphiteAutoEmbeddingsConfigurationsQuery, } from '@/utils/__generated__/graphite.graphql'; -import { ApolloClient, HttpLink, InMemoryCache } from '@apollo/client'; import { useRouter } from 'next/router'; import { useEffect, useMemo, useRef, useState, type ReactElement } from 'react'; @@ -32,43 +32,22 @@ export default function AutoEmbeddingsPage() { const router = useRouter(); const { openDrawer } = useDialog(); - const { currentWorkspace, currentProject } = useCurrentWorkspaceAndProject(); - const adminSecret = currentProject?.config?.hasura?.adminSecret; + const isPlatform = useIsPlatform(); - const serviceUrl = generateAppServiceUrl( - currentProject?.subdomain, - currentProject?.region, - 'graphql', - ); + const { currentWorkspace, currentProject } = useCurrentWorkspaceAndProject(); - const client = useMemo( - () => - new ApolloClient({ - cache: new InMemoryCache(), - link: new HttpLink({ - uri: serviceUrl, - headers: { - 'x-hasura-admin-secret': - process.env.NEXT_PUBLIC_ENV === 'dev' - ? getHasuraAdminSecret() - : adminSecret, - }, - }), - }), - [serviceUrl, adminSecret], - ); + const { adminClient } = useAdminApolloClient(); + const { isGraphiteEnabled } = useIsGraphiteEnabled(); const [currentPage, setCurrentPage] = useState( parseInt(router.query.page as string, 10) || 1, ); - const [nrOfPages, setNrOfPages] = useState(0); - const offset = useMemo(() => currentPage - 1, [currentPage]); const { data, loading, refetch } = useGetGraphiteAutoEmbeddingsConfigurationsQuery({ - client, + client: adminClient, variables: { limit: limit.current, offset, @@ -102,7 +81,7 @@ export default function AutoEmbeddingsPage() { }); }; - if (currentProject.plan.isFree) { + if (isPlatform && currentProject?.plan?.isFree) { return ( diff --git a/dashboard/src/pages/signin.tsx b/dashboard/src/pages/signin.tsx index f3d27ee456..1b7396c3cf 100644 --- a/dashboard/src/pages/signin.tsx +++ b/dashboard/src/pages/signin.tsx @@ -5,6 +5,7 @@ import { Button } from '@/components/ui/v2/Button'; import { Divider } from '@/components/ui/v2/Divider'; import { GitHubIcon } from '@/components/ui/v2/icons/GitHubIcon'; import { Text } from '@/components/ui/v2/Text'; +import { useHostName } from '@/features/projects/common/hooks/useHostName'; import { getToastStyleProps } from '@/utils/constants/settings'; import { nhost } from '@/utils/nhost'; import type { ReactElement } from 'react'; @@ -14,6 +15,8 @@ import { toast } from 'react-hot-toast'; export default function SignUpPage() { const [loading, setLoading] = useState(false); + const redirectTo = useHostName(); + return ( <> - +