11import React , { useCallback , useEffect , useMemo , useState } from "react" ;
2- import * as GQL from "~/admin/viewsGraphql.js" ;
32import type { ListCmsModelsQueryResponse } from "~/admin/viewsGraphql.js" ;
3+ import * as GQL from "~/admin/viewsGraphql.js" ;
44import { withoutBeingDeletedModels } from "~/admin/viewsGraphql.js" ;
55import type {
66 BindComponentRenderProp ,
@@ -11,31 +11,14 @@ import type {
1111import { Options } from "./Options.js" ;
1212import { useReferences } from "../hooks/useReferences.js" ;
1313import { Entry } from "./Entry.js" ;
14- import { Container } from "./Container.js" ;
1514import { ReferencesDialog } from "./ReferencesDialog.js" ;
1615import { useModelFieldGraphqlContext , useQuery } from "~/admin/hooks/index.js" ;
1716import { useSnackbar } from "@webiny/app-admin" ;
1817import type { CmsReferenceValue } from "~/admin/plugins/fieldRenderers/ref/components/types.js" ;
1918import { parseIdentifier } from "@webiny/utils" ;
2019import { Entries } from "./Entries.js" ;
2120import { NewReferencedEntryDialog } from "~/admin/plugins/fieldRenderers/ref/components/NewReferencedEntryDialog.js" ;
22- import {
23- FormComponentErrorMessage ,
24- FormComponentLabel ,
25- OverlayLoader ,
26- Text
27- } from "@webiny/admin-ui" ;
28-
29- const getRecordCountMessage = ( count : number ) => {
30- switch ( count ) {
31- case 0 :
32- return "no records selected" ;
33- case 1 :
34- return "1 record selected" ;
35- default :
36- return `${ count } records selected` ;
37- }
38- } ;
21+ import { FormComponentErrorMessage , FormComponentLabel } from "@webiny/admin-ui" ;
3922
4023interface AdvancedMultipleReferenceFieldProps extends CmsModelFieldRendererProps {
4124 bind : BindComponentRenderProp < CmsReferenceValue [ ] | undefined | null > ;
@@ -105,11 +88,7 @@ export const AdvancedMultipleReferenceField = (props: AdvancedMultipleReferenceF
10588 setLinkEntryDialogModel ( null ) ;
10689 } , [ ] ) ;
10790
108- const {
109- entries,
110- loading : loadingEntries ,
111- loadMore
112- } = useReferences ( {
91+ const { entries, loadMore } = useReferences ( {
11392 values,
11493 perPage : 10 ,
11594 requestContext
@@ -211,10 +190,6 @@ export const AdvancedMultipleReferenceField = (props: AdvancedMultipleReferenceF
211190 [ values ]
212191 ) ;
213192
214- const loading = loadingEntries || loadingModels ;
215-
216- const message = getRecordCountMessage ( values . length ) ;
217-
218193 const { validation } = bind ;
219194 const { isValid : validationIsValid , message : validationMessage } = validation || { } ;
220195 const invalid = useMemo ( ( ) => validationIsValid === false , [ validationIsValid ] ) ;
@@ -223,10 +198,8 @@ export const AdvancedMultipleReferenceField = (props: AdvancedMultipleReferenceF
223198 < >
224199 < div className = { "flex items-center justify-between" } >
225200 < FormComponentLabel text = { field . label } invalid = { invalid } />
226- < Text size = { "sm" } > ({ message } )</ Text >
227201 </ div >
228- < Container className = { "webiny_ref-field-container" } >
229- { loading && < OverlayLoader size = { "md" } /> }
202+ < div className = { "webiny_ref-field-container" } >
230203 < Entries entries = { entries } loadMore = { loadMore } >
231204 { ( entry , index ) => {
232205 const isFirst = index === 0 ;
@@ -251,8 +224,10 @@ export const AdvancedMultipleReferenceField = (props: AdvancedMultipleReferenceF
251224 ) ;
252225 } }
253226 </ Entries >
254- </ Container >
227+ </ div >
255228 < FormComponentErrorMessage text = { validationMessage } invalid = { invalid } />
229+ { values . length > 0 && < div className = "mb-md" /> }
230+
256231 < Options
257232 models = { models }
258233 onNewRecord = { onNewRecord }
0 commit comments