@@ -4,93 +4,143 @@ import { ActionableTargetFunction } from "./actionable-target-function";
4
4
import { ActionableTargetApp } from "./actionable-target-app" ;
5
5
import { ActionableTargetPlugin } from "./actionable-target-plugin" ;
6
6
import { useMacroStore } from "../use-macros-store" ;
7
- import { TargetType } from "common/types" ;
7
+ import { MacroAction , TargetType } from "common/types" ;
8
8
import { ActionableTargetMacro } from "./actionable-target-macro" ;
9
9
10
- export const ActionablePanel = ( props : ActionablePanelProps ) => {
10
+ const isMacroAction = ( action : object ) : action is MacroAction => {
11
+ return "group" in action ;
12
+ } ;
13
+
14
+ export const ActionablePanel = ( props : ActionablePanelProps & { index : number } ) => {
11
15
// eslint-disable-next-line @typescript-eslint/unbound-method
12
- const { deleteActionable, updateActionable } = useMacroStore ( ) ;
13
- const { action, macro } = props ;
16
+ const { deleteActionable, updateActionable, reOrderAction } = useMacroStore ( ) ;
17
+ const { action, macro, index } = props ;
14
18
15
19
return (
16
20
< div
17
21
className = "hover"
18
22
style = { {
19
- margin : "var(--size-6)" ,
23
+ margin : "var(--size-2)" ,
24
+ order : isMacroAction ( action ) ? ( action . group ?? 0 ) * 100 + index : 0 ,
20
25
} } >
21
26
< div
22
27
style = { {
23
- display : "grid" ,
24
- gridTemplateColumns : "auto auto 1fr" ,
25
- gridGap : "var(--size-3)" ,
26
- alignItems : "center" ,
27
- justifyContent : "start" ,
28
- marginBottom : "var(--size-1)" ,
28
+ padding : "var(--size-2)" ,
29
29
} } >
30
- < span
31
- style = { { fontWeight : 500 , display : "flex" , alignItems : "center" } } >
32
- < i
33
- className = "material-icons"
34
- style = { { fontSize : "var(--font-size-3)" } } >
35
- { action . path [ 0 ] === ":function"
36
- ? "code"
37
- : action . path [ 0 ] === ":app"
38
- ? "settings_applications"
39
- : "extension" }
40
- </ i >
41
- < select
42
- onChange = { ( evt ) => {
43
- updateActionable ( macro , {
44
- ...action ,
45
- path : [ evt . target . value as TargetType ] ,
46
- } ) ;
47
- } }
48
- value = { action . path [ 0 ] } >
49
- < option value = ":app" > App</ option >
50
- < option value = ":plugin" > Plugin</ option >
51
- < option value = ":macro" > Macro</ option >
52
- < option value = ":function" > Function</ option >
53
- </ select >
54
- </ span >
55
- < button
30
+ < div
56
31
style = { {
57
- justifySelf : "end" ,
58
- color : "var(--red-4)" ,
59
- fontSize : "var(--font-size-00)" ,
60
- } }
61
- onClick = { ( ) => {
62
- deleteActionable ( macro , action ) ;
32
+ display : "flex" ,
33
+ justifyContent : "space-between" ,
34
+ marginBottom : "var(--size-1)" ,
63
35
} } >
64
- < i
65
- className = "material-icons small"
66
- style = { { fontSize : "var(--font-size-2)" } } >
67
- delete
68
- </ i >
69
- </ button >
70
- </ div >
36
+ < span
37
+ style = { {
38
+ fontWeight : 500 ,
39
+ gap : "var(--size-3)" ,
40
+ display : "flex" ,
41
+ alignItems : "center" ,
42
+ } } >
43
+ < i
44
+ className = "material-icons"
45
+ style = { { fontSize : "var(--font-size-3)" } } >
46
+ { action . path [ 0 ] === ":function"
47
+ ? "code"
48
+ : action . path [ 0 ] === ":app"
49
+ ? "settings_applications"
50
+ : "extension" }
51
+ </ i >
71
52
72
- { action . error && (
73
- < p style = { { color : "var(--red-6)" } } >
74
- { " " }
75
- - { action . error . type } : { action . error . message }
76
- </ p >
77
- ) }
78
- < ErrorBoundary
79
- message = "There was an error with this action"
80
- key = { action . id } >
81
- { action . path [ 0 ] === ":app" && (
82
- < ActionableTargetApp { ...props } action = { action } />
83
- ) }
84
- { action . path [ 0 ] === ":function" && (
85
- < ActionableTargetFunction { ...props } action = { action } />
86
- ) }
87
- { action . path [ 0 ] === ":plugin" && (
88
- < ActionableTargetPlugin { ...props } action = { action } />
89
- ) }
90
- { action . path [ 0 ] === ":macro" && (
91
- < ActionableTargetMacro { ...props } action = { action } />
53
+ < select
54
+ onChange = { ( evt ) => {
55
+ updateActionable ( macro , {
56
+ ...action ,
57
+ path : [ evt . target . value as TargetType ] ,
58
+ } ) ;
59
+ } }
60
+ value = { action . path [ 0 ] } >
61
+ < option value = ":app" > App</ option >
62
+ < option value = ":plugin" > Plugin</ option >
63
+ < option value = ":macro" > Macro</ option >
64
+ < option value = ":function" > Function</ option >
65
+ </ select >
66
+ </ span >
67
+ < span
68
+ style = { {
69
+ display : "flex" ,
70
+ alignItems : "center" ,
71
+ } } >
72
+ { isMacroAction ( action ) && (
73
+ < >
74
+ < i
75
+ style = { { cursor : "pointer" } }
76
+ className = "material-icons"
77
+ onClick = { ( ) =>
78
+ reOrderAction (
79
+ macro . id ,
80
+ action . id ,
81
+ action . group ! ,
82
+ - 1
83
+ )
84
+ } >
85
+ arrow_upward
86
+ </ i >
87
+ < i
88
+ style = { { cursor : "pointer" } }
89
+ className = "material-icons"
90
+ onClick = { ( ) =>
91
+ reOrderAction (
92
+ macro . id ,
93
+ action . id ,
94
+ action . group ! ,
95
+ 1
96
+ )
97
+ } >
98
+ arrow_downward
99
+ </ i >
100
+ </ >
101
+ ) }
102
+
103
+ < button
104
+ style = { {
105
+ justifySelf : "end" ,
106
+ color : "var(--red-4)" ,
107
+ fontSize : "var(--font-size-00)" ,
108
+ } }
109
+ onClick = { ( ) => {
110
+ deleteActionable ( macro , action ) ;
111
+ } } >
112
+ < i
113
+ className = "material-icons small"
114
+ style = { { fontSize : "var(--font-size-2)" } } >
115
+ delete
116
+ </ i >
117
+ </ button >
118
+ </ span >
119
+ </ div >
120
+
121
+ { action . error && (
122
+ < p style = { { color : "var(--red-6)" } } >
123
+ { " " }
124
+ - { action . error . type } : { action . error . message }
125
+ </ p >
92
126
) }
93
- </ ErrorBoundary >
127
+ < ErrorBoundary
128
+ message = "There was an error with this action"
129
+ key = { action . id } >
130
+ { action . path [ 0 ] === ":app" && (
131
+ < ActionableTargetApp { ...props } action = { action } />
132
+ ) }
133
+ { action . path [ 0 ] === ":function" && (
134
+ < ActionableTargetFunction { ...props } action = { action } />
135
+ ) }
136
+ { action . path [ 0 ] === ":plugin" && (
137
+ < ActionableTargetPlugin { ...props } action = { action } />
138
+ ) }
139
+ { action . path [ 0 ] === ":macro" && (
140
+ < ActionableTargetMacro { ...props } action = { action } />
141
+ ) }
142
+ </ ErrorBoundary >
143
+ </ div >
94
144
</ div >
95
145
) ;
96
146
} ;
0 commit comments