+
Developer Tools
@@ -74,22 +74,25 @@ const DeveloperToolsView = ({
}}
/>
-
- Debug Mode
- {
- setDebugMode(e.target.checked);
- }}
- />
-
+
+
+
+ Debug Mode
+ {
+ setDebugMode(e.target.checked);
+ }}
+ />
+
+
diff --git a/frontend/src/components/Editor/EditorView/EditorMenuView.jsx b/frontend/src/components/Editor/EditorView/EditorMenuView.jsx
index 457f070c9..ee9440518 100644
--- a/frontend/src/components/Editor/EditorView/EditorMenuView.jsx
+++ b/frontend/src/components/Editor/EditorView/EditorMenuView.jsx
@@ -8,7 +8,7 @@ const EditorMenuView = ({
isUserIndexer,
handleDeleteIndexer,
isCreateNewIndexer,
- error,
+ schemaError,
// Context
indexerName,
accountId,
@@ -78,7 +78,7 @@ const EditorMenuView = ({
variant="outline-primary"
size="sm"
className="d-flex align-items-center"
- disabled={!!error}
+ disabled={!!schemaError}
onClick={() => setShowPublishModal(true)}
>
diff --git a/frontend/src/components/Editor/EditorViewContainer/EditorMenuContainer.tsx b/frontend/src/components/Editor/EditorViewContainer/EditorMenuContainer.tsx
index 3c6f23734..1fc8b30ef 100644
--- a/frontend/src/components/Editor/EditorViewContainer/EditorMenuContainer.tsx
+++ b/frontend/src/components/Editor/EditorViewContainer/EditorMenuContainer.tsx
@@ -1,6 +1,9 @@
import { request } from 'near-social-bridge';
import React, { useContext } from 'react';
+import { ForkIndexerModal } from '@/components/Modals/ForkIndexerModal';
+import { PublishModal } from '@/components/Modals/PublishModal';
+import { ResetChangesModal } from '@/components/Modals/ResetChangesModal';
import {
CODE_FORMATTING_ERROR_MESSAGE,
FORMATTING_ERROR_TYPE,
@@ -21,28 +24,23 @@ import { sanitizeAccountId, sanitizeIndexerName } from '@/utils/helpers';
import { queryIndexerFunctionDetails as PreviousSavedCode } from '@/utils/queryIndexerFunction';
import { validateJSCode, validateSQLSchema } from '@/utils/validators';
-import { ForkIndexerModal } from '@/components/Modals/ForkIndexerModal';
-import { PublishModal } from '@/components/Modals/PublishModal';
-import { ResetChangesModal } from '@/components/Modals/ResetChangesModal';
import EditorMenuView from '../EditorView/EditorMenuView';
interface EditorMenuContainerProps {
isUserIndexer: boolean;
handleDeleteIndexer: () => void;
isCreateNewIndexer: boolean;
- error: string | undefined;
+ schemaError: string | undefined;
indexingCode: string;
setIndexingCode: (code: string) => void;
currentUserAccountId: string | undefined;
// reset code
setSchema: (schema: string) => void;
setSchemaTypes: (schemaTypes: string) => void;
- setOriginalIndexingCode: (code: string) => void;
- setOriginalSQLCode: (code: string) => void;
// publish
actionButtonText: string;
schema: string;
- setError: (error: string) => void;
+ setSchemaError: (schemaError: string) => void;
showModal: (modalName: string, modalProps: any) => void;
}
@@ -50,19 +48,17 @@ const EditorMenuContainer: React.FC
= ({
isUserIndexer,
handleDeleteIndexer,
isCreateNewIndexer,
- error,
+ schemaError,
indexingCode,
setIndexingCode,
currentUserAccountId,
// reset code
setSchema,
setSchemaTypes,
- setOriginalIndexingCode,
- setOriginalSQLCode,
// publish
actionButtonText,
schema,
- setError,
+ setSchemaError,
showModal,
}) => {
const {
@@ -118,11 +114,9 @@ const EditorMenuContainer: React.FC = ({
const unformattedIndexerCode = wrapCode(data.code);
const unformattedSchemaCode = data.schema;
if (unformattedIndexerCode !== null) {
- setOriginalIndexingCode(unformattedIndexerCode);
setIndexingCode(unformattedIndexerCode);
}
if (unformattedSchemaCode !== null) {
- setOriginalSQLCode(unformattedSchemaCode);
setSchema(unformattedSchemaCode);
}
// todo add reformatting (reformatAll)
@@ -137,7 +131,7 @@ const EditorMenuContainer: React.FC = ({
const { data: validatedCode, error: codeValidationError } = validateJSCode(indexingCode);
if (codeValidationError) {
- setError(CODE_FORMATTING_ERROR_MESSAGE);
+ //todo: setIndexer error(CODE_FORMATTING_ERROR_MESSAGE);
return;
}
@@ -159,7 +153,7 @@ const EditorMenuContainer: React.FC = ({
: 'CONTINUE';
if (schemaValidationError?.type === FORMATTING_ERROR_TYPE) {
- setError(SCHEMA_FORMATTING_ERROR_MESSAGE);
+ setSchemaError(SCHEMA_FORMATTING_ERROR_MESSAGE);
return;
} else if (schemaValidationError?.type === TYPE_GENERATION_ERROR_TYPE) {
showModal(INDEXER_REGISTER_TYPE_GENERATION_ERROR, {
@@ -199,7 +193,7 @@ const EditorMenuContainer: React.FC = ({
isUserIndexer,
handleDeleteIndexer,
isCreateNewIndexer,
- error,
+ schemaError,
// Context
indexerName,
accountId,
diff --git a/frontend/src/contexts/IndexerDetailsContext.tsx b/frontend/src/contexts/IndexerDetailsContext.tsx
index 5bedbf0da..3a98120ac 100644
--- a/frontend/src/contexts/IndexerDetailsContext.tsx
+++ b/frontend/src/contexts/IndexerDetailsContext.tsx
@@ -1,5 +1,5 @@
import { useInitialPayload } from 'near-social-bridge';
-import React, { createContext, useEffect, useState } from 'react';
+import React, { createContext, useCallback, useEffect, useMemo, useState } from 'react';
import { getLatestBlockHeight } from '@/utils/getLatestBlockHeight';
import { queryIndexerFunctionDetails } from '@/utils/queryIndexerFunction';
@@ -19,6 +19,7 @@ interface IndexerDetails {
interface IndexerDetailsContextProps {
indexerDetails: IndexerDetails;
+ setIndexerDetails: (details: IndexerDetails) => void;
showResetCodeModel: boolean;
setShowResetCodeModel: (bool: boolean) => void;
showPublishModal: boolean;
@@ -39,7 +40,6 @@ interface IndexerDetailsContextProps {
setForkedAccountId: (accountId?: string) => void;
forkedIndexerName?: string;
setForkedIndexerName: (indexerName?: string) => void;
- setIndexerDetails: (details: IndexerDetails) => void;
showLogsView: boolean;
setShowLogsView: (showLogsView: boolean) => void;
}
@@ -55,6 +55,7 @@ export const IndexerDetailsContext = createContext({
forkedAccountId: null,
forkedIndexerName: null,
},
+ setIndexerDetails: () => {},
showResetCodeModel: false,
setShowResetCodeModel: () => {},
showPublishModal: false,
@@ -71,7 +72,6 @@ export const IndexerDetailsContext = createContext({
setIndexerName: () => {},
setForkedAccountId: () => {},
setForkedIndexerName: () => {},
- setIndexerDetails: () => {},
showLogsView: false,
setShowLogsView: () => {},
});
@@ -103,13 +103,13 @@ export const IndexerDetailsProvider: React.FC = ({
const [latestHeight, setLatestHeight] = useState(0);
const [isCreateNewIndexer, setIsCreateNewIndexer] = useState(false);
- const activeView = useInitialPayload(); // Adjust the type according to what useInitialPayload returns
+ const activeView = useInitialPayload();
useEffect(() => {
if (activeView === 'status') setShowLogsView(true);
}, [activeView]);
- const requestIndexerDetails = async (): Promise => {
+ const requestIndexerDetails = useCallback(async (): Promise => {
if (!accountId || !indexerName) return undefined;
const data = await queryIndexerFunctionDetails(accountId, indexerName);
if (data) {
@@ -125,13 +125,14 @@ export const IndexerDetailsProvider: React.FC = ({
};
return details;
}
- };
+ }, [accountId, indexerName]);
useEffect(() => {
- (async () => {
+ const fetchData = async () => {
const latestHeight = await getLatestBlockHeight();
setLatestHeight(latestHeight);
- })();
+ };
+ fetchData();
}, []);
useEffect(() => {
@@ -145,42 +146,70 @@ export const IndexerDetailsProvider: React.FC = ({
}));
return;
}
- (async () => {
+ const fetchIndexerDetails = async () => {
const indexer = await requestIndexerDetails();
if (indexer) {
setIndexerDetails(indexer);
}
- })();
- }, [accountId, indexerName, forkedAccountId, forkedIndexerName, isCreateNewIndexer]);
+ };
+ fetchIndexerDetails();
+ }, [
+ accountId,
+ indexerName,
+ forkedAccountId,
+ forkedIndexerName,
+ isCreateNewIndexer,
+ requestIndexerDetails,
+ setIndexerDetails,
+ ]);
- return (
-
- {children}
-
+ const contextValue = useMemo(
+ () => ({
+ accountId,
+ indexerName,
+ setAccountId,
+ setIndexerName,
+ setForkedAccountId,
+ setForkedIndexerName,
+ indexerDetails,
+ setIndexerDetails,
+ showResetCodeModel,
+ setShowResetCodeModel,
+ showPublishModal,
+ setShowPublishModal,
+ showForkIndexerModal,
+ setShowForkIndexerModal,
+ debugMode,
+ setDebugMode,
+ latestHeight,
+ setLatestHeight,
+ isCreateNewIndexer,
+ setIsCreateNewIndexer,
+ showLogsView,
+ setShowLogsView,
+ }),
+ [
+ accountId,
+ indexerName,
+ setAccountId,
+ setIndexerName,
+ setForkedAccountId,
+ setForkedIndexerName,
+ indexerDetails,
+ setIndexerDetails,
+ showResetCodeModel,
+ setShowResetCodeModel,
+ showPublishModal,
+ setShowPublishModal,
+ showForkIndexerModal,
+ setShowForkIndexerModal,
+ debugMode,
+ setDebugMode,
+ latestHeight,
+ isCreateNewIndexer,
+ showLogsView,
+ ],
);
+
+ return {children};
};
diff --git a/frontend/src/pages/query-api-editor/index.js b/frontend/src/pages/query-api-editor/index.js
index 5e047f8db..603bf5148 100644
--- a/frontend/src/pages/query-api-editor/index.js
+++ b/frontend/src/pages/query-api-editor/index.js
@@ -11,34 +11,20 @@ const QueryApiEditorPage = ({ router }) => {
const { setAccountId, setIndexerName, showLogsView } = useContext(IndexerDetailsContext);
useEffect(() => {
- if (accountId == undefined || indexerName == undefined) {
- return;
- }
+ if (!accountId || !indexerName) return;
setAccountId(accountId);
setIndexerName(indexerName);
- }, [accountId, indexerName, setAccountId, setIndexerName]);
+ }, [accountId, indexerName]);
if (accountId == undefined || indexerName == undefined) {
return (
- <>
-
- Both accountId and IndexerName need to be specified in the URL.
-
- >
+
+ Both accountId and IndexerName need to be specified in the URL.
+
);
}
- return (
- <>
- {showLogsView ? (
-
- ) : (
-
- )}
- >
- );
+
+ return showLogsView ? : ;
};
export default withRouter(QueryApiEditorPage);
diff --git a/frontend/src/utils/formatters.js b/frontend/src/utils/formatters.js
index 5c48d08b4..2598aeca8 100644
--- a/frontend/src/utils/formatters.js
+++ b/frontend/src/utils/formatters.js
@@ -39,10 +39,14 @@ export const wrapCode = (code) => {
};
export const formatIndexingCode = (code) => {
- return prettier.format(code, {
- parser: 'babel',
- plugins: [parserBabel],
- });
+ try {
+ return prettier.format(code, {
+ parser: 'babel',
+ plugins: [parserBabel],
+ });
+ } catch (error) {
+ throw new Error(`Failed to format code: ${error.message}`);
+ }
};
export const defaultCode = formatIndexingCode(
diff --git a/frontend/src/utils/validators.ts b/frontend/src/utils/validators.ts
index 685fac29f..eaeecc078 100644
--- a/frontend/src/utils/validators.ts
+++ b/frontend/src/utils/validators.ts
@@ -47,13 +47,11 @@ export function validateJSCode(code: string): { data: string | null; error: Erro
try {
const formattedCode = formatIndexingCode(code);
return { data: formattedCode, error: null };
- } catch (error: unknown) {
- if (error instanceof Error) {
- console.error(error.message);
- return { data: code, error };
- } else {
- throw error;
- }
+ } catch (error: any) {
+ return {
+ data: code,
+ error: error.message, //todo: add specific error messages here
+ };
}
}