Filtering works, but only for first level? :thinking_face:
parent
06d0bd1c82
commit
142611deaa
|
@ -2,5 +2,5 @@ import { throttle } from "lodash";
|
|||
|
||||
/** Too many status updates === too many screen redraws. */
|
||||
export const slowDown =
|
||||
(fn: (...args: unknown[]) => unknown) =>
|
||||
<Returns, Args, Fn extends (u: Args) => Returns>(fn: Fn) =>
|
||||
throttle(fn, 600, { leading: false, trailing: true });
|
||||
|
|
|
@ -106,9 +106,8 @@ const isSearchMatch =
|
|||
};
|
||||
|
||||
/** Given an input search term, returns folder IDs (number) and Sequence UUIDs
|
||||
* that match
|
||||
*/
|
||||
export function searchFoldersAndSequencesForTerm(props: FolderSearchProps) {
|
||||
* that match */
|
||||
export const searchFoldersAndSequencesForTerm = (props: FolderSearchProps) => {
|
||||
type MappableFolder = FolderNodeMedial | FolderNodeTerminal;
|
||||
const searchTerm = props.input.toLowerCase();
|
||||
const sequenceSet = new Set<string>();
|
||||
|
@ -128,17 +127,21 @@ export function searchFoldersAndSequencesForTerm(props: FolderSearchProps) {
|
|||
}
|
||||
};
|
||||
|
||||
const filter = (finalNode: FolderUnion): FolderUnion => {
|
||||
return {
|
||||
...finalNode,
|
||||
content: finalNode.content.filter(seqUUID => sequenceSet.has(seqUUID))
|
||||
};
|
||||
};
|
||||
|
||||
climb(props.folders, (node: FolderUnion) => {
|
||||
node.content.map(sequenceMaper(node));
|
||||
const nodes: MappableFolder[] = node.children || [];
|
||||
nodes.map(nodeMapper);
|
||||
});
|
||||
|
||||
return {
|
||||
folders: Array.from(folderSet),
|
||||
sequences: Array.from(sequenceSet)
|
||||
};
|
||||
}
|
||||
return Array.from(folderSet).map(filter);
|
||||
};
|
||||
|
||||
export const toggleFolderOpenState = (id: number) => Promise
|
||||
.resolve(store.dispatch({ type: Actions.FOLDER_TOGGLE, payload: { id } }));
|
||||
|
|
|
@ -126,6 +126,11 @@ export class RawFolders extends React.Component<Props, State> {
|
|||
<Row>
|
||||
<this.Graph />
|
||||
</Row>
|
||||
<Row>
|
||||
<pre>
|
||||
{JSON.stringify(this.props.folders, undefined, " ")}
|
||||
</pre>
|
||||
</Row>
|
||||
</Col>
|
||||
</Page>;
|
||||
}
|
||||
|
|
|
@ -187,8 +187,8 @@ export let resourceReducer =
|
|||
})
|
||||
.add<string | undefined>(Actions.FOLDER_SEARCH, (s, { payload }) => {
|
||||
s.index.sequenceFolders.searchTerm = payload;
|
||||
if (payload && payload.length > 3) {
|
||||
const { folders } = searchFoldersAndSequencesForTerm({
|
||||
if (payload) {
|
||||
const folders = searchFoldersAndSequencesForTerm({
|
||||
references: s.index.references,
|
||||
input: payload,
|
||||
folders: s.index.sequenceFolders.folders
|
||||
|
|
Loading…
Reference in New Issue