Skip to content

Commit

Permalink
Add id search to dataflow viewer (#1379)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew authored Nov 29, 2023
1 parent 254bec9 commit 53bc4d3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/input-panel/spec-editor/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class Editor extends React.PureComponent<Props> {
prevProps.editorRef && prevProps.editorRef.deltaDecorations(prevProps.decorations, []);
}

if (this.props.parse) {
if (this.editor && this.props.parse) {
this.editor.focus();
this.editor.layout();
this.updateSpec(this.props.value, this.props.configEditorString);
Expand Down
21 changes: 21 additions & 0 deletions src/features/dataflow/Sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
width: 250px;
gap: 10px;
}

.sidebar fieldset {
overflow: hidden;
border-color: var(--light-gray-color);
Expand Down Expand Up @@ -53,3 +54,23 @@
.type-filter {
flex-shrink: 0;
}

.sidebar .id-filter {
padding-bottom: 20px;
flex-shrink: 0;
}

.sidebar .id-filter > div {
display: flex;
height: 30px;
}

.sidebar .id-filter > div input {
width: 70px;
height: 100%;
}

.sidebar .id-filter > div button {
width: 100%;
height: 100%;
}
33 changes: 32 additions & 1 deletion src/features/dataflow/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ import {useDispatch} from 'react-redux';
import {useAppSelector} from '../../hooks';
import {resetPulses, sortedPulsesSelector, pulsesEmptySelector} from './pulsesSlice';
import './Sidebar.css';
import {selectedPulseSelector, selectedTypesSelector, setSelectedPulse, setSelectedType} from './selectionSlice';
import {
setSelectedElements,
selectedPulseSelector,
selectedTypesSelector,
setSelectedPulse,
setSelectedType,
} from './selectionSlice';
import {GraphType, types} from './utils/graph';

export function Sidebar() {
return (
<div className="sidebar">
<Types />
<Id />
<Pulses />
</div>
);
Expand Down Expand Up @@ -42,6 +49,30 @@ function Type({type, label, selected}: {type: GraphType; label: string; selected
);
}

function Id() {
const [searchTerm, setSearchTerm] = React.useState<string | null>(null);
const dispatch = useDispatch();
return (
<fieldset className="id-filter">
<legend>Filter by ID</legend>
<div>
<input type="search" title="Pulse Id Search" onChange={(e) => setSearchTerm(e.target.value)} />
<button
onClick={() => {
if (!searchTerm) {
return;
}
dispatch(setSelectedElements({nodes: [searchTerm], edges: []}));
setSearchTerm(null);
}}
>
Search
</button>
</div>
</fieldset>
);
}

function Pulses() {
return (
<fieldset>
Expand Down
4 changes: 4 additions & 0 deletions src/features/dataflow/utils/allRelated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export function allRelated({nodes, edges}: Graph, selected: Elements): Set<strin
// Mark the compound node relations as visited
// and add their immediate parents to the queue
const node = nodes[id];
// if the user inputs an invalid node, just ignore it
if (node === undefined) {
continue;
}
const parents = node.parent !== undefined ? [node.parent] : [];
const relatedCompound = [...parents, ...node.children];
relatedCompound.forEach((i) => processed.add(i));
Expand Down

0 comments on commit 53bc4d3

Please sign in to comment.