Skip to content

Commit

Permalink
feat: events workflow in wizard (#969)
Browse files Browse the repository at this point in the history
added events into launchpad.
  • Loading branch information
Kevin101Zhang authored Aug 2, 2024
1 parent a0b9284 commit 6a1810b
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 421 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/Editor/EditorComponents/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ const Editor: React.FC = (): ReactElement => {
const fetchData = async () => {
try {
const response = await fetchWizardData('');
const { wizardContractFilter, wizardMethods } = response;
const { wizardContractFilter, wizardMethods, wizardEvents } = response;

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

const codeResponse = await generateCode(wizardContractFilter, wizardMethods);
const codeResponse = await generateCode(wizardContractFilter, wizardMethods, wizardEvents);
setIndexingCode(codeResponse.jsCode);
setSchema(codeResponse.sqlCode);
} catch (error: unknown) {
Expand Down
164 changes: 0 additions & 164 deletions frontend/src/components/Editor/EditorComponents/GenerateCode.tsx

This file was deleted.

6 changes: 2 additions & 4 deletions frontend/src/pages/api/generateCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const validateRequestBody = (body: any): body is RequestBody => {
isStringOrArray(body.contractFilter) &&
Array.isArray(body.selectedMethods) &&
body.selectedMethods.every(isValidMethod)
// && Array.isArray(body.selectedEvents) &&
// body.selectedEvents.every(isValidEvent)
&& Array.isArray(body.selectedEvents) &&
body.selectedEvents.every(isValidEvent)
);
};

Expand All @@ -59,7 +59,6 @@ export default function handler(req: NextApiRequest, res: NextApiResponse): void
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');

if (req.method === 'OPTIONS') {
res.status(200).end();
return;
Expand All @@ -78,7 +77,6 @@ export default function handler(req: NextApiRequest, res: NextApiResponse): void
}

const { contractFilter, selectedMethods, selectedEvents } = req.body;

const filterString = Array.isArray(contractFilter) ? contractFilter.join(', ') : contractFilter;

const generator = new WizardCodeGenerator(filterString, selectedMethods, selectedEvents);
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/pages/query-api-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, { useContext, useEffect } from 'react';
import { Alert } from 'react-bootstrap';

import Editor from '@/components/Editor/EditorComponents/Editor';
import GenerateCode from '@/components/Editor/EditorComponents/GenerateCode';
import IndexerLogsContainer from '@/components/Logs/LogsViewContainer/IndexerLogsContainer';
import { IndexerDetailsContext } from '@/contexts/IndexerDetailsContext';

Expand All @@ -25,10 +24,6 @@ const QueryApiEditorPage = ({ router }) => {
);
}

if (accountId == 'test' && indexerName == 'test') {
return <GenerateCode />;
}

return showLogsView ? <IndexerLogsContainer /> : <Editor />;
};

Expand Down
55 changes: 53 additions & 2 deletions frontend/src/test/api/generateCode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const createRequestResponseMocks = (
};
};

describe('generateCode API', () => {
it('should return generated JS and SQL code for valid input', async () => {
describe('generateCode API ', () => {
it('should return generated JS and SQL code for valid input methods', async () => {
const { req, res } = createRequestResponseMocks('POST', {
contractFilter: 'filter',
selectedMethods: [
Expand Down Expand Up @@ -65,6 +65,56 @@ describe('generateCode API', () => {
},
},
],
selectedEvents: [],
});

handler(req, res);

expect(res._getStatusCode()).toBe(200);
const responseData = JSON.parse(res._getData());
console.log(responseData);
});

it('should return generated JS and SQL code for valid input events', async () => {
const { req, res } = createRequestResponseMocks('POST', {
contractFilter: 'filter',
selectedMethods: [],
selectedEvents: [{
event_name: 'register',
schema: {
type: 'object',
properties: {
function_name: {
type: 'string',
},
code: {
type: 'string',
},
schema: {
type: 'string',
},
start_block_height: {
type: 'integer',
},
filter_json: {
type: 'string',
},
},
required: ['function_name', 'code', 'schema', 'start_block_height', 'filter_json'],
},
},
{
event_name: 'remove_indexer_function',
schema: {
type: 'object',
properties: {
function_name: {
type: 'string',
},
},
required: ['function_name'],
},
},],
});

handler(req, res);
Expand All @@ -73,6 +123,7 @@ describe('generateCode API', () => {
const responseData = JSON.parse(res._getData());
console.log(responseData);
});

it('should handle empty arrays correctly because I mean maybe they just want something to do with contractName?', async () => {
const { req, res } = createRequestResponseMocks('POST', {
contractFilter: 'filter',
Expand Down
3 changes: 3 additions & 0 deletions frontend/widgets/src/QueryApi.Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const [activeTab, setActiveTab] = useState(props.view === "create-new-indexer" ?
const [activeIndexerTabView, setActiveIndexerTabView] = useState(props.activeIndexerView ?? "editor");
const [selectedIndexer, setSelectedIndexer] = useState(props.selectedIndexerPath);

const [wizardEvents, setWizardEvents] = useState({});
const [wizardMethods, setWizardMethods] = useState({});
const [wizardContractFilter, setWizardContractFilter] = useState('');

Expand Down Expand Up @@ -109,6 +110,7 @@ return (
setSelectedIndexer: setSelectedIndexer,
setWizardContractFilter: setWizardContractFilter,
setWizardMethods: setWizardMethods,
setWizardEvents: setWizardEvents,
}}
/>
</Section>
Expand All @@ -131,6 +133,7 @@ return (
path: "create-new-indexer",
wizardContractFilter: wizardContractFilter,
wizardMethods: wizardMethods,
wizardEvents: wizardEvents,
}}
/>
</Section>
Expand Down
5 changes: 3 additions & 2 deletions frontend/widgets/src/QueryApi.Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const activeView = props.activeView || "editor";
let accountId = props.accountId || context.accountId;
let externalAppUrl = `${REPL_EXTERNAL_APP_URL}/${path}?accountId=${accountId}`;

const { wizardContractFilter, wizardMethods } = props;
const { wizardContractFilter, wizardMethods, wizardEvents } = props;

if (props.indexerName) {
externalAppUrl += `&indexerName=${props.indexerName}`;
Expand Down Expand Up @@ -60,7 +60,8 @@ let deleteIndexer = (request) => {
const getLaunchpadCode = (request, response) => {
const wizardContractFilter = wizardContractFilter ?? 'noFilter';
const wizardMethods = wizardMethods;
response(request).send({ wizardContractFilter, wizardMethods });
const wizardEvents = wizardEvents;
response(request).send({ wizardContractFilter, wizardMethods, wizardEvents });
}

/**
Expand Down
Loading

0 comments on commit 6a1810b

Please sign in to comment.