@@ -91,46 +91,46 @@ const Shortcuts: React.FC = () => {
91
91
} , [ ] ) ;
92
92
93
93
const shortcutOptions = useMemo < [ string , ShortcutsItem | ShortcutsItem [ ] ] [ ] > ( ( ) => {
94
- let options ;
95
- if ( configs ?. shortcuts && configs ? .shortcuts ) {
96
- const formatConfig = Object . keys ( configs . shortcuts ) . map ( item => {
94
+ const options : [ string , ShortcutsItem | ShortcutsItem [ ] ] [ ] = [ ] ;
95
+ if ( configs && configs . shortcuts ) {
96
+ Object . keys ( configs . shortcuts ) . forEach ( item => {
97
97
if ( Object . keys ( DEFAULT_SHORTCUTS ) . includes ( item ) ) {
98
- return [ item , DEFAULT_SHORTCUTS [ item ] ] ;
98
+ options . push ( [ item , DEFAULT_SHORTCUTS [ item ] ] ) ;
99
99
} else {
100
- // using | makes this fail in typecheck as [string] is no longer recognised?
101
- if ( configs . shortcuts && configs ?. shortcuts [ item ] ) {
102
- const customConfig = configs ?. shortcuts [ item ] ;
103
- const text = customConfig ?. text ;
104
- const start = dayjs ( customConfig ?. period ?. start ) ;
105
- const end = dayjs ( customConfig ?. period ?. end ) ;
106
- if (
107
- text &&
108
- start . isValid ( ) &&
109
- end . isValid ( ) &&
110
- ( start . isBefore ( end ) || start . isSame ( end ) )
111
- ) {
112
- return [
113
- item ,
114
- {
100
+ if (
101
+ configs . shortcuts &&
102
+ configs . shortcuts . custom &&
103
+ configs . shortcuts . custom . length > 0
104
+ ) {
105
+ configs . shortcuts . custom . forEach ( customConfig => {
106
+ const text = customConfig . text ;
107
+ const start = dayjs ( customConfig . period . start ) ;
108
+ const end = dayjs ( customConfig . period . end ) ;
109
+ if (
110
+ text &&
111
+ start . isValid ( ) &&
112
+ end . isValid ( ) &&
113
+ ( start . isBefore ( end ) || start . isSame ( end ) )
114
+ ) {
115
+ options . push ( [
115
116
text ,
116
- period : {
117
- start : start . format ( DATE_FORMAT ) ,
118
- end : end . format ( DATE_FORMAT )
117
+ {
118
+ text,
119
+ period : {
120
+ start : start . format ( DATE_FORMAT ) ,
121
+ end : end . format ( DATE_FORMAT )
122
+ }
119
123
}
120
- }
121
- ] ;
122
- } else {
123
- return undefined ;
124
- }
124
+ ] ) ;
125
+ }
126
+ } ) ;
125
127
}
126
- return undefined ;
127
128
}
128
129
} ) ;
129
- options = formatConfig ?. filter ( item => ! ! item ) ;
130
130
} else {
131
- options = Object . entries ( DEFAULT_SHORTCUTS ) ;
131
+ return Object . entries ( DEFAULT_SHORTCUTS ) ;
132
132
}
133
- return options as [ string , ShortcutsItem | ShortcutsItem [ ] ] [ ] ;
133
+ return options ;
134
134
} , [ configs ] ) ;
135
135
136
136
const printItemText = useCallback ( ( item : ShortcutsItem ) => {
@@ -140,7 +140,7 @@ const Shortcuts: React.FC = () => {
140
140
return shortcutOptions ?. length ? (
141
141
< div className = "md:border-b mb-3 lg:mb-0 lg:border-r lg:border-b-0 border-gray-300 dark:border-gray-700 pr-1" >
142
142
< ul className = "w-full tracking-wide flex flex-wrap lg:flex-col pb-1 lg:pb-0" >
143
- { shortcutOptions ? .map ( ( [ key , item ] , index : number ) =>
143
+ { shortcutOptions . map ( ( [ key , item ] , index : number ) =>
144
144
Array . isArray ( item ) ? (
145
145
item . map ( ( item , index ) => (
146
146
< ItemTemplate key = { index } item = { item } >
0 commit comments