diff --git a/instances/infrastructure-committee.near/widget/components/molecule/LinkedProposalsDropdown.jsx b/instances/infrastructure-committee.near/widget/components/molecule/LinkedProposalsDropdown.jsx index b5ba8401..7aceb3a5 100644 --- a/instances/infrastructure-committee.near/widget/components/molecule/LinkedProposalsDropdown.jsx +++ b/instances/infrastructure-committee.near/widget/components/molecule/LinkedProposalsDropdown.jsx @@ -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)) { @@ -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 ( <> @@ -150,7 +96,7 @@ return ( defaultLabel: "Search proposals", searchByValue: true, onSearch: (value) => { - setSearchProposalId(value); + setTextAfterHash(value); }, }} /> diff --git a/instances/infrastructure-committee.near/widget/components/molecule/LinkedRfpDropdown.jsx b/instances/infrastructure-committee.near/widget/components/molecule/LinkedRfpDropdown.jsx index 329d19df..b9f01c54 100644 --- a/instances/infrastructure-committee.near/widget/components/molecule/LinkedRfpDropdown.jsx +++ b/instances/infrastructure-committee.near/widget/components/molecule/LinkedRfpDropdown.jsx @@ -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 = () => {}); @@ -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) { diff --git a/playwright-tests/tests/infrastructure/proposal.spec.js b/playwright-tests/tests/infrastructure/proposal.spec.js index 5a7a3aef..2efc2c45 100644 --- a/playwright-tests/tests/infrastructure/proposal.spec.js +++ b/playwright-tests/tests/infrastructure/proposal.spec.js @@ -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" })