Skip to content

Commit

Permalink
Feature/1012 infra proposal rfp pages (#1016)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Tguntenaar and petersalomonsen authored Dec 9, 2024
1 parent 6b3a866 commit 28a44ab
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 137 deletions.
Original file line number Diff line number Diff line change
@@ -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 = () => {});
Expand Down Expand Up @@ -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(() => {
Expand Down
122 changes: 39 additions & 83 deletions instances/infrastructure-committee.near/widget/components/rfps/Rfp.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const {
RFP_TIMELINE_STATUS,
fetchGraphQL,
CANCEL_RFP_OPTIONS,
parseJSON,
PROPOSALS_APPROVED_STATUS_ARRAY,
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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 },
]);
}
});
});
}

Expand Down Expand Up @@ -495,7 +449,9 @@ const accessControlInfo =
const moderatorList =
accessControlInfo?.members_list?.["team:moderators"]?.children;

fetchApprovedRfpProposals();
useEffect(() => {
fetchApprovedRfpProposals();
}, [snapshot]);

const SubmitProposalBtn = () => {
return (
Expand Down

0 comments on commit 28a44ab

Please sign in to comment.