@@ -2,7 +2,7 @@ import React, { forwardRef, useEffect, useRef, useState, useImperativeHandle } f
22import $ from 'jquery' ;
33import { observer } from 'mobx-react' ;
44import { Icon } from 'Component' ;
5- import { I , S , U , J , translate , analytics , focus , Renderer , Relation , Action , Onboarding , keyboard } from 'Lib' ;
5+ import { I , C , S , U , J , translate , analytics , focus , Renderer , Relation , Action , Onboarding , keyboard } from 'Lib' ;
66
77interface Props {
88 rootId : string ;
@@ -32,8 +32,10 @@ const ControlButtons = observer(forwardRef<ControlButtonsRef, Props>((props, ref
3232 const isBookmark = U . Object . isBookmarkLayout ( root ?. layout ) ;
3333 const isChat = U . Object . isChatLayout ( root ?. layout ) ;
3434 const isType = U . Object . isTypeLayout ( root ?. layout ) ;
35- const object = S . Detail . get ( rootId , rootId , [ 'featuredRelations' , 'targetObjectType' , 'layoutAlign' ] ) ;
35+ const object = S . Detail . get ( rootId , rootId , [ 'featuredRelations' , 'targetObjectType' , 'layoutAlign' , 'type' , 'templateNamePrefillType' ] ) ;
36+ const isTemplate = U . Object . isTemplateType ( object . type ) ;
3637 const hasDescription = Relation . getArrayValue ( object . featuredRelations ) . includes ( 'description' ) ;
38+ const prefillType = Number ( object . templateNamePrefillType ) || 0 ;
3739 const hasConflict = U . Object . hasLayoutConflict ( object ) ;
3840 const check = U . Data . checkDetails ( rootId ) ;
3941 const nodeRef = useRef ( null ) ;
@@ -68,6 +70,10 @@ const ControlButtons = observer(forwardRef<ControlButtonsRef, Props>((props, ref
6870 Action . toggleFeatureRelation ( rootId , 'description' ) ;
6971 } ;
7072
73+ const onPrefillNameHandler = ( e : any ) => {
74+ C . ObjectListSetDetails ( [ rootId ] , [ { key : 'templateNamePrefillType' , value : prefillType ? 0 : 1 } ] ) ;
75+ } ;
76+
7177 const onCoverHandler = ( e : any ) => {
7278 e . preventDefault ( ) ;
7379 e . stopPropagation ( ) ;
@@ -158,14 +164,15 @@ const ControlButtons = observer(forwardRef<ControlButtonsRef, Props>((props, ref
158164 } ) ;
159165 } ;
160166
161- const getAllowedButtons = ( ) : { allowedIcon : boolean , allowedLayout : boolean , allowedCover : boolean , allowedDescription : boolean } => {
167+ const getAllowedButtons = ( ) : { allowedIcon : boolean , allowedLayout : boolean , allowedCover : boolean , allowedDescription : boolean , allowedPrefillName : boolean } => {
162168 let allowedLayout = false ;
163169 let allowedIcon = false ;
164170 let allowedCover = false ;
165171 let allowedDescription = false ;
172+ let allowedPrefillName = false ;
166173
167174 if ( ! root ) {
168- return { allowedIcon, allowedLayout, allowedCover, allowedDescription } ;
175+ return { allowedIcon, allowedLayout, allowedCover, allowedDescription, allowedPrefillName } ;
169176 } ;
170177
171178 const allowedDetails = S . Block . checkFlags ( rootId , rootId , [ I . RestrictionObject . Details ] ) ;
@@ -174,6 +181,7 @@ const ControlButtons = observer(forwardRef<ControlButtonsRef, Props>((props, ref
174181 allowedIcon = allowedDetails && ! isTask && ! isNote && ! isBookmark && ! isType ;
175182 allowedCover = allowedDetails && ! isNote && ! isType ;
176183 allowedDescription = allowedDetails && ! isNote ;
184+ allowedPrefillName = allowedDetails && isTemplate ;
177185
178186 if ( isInSets && ! hasConflict ) {
179187 allowedLayout = false ;
@@ -184,17 +192,18 @@ const ControlButtons = observer(forwardRef<ControlButtonsRef, Props>((props, ref
184192 allowedLayout = false ;
185193 allowedCover = false ;
186194 allowedDescription = false ;
195+ allowedPrefillName = false ;
187196 } ;
188197
189- return { allowedIcon, allowedLayout, allowedCover, allowedDescription } ;
198+ return { allowedIcon, allowedLayout, allowedCover, allowedDescription, allowedPrefillName } ;
190199 } ;
191200
192201 const resize = ( ) => {
193202 const { ww } = U . Common . getWindowDimensions ( ) ;
194203 $ ( nodeRef . current ) . toggleClass ( 'small' , ww <= 900 ) ;
195204 } ;
196205
197- const { allowedIcon, allowedLayout, allowedCover, allowedDescription } = getAllowedButtons ( ) ;
206+ const { allowedIcon, allowedLayout, allowedCover, allowedDescription, allowedPrefillName } = getAllowedButtons ( ) ;
198207
199208 useEffect ( ( ) => {
200209 if ( allowedDescription ) {
@@ -238,6 +247,13 @@ const ControlButtons = observer(forwardRef<ControlButtonsRef, Props>((props, ref
238247 </ div >
239248 ) : '' }
240249
250+ { allowedPrefillName ? (
251+ < div id = "button-prefill-name" className = "btn white withIcon" onClick = { onPrefillNameHandler } >
252+ < Icon className = "preFillName" />
253+ < div className = "txt" > { translate ( `editorControlPrefillName${ prefillType } ` ) } </ div >
254+ </ div >
255+ ) : '' }
256+
241257 { allowedLayout ? (
242258 < div id = "button-layout" className = "btn white withIcon small" onClick = { onLayoutHandler } >
243259 < Icon className = "layout" />
0 commit comments