From 28a44abaf19c944a6122a3ae0b6895125d970116 Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 9 Dec 2024 22:20:13 +0100 Subject: [PATCH] Feature/1012 infra proposal rfp pages (#1016) * feat: fetch from devhub-cache-api-rs.fly.dev * @Megha-Dev-19 WIP * wip * fmt * wip * events and devhub are ready to be reviewed * feat: infra proposals * fmt * feat: rfps infra * remove comments * fix: spelling * fix: spelling * replace all nearqueryapi in devhub related to proposals and rfps * devhub: simplemde, acceptedTerms, passing instance * fix: devhub * refactor events: deleted SimpleMDE and LinkedProposalsDropdown for both * test: replace all references of queryapi in tests * test: fix linkedProposals and simpleMDE test :) * test: skip discussions test for now * clean up SimpleMDE * infra: SimpleMDE, LinkedDropdown rfp + proposal, Proposal + Rfp.jsx, remove fetchgraphql from common * test: fix events test, 1. had to deploy events with new cors policy, 2. passing instance down to simplemde, 3. mock the test on the right api path. * test: infra -- fix: should show correct linked RFP to a proposal in feed page * test: infra -- fix: should create proposal and link an RFP * remove comments * test: @petersalomonsen fixed! * fmt * test: discussions test back in * test: skip discussions test * revert: changes to rfp comment test * initial commit 1002 * fmt * test for comparing local feed with production * add events committee feed components + by-sort component * fmt * compare links in prod and local * test: update events test * add events committee feed components + by-sort component * fmt * test: update events test * test: comment spec * test: included some test from pr 982 * revert commit * feat: simpleMDE to new api * fmt * feat: linkedproposaldropdown to new api * fmt * test: proposal autolink * fix: simplemde + test * linked dropdowns * feature: update feeds with new api * fmt * feat: new api on proposal and rfp page --------- Co-authored-by: Peter Salomonsen --- .../widget/components/proposals/Proposal.jsx | 82 ++++-------- .../widget/components/rfps/Rfp.jsx | 122 ++++++------------ 2 files changed, 67 insertions(+), 137 deletions(-) diff --git a/instances/infrastructure-committee.near/widget/components/proposals/Proposal.jsx b/instances/infrastructure-committee.near/widget/components/proposals/Proposal.jsx index 9bc4582a6..b8f0ca934 100644 --- a/instances/infrastructure-committee.near/widget/components/proposals/Proposal.jsx +++ b/instances/infrastructure-committee.near/widget/components/proposals/Proposal.jsx @@ -1,9 +1,10 @@ -const { PROPOSAL_TIMELINE_STATUS, fetchGraphQL, parseJSON, isNumber } = - VM.require(`${REPL_INFRASTRUCTURE_COMMITTEE}/widget/core.common`) || { - PROPOSAL_TIMELINE_STATUS: {}, - parseJSON: () => {}, - isNumber: () => {}, - }; +const { PROPOSAL_TIMELINE_STATUS, parseJSON, isNumber } = VM.require( + `${REPL_INFRASTRUCTURE_COMMITTEE}/widget/core.common` +) || { + PROPOSAL_TIMELINE_STATUS: {}, + parseJSON: () => {}, + isNumber: () => {}, +}; const { href } = VM.require(`${REPL_DEVHUB}/widget/core.lib.url`); href || (href = () => {}); @@ -279,56 +280,29 @@ const proposal = Near.view( const [snapshotHistory, setSnapshotHistory] = useState([]); -const queryName = "${REPL_PROPOSAL_QUERY_NAME}"; -const query = `query GetLatestSnapshot($offset: Int = 0, $limit: Int = 10, $where: ${queryName}_bool_exp = {}) { - ${queryName}( - offset: $offset - limit: $limit - order_by: {ts: asc} - where: $where - ) { - editor_id - name - summary - description - ts - proposal_id - timeline - labels - linked_proposals - linked_rfp - requested_sponsorship_usd_amount - requested_sponsorship_paid_in_currency - receiver_account - requested_sponsor - supervisor - } -}`; - const fetchSnapshotHistory = () => { - const variables = { - where: { proposal_id: { _eq: id } }, - }; - if (typeof fetchGraphQL !== "function") { - return; - } - fetchGraphQL(query, "GetLatestSnapshot", variables).then(async (result) => { - if (result.status === 200) { - if (result.body.data) { - const data = result.body.data?.[queryName]; - const history = data.map((item) => { - const proposalData = { - ...item, - timestamp: item.ts, - timeline: parseJSON(item.timeline), - }; - delete proposalData.ts; - return proposalData; - }); - setSnapshotHistory(history); + asyncFetch(`https://infra-cache-api-rs.fly.dev/proposal/${id}/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) => { + const history = snapshots.map((item) => { + const proposalData = { + ...item, + timestamp: item.ts, + timeline: parseJSON(item.timeline), + }; + delete proposalData.ts; + return proposalData; + }); + setSnapshotHistory(history); + }); }; useEffect(() => { diff --git a/instances/infrastructure-committee.near/widget/components/rfps/Rfp.jsx b/instances/infrastructure-committee.near/widget/components/rfps/Rfp.jsx index 2ef92c2da..b4bd6f2a7 100644 --- a/instances/infrastructure-committee.near/widget/components/rfps/Rfp.jsx +++ b/instances/infrastructure-committee.near/widget/components/rfps/Rfp.jsx @@ -1,6 +1,5 @@ const { RFP_TIMELINE_STATUS, - fetchGraphQL, CANCEL_RFP_OPTIONS, parseJSON, PROPOSALS_APPROVED_STATUS_ARRAY, @@ -279,51 +278,29 @@ const rfp = Near.view("${REPL_INFRASTRUCTURE_COMMITTEE_CONTRACT}", "get_rfp", { rfp_id: parseInt(id), }); -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: {ts: asc} - where: $where - ) { - editor_id - name - summary - description - ts - rfp_id - timeline - labels - submission_deadline - linked_proposals - } -}`; - const fetchSnapshotHistory = () => { - const variables = { - where: { rfp_id: { _eq: id } }, - }; - if (typeof fetchGraphQL !== "function") { - return; - } - fetchGraphQL(query, "GetLatestSnapshot", variables).then(async (result) => { - if (result.status === 200) { - if (result.body.data) { - const data = result.body.data?.[queryName]; - const history = data.map((item) => { - const rfpData = { - ...item, - timestamp: item.ts, - timeline: parseJSON(item.timeline), - }; - delete rfpData.ts; - return rfpData; - }); - setSnapshotHistory(history); + asyncFetch(`https://infra-cache-api-rs.fly.dev/rfp/${id}/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) => { + const history = snapshots.map((item) => { + const rfpData = { + ...item, + timestamp: item.ts, + timeline: parseJSON(item.timeline), + }; + delete rfpData.ts; + return rfpData; + }); + setSnapshotHistory(history); + }); }; useEffect(() => { @@ -410,45 +387,22 @@ useEffect(() => { }, [snapshot]); function fetchApprovedRfpProposals() { - const queryName = "${REPL_PROPOSAL_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 - ) { - proposal_id - name - timeline - } - }`; - - const FETCH_LIMIT = 50; - const variables = { - limit: FETCH_LIMIT, - offset, - where: { - proposal_id: { _in: rfp.snapshot.linked_proposals }, - }, - }; - if (typeof fetchGraphQL !== "function") { - return; - } - fetchGraphQL(query, "GetLatestSnapshot", variables).then(async (result) => { - if (result.status === 200) { - if (result.body.data) { - const data = result.body.data?.[queryName]; - const approved = []; - data.map((item) => { - const timeline = parseJSON(item.timeline); - if (PROPOSALS_APPROVED_STATUS_ARRAY.includes(timeline.status)) { - approved.push(item); - } - }); - setApprovedProposals(approved); + snapshot.linked_proposals.map((item) => { + Near.asyncView( + "${REPL_INFRASTRUCTURE_COMMITTEE_CONTRACT}", + "get_proposal", + { + proposal_id: item, } - } + ).then((item) => { + const timeline = parseJSON(item.snapshot.timeline); + if (PROPOSALS_APPROVED_STATUS_ARRAY.includes(timeline.status)) { + setApprovedProposals((prevApprovedProposals) => [ + ...prevApprovedProposals, + { proposal_id: item.id, ...item.snapshot }, + ]); + } + }); }); } @@ -495,7 +449,9 @@ const accessControlInfo = const moderatorList = accessControlInfo?.members_list?.["team:moderators"]?.children; -fetchApprovedRfpProposals(); +useEffect(() => { + fetchApprovedRfpProposals(); +}, [snapshot]); const SubmitProposalBtn = () => { return (