1
1
import { parseConfigYaml } from "@continuedev/config-yaml" ;
2
- import { PencilIcon } from "@heroicons/react/24/outline" ;
2
+ import { ArrowsPointingOutIcon , PencilIcon } from "@heroicons/react/24/outline" ;
3
3
import { useContext , useMemo } from "react" ;
4
4
import { useSelector } from "react-redux" ;
5
5
import { defaultBorderRadius , vscCommandCenterActiveBorder } from "../../.." ;
6
6
import { useAuth } from "../../../../context/Auth" ;
7
7
import { IdeMessengerContext } from "../../../../context/IdeMessenger" ;
8
+ import { useAppDispatch } from "../../../../redux/hooks" ;
9
+ import {
10
+ setDialogMessage ,
11
+ setShowDialog ,
12
+ } from "../../../../redux/slices/uiSlice" ;
8
13
import { RootState } from "../../../../redux/store" ;
9
14
import { fontSize } from "../../../../util" ;
10
15
import HeaderButtonWithToolTip from "../../../gui/HeaderButtonWithToolTip" ;
11
- import { AddBlockButton } from "./AddBlockButton " ;
16
+ import { ExploreBlocksButton } from "./ExploreBlocksButton " ;
12
17
13
18
interface RuleCardProps {
14
19
index : number ;
@@ -18,12 +23,19 @@ interface RuleCardProps {
18
23
}
19
24
20
25
const RuleCard : React . FC < RuleCardProps > = ( { index, rule, onClick, title } ) => {
21
- const truncateRule = ( rule : string ) => {
22
- const maxLength = 75 ;
23
- return rule . length > maxLength
24
- ? `${ rule . substring ( 0 , maxLength ) } ...`
25
- : rule ;
26
- } ;
26
+ const dispatch = useAppDispatch ( ) ;
27
+
28
+ function onClickExpand ( ) {
29
+ dispatch ( setShowDialog ( true ) ) ;
30
+ dispatch (
31
+ setDialogMessage (
32
+ < div className = "p-4 text-center" >
33
+ < h3 > { title } </ h3 >
34
+ < pre className = "max-w-full overflow-x-scroll" > { rule } </ pre >
35
+ </ div > ,
36
+ ) ,
37
+ ) ;
38
+ }
27
39
28
40
return (
29
41
< div
@@ -33,29 +45,35 @@ const RuleCard: React.FC<RuleCardProps> = ({ index, rule, onClick, title }) => {
33
45
} }
34
46
className = "px-2 py-1 transition-colors"
35
47
>
36
- < div className = "flex items-start justify-between" >
37
- < div className = "flex-1" >
38
- < div
39
- className = "text-vsc-foreground mb-1"
40
- style = { {
41
- fontSize : fontSize ( - 2 ) ,
42
- } }
43
- >
44
- { title }
48
+ < div className = "flex flex-col gap-2" >
49
+ < div className = "flex items-start justify-between" >
50
+ < div className = "flex-1" >
51
+ < div
52
+ className = "text-vsc-foreground mb-1"
53
+ style = { {
54
+ fontSize : fontSize ( - 2 ) ,
55
+ } }
56
+ >
57
+ { title }
58
+ </ div >
59
+ < div
60
+ style = { {
61
+ fontSize : fontSize ( - 3 ) ,
62
+ } }
63
+ className = "line-clamp-3 text-gray-400"
64
+ >
65
+ { rule }
66
+ </ div >
45
67
</ div >
46
- < div
47
- style = { {
48
- fontSize : fontSize ( - 3 ) ,
49
- whiteSpace : "pre-line" ,
50
- } }
51
- className = "text-gray-400"
52
- >
53
- { truncateRule ( rule ) }
68
+ < div className = "flex items-center gap-2" >
69
+ < HeaderButtonWithToolTip onClick = { onClickExpand } text = "Expand" >
70
+ < ArrowsPointingOutIcon className = "h-3 w-3 text-gray-400" />
71
+ </ HeaderButtonWithToolTip > { " " }
72
+ < HeaderButtonWithToolTip onClick = { onClick } text = "Edit" >
73
+ < PencilIcon className = "h-3 w-3 text-gray-400" />
74
+ </ HeaderButtonWithToolTip >
54
75
</ div >
55
76
</ div >
56
- < HeaderButtonWithToolTip onClick = { onClick } text = "Edit" >
57
- < PencilIcon className = "h-3 w-3 text-gray-400" />
58
- </ HeaderButtonWithToolTip >
59
77
</ div >
60
78
</ div >
61
79
) ;
@@ -86,63 +104,60 @@ export function RulesSection() {
86
104
} ) ;
87
105
88
106
return (
89
- < div className = "space-y-4" >
90
- { mergedRules . length === 0 ? (
91
- < div className = "rounded-lg bg-[#1e1e1e] p-6" >
92
- < p className = "italic text-gray-400" > No rules defined yet</ p >
93
- </ div >
94
- ) : (
95
- < div className = "space-y-3" >
96
- { mergedRules . map ( ( rule , index ) => {
97
- if ( ! rule . ruleFromYaml ) {
98
- return (
99
- < RuleCard
100
- key = { index }
101
- index = { index }
102
- rule = { rule . unrolledRule }
103
- onClick = { ( ) =>
104
- ideMessenger . post ( "config/openProfile" , {
105
- profileId : undefined ,
106
- } )
107
- }
108
- title = "Locally Defined Rule"
109
- />
110
- ) ;
111
- }
112
-
113
- if ( typeof rule . ruleFromYaml === "string" ) {
114
- const slug = `${ selectedProfile ?. fullSlug . ownerSlug } /${ selectedProfile ?. fullSlug . packageSlug } ` ;
115
-
116
- return (
117
- < RuleCard
118
- key = { index }
119
- index = { index }
120
- rule = { rule . unrolledRule }
121
- onClick = { ( ) => openUrl ( `${ slug } /new-version` ) }
122
- title = "Inline Rule"
123
- />
124
- ) ;
125
- }
126
-
127
- if ( ! rule . ruleFromYaml ?. uses ) {
128
- return null ;
129
- }
107
+ < div >
108
+ < div className = "space-y-3" >
109
+ { mergedRules . map ( ( rule , index ) => {
110
+ if ( ! rule . ruleFromYaml ) {
111
+ return (
112
+ < RuleCard
113
+ key = { index }
114
+ index = { index }
115
+ rule = { rule . unrolledRule }
116
+ onClick = { ( ) =>
117
+ ideMessenger . post ( "config/openProfile" , {
118
+ profileId : undefined ,
119
+ } )
120
+ }
121
+ title = "Locally Defined Rule"
122
+ />
123
+ ) ;
124
+ }
130
125
131
- const ruleSlug = rule . ruleFromYaml ?. uses ;
126
+ if ( typeof rule . ruleFromYaml === "string" ) {
127
+ const slug = `${ selectedProfile ?. fullSlug . ownerSlug } /${ selectedProfile ?. fullSlug . packageSlug } ` ;
132
128
133
129
return (
134
130
< RuleCard
135
131
key = { index }
136
132
index = { index }
137
133
rule = { rule . unrolledRule }
138
- onClick = { ( ) => openUrl ( `${ ruleSlug } /new-version` ) }
139
- title = { ruleSlug }
134
+ onClick = { ( ) => openUrl ( `${ slug } /new-version` ) }
135
+ title = "Inline Rule"
140
136
/>
141
137
) ;
142
- } ) }
143
- </ div >
144
- ) }
145
- < AddBlockButton blockType = "rules" />
138
+ }
139
+
140
+ if ( ! rule . ruleFromYaml ?. uses ) {
141
+ return null ;
142
+ }
143
+
144
+ const ruleSlug = rule . ruleFromYaml ?. uses ;
145
+
146
+ return (
147
+ < RuleCard
148
+ key = { index }
149
+ index = { index }
150
+ rule = { rule . unrolledRule }
151
+ onClick = { ( ) => openUrl ( `${ ruleSlug } /new-version` ) }
152
+ title = { ruleSlug }
153
+ />
154
+ ) ;
155
+ } ) }
156
+ </ div >
157
+ < ExploreBlocksButton blockType = "rules" />
146
158
</ div >
147
159
) ;
148
160
}
161
+ function useTypedDispatch ( ) {
162
+ throw new Error ( "Function not implemented." ) ;
163
+ }
0 commit comments