@@ -91,41 +91,43 @@ const Shortcuts: React.FC = () => {
91
91
} , [ ] ) ;
92
92
93
93
const shortcutOptions = useMemo < [ string , ShortcutsItem | ShortcutsItem [ ] ] [ ] > ( ( ) => {
94
- const options : [ string , ShortcutsItem | ShortcutsItem [ ] ] [ ] = [ ] ;
95
- if ( configs && configs . shortcuts ) {
96
- Object . keys ( configs . shortcuts ) . forEach ( item => {
97
- if ( Object . keys ( DEFAULT_SHORTCUTS ) . includes ( item ) ) {
98
- options . push ( [ item , DEFAULT_SHORTCUTS [ item ] ] ) ;
99
- }
100
- } ) ;
101
- if ( configs . shortcuts . custom && configs . shortcuts . custom . length > 0 ) {
102
- configs . shortcuts . custom . forEach ( customConfig => {
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
- options . push ( [
94
+ if ( ! configs ?. shortcuts ) {
95
+ return Object . entries ( DEFAULT_SHORTCUTS ) ;
96
+ }
97
+
98
+ return Object . entries ( configs . shortcuts ) . flatMap ( ( [ key , customConfig ] ) => {
99
+ if ( Object . prototype . hasOwnProperty . call ( DEFAULT_SHORTCUTS , key ) ) {
100
+ return [ [ key , DEFAULT_SHORTCUTS [ key ] ] ] ;
101
+ }
102
+
103
+ const { text, period } = customConfig as {
104
+ text : string ;
105
+ period : { start : string ; end : string } ;
106
+ } ;
107
+ if ( ! text || ! period ) {
108
+ return [ ] ;
109
+ }
110
+
111
+ const start = dayjs ( period . start ) ;
112
+ const end = dayjs ( period . end ) ;
113
+
114
+ if ( start . isValid ( ) && end . isValid ( ) && ( start . isBefore ( end ) || start . isSame ( end ) ) ) {
115
+ return [
116
+ [
117
+ text ,
118
+ {
113
119
text,
114
- {
115
- text,
116
- period : {
117
- start : start . format ( DATE_FORMAT ) ,
118
- end : end . format ( DATE_FORMAT )
119
- }
120
+ period : {
121
+ start : start . format ( DATE_FORMAT ) ,
122
+ end : end . format ( DATE_FORMAT )
120
123
}
121
- ] ) ;
122
- }
123
- } ) ;
124
+ }
125
+ ]
126
+ ] ;
124
127
}
125
- } else {
126
- return Object . entries ( DEFAULT_SHORTCUTS ) ;
127
- }
128
- return options ;
128
+
129
+ return [ ] ;
130
+ } ) ;
129
131
} , [ configs ] ) ;
130
132
131
133
const printItemText = useCallback ( ( item : ShortcutsItem ) => {
0 commit comments