Skip to content

Commit

Permalink
Merge pull request #47 from qresp-code-development/develop
Browse files Browse the repository at this point in the history
New Release, v2.0.4
  • Loading branch information
mgovoni-devel authored Jan 17, 2021
2 parents 61f7ed4 + 7b72a23 commit d62728d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## v2.0.4 (2021/01/09)

Patch Update

- Fixed bug causing workflow graph to break on deleting nodes.
- Added new warnings when using start from scratch button to avoid accidental deletion of work.
## v2.0.3 (2020/11/27)

Patch Update
Expand Down
2 changes: 1 addition & 1 deletion backend/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='qresp',
version='2.0.3',
version='2.0.4',
url='https://qresp.org/',
entry_points = {
'console_scripts': ['qresp=project.__main__:main'],
Expand Down
17 changes: 14 additions & 3 deletions frontend/Context/Curator/curatorReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
SET_DOCUMENTATION,
} from "../types";

import { getNodeNumber, reduceEdgeNodeId } from "../../Utils/graph";

export default (state, action) => {
switch (action.type) {
case SET_CURATORINFO:
Expand Down Expand Up @@ -54,10 +56,19 @@ export default (state, action) => {

case DELETE:
const prefix = action.payload.type.charAt(0);
const node_number_to_delete = getNodeNumber(action.payload.id);

const newEdges = state.workflow.edges.filter(
(edge) => edge.to != action.payload.id && edge.from != action.payload.id
);
/*
1st filter removes the edges corresponding to the deleted node.
2nd filter fixes the node and id mapping, deleting a node causes the node with higher id having incorrect edges
*/

const newEdges = state.workflow.edges
.filter(
(edge) =>
edge.to != action.payload.id && edge.from != action.payload.id
)
.map((edge) => reduceEdgeNodeId(node_number_to_delete, prefix, edge));

return {
...state,
Expand Down
23 changes: 22 additions & 1 deletion frontend/Utils/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ const createGraph = ({ nodes, edges }) => {
return graph;
};

// Returns the number of record in the corresponding section
const getNodeNumber = (id) => parseInt(id.substring(1));

/*
When a node is deleted, we rempa their ids to the lower number.
So we also have to rempa the edges, this is what reduce means in this context.
*/
const reduceEdgeNodeId = (node_number_to_delete, prefix, edge) => {
if (edge.to.charAt(0) == prefix) {
if (getNodeNumber(edge.to) > node_number_to_delete) {
edge.to = prefix + (getNodeNumber(edge.to) - 1).toString();
}
}
if (edge.from.charAt(0) == prefix) {
if (getNodeNumber(edge.from) > node_number_to_delete) {
edge.from = prefix + (getNodeNumber(edge.from) - 1).toString();
}
}
return edge;
};

const isGraphCyclicUtil = (node, graph, visited, stack) => {
if (!visited[node]) {
visited[node] = true;
Expand Down Expand Up @@ -61,4 +82,4 @@ const isGraph = {
},
};

export { isGraph };
export { isGraph, getNodeNumber, reduceEdgeNodeId };
29 changes: 27 additions & 2 deletions frontend/components/CuratorElements/TopActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const preview = (metadata, setAlert, router) => {

const TopActions = () => {
const { metadata, setAll, resetAll } = useContext(CuratorContext);
const { setAlert } = useContext(AlertContext);
const { setAlert, unsetAlert } = useContext(AlertContext);
const { setSelectedHttp, selectedHttp } = useContext(ServerContext);
const [mdata, setMdata] = useState("");
const [resumeDialogOpen, setResumeDialogOpen] = useState(false);
Expand All @@ -59,6 +59,31 @@ const TopActions = () => {
resume: () => {
setResumeDialogOpen(true);
},
scratch: () => {
setAlert(
"Warning",
"This is an irreversible operation, please download your work if you plan to use it in the future. Do you still wish to continue ?",
<Fragment>
<RegularStyledButton
endIcon={<GetApp />}
href={`data:text/json;charset=utf-8,${encodeURIComponent(
JSON.stringify(onClicks.download(metadata), null, 2)
)}`}
download="metadata.json"
>
Download Metadata
</RegularStyledButton>
<RegularStyledButton
onClick={() => {
resetAll();
unsetAlert();
}}
>
Yes, start from Scratch
</RegularStyledButton>
</Fragment>
);
},
download: (metadata) => {
return { ...metadata, selectedHttp: selectedHttp };
},
Expand All @@ -78,7 +103,7 @@ const TopActions = () => {
),
scratch: (fullWidth = false) => (
<StyledTooltip title="Clear the session and start afresh">
<RegularStyledButton fullWidth={fullWidth} onClick={resetAll}>
<RegularStyledButton fullWidth={fullWidth} onClick={onClicks.scratch}>
Start from Scratch
</RegularStyledButton>
</StyledTooltip>
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qresp",
"version": "2.0.3",
"version": "2.0.4",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down

0 comments on commit d62728d

Please sign in to comment.