Skip to content

Commit

Permalink
fix: clarified BOS Editor code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin101Zhang committed Jul 31, 2024
1 parent 0e4ba08 commit 0bb5f0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
9 changes: 7 additions & 2 deletions frontend/src/components/Editor/EditorComponents/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ const Editor: React.FC = (): ReactElement => {
throw new Error('Network response was not ok');
}
const data = await response.json();

if (!data.hasOwnProperty('jsCode') || !data.hasOwnProperty('sqlCode')) {
throw new Error('No code was returned from the server');
}

return data;
} catch (error) {
throw error;
Expand All @@ -140,16 +145,16 @@ const Editor: React.FC = (): ReactElement => {
try {
const response = await fetchWizardData('');
const { wizardContractFilter, wizardMethods } = response;

if (wizardContractFilter === 'noFilter') {
//request returns user did not navigate from the launchpad. Exit
return;
}

const codeResponse = await generateCode(wizardContractFilter, wizardMethods);
setIndexingCode(codeResponse.jsCode);
setSchema(codeResponse.sqlCode);
} catch (error: unknown) {
//todo: figure out best course of action for user if api fails
console.error(error);
}
};
Expand Down
19 changes: 7 additions & 12 deletions frontend/widgets/src/QueryApi.Launchpad.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ const [checkboxState, setCheckboxState] = useState(initialCheckboxState);
const [methodCount, setMethodCount] = useState(0);
const [contractInputMessage, setContractInputMessage] = useState('');
const [inputValue, setInputValue] = useState('');
const [allIndexers, setAllIndexers] = useState([]);
const [loading, setLoading] = useState(false);


Expand All @@ -460,7 +459,6 @@ const initializeCheckboxState = (data) => {
});
}
});

return initialState;
};

Expand All @@ -473,7 +471,7 @@ const generateMethods = () => {
const parentChecked = checkboxState[item.method_name];
if (!item.schema) return null;

if (item.schema && !item.schema.properties) {
if (!item.schema.properties) {
if (parentChecked) {
return {
method_name: item.method_name,
Expand All @@ -483,23 +481,21 @@ const generateMethods = () => {
};
}
return null;
}

if (item.schema && item.schema.properties) {
const filteredProperties = Object.keys(item.schema.properties).reduce((acc, property) => {
} else {
const result = Object.entries(item.schema.properties).reduce((acc, [property, details]) => {
const childKey = `${item.method_name}::${property}`;
if (checkboxState[childKey]) {
acc[property] = item.schema.properties[property];
acc.filteredProperties[property] = details;
}
return acc;
}, {});
}, { filteredProperties: {}, shouldReturn: parentChecked });

if (parentChecked || Object.keys(filteredProperties).length > 0) {
if (result.shouldReturn || Object.keys(result.filteredProperties).length > 0) {
return {
method_name: item.method_name,
schema: {
...item.schema,
properties: filteredProperties
properties: result.filteredProperties
}
};
}
Expand Down Expand Up @@ -561,7 +557,6 @@ const handleFetchCheckboxData = async () => {

};


const handleParentChange = (methodName) => {
setCheckboxState(prevState => {
const newState = !prevState[methodName];
Expand Down

0 comments on commit 0bb5f0a

Please sign in to comment.