Skip to content

Commit

Permalink
Feature/1010 dropdowns infra (#1014)
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

* test: search for rfp by id

---------

Co-authored-by: Peter Salomonsen <[email protected]>
  • Loading branch information
Tguntenaar and petersalomonsen authored Dec 9, 2024
1 parent 41fcadb commit 2846387
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 139 deletions.
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
1 change: 1 addition & 0 deletions playwright-tests/tests/infrastructure/proposal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ test.describe("Wallet is connected as admin", () => {
await pauseIfVideoRecording(page);
if (linkRfp) {
await page.getByText("Search RFP").click();
await page.getByPlaceholder("Search by Id").fill("0");
await page.getByText("# 0 : A Cool RFP").click();
await expect(
await page.getByRole("link", { name: "# 0 : A Cool RFP" })
Expand Down

0 comments on commit 2846387

Please sign in to comment.