-
Notifications
You must be signed in to change notification settings - Fork 3
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: show wizard data on Editor UI from BOS #936
Changes from all commits
08e514c
6315b17
7ca2eb8
e42d5cf
221540e
025663a
aa62353
0e4ba08
0bb5f0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,4 @@ | ||
const { setActiveTab, activeTab, setSelectedIndexer, setWizardContractFilter, setWizardMethods } = props; | ||
const AlertText = styled.p` | ||
font-family: 'Mona Sans', sans-serif; | ||
font-size: 14px; | ||
line-height: 21px; | ||
text-align: center; | ||
color:red; | ||
margin: 0; | ||
padding: 0; | ||
bg-color: #f9f9f9; | ||
`; | ||
|
||
const NoQueryContainer = styled.div` | ||
display: flex; | ||
|
@@ -210,6 +200,7 @@ scrollbar-color: #888 #f1f1f1; | |
`; | ||
|
||
const GenerateMethodsButton = styled.button` | ||
margin-top: 16px; | ||
width: 100%; | ||
background-color: #37CD83; | ||
border: none; | ||
|
@@ -222,6 +213,12 @@ const GenerateMethodsButton = styled.button` | |
justify-content: center; | ||
position:relative; | ||
z-index:10; | ||
|
||
&:disabled { | ||
background-color: #F3F3F2; | ||
color: #999; | ||
cursor: not-allowed; | ||
} | ||
` | ||
|
||
const InputWrapper = styled.div` | ||
|
@@ -448,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); | ||
|
||
|
||
|
@@ -463,7 +459,6 @@ const initializeCheckboxState = (data) => { | |
}); | ||
} | ||
}); | ||
|
||
return initialState; | ||
}; | ||
|
||
|
@@ -474,24 +469,36 @@ useEffect(() => { | |
const generateMethods = () => { | ||
const filteredData = checkBoxData.map(item => { | ||
const parentChecked = checkboxState[item.method_name]; | ||
if (!item.schema || !item.schema.properties) return null; | ||
|
||
const filteredProperties = Object.keys(item.schema.properties).reduce((acc, property) => { | ||
const childKey = `${item.method_name}::${property}`; | ||
if (checkboxState[childKey]) { | ||
acc[property] = item.schema.properties[property]; | ||
if (!item.schema) return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you have an if statement like this, you don't need to have item.schema checks in following if statements. You can leave it out as you know following code is guaranteed to have item.schema. The same follows for any other things you check. If you want that to be readily apparent, you can leave in the else block that's omitted here. All subsequent code lives in the else instead. This leads to a lot of tabbing, which can then be a signal that maybe a refactor is needed. You can maybe try something like the following:
Something like that. In any case, my main point is this code is confusing. Can you refactor this code to make its logic more apparent at first glance?
|
||
|
||
if (!item.schema.properties) { | ||
if (parentChecked) { | ||
return { | ||
method_name: item.method_name, | ||
schema: { | ||
...item.schema | ||
} | ||
}; | ||
} | ||
return acc; | ||
}, {}); | ||
|
||
if (parentChecked || Object.keys(filteredProperties).length > 0) { | ||
return { | ||
method_name: item.method_name, | ||
schema: { | ||
...item.schema, | ||
properties: filteredProperties | ||
return null; | ||
} else { | ||
const result = Object.entries(item.schema.properties).reduce((acc, [property, details]) => { | ||
const childKey = `${item.method_name}::${property}`; | ||
if (checkboxState[childKey]) { | ||
acc.filteredProperties[property] = details; | ||
} | ||
}; | ||
return acc; | ||
}, { filteredProperties: {}, shouldReturn: parentChecked }); | ||
|
||
if (result.shouldReturn || Object.keys(result.filteredProperties).length > 0) { | ||
return { | ||
method_name: item.method_name, | ||
schema: { | ||
...item.schema, | ||
properties: result.filteredProperties | ||
} | ||
}; | ||
} | ||
} | ||
|
||
return null; | ||
|
@@ -540,9 +547,8 @@ const handleFetchCheckboxData = async () => { | |
setLoading(false); | ||
return; | ||
}; | ||
|
||
setCheckBoxData(data); | ||
setMethodCount(data.length); | ||
setCheckBoxData(data.methods); | ||
setMethodCount(data.methods.length); | ||
setLoading(false); | ||
}).catch(error => { | ||
setLoading(false); | ||
|
@@ -551,7 +557,6 @@ const handleFetchCheckboxData = async () => { | |
|
||
}; | ||
|
||
|
||
const handleParentChange = (methodName) => { | ||
setCheckboxState(prevState => { | ||
const newState = !prevState[methodName]; | ||
|
@@ -585,9 +590,12 @@ const handleChildChange = (key) => { | |
}); | ||
}; | ||
|
||
const hasSelectedMethod = (checkboxState) => { | ||
return Object.values(checkboxState).some(value => value === true); | ||
} | ||
|
||
return ( | ||
<> | ||
<AlertText>Please note that this page is currently under development. Features may be incomplete or inaccurate</AlertText> | ||
<Hero> | ||
<Container> | ||
<HeadlineContainer> | ||
|
@@ -623,7 +631,7 @@ return ( | |
</NoQueryContainer> | ||
</> | ||
: ( | ||
<div> | ||
<SubContainerContent> | ||
{checkBoxData.length > 0 && ( | ||
<MethodsText> | ||
Methods <MethodsSpan>{methodCount}</MethodsSpan> | ||
|
@@ -665,10 +673,9 @@ return ( | |
) | ||
} | ||
</ScrollableDiv> | ||
<GenerateMethodsButton onClick={generateMethods}> Generate</GenerateMethodsButton> | ||
</div> | ||
</SubContainerContent> | ||
)} | ||
|
||
<GenerateMethodsButton onClick={generateMethods} disabled={!checkboxState || !hasSelectedMethod(checkboxState)}> Generate</GenerateMethodsButton> | ||
</SubContainerContent> | ||
</SubContainer> | ||
</WidgetContainer> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we validate the data returned as well? To make sure it has jsCode and sqlCode fields? And how do we handle a failure here visually? If something goes wrong, what would be the next best customer experience? Being redirected to a page which lets them explore existing indexers? The Create new indexer page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I can validate it to check for a correct response. Im not sure what the correct user response would be if the generateAPI fails. we have already forcefully already navigated them to the editor component outside of BOS.