@@ -91,46 +91,46 @@ const Shortcuts: React.FC = () => {
9191 } , [ ] ) ;
9292
9393 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 => {
9797 if ( Object . keys ( DEFAULT_SHORTCUTS ) . includes ( item ) ) {
98- return [ item , DEFAULT_SHORTCUTS [ item ] ] ;
98+ options . push ( [ item , DEFAULT_SHORTCUTS [ item ] ] ) ;
9999 } 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 ( [
115116 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+ }
119123 }
120- }
121- ] ;
122- } else {
123- return undefined ;
124- }
124+ ] ) ;
125+ }
126+ } ) ;
125127 }
126- return undefined ;
127128 }
128129 } ) ;
129- options = formatConfig ?. filter ( item => ! ! item ) ;
130130 } else {
131- options = Object . entries ( DEFAULT_SHORTCUTS ) ;
131+ return Object . entries ( DEFAULT_SHORTCUTS ) ;
132132 }
133- return options as [ string , ShortcutsItem | ShortcutsItem [ ] ] [ ] ;
133+ return options ;
134134 } , [ configs ] ) ;
135135
136136 const printItemText = useCallback ( ( item : ShortcutsItem ) => {
@@ -140,7 +140,7 @@ const Shortcuts: React.FC = () => {
140140 return shortcutOptions ?. length ? (
141141 < 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" >
142142 < 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 ) =>
144144 Array . isArray ( item ) ? (
145145 item . map ( ( item , index ) => (
146146 < ItemTemplate key = { index } item = { item } >
0 commit comments