-
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: Update frontend to handle new registry types #566
Changes from all commits
b82ce8d
17640df
a8c51ce
7f0af0f
78607ec
bd39fb7
7fcb435
655e734
8630b9d
1682be3
b4e386b
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,49 +1,73 @@ | ||
import React, { useContext, useState, useEffect } from "react"; | ||
import { InputGroup, Alert } from "react-bootstrap"; | ||
import Form from "react-bootstrap/Form"; | ||
|
||
import { IndexerDetailsContext } from '../../contexts/IndexerDetailsContext'; | ||
import { validateContractIds } from "../../utils/validators"; | ||
|
||
const GENESIS_BLOCK_HEIGHT = 9820210; | ||
|
||
const START_BLOCK = { | ||
CONTINUE: "startBlockContinue", | ||
LATEST: "startBlockLatest", | ||
HEIGHT: "startBlockHeight", | ||
} | ||
|
||
const IndexerConfigOptions = ({ updateConfig }) => { | ||
const { indexerDetails, showPublishModal, isCreateNewIndexer, latestHeight } = useContext(IndexerDetailsContext); | ||
const [blockHeight, setBlockHeight] = useState("0"); | ||
const [contractFilter, setContractFilter] = useState("social.near"); | ||
const [selectedOption, setSelectedOption] = useState("latestBlockHeight"); | ||
const [startBlock, setStartBlock] = useState(START_BLOCK.LATEST); | ||
const [isContractFilterValid, setIsContractFilterValid] = useState(true); | ||
const [indexerNameField, setIndexerNameField] = useState(indexerDetails.indexerName || ""); | ||
const [blockHeightError, setBlockHeightError] = useState(null) | ||
|
||
const handleOptionChange = (event) => { | ||
setSelectedOption(event.target.value); | ||
// setBlockHeightError(null); | ||
}; | ||
|
||
useEffect(() => { | ||
if (indexerDetails.config?.startBlockHeight) { | ||
setSelectedOption("specificBlockHeight") | ||
setBlockHeight(indexerDetails.config.startBlockHeight) | ||
if (indexerDetails.rule?.affected_account_id) { | ||
setContractFilter(indexerDetails.rule.affected_account_id) | ||
} | ||
if (indexerDetails.config?.filter) { | ||
setContractFilter(indexerDetails.config.filter) | ||
|
||
if (indexerDetails.startBlock?.HEIGHT) { | ||
setStartBlock(START_BLOCK.HEIGHT) | ||
setBlockHeight(indexerDetails.startBlock.HEIGHT) | ||
return; | ||
} | ||
|
||
if (indexerDetails.startBlock == "LATEST") { | ||
setStartBlock(START_BLOCK.LATEST) | ||
return; | ||
} | ||
|
||
if (indexerDetails.startBlock == "CONTINUE") { | ||
setStartBlock(START_BLOCK.CONTINUE) | ||
return; | ||
} | ||
}, [indexerDetails]) | ||
|
||
function handleSetContractFilter(e) { | ||
const contractFilter = e.target.value; | ||
const onChangeStartBlock = (e) => { | ||
setStartBlock(e.target.value) | ||
|
||
if (e.target.value === START_BLOCK.CONTINUE) { | ||
handleSetContractFilter(indexerDetails.rule.affected_account_id) | ||
} | ||
} | ||
|
||
function handleSetContractFilter(contractFilter) { | ||
setContractFilter(contractFilter); | ||
const isContractFilterValid = validateContractIds(contractFilter); | ||
setIsContractFilterValid(isContractFilterValid); | ||
} | ||
|
||
useEffect(() => { | ||
if (selectedOption == "specificBlockHeight" && blockHeight <= GENESIS_BLOCK_HEIGHT) { | ||
setBlockHeightError(() => `Choose a block height greater than the Genesis BlockHeight ${GENESIS_BLOCK_HEIGHT}. Latest Block Height is ${latestHeight}`) | ||
return | ||
} | ||
setBlockHeightError(() => null) | ||
updateConfig(indexerNameField, contractFilter, blockHeight, selectedOption) | ||
}, | ||
[indexerNameField, contractFilter, selectedOption, blockHeight]) | ||
if (startBlock == START_BLOCK.HEIGHT && blockHeight <= GENESIS_BLOCK_HEIGHT) { | ||
setBlockHeightError(() => `Choose a block height greater than the Genesis BlockHeight ${GENESIS_BLOCK_HEIGHT}. Latest Block Height is ${latestHeight}`) | ||
return | ||
} | ||
setBlockHeightError(() => null) | ||
updateConfig(indexerNameField, contractFilter, blockHeight, startBlock) | ||
}, | ||
[indexerNameField, contractFilter, startBlock, blockHeight] | ||
) | ||
|
||
return ( | ||
<> | ||
|
@@ -58,23 +82,34 @@ const IndexerConfigOptions = ({ updateConfig }) => { | |
onChange={(e) => setIndexerNameField(e.target.value.toLowerCase().trim())} | ||
/> | ||
</InputGroup> | ||
<InputGroup size="sm" className="pt-3"> | ||
<InputGroup.Checkbox | ||
value={START_BLOCK.LATEST} | ||
checked={startBlock === START_BLOCK.LATEST} | ||
onChange={onChangeStartBlock} | ||
aria-label="Checkbox for following text input" | ||
/> | ||
<InputGroup.Text>Start from latest block</InputGroup.Text> | ||
</InputGroup> | ||
{!isCreateNewIndexer && ( | ||
<InputGroup size="sm" className="pt-3"> | ||
<InputGroup.Checkbox | ||
value="latestBlockHeight" | ||
checked={selectedOption === "latestBlockHeight"} | ||
onChange={handleOptionChange} | ||
value={START_BLOCK.CONTINUE} | ||
checked={startBlock === START_BLOCK.CONTINUE} | ||
onChange={onChangeStartBlock} | ||
aria-label="Checkbox for following text input" | ||
/> | ||
<InputGroup.Text>From Latest Block Height</InputGroup.Text> | ||
<InputGroup.Text>Continue from last processed block</InputGroup.Text> | ||
</InputGroup> | ||
<InputGroup size="sm" className="px-1 pt-3"> | ||
)} | ||
<InputGroup size="sm" className="pt-3"> | ||
<InputGroup.Checkbox | ||
value="specificBlockHeight" | ||
checked={selectedOption === "specificBlockHeight"} | ||
onChange={handleOptionChange} | ||
value={START_BLOCK.HEIGHT} | ||
checked={startBlock === START_BLOCK.HEIGHT} | ||
onChange={onChangeStartBlock} | ||
aria-label="Checkbox for following text input" | ||
/> | ||
<InputGroup.Text>Specific Block Height</InputGroup.Text> | ||
<InputGroup.Text>Start from block height</InputGroup.Text> | ||
<Form.Control | ||
value={blockHeight} | ||
onChange={(e) => setBlockHeight(parseInt(e.target.value))} | ||
|
@@ -86,19 +121,25 @@ const IndexerConfigOptions = ({ updateConfig }) => { | |
</Alert> | ||
)} | ||
</InputGroup> | ||
<InputGroup size="sm" hasValidation={true} className="px-1 pt-3"> | ||
<InputGroup.Text> Contract Filter</InputGroup.Text> | ||
<InputGroup size="sm" hasValidation={true} className="pt-3"> | ||
<InputGroup.Text>Contract Filter</InputGroup.Text> | ||
<Form.Control | ||
value={contractFilter} | ||
onChange={handleSetContractFilter} | ||
value={startBlock === START_BLOCK.CONTINUE ? indexerDetails.rule.affected_account_id : contractFilter} | ||
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. Is it possible to change the filter on LATEST, then check CONTINUE and it publishes new filter IDs anyway? 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. Nope, when we change to |
||
onChange={(e) => handleSetContractFilter(e.target.value)} | ||
isValid={isContractFilterValid} | ||
type="text" | ||
placeholder="social.near" | ||
required={true} | ||
disabled={startBlock === START_BLOCK.CONTINUE} | ||
/> | ||
<Form.Control.Feedback type="invalid"> | ||
Please provide a valid contract name. | ||
</Form.Control.Feedback> | ||
{startBlock === START_BLOCK.CONTINUE && ( | ||
<Alert className="px-3 mt-3" variant="warning"> | ||
Contract filter cannot be changed for "Continue" option. | ||
</Alert> | ||
)} | ||
</InputGroup> | ||
</> | ||
); | ||
|
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.
How come startBlockHeight sets startBlock to an object whereas latest and continue set it to a string? Is this a quirk of the way the new register function expects it?