Skip to content

Commit

Permalink
[Refactor] Remove @ts-ignore comments
Browse files Browse the repository at this point in the history
- remove @ts-ignore comments which did not cause compilation error,
- reduce @ts-ignore comments in system and fault tree Editors. Encapsulate @ts-ignore comments getter methods and refactor @ts-ignore comment lines to use the getters
  • Loading branch information
kostobog committed Jan 16, 2024
1 parent d42f842 commit b528f78
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
24 changes: 16 additions & 8 deletions src/components/editor/faultTree/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ const Editor = ({setAppBarName}: DashboardTitleProps) => {
const [highlightedElementView, setHighlightedElementView] = useState(null)
const _localContext = useLocalContext({rootEvent: rootEvent, highlightedElementView: highlightedElementView})

const getRootEvent = () : FaultEvent => {
// @ts-ignore
return _localContext.rootEvent;
}

const getHighlightedElementView = () => {
// @ts-ignore
return _localContext.highlightedElementView
}

useEffect(() => {
if (faultTree) {
setAppBarName(faultTree.name)
Expand Down Expand Up @@ -61,16 +71,15 @@ const Editor = ({setAppBarName}: DashboardTitleProps) => {
const [contextMenuAnchor, setContextMenuAnchor] = useState<ElementContextMenuAnchor>(contextMenuDefaultAnchor)
const handleContextMenu = (elementView, evt) => {
const elementIri = elementView.model.get(JOINTJS_NODE_MODEL.faultEventIri);
// @ts-ignore
const foundEvent = findEventByIri(elementIri, _localContext.rootEvent);

const foundEvent = findEventByIri(elementIri, getRootEvent());
setContextMenuSelectedEvent(foundEvent);
setContextMenuAnchor({mouseX: evt.pageX, mouseY: evt.pageY,})
}

const handleElementPointerClick = (elementView) => {
const elementIri = elementView.model.get(JOINTJS_NODE_MODEL.faultEventIri);
// @ts-ignore
const foundEvent = findEventByIri(elementIri, _localContext.rootEvent);
const foundEvent = findEventByIri(elementIri, getRootEvent());

setSidebarSelectedEvent(foundEvent);
setHighlightedElementView(elementView);
Expand All @@ -83,8 +92,8 @@ const Editor = ({setAppBarName}: DashboardTitleProps) => {

const handleMoveEvent = (elementView, evt) => {
const faultEventIri = elementView.model.get(JOINTJS_NODE_MODEL.faultEventIri);
// @ts-ignore
const movedEvent = findEventByIri(faultEventIri, _localContext.rootEvent);

const movedEvent = findEventByIri(faultEventIri, getRootEvent());
const rect :Rectangle = movedEvent.rectangle;
const size = elementView.model.attributes.size;
const position = elementView.model.attributes.position;
Expand All @@ -104,8 +113,7 @@ const Editor = ({setAppBarName}: DashboardTitleProps) => {
elementView.addTools(tools);
}
const hideHighlightedBorders = () => {
// @ts-ignore
_localContext.highlightedElementView?.removeTools();
getHighlightedElementView()?.removeTools();
setHighlightedElementView(null);
}

Expand Down
2 changes: 0 additions & 2 deletions src/components/editor/faultTree/canvas/EditorCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const EditorCanvas = ({
const divContainer = document.getElementById("jointjs-container");
const paper = new joint.dia.Paper({

// @ts-ignore
el: divContainer,
model: graph,
width: canvasWidth,
Expand All @@ -89,7 +88,6 @@ const EditorCanvas = ({
});
setSvgZoom(diagramZoom);

// @ts-ignore
paper.on({
'element:contextmenu': (elementView, evt) => {
onElementContextMenu(elementView, evt)
Expand Down
19 changes: 13 additions & 6 deletions src/components/editor/system/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,20 @@ const Editor = ({setAppBarName}: DashboardTitleProps) => {
setContextMenuAnchor({mouseX: evt.pageX, mouseY: evt.pageY,})
}

const getSystem = () => {
// @ts-ignore
return _localContext.system;
}

const getHighlightedElementView = () => {
// @ts-ignore
return _localContext.highlightedElementView
}

const handleContextMenu = (elementView, evt) => {
const componentIri = elementView.model.get('custom/componentIri');

// @ts-ignore
const flattenedComponents = flatten([_localContext.system.components]);
const flattenedComponents = flatten([getSystem().components]);
const index = findIndex(flattenedComponents, el => el.iri === componentIri);
if (index > -1) {
setContextMenuSelectedComponent(flattenedComponents[index]);
Expand All @@ -60,8 +69,7 @@ const Editor = ({setAppBarName}: DashboardTitleProps) => {
const handleElementPointerClick = (elementView) => {
const componentIri = elementView.model.get('custom/componentIri');

// @ts-ignore
const flattenedComponents = flatten([_localContext.system.components]);
const flattenedComponents = flatten([getSystem().components]);
const index = findIndex(flattenedComponents, el => el.iri === componentIri);
if (index > -1) {
setSidebarSelectedComponent(flattenedComponents[index]);
Expand All @@ -82,8 +90,7 @@ const Editor = ({setAppBarName}: DashboardTitleProps) => {
elementView.addTools(tools);
}
const hideHighlightedBorders = () => {
// @ts-ignore
_localContext.highlightedElementView?.removeTools();
getHighlightedElementView()?.removeTools();
setHighlightedElementView(null);
}

Expand Down
2 changes: 0 additions & 2 deletions src/components/editor/system/canvas/EditorCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ const EditorCanvas = ({
const graph = new joint.dia.Graph;
const divContainer = document.getElementById("jointjs-system-container");
const paper = new joint.dia.Paper({
// @ts-ignore
el: divContainer,
model: graph,
width: canvasWidth,
Expand All @@ -73,7 +72,6 @@ const EditorCanvas = ({
});
setSvgZoom(diagramZoom);

// @ts-ignore
paper.on({
'blank:contextmenu': (evt) => {
onBlankContextMenu(evt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const ComponentEditMenu = ({component, onComponentUpdated}: Props) => {


useEffect(() => {
// @ts-ignore
reset(defaultValues)
}, [component])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ const ComponentFunctionsList = ({ component }) => {
})
}

// @ts-ignore
return (
<React.Fragment>
<List>
Expand Down

0 comments on commit b528f78

Please sign in to comment.