Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wrap generated wizard code with header code #997

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions frontend/src/components/Editor/EditorComponents/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { request, useInitialPayload } from 'near-social-bridge';

Check warning on line 1 in frontend/src/components/Editor/EditorComponents/Editor.tsx

View workflow job for this annotation

GitHub Actions / lint

Run autofix to sort these imports!
import type { ReactElement } from 'react';
import type { Method, Event } from '@/pages/api/generateCode';

Expand All @@ -15,7 +15,14 @@
} from '@/constants/Strings';
import { IndexerDetailsContext } from '@/contexts/IndexerDetailsContext';
import { useModal } from '@/contexts/ModalContext';
import { defaultCode, defaultSchema, defaultSchemaTypes, formatIndexingCode, formatSQL } from '@/utils/formatters';
import {
defaultCode,
defaultSchema,
defaultSchemaTypes,
formatIndexingCode,
formatSQL,
wrapCode,
} from '@/utils/formatters';
import { getLatestBlockHeight } from '@/utils/getLatestBlockHeight';
import IndexerRunner from '@/utils/indexerRunner';
import { PgSchemaTypeGen } from '@/utils/pgSchemaTypeGen';
Expand All @@ -31,7 +38,7 @@

declare const monaco: any;
const INDEXER_TAB_NAME = 'indexer.js';
const SCHEMA_TAB_NAME = 'schema.sql';

Check warning on line 41 in frontend/src/components/Editor/EditorComponents/Editor.tsx

View workflow job for this annotation

GitHub Actions / lint

'SCHEMA_TAB_NAME' is assigned a value but never used. Allowed unused vars must match /^_/u
const originalSQLCode = formatSQL(defaultSchema);
const originalIndexingCode = formatIndexingCode(defaultCode);
const pgSchemaTypeGen = new PgSchemaTypeGen();
Expand Down Expand Up @@ -71,7 +78,7 @@
const [heights, setHeights] = useState<number[]>(initialHeights);

const [diffView, setDiffView] = useState<boolean>(false);
const [blockView, setBlockView] = useState<boolean>(false);

Check warning on line 81 in frontend/src/components/Editor/EditorComponents/Editor.tsx

View workflow job for this annotation

GitHub Actions / lint

'setBlockView' is assigned a value but never used. Allowed unused vars must match /^_/u
const { showModal } = useModal();

const [isExecutingIndexerFunction, setIsExecutingIndexerFunction] = useState<boolean>(false);
Expand Down Expand Up @@ -141,26 +148,24 @@
};

useEffect(() => {
const fetchData = async () => {
(async () => {
try {
const response = await fetchWizardData('');
const { wizardContractFilter, wizardMethods, wizardEvents } = response;
const { wizardContractFilter, wizardMethods, wizardEvents } = await fetchWizardData('');

if (wizardContractFilter === 'noFilter') {
return;
}
if (wizardContractFilter === 'noFilter') return;

const { jsCode, sqlCode } = await generateCode(wizardContractFilter, wizardMethods, wizardEvents);
const wrappedIndexingCode = wrapCode(jsCode) ? wrapCode(jsCode) : jsCode;
const { validatedCode, validatedSchema } = reformatAll(wrappedIndexingCode, sqlCode);

const codeResponse = await generateCode(wizardContractFilter, wizardMethods, wizardEvents);
const { validatedCode, validatedSchema } = reformatAll(codeResponse.jsCode, codeResponse.sqlCode);
validatedCode && setIndexingCode(validatedCode);
validatedSchema && setSchema(validatedSchema);
} catch (error: unknown) {
//todo: figure out best course of action for user if api fails
console.error(error);
}
};
fetchData();
})();
}, []);

Check warning on line 168 in frontend/src/components/Editor/EditorComponents/Editor.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'reformatAll'. Either include it or remove the dependency array

useEffect(() => {
//* Load saved code from local storage if it exists else load code from context
Expand All @@ -178,7 +183,7 @@
monacoEditorRef.current.setPosition(savedCursorPosition || { lineNumber: 1, column: 1 });
monacoEditorRef.current.focus();
}
}, [indexerDetails.code]);

Check warning on line 186 in frontend/src/components/Editor/EditorComponents/Editor.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has missing dependencies: 'fileName' and 'storageManager'. Either include them or remove the dependency array

useEffect(() => {
//* Load saved schema from local storage if it exists else load code from context
Expand All @@ -189,7 +194,7 @@
schemaErrorHandler(schemaError);
formattedSchema && setSchema(formattedSchema);
}
}, [indexerDetails.schema]);

Check warning on line 197 in frontend/src/components/Editor/EditorComponents/Editor.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'storageManager'. Either include it or remove the dependency array

useEffect(() => {
const { error: schemaError } = validateSQLSchema(schema);
Expand All @@ -202,11 +207,11 @@
}

handleCodeGen();
}, [fileName]);

Check warning on line 210 in frontend/src/components/Editor/EditorComponents/Editor.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has missing dependencies: 'handleCodeGen', 'indexingCode', and 'schema'. Either include them or remove the dependency array

useEffect(() => {
cacheToLocal();
}, [indexingCode, schema]);

Check warning on line 214 in frontend/src/components/Editor/EditorComponents/Editor.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'cacheToLocal'. Either include it or remove the dependency array

useEffect(() => {
if (!monacoEditorRef.current) return;
Expand All @@ -217,12 +222,12 @@
return () => {
editorInstance.dispose();
};
}, [monacoEditorRef.current]);

Check warning on line 225 in frontend/src/components/Editor/EditorComponents/Editor.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has a missing dependency: 'handleCursorChange'. Either include it or remove the dependency array. Mutable values like 'monacoEditorRef.current' aren't valid dependencies because mutating them doesn't re-render the component

useEffect(() => {
storageManager?.setSchemaTypes(schemaTypes);
handleCodeGen();
}, [schemaTypes, monacoMount]);

Check warning on line 230 in frontend/src/components/Editor/EditorComponents/Editor.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useEffect has missing dependencies: 'handleCodeGen' and 'storageManager'. Either include them or remove the dependency array

useEffect(() => {
storageManager?.setDebugList(heights);
Expand Down
Loading