Skip to content
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

Feature/1012 infra proposal rfp pages #1016

Merged
merged 58 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b5e9375
feat: fetch from devhub-cache-api-rs.fly.dev
Tguntenaar Nov 6, 2024
48d8365
@Megha-Dev-19 WIP
Tguntenaar Nov 13, 2024
c6fde60
wip
Tguntenaar Nov 13, 2024
97d10d5
fmt
Tguntenaar Nov 13, 2024
c4d856e
wip
Tguntenaar Nov 15, 2024
32965d6
events and devhub are ready to be reviewed
Tguntenaar Nov 15, 2024
bc05626
feat: infra proposals
Tguntenaar Nov 15, 2024
f126fc8
fmt
Tguntenaar Nov 15, 2024
a4980a5
feat: rfps infra
Tguntenaar Nov 15, 2024
d9a8b6a
remove comments
Tguntenaar Nov 15, 2024
e796489
fix: spelling
Tguntenaar Nov 19, 2024
ec7c610
fix: spelling
Tguntenaar Nov 20, 2024
96ab80c
replace all nearqueryapi in devhub related to proposals and rfps
Tguntenaar Nov 20, 2024
6d9bbdf
devhub: simplemde, acceptedTerms, passing instance
Tguntenaar Nov 21, 2024
e721ee6
fix: devhub
Tguntenaar Nov 21, 2024
e17e72c
refactor events: deleted SimpleMDE and LinkedProposalsDropdown for both
Tguntenaar Nov 21, 2024
0d25bac
test: replace all references of queryapi in tests
Tguntenaar Nov 21, 2024
f63612a
test: fix linkedProposals and simpleMDE test :)
Tguntenaar Nov 21, 2024
0484689
test: skip discussions test for now
Tguntenaar Nov 21, 2024
7546c0f
clean up SimpleMDE
Tguntenaar Nov 22, 2024
330476a
infra: SimpleMDE, LinkedDropdown rfp + proposal, Proposal + Rfp.jsx, …
Tguntenaar Nov 22, 2024
a6a28a3
test: fix events test, 1. had to deploy events with new cors policy, …
Tguntenaar Nov 22, 2024
f744909
test: infra -- fix: should show correct linked RFP to a proposal in f…
Tguntenaar Nov 22, 2024
7f6a2f4
test: infra -- fix: should create proposal and link an RFP
Tguntenaar Nov 22, 2024
f6fa221
remove comments
Tguntenaar Nov 22, 2024
dff2af3
test: @petersalomonsen fixed!
Tguntenaar Nov 22, 2024
d904a6b
fmt
Tguntenaar Nov 22, 2024
99bf15a
test: discussions test back in
Tguntenaar Nov 22, 2024
b08601f
test: skip discussions test
Tguntenaar Nov 23, 2024
4805d33
revert: changes to rfp comment test
Tguntenaar Nov 24, 2024
83785a6
initial commit 1002
Tguntenaar Dec 3, 2024
14a1341
fmt
Tguntenaar Dec 3, 2024
5061189
Merge branch 'main' into feature/1002-feed
petersalomonsen Dec 3, 2024
7edd4ad
test for comparing local feed with production
petersalomonsen Dec 3, 2024
4a8f7b3
add events committee feed components + by-sort component
Tguntenaar Dec 4, 2024
9f4b5f0
fmt
Tguntenaar Dec 4, 2024
a938540
compare links in prod and local
petersalomonsen Dec 4, 2024
d8f882e
test: update events test
Tguntenaar Dec 5, 2024
3d95784
add events committee feed components + by-sort component
Tguntenaar Dec 4, 2024
be199e6
fmt
Tguntenaar Dec 4, 2024
3211999
test: update events test
Tguntenaar Dec 5, 2024
bf4ac5f
Merge branch 'feature/1002-feed' of github.com:Tguntenaar/neardevhub-…
Tguntenaar Dec 5, 2024
ea1d5bb
test: comment spec
Tguntenaar Dec 5, 2024
29ab16a
test: included some test from pr 982
Tguntenaar Dec 5, 2024
98d752a
revert commit
Tguntenaar Dec 6, 2024
444dee5
feat: simpleMDE to new api
Tguntenaar Dec 6, 2024
6fc1d60
fmt
Tguntenaar Dec 6, 2024
c768b10
feat: linkedproposaldropdown to new api
Tguntenaar Dec 6, 2024
8984298
fmt
Tguntenaar Dec 6, 2024
ca5f1e0
test: proposal autolink
Tguntenaar Dec 6, 2024
0292094
Merge branch 'main' of github.com:NEAR-DevHub/neardevhub-bos into fea…
Tguntenaar Dec 7, 2024
dba0972
Merge branch 'feature/replace-indexer-with-api' of github.com:Tgunten…
Tguntenaar Dec 7, 2024
6e310da
fix: simplemde + test
Tguntenaar Dec 8, 2024
2a55cfc
linked dropdowns
Tguntenaar Dec 8, 2024
96dc94c
feature: update feeds with new api
Tguntenaar Dec 8, 2024
7b49c4a
fmt
Tguntenaar Dec 8, 2024
f2a18a8
weird merge conflict
Tguntenaar Dec 8, 2024
aeaf7d8
feat: new api on proposal and rfp page
Tguntenaar Dec 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,44 @@ State.init({
proposalBlockHeight: null,
});

const proposalId = props.proposalId;
const instance = props.instance ?? "";

const QUERYAPI_ENDPOINT = `https://near-queryapi.api.pagoda.co/v1/graphql`;
const fetchGraphQL = (operationsDoc, operationName, variables) => {
return asyncFetch(QUERYAPI_ENDPOINT, {
method: "POST",
headers: { "x-hasura-role": "${REPL_INDEXER_HASURA_ROLE}" },
body: JSON.stringify({
query: operationsDoc,
variables: variables,
operationName: operationName,
}),
});
};
const { cacheUrl } = VM.require(`${instance}/widget/config.data`);

const queryName = "${REPL_PROPOSAL_FEED_INDEXER_QUERY_NAME}";
const query = `query GetLatestSnapshot($offset: Int = 0, $limit: Int = 10, $where: ${queryName}_bool_exp = {}) {
${queryName}(
offset: $offset
limit: $limit
order_by: {proposal_id: desc}
where: $where
) {
block_height
}
}`;
const fetchAndSetProposalSnapshot = () => {
if (!props.proposalId) {
return;
}
asyncFetch(`${cacheUrl}/proposal/${props.proposalId}/snapshots`, {
method: "GET",
headers: { accept: "application/json" },
})
.then((response) => {
if (!response.ok) {
console.error(`Failed to fetch snapshots: ${response.status}`);
}
return response.body;
})
.then((snapshots) => {
if (!Array.isArray(snapshots) || snapshots.length === 0) {
console.log("No snapshots found");
return;
}

const variables = {
limit: 10,
offset,
where: { proposal_id: { _eq: proposalId } },
// Get the most recent snapshot
const latestSnapshot = (snapshots || []).reduce((latest, current) =>
current.block_height > latest.block_height ? current : latest
);

State.update({ proposalBlockHeight: latestSnapshot.block_height });
})
.catch((error) => {
console.error("Failed to fetch proposal snapshot:", error);
});
};

fetchGraphQL(query, "GetLatestSnapshot", variables).then(async (result) => {
if (result.status === 200) {
if (result.body.data) {
const data = result.body.data?.[queryName];
State.update({ proposalBlockHeight: data[0].block_height });
}
}
});
// Fetch snapshot data on component mount
fetchAndSetProposalSnapshot();

let acceptedTermsVersion = Near.block().header.height;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const Comment = ({ commentItem }) => {
};
const content = JSON.parse(Social.get(item.path, blockHeight) ?? "null");
const link = `https://${instanceAccount}.page/proposal/${proposalId}?accountId=${accountId}&blockHeight=${blockHeight}`;
const hightlightComment =
const highlightComment =
parseInt(props.blockHeight ?? "") === blockHeight &&
props.accountId === accountId;

Expand All @@ -188,7 +188,7 @@ const Comment = ({ commentItem }) => {
</div>
<CommentContainer
id={`${accountId.replace(/[^a-z0-9]/g, "")}${blockHeight}`}
style={{ border: hightlightComment ? "2px solid black" : "" }}
style={{ border: highlightComment ? "2px solid black" : "" }}
className="rounded-2 flex-1"
>
<Header className="d-flex gap-3 align-items-center p-2 px-3">
Expand Down Expand Up @@ -334,7 +334,7 @@ const parseProposalKeyAndValue = (key, modifiedValue, originalValue) => {
accepted
<Widget
src={"${REPL_DEVHUB}/widget/devhub.entity.proposal.AcceptedTerms"}
props={{ proposalId: proposalId }}
props={{ ...props, proposalId: proposalId }}
/>
</span>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ const ConsentComponent = useMemo(() => {
src={
"${REPL_DEVHUB}/widget/devhub.entity.proposal.AcceptedTerms"
}
props={{ proposalId: proposalId, portal: "DevHub" }}
props={{ ...props, proposalId: proposalId, portal: "DevHub" }}
/>
and commit to honoring it
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ return (
}
props={{
...props,
instance: props.instance,
item: item,
notifyAccountId: authorId,
id: proposal.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const options = [
{ label: "All", value: "" },
{ label: "Most recent", value: "id_desc" }, // proposal_id desc
{ label: "Oldest", value: "id_asc" }, // proposal_id desc
{ label: "Recently updated", value: "ts_desc" }, // timestamp desc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ useEffect(() => {
}
}, [props.transactionHashes]);

const DropdowntBtnContainer = styled.div`
const DropdownBtnContainer = styled.div`
font-size: 13px;
min-width: 150px;

Expand Down Expand Up @@ -670,7 +670,7 @@ const SubmitBtn = () => {
const selectedOption = btnOptions.find((i) => i.value === selectedStatus);

return (
<DropdowntBtnContainer>
<DropdownBtnContainer>
<div
className="custom-select"
tabIndex="0"
Expand Down Expand Up @@ -722,7 +722,7 @@ const SubmitBtn = () => {
</div>
)}
</div>
</DropdowntBtnContainer>
</DropdownBtnContainer>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"REPL_RFP_INDEXER_QUERY_NAME": "polyprogrammist_near_devhub_ic_v1_rfp_snapshots",
"REPL_PROPOSAL_FEED_INDEXER_QUERY_NAME": "polyprogrammist_near_devhub_ic_v1_proposals_with_latest_snapshot",
"REPL_PROPOSAL_QUERY_NAME": "polyprogrammist_near_devhub_ic_v1_proposal_snapshots",
"REPL_INDEXER_HASURA_ROLE": "polyprogrammist_near"
"REPL_INDEXER_HASURA_ROLE": "polyprogrammist_near",
"REPL_CACHE_URL": "https://infra-cache-api-rs.fly.dev"
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
const { fetchGraphQL } = VM.require(
`${REPL_INFRASTRUCTURE_COMMITTEE}/widget/core.common`
);

const { href } = VM.require(`${REPL_DEVHUB}/widget/core.lib.url`);
href || (href = () => {});

const { fetchCacheApi, searchCacheApi } = VM.require(
`${REPL_INFRASTRUCTURE_COMMITTEE}/widget/core.common`
);

const linkedProposals = props.linkedProposals;
const onChange = props.onChange;
const [selectedProposals, setSelectedProposals] = useState(linkedProposals);
const [proposalsOptions, setProposalsOptions] = useState([]);
const [searchProposalId, setSearchProposalId] = useState("");

const queryName = "${REPL_PROPOSAL_FEED_INDEXER_QUERY_NAME}";
const query = `query GetLatestSnapshot($offset: Int = 0, $limit: Int = 10, $where: ${queryName}_bool_exp = {}) {
${queryName}(
offset: $offset
limit: $limit
order_by: {proposal_id: desc}
where: $where
) {
name
proposal_id
}
}`;
const [textAfterHash, setTextAfterHash] = useState("");

useEffect(() => {
if (JSON.stringify(linkedProposals) !== JSON.stringify(selectedProposals)) {
Expand All @@ -36,70 +23,29 @@ useEffect(() => {
}
}, [selectedProposals]);

function separateNumberAndText(str) {
const numberRegex = /\d+/;
function searchProposals(input) {
if (state.loading) return;
State.update({ loading: true });

if (numberRegex.test(str)) {
const number = str.match(numberRegex)[0];
const text = str.replace(numberRegex, "").trim();
return { number: parseInt(number), text };
} else {
return { number: null, text: str.trim() };
}
}
searchCacheApi("proposals", input).then((result) => {
let proposalsData = result.body.records;

const buildWhereClause = () => {
let where = {};
const { number, text } = separateNumberAndText(searchProposalId);

if (number) {
where = { proposal_id: { _eq: number }, ...where };
}

if (text) {
where = {
_or: [
{ name: { _iregex: `${text}` } },
{ summary: { _iregex: `${text}` } },
{ description: { _iregex: `${text}` } },
],
...where,
};
}

return where;
};

const fetchProposals = () => {
const FETCH_LIMIT = 30;
const variables = {
limit: FETCH_LIMIT,
offset: 0,
where: buildWhereClause(),
};
if (typeof fetchGraphQL !== "function") {
return;
}
fetchGraphQL(query, "GetLatestSnapshot", variables).then(async (result) => {
if (result.status === 200) {
if (result.body.data) {
const proposalsData = result.body.data?.[queryName];
const data = [];
for (const prop of proposalsData) {
data.push({
label: "# " + prop.proposal_id + " : " + prop.name,
value: prop.proposal_id,
});
}
setProposalsOptions(data);
}
const data = [];
for (const prop of proposalsData) {
data.push({
label: "# " + prop.proposal_id + " : " + prop.name,
value: prop.proposal_id,
});
}
setProposalsOptions(data);
});
};
}

useEffect(() => {
fetchProposals();
}, [searchProposalId]);
if (textAfterHash.trim()) {
searchProposals(textAfterHash);
}
}, [textAfterHash]);

return (
<>
Expand Down Expand Up @@ -150,7 +96,7 @@ return (
defaultLabel: "Search proposals",
searchByValue: true,
onSearch: (value) => {
setSearchProposalId(value);
setTextAfterHash(value);
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const { RFP_TIMELINE_STATUS, fetchGraphQL, parseJSON } = VM.require(
`${REPL_INFRASTRUCTURE_COMMITTEE}/widget/core.common`
) || { RFP_TIMELINE_STATUS: {}, parseJSON: () => {} };
const { RFP_TIMELINE_STATUS, parseJSON, fetchCacheApi, searchCacheApi } =
VM.require(`${REPL_INFRASTRUCTURE_COMMITTEE}/widget/core.common`) || {
RFP_TIMELINE_STATUS: {},
parseJSON: () => {},
fetchCacheApi: () => {},
searchCacheApi: () => {},
};
const { href } = VM.require(`${REPL_DEVHUB}/widget/core.lib.url`);
href || (href = () => {});

Expand All @@ -20,69 +24,14 @@ const [allRfpOptions, setAllRfpOptions] = useState([]);
const [searchRFPId, setSearchRfpId] = useState("");
const [initialStateApplied, setInitialState] = useState(false);

const queryName = "${REPL_RFP_FEED_INDEXER_QUERY_NAME}";
const query = `query GetLatestSnapshot($offset: Int = 0, $limit: Int = 10, $where: ${queryName}_bool_exp = {}) {
${queryName}(
offset: $offset
limit: $limit
order_by: {rfp_id: desc}
where: $where
) {
name
rfp_id
timeline
}
}`;

function separateNumberAndText(str) {
const numberRegex = /\d+/;

if (numberRegex.test(str)) {
const number = str.match(numberRegex)[0];
const text = str.replace(numberRegex, "").trim();
return { number: parseInt(number), text };
} else {
return { number: null, text: str.trim() };
}
}

const buildWhereClause = () => {
// show only accepting submissions stage rfps
let where = {};
const { number, text } = separateNumberAndText(searchRFPId);

if (number) {
where = { rfp_id: { _eq: number }, ...where };
}

if (text) {
where = {
_or: [
{ name: { _iregex: `${text}` } },
{ summary: { _iregex: `${text}` } },
{ description: { _iregex: `${text}` } },
],
...where,
};
}

return where;
};

const fetchRfps = () => {
const FETCH_LIMIT = 30;
const variables = {
limit: FETCH_LIMIT,
offset: 0,
where: buildWhereClause(),
};
if (typeof fetchGraphQL !== "function") {
if (typeof searchCacheApi !== "function") {
return;
}
fetchGraphQL(query, "GetLatestSnapshot", variables).then(async (result) => {
searchCacheApi("rfps", searchRFPId).then(async (result) => {
if (result.status === 200) {
if (result.body.data) {
const rfpsData = result.body.data?.[queryName];
if (result.body.records) {
const rfpsData = result.body.records;
const data = [];
const acceptingData = [];
for (const prop of rfpsData) {
Expand Down
Loading
Loading