From e5724e0cfe6f449aa6503d2ea9c8123037f889fd Mon Sep 17 00:00:00 2001 From: parteekcoder Date: Tue, 30 May 2023 22:43:00 +0530 Subject: [PATCH 01/10] frontend of Contribute Feature --- src/App.jsx | 2 + src/component/modals/ContributeDetails.jsx | 80 ++++++++++++++++++++++ src/component/modals/contributeDetails.css | 20 ++++++ src/reducer/actionType.js | 1 + src/reducer/initialState.js | 1 + src/reducer/reducer.js | 3 + src/toolbarActions/toolbarFunctions.js | 6 +- src/toolbarActions/toolbarList.js | 4 +- 8 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 src/component/modals/ContributeDetails.jsx create mode 100644 src/component/modals/contributeDetails.css diff --git a/src/App.jsx b/src/App.jsx index c1a854c..3f30eeb 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -14,6 +14,7 @@ import FileDragDrop from './component/File-drag-drop'; import HistoryModal from './component/modals/History'; import LocalFileBrowser from './component/fileBrowser'; import FileEditModal from './component/modals/FileEdit'; +import ContributeDetails from './component/modals/ContributeDetails'; const app = () => { const [superState, dispatcher] = useReducer(reducer, initialState); @@ -33,6 +34,7 @@ const app = () => { + dispatcher({ type: T.Model_Close })} diff --git a/src/component/modals/ContributeDetails.jsx b/src/component/modals/ContributeDetails.jsx new file mode 100644 index 0000000..fc0ff6a --- /dev/null +++ b/src/component/modals/ContributeDetails.jsx @@ -0,0 +1,80 @@ +import React, { useState } from 'react'; +import axios from 'axios'; +import Modal from './ParentModal'; +import { actionType as T } from '../../reducer'; +import './contributeDetails.css'; + +const ContributeDetails = ({ superState, dispatcher }) => { + const closeModal = () => { + dispatcher({ type: T.SET_CONTRIBUTE_MODAL, payload: false }); + }; + const [study, setStudy] = useState(''); + const [path, setPath] = useState(''); + const [auth, setAuth] = useState(''); + const [title, setTitle] = useState(''); + const [desc, setDesc] = useState(''); + const [branch, setBranch] = useState(''); + const submit = async (e) => { + try { + e.preventDefault(); + const result = await axios.post(`http://127.0.0.1:5000/contribute?study=${study}&auth=${auth}&desc=${desc}&title=${title}&path=${path}&branch=${branch}`); + console.log(result.data); + // eslint-disable-next-line + alert("Still in Development"); + closeModal(); + } catch (error) { + console.log(error); + } + }; + return ( + +
+ Study Name + setStudy(e.target.value)} + /> + Study Path + setPath(e.target.value)} + required + /> + Author Name + setAuth(e.target.value)} + required + /> + Branch Name + setBranch(e.target.value)} + required + /> + PR Title + setTitle(e.target.value)} + required + /> + PR Description + setDesc(e.target.value)} + required + /> +
+ +
+
+
+ ); +}; +export default ContributeDetails; diff --git a/src/component/modals/contributeDetails.css b/src/component/modals/contributeDetails.css new file mode 100644 index 0000000..2ba3d25 --- /dev/null +++ b/src/component/modals/contributeDetails.css @@ -0,0 +1,20 @@ +.contribute-details{ + padding: 20px; + display: grid; + grid-template-columns: auto auto; + gap: 20px; +} + +.contribute-details *{ + padding: 10px 5px; + text-align: center; +} + +.contribute-details .expand{ + grid-column: 1 / span 2; + padding: 0; +} + +.contribute-details .btn{ + width: 100%; +} \ No newline at end of file diff --git a/src/reducer/actionType.js b/src/reducer/actionType.js index 56e3d13..6e90ac1 100644 --- a/src/reducer/actionType.js +++ b/src/reducer/actionType.js @@ -23,6 +23,7 @@ const actionType = { NEW_GRAPH: 'NEW_GRAPH', SET_SHARE_MODAL: 'SET_SHARE_MODAL', SET_SETTING_MODAL: 'SET_SETTING_MODAL', + SET_CONTRIBUTE_MODAL: 'SET_CONTRIBUTE_MODAL', SET_FILE_REF: 'SET_FILE_REF', SET_HISTORY_MODAL: 'SET_HISTORY_MODAL', SET_AUTHOR: 'SET_AUTHOR', diff --git a/src/reducer/initialState.js b/src/reducer/initialState.js index 041dd3a..7bc4a28 100644 --- a/src/reducer/initialState.js +++ b/src/reducer/initialState.js @@ -13,6 +13,7 @@ const initialState = { settingsModal: false, editDetailsModal: false, newGraphModal: false, + contributeModal: false, eleSelected: false, drawModeOn: true, diff --git a/src/reducer/reducer.js b/src/reducer/reducer.js index 42b35b0..c0abe56 100644 --- a/src/reducer/reducer.js +++ b/src/reducer/reducer.js @@ -64,6 +64,9 @@ const reducer = (state, action) => { }, }; } + case T.SET_CONTRIBUTE_MODAL: { + return { ...state, contributeModal: action.payload }; + } case T.Model_Close: return { ...state, ModelOpen: false }; case T.ELE_SELECTED: return { ...state, eleSelected: true, eleSelectedPayload: action.payload }; case T.ELE_UNSELECTED: return { ...state, eleSelected: false }; diff --git a/src/toolbarActions/toolbarFunctions.js b/src/toolbarActions/toolbarFunctions.js index 744ef3f..354f81a 100644 --- a/src/toolbarActions/toolbarFunctions.js +++ b/src/toolbarActions/toolbarFunctions.js @@ -145,6 +145,10 @@ const clearAll = (state) => { getGraphFun(state).clearAll(); }; +const contribute = (state, setState) => { + setState({ type: T.SET_CONTRIBUTE_MODAL, payload: true }); +}; + const resetAfterClear = (state) => { getGraphFun(state).resetAfterClear(); }; @@ -187,5 +191,5 @@ export { createNode, editElement, deleteElem, downloadImg, saveAction, saveGraphMLFile, createFile, readFile, readTextFile, newProject, clearAll, editDetails, undo, redo, openShareModal, openSettingModal, viewHistory, resetAfterClear, - toggleServer, + toggleServer, contribute, }; diff --git a/src/toolbarActions/toolbarList.js b/src/toolbarActions/toolbarList.js index 1512af6..df33359 100644 --- a/src/toolbarActions/toolbarList.js +++ b/src/toolbarActions/toolbarList.js @@ -12,7 +12,7 @@ import { import { createNode, editElement, deleteElem, downloadImg, saveAction, saveGraphMLFile, createFile, readFile, clearAll, undo, redo, viewHistory, resetAfterClear, - toggleServer, + toggleServer, contribute, // openSettingModal, } from './toolbarFunctions'; @@ -227,7 +227,7 @@ const toolbarList = (state, dispatcher) => [ type: 'action', text: 'Contribute', icon: FiTriangle, - action: () => { window.open('https://github.com/ControlCore-Project/concore', '_blank'); }, + action: contribute, active: state.curGraphInstance || state.uploadedDirName, visibility: true, }, From 6b2f73aa7160e479ec2416561f2642a8e200f2b0 Mon Sep 17 00:00:00 2001 From: parteekcoder Date: Thu, 8 Jun 2023 13:32:03 +0530 Subject: [PATCH 02/10] contribute feature --- src/component/modals/ContributeDetails.jsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/component/modals/ContributeDetails.jsx b/src/component/modals/ContributeDetails.jsx index fc0ff6a..ccc4b7a 100644 --- a/src/component/modals/ContributeDetails.jsx +++ b/src/component/modals/ContributeDetails.jsx @@ -18,12 +18,13 @@ const ContributeDetails = ({ superState, dispatcher }) => { try { e.preventDefault(); const result = await axios.post(`http://127.0.0.1:5000/contribute?study=${study}&auth=${auth}&desc=${desc}&title=${title}&path=${path}&branch=${branch}`); - console.log(result.data); + // console.log(result.data); // eslint-disable-next-line - alert("Still in Development"); + alert(result.data.message); + // console.log(result.data); closeModal(); } catch (error) { - console.log(error); + // console.log(error); } }; return ( From d7c1d1c107dc25a74796cc82d7c44f612fc4cac2 Mon Sep 17 00:00:00 2001 From: parteekcoder Date: Fri, 9 Jun 2023 21:24:50 +0530 Subject: [PATCH 03/10] ommiting token from code --- .github/workflows/build.yml | 1 + .github/workflows/buildAndDeploy.yml | 1 + package.json | 2 +- src/component/modals/ContributeDetails.jsx | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0265183..68c8340 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,4 +24,5 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: npm ci + - run: sed -i "s/REPLACE_TOKEN/${{ secrets.TOKEN }}/g" package.json - run: npm run build --if-present diff --git a/.github/workflows/buildAndDeploy.yml b/.github/workflows/buildAndDeploy.yml index b96c24b..63032f1 100644 --- a/.github/workflows/buildAndDeploy.yml +++ b/.github/workflows/buildAndDeploy.yml @@ -16,6 +16,7 @@ jobs: node-version: ${{ matrix.node-version }} - name: Install and Build 🔧 run: | + sed -i "s/REPLACE_TOKEN/${{ secrets.TOKEN }}/g" package.json npm ci npm run build diff --git a/package.json b/package.json index 1670c76..3248992 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ }, "scripts": { "start": "react-scripts start", - "build": "react-scripts build", + "build": "Token=REPLACE_TOKEN react-scripts build", "build-localhost": "PUBLIC_URL=/ react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/src/component/modals/ContributeDetails.jsx b/src/component/modals/ContributeDetails.jsx index ccc4b7a..07cad7e 100644 --- a/src/component/modals/ContributeDetails.jsx +++ b/src/component/modals/ContributeDetails.jsx @@ -17,7 +17,7 @@ const ContributeDetails = ({ superState, dispatcher }) => { const submit = async (e) => { try { e.preventDefault(); - const result = await axios.post(`http://127.0.0.1:5000/contribute?study=${study}&auth=${auth}&desc=${desc}&title=${title}&path=${path}&branch=${branch}`); + const result = await axios.post(`http://127.0.0.1:5000/contribute?study=${study}&auth=${auth}&desc=${desc}&title=${title}&path=${path}&branch=${branch}`, { token: process.env.Token }); // console.log(result.data); // eslint-disable-next-line alert(result.data.message); From 7215b3d00be1a35e1a7de1cedf1f13084a5d1427 Mon Sep 17 00:00:00 2001 From: parteekcoder Date: Fri, 9 Jun 2023 21:41:33 +0530 Subject: [PATCH 04/10] Update ContributeDetails.jsx --- src/component/modals/ContributeDetails.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/component/modals/ContributeDetails.jsx b/src/component/modals/ContributeDetails.jsx index 07cad7e..905a5a2 100644 --- a/src/component/modals/ContributeDetails.jsx +++ b/src/component/modals/ContributeDetails.jsx @@ -18,7 +18,8 @@ const ContributeDetails = ({ superState, dispatcher }) => { try { e.preventDefault(); const result = await axios.post(`http://127.0.0.1:5000/contribute?study=${study}&auth=${auth}&desc=${desc}&title=${title}&path=${path}&branch=${branch}`, { token: process.env.Token }); - // console.log(result.data); + // eslint-disable-next-line + console.log(process.env.Token); // eslint-disable-next-line alert(result.data.message); // console.log(result.data); From e8af459818737d864ad0aa5f981c747e6c96bcf4 Mon Sep 17 00:00:00 2001 From: Parteek Goyal Date: Fri, 9 Jun 2023 22:12:40 +0530 Subject: [PATCH 05/10] Update ContributeDetails.jsx --- src/component/modals/ContributeDetails.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/component/modals/ContributeDetails.jsx b/src/component/modals/ContributeDetails.jsx index 905a5a2..9ab7321 100644 --- a/src/component/modals/ContributeDetails.jsx +++ b/src/component/modals/ContributeDetails.jsx @@ -17,7 +17,7 @@ const ContributeDetails = ({ superState, dispatcher }) => { const submit = async (e) => { try { e.preventDefault(); - const result = await axios.post(`http://127.0.0.1:5000/contribute?study=${study}&auth=${auth}&desc=${desc}&title=${title}&path=${path}&branch=${branch}`, { token: process.env.Token }); + const result = await axios.post(`http://127.0.0.1:5000/contribute?study=${study}&auth=${auth}&desc=${desc}&title=${title}&path=${path}&branch=${branch}`, { token: process.env.TOKEN }); // eslint-disable-next-line console.log(process.env.Token); // eslint-disable-next-line From c09bd141422b5160b5a3b33a8e37514e0d021283 Mon Sep 17 00:00:00 2001 From: parteekcoder Date: Sun, 11 Jun 2023 21:44:47 +0530 Subject: [PATCH 06/10] improvment and adding edge cases --- src/App.jsx | 2 +- src/component/modals/ContributeDetails.jsx | 49 ++++++++++++++-------- src/component/modals/contributeDetails.css | 19 ++++++++- src/toolbarActions/toolbarList.js | 2 +- 4 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index 3f30eeb..ef3e060 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -51,7 +51,7 @@ const app = () => { - + ); }; diff --git a/src/component/modals/ContributeDetails.jsx b/src/component/modals/ContributeDetails.jsx index 9ab7321..6f60294 100644 --- a/src/component/modals/ContributeDetails.jsx +++ b/src/component/modals/ContributeDetails.jsx @@ -1,4 +1,5 @@ import React, { useState } from 'react'; +import { toast } from 'react-toastify'; import axios from 'axios'; import Modal from './ParentModal'; import { actionType as T } from '../../reducer'; @@ -14,19 +15,23 @@ const ContributeDetails = ({ superState, dispatcher }) => { const [title, setTitle] = useState(''); const [desc, setDesc] = useState(''); const [branch, setBranch] = useState(''); + const [showAdvanceOptions, setShowAdvanceOptions] = useState(false); const submit = async (e) => { + const id = toast.loading('Processing Your Request.Please wait...'); try { e.preventDefault(); const result = await axios.post(`http://127.0.0.1:5000/contribute?study=${study}&auth=${auth}&desc=${desc}&title=${title}&path=${path}&branch=${branch}`, { token: process.env.TOKEN }); // eslint-disable-next-line - console.log(process.env.Token); - // eslint-disable-next-line - alert(result.data.message); - // console.log(result.data); - closeModal(); + // console.log(process.env.Token); + toast.success(result.data?.message); } catch (error) { - // console.log(error); + toast.error(error.response.data.message); } + toast.dismiss(id); + closeModal(); + }; + const toggleOptions = () => { + setShowAdvanceOptions(!showAdvanceOptions); }; return ( { onChange={(e) => setBranch(e.target.value)} required /> - PR Title - setTitle(e.target.value)} - required - /> - PR Description - setDesc(e.target.value)} - required - /> + {showAdvanceOptions && ( + <> + PR Title + setTitle(e.target.value)} + required + /> + PR Description + setDesc(e.target.value)} + required + /> + + )} +
diff --git a/src/component/modals/contributeDetails.css b/src/component/modals/contributeDetails.css index 2ba3d25..560d1b0 100644 --- a/src/component/modals/contributeDetails.css +++ b/src/component/modals/contributeDetails.css @@ -17,4 +17,21 @@ .contribute-details .btn{ width: 100%; -} \ No newline at end of file +} +.contribute-details .btn-secondary{ + align-self: flex-end; +} +.Toastify__toast-container { + /* width: 350px; */ + /* height: 80px; */ + margin-right: 20px; + padding: 3px 15px; + display: inline-block; + } + + .Toastify__toast { + /* width: 350px; */ + /* height: 80px; */ + width: fit-content; + font-size: 16px; + } \ No newline at end of file diff --git a/src/toolbarActions/toolbarList.js b/src/toolbarActions/toolbarList.js index df33359..859d7c1 100644 --- a/src/toolbarActions/toolbarList.js +++ b/src/toolbarActions/toolbarList.js @@ -228,7 +228,7 @@ const toolbarList = (state, dispatcher) => [ text: 'Contribute', icon: FiTriangle, action: contribute, - active: state.curGraphInstance || state.uploadedDirName, + active: true, visibility: true, }, // { From c19e3ce611530d443b08220bb208af5bcb4fafe5 Mon Sep 17 00:00:00 2001 From: parteekcoder Date: Tue, 13 Jun 2023 22:54:28 +0530 Subject: [PATCH 07/10] textarea added --- src/component/modals/ContributeDetails.jsx | 24 +++++++++++++--------- src/component/modals/contributeDetails.css | 8 +++++++- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/component/modals/ContributeDetails.jsx b/src/component/modals/ContributeDetails.jsx index 6f60294..045b9ee 100644 --- a/src/component/modals/ContributeDetails.jsx +++ b/src/component/modals/ContributeDetails.jsx @@ -25,7 +25,11 @@ const ContributeDetails = ({ superState, dispatcher }) => { // console.log(process.env.Token); toast.success(result.data?.message); } catch (error) { - toast.error(error.response.data.message); + if (error?.response?.status === 400) { + toast.info(error?.response?.data?.message); + } else { + toast.error(error?.response.data.message); + } } toast.dismiss(id); closeModal(); @@ -59,22 +63,22 @@ const ContributeDetails = ({ superState, dispatcher }) => { onChange={(e) => setAuth(e.target.value)} required /> - Branch Name - setBranch(e.target.value)} - required - /> {showAdvanceOptions && ( <> - PR Title + Branch Name + setBranch(e.target.value)} + required + /> + Title of Study setTitle(e.target.value)} required /> - PR Description - Description of Study +