@@ -7,14 +7,11 @@ import { useFormConfiguration } from '@/providers/form/api';
77import { FormIdentifier } from '@/providers/form/models' ;
88import ParentProvider from '@/providers/parentProvider' ;
99import { get } from '@/utils/fetchers' ;
10- import { App , Button , Popover , PopoverProps , Spin } from 'antd' ;
10+ import { App , Button , Popover , PopoverProps } from 'antd' ;
1111import React , { CSSProperties , FC , PropsWithChildren , useEffect , useMemo , useState } from 'react' ;
1212import { ShaIconTypes } from '../iconPicker' ;
13- import {
14- getQuickViewInitialValues ,
15- innerEntityReferenceButtonBoxStyle ,
16- innerEntityReferenceSpanBoxStyle ,
17- } from './utils' ;
13+ import { formItemLayout , getQuickViewInitialValues , loadingBox } from './utils' ;
14+ import { useStyles } from './styles/styles' ;
1815
1916export interface IQuickViewProps extends PropsWithChildren {
2017 /** The id or guid for the entity */
@@ -48,19 +45,6 @@ export interface IQuickViewProps extends PropsWithChildren {
4845 emptyText ?: string ;
4946}
5047
51- const formItemLayout = {
52- labelCol : {
53- xs : { span : 24 } ,
54- md : { span : 8 } ,
55- sm : { span : 8 } ,
56- } ,
57- wrapperCol : {
58- xs : { span : 24 } ,
59- md : { span : 16 } ,
60- sm : { span : 16 } ,
61- } ,
62- } ;
63-
6448const QuickView : FC < Omit < IQuickViewProps , 'formType' > > = ( {
6549 children,
6650 entityId,
@@ -87,6 +71,7 @@ const QuickView: FC<Omit<IQuickViewProps, 'formType'>> = ({
8771 const { backendUrl, httpHeaders } = useSheshaApplication ( ) ;
8872 const { refetch : fetchForm } = useFormConfiguration ( { formId : formIdentifier , lazy : true } ) ;
8973 const { notification } = App . useApp ( ) ;
74+ const { styles, cx} = useStyles ( ) ;
9075
9176 useEffect ( ( ) => {
9277 if ( formIdentifier ) {
@@ -144,61 +129,61 @@ const QuickView: FC<Omit<IQuickViewProps, 'formType'>> = ({
144129
145130 const render = ( ) => {
146131 if ( children ) {
147- return < div style = { { ... innerEntityReferenceButtonBoxStyle , ... style } } > { children } </ div > ;
132+ return < div className = { cx ( styles . innerEntityReferenceButtonBoxStyle ) } > { children } </ div > ;
148133 }
149134
150135 if ( displayType === 'icon' ) {
151136 return (
152- < Button type = "link" style = { { ... innerEntityReferenceButtonBoxStyle , ... style } } >
137+ < Button type = "link" className = { cx ( styles . innerEntityReferenceButtonBoxStyle ) } style = { style } >
153138 < ShaIcon iconName = { iconName } />
154139 </ Button >
155140 ) ;
156141 }
157142
158143 if ( displayType === 'textTitle' ) {
159144 return (
160- < Button type = "link" style = { { ... innerEntityReferenceButtonBoxStyle , ... style } } >
145+ < Button type = "link" className = { cx ( styles . innerEntityReferenceButtonBoxStyle ) } style = { style } >
161146 { textTitle ? (
162- < span style = { innerEntityReferenceSpanBoxStyle } > { textTitle } </ span >
147+ < span className = { cx ( styles . innerEntityReferenceSpanBoxStyle ) } > { textTitle } </ span >
163148 ) : (
164149 < >
165- < Spin size = "small" />
166- < span style = { innerEntityReferenceSpanBoxStyle } > Loading...</ span >
150+ { loadingBox ( cx , styles ) }
167151 </ >
168152 ) }
169153 </ Button >
170154 ) ;
171155 }
172156
157+ const ifLoadingStateSuccess = ( ) => loadingState === 'success' ? (
158+ < span className = { cx ( styles . innerEntityReferenceSpanBoxStyle ) } > { formTitle || emptyText } </ span >
159+ ) : (
160+ < span className = { cx ( styles . innerEntityReferenceSpanBoxStyle ) } > Quickview not configured properly</ span >
161+ ) ;
162+
173163 return (
174- < Button type = "link" style = { { ... innerEntityReferenceButtonBoxStyle , ... style } } >
164+ < Button type = "link" className = { cx ( styles . innerEntityReferenceButtonBoxStyle ) } style = { style } >
175165 { loadingState === 'loading' ? (
176166 < >
177- < Spin size = "small" />
178- < span style = { innerEntityReferenceSpanBoxStyle } > Loading...</ span >
167+ { loadingBox ( cx , styles ) }
179168 </ >
180- ) : loadingState === 'success' ? (
181- < span style = { innerEntityReferenceSpanBoxStyle } > { formTitle || emptyText } </ span >
182- ) : (
183- < span style = { innerEntityReferenceSpanBoxStyle } > Quickview not configured properly</ span >
184- ) }
169+ ) : ifLoadingStateSuccess ( ) }
185170 </ Button >
186171 ) ;
187172 } ;
188173
189174 if ( disabled )
190175 return (
191- < Button disabled type = "link" style = { { ... innerEntityReferenceButtonBoxStyle , ... style } } >
192- < span style = { innerEntityReferenceSpanBoxStyle } > { formTitle || emptyText } </ span >
176+ < Button disabled type = "link" className = { cx ( styles . innerEntityReferenceButtonBoxStyle ) } style = { style } >
177+ < span className = { cx ( styles . innerEntityReferenceSpanBoxStyle ) } > { formTitle || emptyText } </ span >
193178 </ Button >
194179 ) ;
195180
196181 const title = loadingState === 'error' ? 'Quickview not configured properly' : formTitle ;
197182 return (
198- < Popover
199- overlayInnerStyle = { { width, minWidth : width , maxHeight : '80vh' , overflowY : 'auto' , overflowX : 'auto' } }
200- content = { formContent }
201- title = { < div style = { { width, textOverflow : 'ellipsis' , overflow : 'hidden' , whiteSpace : 'nowrap' } } > { title } </ div > }
183+ < Popover
184+ overlayInnerStyle = { { width, minWidth : width , maxHeight : '80vh' , overflowY : 'auto' , overflowX : 'auto' } }
185+ content = { formContent }
186+ title = { < div style = { { width, textOverflow : 'ellipsis' , overflow : 'hidden' , whiteSpace : 'nowrap' } } > { title } </ div > }
202187 { ...popoverProps }
203188 >
204189 { render ( ) }
@@ -209,6 +194,7 @@ const QuickView: FC<Omit<IQuickViewProps, 'formType'>> = ({
209194export const GenericQuickView : FC < IQuickViewProps > = ( props ) => {
210195 const { getEntityFormId } = useConfigurationItemsLoader ( ) ;
211196 const [ formConfig , setFormConfig ] = useState < FormIdentifier > ( props . formIdentifier ?? undefined ) ;
197+ const { styles, cx} = useStyles ( ) ;
212198
213199 useEffect ( ( ) => {
214200 if ( props . className && ! formConfig )
@@ -221,17 +207,15 @@ export const GenericQuickView: FC<IQuickViewProps> = (props) => {
221207 } ) ;
222208 } , [ props . className , props . formType , formConfig ] ) ;
223209
224- return formConfig ? (
225- < QuickView { ...props } formIdentifier = { formConfig } />
226- ) : formConfig === undefined ? (
227- < Button type = "link" style = { { ...innerEntityReferenceButtonBoxStyle , ...props . style } } >
228- < span style = { innerEntityReferenceSpanBoxStyle } >
229- < Spin size = "small" /> Loading...
230- </ span >
210+ const buttonOrPopover = formConfig === undefined ? (
211+ < Button type = "link" className = { cx ( styles . innerEntityReferenceButtonBoxStyle ) } style = { props . style } >
212+ { loadingBox ( cx , styles ) }
231213 </ Button >
232214 ) : (
233215 < Popover content = { 'Quickview not configured properly' } title = "Quickview not configured properly" > </ Popover >
234216 ) ;
217+
218+ return formConfig ? < QuickView { ...props } formIdentifier = { formConfig } /> : buttonOrPopover ;
235219} ;
236220
237221export default QuickView ;
0 commit comments