Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search/filter command by pattern, function name, and effect type #21

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
1 change: 0 additions & 1 deletion src/components/Effect/Effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class Effect extends React.Component {
const {effect} = this.props
const { status, result, error, winner } = effect


let nodes = []
let data

Expand Down
1 change: 1 addition & 0 deletions src/components/ListView/ListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ListView extends React.Component {
render() {
const indent = this.props.indent || DEFAULT_INDENT

console.log(this.props.nodes);
return (
<ListViewContainer>
{ this.props.nodes.map(node => {
Expand Down
1 change: 0 additions & 1 deletion src/containers/ActionList/ActionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class ActionEntry extends React.Component {

render() {
const {action } = this.props
console.log(action.action.type)

return (
<ActionEntryContainer onClick={this.onSelect}>
Expand Down
7 changes: 6 additions & 1 deletion src/containers/EffectEntry/EffectEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ class EffectEntry extends React.Component {
onUnpin = () => this.props.onUnpin(-1)

render() {
const {effect, collapsed, pinned, hasChildren} = this.props
const {effect, collapsed, pinned, hasChildren, passFilter} = this.props

let pinNode
console.log(effect)
if(!effect.root) {
pinNode = (
pinned
Expand All @@ -60,6 +61,7 @@ class EffectEntry extends React.Component {
}

return (
passFilter ?
<EffectEntryContainer>
<Row onMouseDown={this.onSelect}>
<Cell>
Expand Down Expand Up @@ -88,6 +90,8 @@ class EffectEntry extends React.Component {
)
}
</EffectEntryContainer>
:
null
)
}
}
Expand All @@ -99,6 +103,7 @@ EffectEntry.propTypes = {
collapsed: PropTypes.bool.isRequired,
onCollapse: PropTypes.func.isRequired,
onSelect: PropTypes.func.isRequired,
passFilter: PropTypes.bool.isRequired,
// injected by Redux store
effect: PropTypes.object.isRequired,
hasChildren: PropTypes.bool.isRequired,
Expand Down
37 changes: 36 additions & 1 deletion src/containers/EffectList/EffectList.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
import React from 'react';
import styled, { css } from 'styled-components'
import { connect } from 'react-redux'
import { asEffect } from 'redux-saga/utils'
import { matchCurrentAction } from '../../store/selectors'
import {
KEY_ARROW_DOWN,
Expand All @@ -25,16 +26,49 @@ const cssMatchAction = css`
margin-top: -1px;
`

const effectTypes = ['take', 'put', 'fork', 'call', 'cps', 'join', 'cancel']

class EffectList extends React.Component {

state = {
collapsedEffects: {}
collapsedEffects: {},
filter: { word: 'a', type: undefined }
}

isCollapsed = effectId => {
return !!this.state.collapsedEffects[effectId]
}

isFiltered = effectId => {
const { filter } = this.state

if (!filter.word) return true

let data = {}, description
const effect = this.props.effectsById[effectId]

if (effect.root) {
data = { type: 'root', name: effect.effect.saga.name }
}

else {
effectTypes.forEach(type => {
if (description = asEffect[type](effect.effect)) {
data = {
type,
name: description.pattern
|| description.channel
|| description.action
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sould be description.action.name ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry description.action.type

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out. But, I wasn't sure with what are needed to be checked by the filter, because some of them have payload. So for now, I just made it as simple as possible. Do you think the filter better check for the payload including the keys and values as well?

|| (description.fn && description.fn.name)
}
}
})
}

console.log(data)
return data.name && data.name.toLowerCase().includes(filter.word.toLowerCase())
}

collapseEffect = (effectId, collapsed) => {
this.setState(state => ({
collapsedEffects: {
Expand Down Expand Up @@ -121,6 +155,7 @@ class EffectList extends React.Component {
selected={this.props.selectedEffectId === effectId}
pinned={this.props.pinnedEffectId === effectId}
collapsed={this.isCollapsed(effectId)}
passFilter={this.isFiltered(effectId)}
onCollapse={this.collapseEffect}
onPin={this.props.onPin}
onUnpin={this.props.onUnpin}
Expand Down
1 change: 1 addition & 0 deletions src/store/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function effectsById(state = {}, action) {
switch (action.type) {
case EFFECT_TRIGGERED:
effect = action.effect
console.log(effect)
effectId = effect.effectId
newState = {...state,
[effectId]: {
Expand Down