Skip to content

Commit

Permalink
Merge pull request #232 from Spyderisk/231-hide-all-relations-of-a-ce…
Browse files Browse the repository at this point in the history
…rtain-type

#231: Add "Hide all relations of this type" option to relation context menu
  • Loading branch information
kenmeacham authored Feb 14, 2025
2 parents d68f540 + d68cabb commit b968c55
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/main/webapp/app/modeller/actions/ModellerActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,17 @@ export function hideRelation(relationId) {
}
}

export function hideRelationsOfType(relationType) {
return function (dispatch) {
dispatch({
type: instr.HIDE_RELATIONS_OF_TYPE,
payload: {
relationType: relationType,
}
});
}
}

export function putRelationRedefine(modelId, relation) {
let { assetIdFrom, assetIdTo, relType, relationId } = relation;
console.log(`Updating relation ${relationId} from ${assetIdFrom} to ${assetIdTo}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import {deleteAssertedRelation, hideRelation, putRelationRedefine} from "../../../actions/ModellerActions";
import {deleteAssertedRelation, hideRelation, hideRelationsOfType, putRelationRedefine} from "../../../actions/ModellerActions";
import {ContextMenu, ContextMenuTrigger, MenuItem, SubMenu} from "react-contextmenu";
import {wordWrap} from "../../util/wordWrap"

Expand All @@ -13,6 +13,7 @@ class RelationCtxMenu extends React.Component {
this.handleCardinalities = this.handleCardinalities.bind(this);
this.handleChangeRelation = this.handleChangeRelation.bind(this);
this.handleHideRelation = this.handleHideRelation.bind(this);
this.handleHideRelationsOfType = this.handleHideRelationsOfType.bind(this);

this.state = {
loading: false,
Expand Down Expand Up @@ -75,6 +76,9 @@ class RelationCtxMenu extends React.Component {
<MenuItem onClick={this.handleHideRelation}>{this.props.relation.hidden ? "Unhide" : "Hide"}
</MenuItem>

<MenuItem onClick={this.handleHideRelationsOfType}>{"Hide all relations of this type"}
</MenuItem>

<MenuItem onClick={this.handleDeleteRelation}
disabled={!this.props.relation.asserted}>Delete
</MenuItem>
Expand Down Expand Up @@ -172,6 +176,9 @@ class RelationCtxMenu extends React.Component {
this.props.dispatch(hideRelation(this.props.relation.id));
}

handleHideRelationsOfType() {
this.props.dispatch(hideRelationsOfType(this.props.relation.type));
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/app/modeller/modellerConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const GET_RELATION = "GET_RELATION";
export const POST_RELATION = "POST_RELATION";
export const PATCH_RELATION = "PATCH_RELATION";
export const HIDE_RELATION = "HIDE_RELATION";
export const HIDE_RELATIONS_OF_TYPE = "HIDE_RELATIONS_OF_TYPE";
export const DELETE_RELATION = "DELETE_RELATION";
export const CHANGE_SELECTED_ASSET = "CHANGE_SELECTED_ASSET";
export const CHANGE_SELECTED_TWAS = "CHANGE_SELECTED_TWAS";
Expand Down
17 changes: 17 additions & 0 deletions src/main/webapp/app/modeller/reducers/modeller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,23 @@ export default function modeller(state = modelState, action) {
}
}

if (action.type === instr.HIDE_RELATIONS_OF_TYPE) {
let relationType = action.payload["relationType"];

return {
...state,
model: {
...state.model,
relations: [...state.model.relations.map((relation) => {
if (relation["type"] === relationType) {
relation.hidden = !relation.hidden;
}
return relation;
})]
}
}
}

if (action.type === instr.PATCH_UPDATED_CONTROL) {
return state;
}
Expand Down

0 comments on commit b968c55

Please sign in to comment.