-
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
DPLT-1034 feat: allow to edit indexer when forking #127
Changes from all commits
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 |
---|---|---|
|
@@ -34,6 +34,7 @@ const Editor = ({ | |
debugMode, | ||
isCreateNewIndexer, | ||
indexerNameField, | ||
setAccountId, | ||
} = useContext(IndexerDetailsContext); | ||
|
||
const DEBUG_LIST_STORAGE_KEY = `QueryAPI:debugList:${indexerDetails.accountId}#${indexerDetails.indexerName}` | ||
|
@@ -90,28 +91,6 @@ const Editor = ({ | |
localStorage.setItem(DEBUG_LIST_STORAGE_KEY, heights); | ||
}, [heights]); | ||
|
||
// useEffect(() => { | ||
// if (selectedOption == "latestBlockHeight") { | ||
// setBlockHeightError(null); | ||
// return; | ||
// } | ||
// | ||
// if (height - blockHeight > BLOCKHEIGHT_LIMIT) { | ||
// setBlockHeightError( | ||
// `Warning: Please enter a valid start block height. At the moment we only support historical indexing of the last ${BLOCKHEIGHT_LIMIT} blocks or ${BLOCKHEIGHT_LIMIT / 3600 | ||
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. Code that is not needed anymore. |
||
// } hrs. Choose a start block height between ${height - BLOCKHEIGHT_LIMIT | ||
// } - ${height}.` | ||
// ); | ||
// } else if (blockHeight > height) { | ||
// setBlockHeightError( | ||
// `Warning: Start Block Hieght can not be in the future. Please choose a value between ${height - BLOCKHEIGHT_LIMIT | ||
// } - ${height}.` | ||
// ); | ||
// } else { | ||
// setBlockHeightError(null); | ||
// } | ||
// }, [blockHeight, height, selectedOption]); | ||
|
||
const checkSQLSchemaFormatting = () => { | ||
try { | ||
let formatted_sql = formatSQL(schema); | ||
|
@@ -127,10 +106,21 @@ const Editor = ({ | |
} | ||
}; | ||
|
||
|
||
const forkIndexer = async(indexerName) => { | ||
let code = indexingCode; | ||
setAccountId(currentUserAccountId) | ||
let prevAccountId = indexerDetails.accountId.replaceAll(".", "_"); | ||
let newAccountId = currentUserAccountId.replaceAll(".", "_"); | ||
let prevIndexerName = indexerDetails.indexerName.replaceAll("-", "_").trim().toLowerCase(); | ||
let newIndexerName = indexerName.replaceAll("-", "_").trim().toLowerCase(); | ||
code = code.replaceAll(prevAccountId, newAccountId); | ||
code = code.replaceAll(prevIndexerName, newIndexerName); | ||
setIndexingCode(formatIndexingCode(code)) | ||
} | ||
|
||
const registerFunction = async (indexerName, indexerConfig) => { | ||
let formatted_schema = checkSQLSchemaFormatting(); | ||
let isForking = indexerDetails.accountId !== currentUserAccountId; | ||
|
||
let innerCode = indexingCode.match(/getBlock\s*\([^)]*\)\s*{([\s\S]*)}/)[1]; | ||
indexerName = indexerName.replaceAll(" ", "_"); | ||
if (formatted_schema == undefined) { | ||
|
@@ -140,14 +130,6 @@ const Editor = ({ | |
); | ||
return; | ||
} | ||
|
||
if (isForking) { | ||
let prevAccountName = indexerDetails.accountId.replace(".", "_"); | ||
let newAccountName = currentUserAccountId.replace(".", "_"); | ||
|
||
innerCode = innerCode.replaceAll(prevAccountName, newAccountName); | ||
} | ||
|
||
setError(() => undefined); | ||
|
||
request("register-function", { | ||
|
@@ -170,8 +152,8 @@ const Editor = ({ | |
const handleReload = async () => { | ||
if (isCreateNewIndexer) { | ||
setShowResetCodeModel(false); | ||
setIndexingCode(defaultCode); | ||
setSchema(defaultSchema); | ||
setIndexingCode((formatIndexingCode(indexerDetails.code))); | ||
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. When reloading, if you have forked an indexer, then it will reload the forked indexer rather than the default code. 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. This is a pretty nice change! |
||
setSchema(formatSQL(indexerDetails.schema)) | ||
return; | ||
} | ||
|
||
|
@@ -331,7 +313,7 @@ const Editor = ({ | |
blockHeightError={blockHeightError} | ||
/> | ||
<ForkIndexerModal | ||
registerFunction={registerFunction} | ||
forkIndexer={forkIndexer} | ||
/> | ||
|
||
<div | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,7 @@ const EditorButtons = ({ | |
<Breadcrumb.Item className="flex align-center " href="#"> | ||
{accountId} | ||
</Breadcrumb.Item> | ||
{!isCreateNewIndexer && ( | ||
{indexerName && ( | ||
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. when you have a forked Indexer, it has a But when we are creating a new indexer, it is fine not to show any breadcrumbs. 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. What is a Breadcrumb in this case? 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. |
||
<Breadcrumb.Item href="#" active style={{ display: "flex" }}> | ||
{indexerName} | ||
</Breadcrumb.Item> | ||
|
@@ -169,21 +169,33 @@ const EditorButtons = ({ | |
<Justify style={{ paddingRight: "2px" }} size={24} /> | ||
</Button> | ||
</OverlayTrigger> | ||
{currentUserAccountId && ( | ||
{(!isUserIndexer && !isCreateNewIndexer) ? ( | ||
<OverlayTrigger | ||
placement="bottom" | ||
overlay={<Tooltip>{getActionButtonText()}</Tooltip>} | ||
overlay={<Tooltip>Fork Indexer</Tooltip>} | ||
> | ||
<Button | ||
variant="primary" | ||
className="px-3" | ||
onClick={() => setShowForkIndexerModal(true)} | ||
> | ||
Fork Indexer | ||
</Button> | ||
</OverlayTrigger> | ||
) : ( | ||
<OverlayTrigger | ||
placement="bottom" | ||
overlay={<Tooltip>Publish</Tooltip>} | ||
> | ||
<Button | ||
variant="primary" | ||
className="px-3" | ||
onClick={() => setShowPublishModal(true)} | ||
> | ||
{getActionButtonText()} | ||
Publish | ||
</Button> | ||
</OverlayTrigger> | ||
)} | ||
|
||
</ButtonGroup> | ||
</Col> | ||
</Row> | ||
|
@@ -208,6 +220,5 @@ const EditorButtons = ({ | |
</> | ||
); | ||
}; | ||
|
||
|
||
export default EditorButtons; |
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.
This commented code seems to be doing something useful, checking for too large block heights. Is this code implemented elsewhere or do we not need to do this check anymore? Also the code on line 24 and 43 may not be needed since they reference things that are only present in the code being removed. Unless they're used by another class somewhere else. Also, given that this code is in FrontEnd, would it be worth it to add unit tests which pass in valid and invalid block heights?
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.
We used to have a limitation in the number of blocks we would allow to be historically indexed. As a result we showed error messages if the user's set the block height prior to what our limit at that time was. I believe it was an hour or 3,600 blocks.
We have removed this limit now, and this code is not going to be needed anymore.
@gabehamilton thought that the relative block heights that we provided were quite helpful, so we still provide some helpful information regarding setting block height in this modal.