Skip to content

Commit

Permalink
Merge upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sync Fork committed Feb 21, 2024
1 parent e6b1004 commit e92007f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-camels-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@nhost/dashboard': patch
---

fix: refresh table list after running SQL using the editor
5 changes: 5 additions & 0 deletions .changeset/fluffy-apples-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@nhost/dashboard': patch
---

fix: handle `Error` objects properly in the `ErrorToast` component
54 changes: 41 additions & 13 deletions dashboard/src/components/ui/v2/ErrorToast/ErrorToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { XIcon } from '@/components/ui/v2/icons/XIcon';
import { useCurrentWorkspaceAndProject } from '@/features/projects/common/hooks/useCurrentWorkspaceAndProject';
import { getToastBackgroundColor } from '@/utils/constants/settings';
import { copy } from '@/utils/copy';
import { type ApolloError } from '@apollo/client';
import { ApolloError } from '@apollo/client';
import { useUserData } from '@nhost/nextjs';
import { AnimatePresence, motion } from 'framer-motion';
import { useRouter } from 'next/router';
Expand All @@ -20,6 +20,43 @@ interface ErrorDetails {
error: any;
}

const getInternalErrorMessage = (
error: Error | ApolloError | undefined,
): string | null => {
if (!error) {
return null;
}

if (error instanceof ApolloError) {
const internalError = error.graphQLErrors?.[0]?.extensions?.internal as
| { error: { message: string } }
| undefined;
return internalError?.error?.message || null;
}

if (error instanceof Error) {
return error.message;
}

return null;
};

const errorToObject = (error: ApolloError | Error) => {
if (error instanceof ApolloError) {
return error;
}

if (error instanceof Error) {
return {
name: error.name,
message: error.message,
stack: error.stack,
};
}

return {};
};

export default function ErrorToast({
isVisible,
errorMessage,
Expand All @@ -28,7 +65,7 @@ export default function ErrorToast({
}: {
isVisible: boolean;
errorMessage: string;
error: ApolloError;
error: ApolloError | Error;
close: () => void;
}) {
const userData = useUserData();
Expand All @@ -43,19 +80,10 @@ export default function ErrorToast({
userId: userData?.id || 'local',
url: asPath,
},
error,
};

const internalError = error?.graphQLErrors?.at(0)?.extensions?.internal as {
error: {
message: string;
};
error: errorToObject(error),
};

const msg =
internalError?.error?.message ||
error?.graphQLErrors?.at(0).message ||
errorMessage;
const msg = getInternalErrorMessage(error) || errorMessage;

return (
<AnimatePresence>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useDatabaseQuery } from '@/features/database/dataGrid/hooks/useDatabaseQuery';
import { useCurrentWorkspaceAndProject } from '@/features/projects/common/hooks/useCurrentWorkspaceAndProject';
import { generateAppServiceUrl } from '@/features/projects/common/utils/generateAppServiceUrl';
import { getToastStyleProps } from '@/utils/constants/settings';
import { getHasuraAdminSecret } from '@/utils/env';
import { parseIdentifiersFromSQL } from '@/utils/sql';
import toast from 'react-hot-toast';
import { useRouter } from 'next/router';
import { useState } from 'react';
import toast from 'react-hot-toast';

export default function useRunSQL(
sqlCode: string,
Expand All @@ -22,6 +24,14 @@ export default function useRunSQL(
const [columns, setColumns] = useState<string[]>([]);
const [rows, setRows] = useState<string[][]>([[]]);

const router = useRouter();

const {
query: { dataSourceSlug },
} = router;

const { refetch } = useDatabaseQuery([dataSourceSlug as string]);

const appUrl = generateAppServiceUrl(
currentProject?.subdomain,
currentProject?.region,
Expand Down Expand Up @@ -269,6 +279,9 @@ export default function useRunSQL(
}
}

// refresh the table list after running the sql
await refetch();

setLoading(false);
};

Expand Down

0 comments on commit e92007f

Please sign in to comment.