Skip to content

Commit ec2775e

Browse files
committed
icon to collapse/expand actions
1 parent 36646bd commit ec2775e

17 files changed

Lines changed: 365 additions & 190 deletions

dist/hyperapp-devtools.js

Lines changed: 142 additions & 87 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/hyperapp-devtools.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/actions.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import { ActionsType } from "hyperapp";
22
import * as api from "./api";
3+
export declare const INITIAL_ACTION = "%%% INITIAL STATE %%%";
34
export declare const actions: ActionsType<api.State, api.Actions>;

dist/src/api.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export interface AppAction {
22
name: string;
33
done: boolean;
4-
nestedActions: AppAction[];
4+
actions: AppAction[];
55
previousState: any | null;
66
collapsed: boolean;
77
nextState?: any;
@@ -46,7 +46,7 @@ export interface State {
4646
}
4747
export interface ToggleActionPayload {
4848
run: string;
49-
actionId: number;
49+
path: number[];
5050
}
5151
export interface Actions {
5252
log(event: RuntimeEvent): any;
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import "./RunActionItem.scss";
2-
import { State, Actions, AppAction } from "../api";
2+
import { State, Actions, AppAction, Run } from "../api";
33
export interface RunActionItemProps {
44
state: State;
55
actions: Actions;
6-
array: AppAction[];
7-
index: number;
6+
run: Run;
7+
actionList: AppAction[];
8+
indexInList: number;
89
action: AppAction;
10+
path: number[];
911
}
1012
export declare function RunActionItem(props: RunActionItemProps): any;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import "./RunActionItemList.scss";
2+
import { State, Actions, AppAction, Run } from "../api";
3+
export interface RunActionItemListProps {
4+
state: State;
5+
actions: Actions;
6+
run: Run;
7+
actionList: AppAction[];
8+
collapsed: boolean;
9+
path: number[];
10+
}
11+
export declare function RunActionItemList(props: RunActionItemListProps): any;

dist/src/components/RunsPaneItem.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ export interface RunsPaneItemProps {
55
actions: Actions;
66
run: Run;
77
current: boolean;
8+
path: any[];
89
}
910
export declare function RunsPaneItem(props: RunsPaneItemProps): JSX.Element;

src/actions.ts

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ function isCurrentAction(action: api.AppAction): boolean {
1717
return false
1818
}
1919

20-
const length = action.nestedActions.length
21-
return length === 0 || action.nestedActions[length - 1].done
20+
const length = action.actions.length
21+
return length === 0 || action.actions[length - 1].done
2222
}
2323

2424
/**
@@ -41,13 +41,13 @@ function appendActionEvent(
4141
done: false,
4242
collapsed: false,
4343
actionData: event.data,
44-
nestedActions: [],
44+
actions: [],
4545
previousState: action.previousState
4646
}
4747

4848
return {
4949
...action,
50-
nestedActions: action.nestedActions.concat(nestedAction)
50+
actions: action.actions.concat(nestedAction)
5151
}
5252
} else if (action.name === event.action) {
5353
// the previous call is now complete: set to done and compute the result
@@ -65,19 +65,41 @@ function appendActionEvent(
6565
}
6666
} else {
6767
// there are already some nested actions: call recursivelly
68-
const nested = action.nestedActions
68+
const nested = action.actions
6969
const nestedAction = nested[nested.length - 1]
7070
const newNestedAction = appendActionEvent(nestedAction, event)
7171
if (nestedAction === newNestedAction) {
7272
return action
7373
}
7474
return {
7575
...action,
76-
nestedActions: nested.slice(0, nested.length - 1).concat(newNestedAction)
76+
actions: nested.slice(0, nested.length - 1).concat(newNestedAction)
7777
}
7878
}
7979
}
8080

81+
function toggleAction(
82+
runs: api.Runs,
83+
runId: string,
84+
actionPath: number[]
85+
): api.Runs {
86+
const path: any[] = [runId]
87+
actionPath.forEach(index => {
88+
path.push("actions", index)
89+
})
90+
path.push("collapsed")
91+
92+
const collapsed = get(runs, path)
93+
if (typeof collapsed !== "boolean") {
94+
console.log("WARN: try to collapse invalid action, path: ", actionPath)
95+
return runs
96+
}
97+
98+
return set(runs, path, !collapsed)
99+
}
100+
101+
export const INITIAL_ACTION = "%%% INITIAL STATE %%%"
102+
81103
export const actions: ActionsType<api.State, api.Actions> = {
82104
log: (event: api.RuntimeEvent) => state => {
83105
return { logs: state.logs.concat([event]) }
@@ -86,10 +108,10 @@ export const actions: ActionsType<api.State, api.Actions> = {
86108
const runs = { ...state.runs }
87109

88110
const action: api.AppAction = {
89-
name: "Initial State",
111+
name: INITIAL_ACTION,
90112
done: true,
91113
collapsed: false,
92-
nestedActions: [],
114+
actions: [],
93115
previousState: null,
94116
nextState: event.state
95117
}
@@ -116,7 +138,7 @@ export const actions: ActionsType<api.State, api.Actions> = {
116138
selectedAction = {
117139
done: false,
118140
collapsed: false,
119-
nestedActions: [],
141+
actions: [],
120142
name: event.action,
121143
actionData: event.data,
122144
previousState: prevAction.nextState
@@ -141,10 +163,8 @@ export const actions: ActionsType<api.State, api.Actions> = {
141163
return { runs }
142164
},
143165
toggleAction: (payload: api.ToggleActionPayload) => state => {
144-
const { run, actionId } = payload
145-
const path = [run, "actions", actionId, "collapsed"]
146-
const collapsed = get(state.runs, path)
147-
const runs = set(state.runs, path, !collapsed)
166+
const { run, path } = payload
167+
const runs = toggleAction(state.runs, run, path)
148168
return { runs }
149169
},
150170
select: (selectedAction: api.AppAction | null) => {

src/api.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export interface AppAction {
44
name: string
55
done: boolean
6-
nestedActions: AppAction[]
6+
actions: AppAction[]
77
previousState: any | null
88
collapsed: boolean
99
nextState?: any
@@ -15,9 +15,6 @@ export interface Run {
1515
id: string
1616
timestamp: number
1717
actions: AppAction[]
18-
// // used internally when loging actions
19-
// // each number is the
20-
// currentActionPath: number[]
2118
collapsed: boolean
2219
}
2320

@@ -61,7 +58,7 @@ export interface State {
6158

6259
export interface ToggleActionPayload {
6360
run: string
64-
actionId: number
61+
path: number[]
6562
}
6663

6764
export interface Actions {

src/components/RunActionItem.scss

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
@import "node_modules/spectre.css/src/spectre";
1+
@import "./index.scss";
22

33
.run-action-item-count {
44
color: orange;
55
}
66

77
.run-action-item {
8-
display: block;
8+
margin: 0rem;
9+
width: 100%;
910

10-
&:hover {
11-
background-color: $secondary-color;
12-
}
11+
.item-link {
12+
display: block;
13+
color: black;
14+
15+
&:hover {
16+
background-color: $secondary-color;
17+
color: black;
18+
}
1319

14-
&.selected {
15-
background-color: $secondary-color-dark;
20+
&.selected {
21+
background-color: $secondary-color-dark;
22+
font-weight: bold;
23+
color: black;
24+
}
1625
}
1726
}

0 commit comments

Comments
 (0)