Skip to content

Commit

Permalink
Added Feature to calculate BH, Modified Redirect Links, and Resolved …
Browse files Browse the repository at this point in the history
…Minor Bugs (#775)

Enhanced the logs table by adding contextual information such as
timestamps and the number of blocks from NEAR's latest block for
developers on the Logs Table.
  • Loading branch information
Kevin101Zhang authored Jun 6, 2024
1 parent 0c3b7cf commit eb87759
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const DeveloperToolsView = ({
</button>


<div class="h-full border-r border-gray-300 mx-4"></div>
<div className="h-full border-r border-gray-300 mx-4"></div>

<div className={`relative flex items-center justify-center px-2 py-1 bg-gray-200 hover:bg-gray-300 text-gray-700 text-xs rounded ${diffView ? 'bg-gray-600 hover:bg-gray-700 text-white' : 'bg-gray-200 hover:bg-gray-300'}`} onClick={handleCodeGen}>
<span className="px-3">Diff View</span>
Expand Down
12 changes: 10 additions & 2 deletions frontend/src/components/Logs/LogsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useQuery, gql } from "@apollo/client";
import { Button, Navbar, Container, ButtonGroup, Spinner } from "react-bootstrap";
import { ArrowCounterclockwise, Code } from "react-bootstrap-icons";
import { IndexerDetailsContext } from "../../contexts/IndexerDetailsContext";
import { calculateBlockTimeDifference } from "../../utils/calculateBlockTimeDifference";

interface LogsMenuProps {
currentUserAccountId: string;
Expand Down Expand Up @@ -78,7 +79,7 @@ const LogsMenu: React.FC<LogsMenuProps> = ({
console.error('Error reloading data:', error);
}
};

return (
<Navbar bg="white" variant="light" className="shadow-sm p-3 mb-4 bg-white rounded">
<Container fluid className="d-flex flex-wrap justify-content-between align-items-center">
Expand All @@ -92,9 +93,16 @@ const LogsMenu: React.FC<LogsMenuProps> = ({
<span className="me-4 text-secondary text-sm">
Height: <strong>{loading ? <Spinner animation="border" size="sm" /> : blockHeight ?? "N/A"}</strong>
</span>
<span className="text-secondary text-sm">
<span className="me-4 text-secondary text-sm">
Status: <strong>{loading ? <Spinner animation="border" size="sm" /> : status ?? "UNKNOWN"}</strong>
</span>
{!loading && blockHeight && latestHeight && (
<div className="bg-gray-100 border border-gray-300 rounded p-1 text-xs text-gray-700">
<span className="text-secondary">
Indexer is {Number(latestHeight) - Number(blockHeight)} blocks or {calculateBlockTimeDifference(Number(latestHeight), Number(blockHeight))} behind tip.
</span>
</div>
)}
</div>
<ButtonGroup className="mt-3 mt-md-0">
<Button size="sm" variant="outline-primary" className="d-flex align-items-center" onClick={handleReload}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const ViewContainer: React.FC<Props> = ({ updateConfig }) => {
}
setBlockHeightError(null);
updateConfig(indexerNameField, contractFilter, blockHeight, startBlock);
}, [indexerNameField, contractFilter, startBlock, blockHeight, latestHeight, updateConfig]);
}, [indexerNameField, contractFilter, startBlock, blockHeight, latestHeight]);

return (
<PublishFormView
Expand All @@ -89,6 +89,7 @@ const ViewContainer: React.FC<Props> = ({ updateConfig }) => {
setBlockHeight={setBlockHeight}
handleSetContractFilter={handleSetContractFilter}
updateConfig={updateConfig}
indexerDetails={indexerDetails}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const PublishFormView = ({
setBlockHeight,
handleSetContractFilter,
updateConfig,
indexerDetails,
}) => (
<div className="space-y-6">
<div className="flex flex-col">
Expand Down
25 changes: 25 additions & 0 deletions frontend/src/utils/calculateBlockTimeDifference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const calculateBlockTimeDifference = (latestBlockHeight: number, currentBlockHeight: number): string => {
const averageBlockTimeSeconds: number = 1.3;
const blocksDifference: number = Math.abs(currentBlockHeight - latestBlockHeight);

const timeDifferenceSeconds: number = blocksDifference * averageBlockTimeSeconds;

const days: number = Math.floor(timeDifferenceSeconds / (3600 * 24));
const hours: number = Math.floor((timeDifferenceSeconds % (3600 * 24)) / 3600);
const minutes: number = Math.floor((timeDifferenceSeconds % 3600) / 60);
const seconds: number = Math.floor(timeDifferenceSeconds % 60);

let timeDifferenceString: string = '';
if (days > 0) {
timeDifferenceString += `${days}day${days > 1 ? 's' : ''} `;
}
if (hours > 0) {
timeDifferenceString += `${hours}hr${hours > 1 ? 's' : ''} `;
}
if (minutes > 0 || hours > 0) {
timeDifferenceString += `${minutes}min${minutes > 1 ? 's' : ''} `;
}
timeDifferenceString += `${seconds}s`;

return timeDifferenceString.trim();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if (props.tab && props.tab !== state.selectedTab) {
});
}

const activityUrl = `/#/${APP_OWNER}/widget/QueryApi.Feed`;
const activityUrl = `/${APP_OWNER}/widget/QueryApi.Feed`;

const Wrapper = styled.div`
margin-top: calc(var(--body-top-padding) * -1);
Expand Down
8 changes: 4 additions & 4 deletions frontend/widgets/src/QueryApi.Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ const selectIndexerPage = (viewName) => {
});
};
const indexerView = (accountId, indexerName) => {
const editUrl = `https://dev.near.org/#/${REPL_ACCOUNT_ID}/widget/QueryApi.App?selectedIndexerPath=${accountId}/${indexerName}`;
const statusUrl = `https://dev.near.org/#/${REPL_ACCOUNT_ID}/widget/QueryApi.App?selectedIndexerPath=${accountId}/${indexerName}&view=indexer&activeIndexerView=status`;
const editUrl = `https://dev.near.org/${REPL_ACCOUNT_ID}/widget/QueryApi.App?selectedIndexerPath=${accountId}/${indexerName}`;
const statusUrl = `https://dev.near.org/${REPL_ACCOUNT_ID}/widget/QueryApi.App?selectedIndexerPath=${accountId}/${indexerName}&view=indexer&activeIndexerView=status`;
const playgroundLink = `https://cloud.hasura.io/public/graphiql?endpoint=${REPL_GRAPHQL_ENDPOINT}/v1/graphql&header=x-hasura-role%3A${accountId.replaceAll(
".",
"_"
Expand Down Expand Up @@ -406,7 +406,7 @@ return (
<Main>
<Section active={state.activeTab === "explore"}>
<NavBarLogo
href={`https://dev.near.org/#/${REPL_ACCOUNT_ID}/widget/QueryApi.App`}
href={`https://dev.near.org/${REPL_ACCOUNT_ID}/widget/QueryApi.App`}
title="QueryApi"
onClick={() => selectTab("explore")}
>
Expand All @@ -429,7 +429,7 @@ return (
</SignUpLink>
<div>
<ButtonLink
href={`/#/${REPL_ACCOUNT_ID}/widget/QueryApi.App/?view=create-new-indexer`}
href={`/${REPL_ACCOUNT_ID}/widget/QueryApi.App/?view=create-new-indexer`}
style={{ "margin-top": "10px" }}
onClick={() => {
State.update({
Expand Down
4 changes: 2 additions & 2 deletions frontend/widgets/src/QueryApi.IndexerCard.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const accountId = props.accountId || context.accountId;
const indexerName = props.indexerName;
const editUrl = `https://dev.near.org/#/${REPL_ACCOUNT_ID}/widget/QueryApi.App?selectedIndexerPath=${accountId}/${indexerName}`;
const statusUrl = `https://dev.near.org/#/${REPL_ACCOUNT_ID}/widget/QueryApi.App?selectedIndexerPath=${accountId}/${indexerName}&view=indexer&activeIndexerView=status`;
const editUrl = `https://dev.near.org/${REPL_ACCOUNT_ID}/widget/QueryApi.App?selectedIndexerPath=${accountId}/${indexerName}`;
const statusUrl = `https://dev.near.org/${REPL_ACCOUNT_ID}/widget/QueryApi.App?selectedIndexerPath=${accountId}/${indexerName}&view=indexer&activeIndexerView=status`;
const playgroundLink = `https://cloud.hasura.io/public/graphiql?endpoint=${REPL_GRAPHQL_ENDPOINT}/v1/graphql&header=x-hasura-role%3A${accountId.replaceAll(
".",
"_"
Expand Down

0 comments on commit eb87759

Please sign in to comment.