1- import { useDebounce } from "@prismicio/editor-support/React" ;
1+ import { useDebounce , useStableEffect } from "@prismicio/editor-support/React" ;
22import {
33 Box ,
44 Button ,
@@ -24,6 +24,7 @@ import { ReactNode, Suspense, useEffect, useMemo, useState } from "react";
2424import { toast } from "react-toastify" ;
2525
2626import { getState , telemetry } from "@/apiClient" ;
27+ import { getFrameworkFromAdapter } from "@/features/customTypes/customTypesBuilder/ImportSlicesFromLibraryModal/utils/getFrameworkFromAdapter" ;
2728import { useOnboarding } from "@/features/onboarding/useOnboarding" ;
2829import { useAutoSync } from "@/features/sync/AutoSyncProvider" ;
2930import { useRepositoryInformation } from "@/hooks/useRepositoryInformation" ;
@@ -37,6 +38,7 @@ import { EmptyView } from "./EmptyView";
3738import { useGitIntegration } from "./hooks/useGitIntegration" ;
3839import { SliceCard } from "./SliceCard" ;
3940import {
41+ AdapterSchema ,
4042 CommonDialogContentProps ,
4143 GitIntegration ,
4244 NewSlice ,
@@ -71,16 +73,16 @@ function LibrarySlicesDialogSuspenseContent(
7173
7274 const {
7375 integrations,
76+ fetchedSlices,
7477 isImportingSlices,
7578 fetchSlicesFromGithub,
76- importedSlices,
7779 resetImportedSlices,
7880 } = useGitIntegration ( ) ;
7981
8082 const smActions = useSliceMachineActions ( ) ;
8183 const { syncChanges } = useAutoSync ( ) ;
8284 const { completeStep : completeOnboardingStep } = useOnboarding ( ) ;
83- const prismicRepositoryInformation = useRepositoryInformation ( ) ;
85+ const prismicRepositoryInformation = usePrismicRepositoryDetails ( ) ;
8486
8587 useEffect ( ( ) => {
8688 if ( isTabSelected ) {
@@ -102,11 +104,14 @@ function LibrarySlicesDialogSuspenseContent(
102104 const onSelectRepository = ( repository : RepositorySelection ) => {
103105 setSelectedRepository ( repository ) ;
104106 setSelectedSlices ( [ ] ) ;
105- void fetchSlicesFromGithub ( { repository } ) ;
107+ void fetchSlicesFromGithub ( {
108+ repository,
109+ targetFramework : prismicRepositoryInformation . framework ,
110+ } ) ;
106111 } ;
107112
108113 const onSelectAll = ( checked : boolean ) => {
109- setSelectedSlices ( checked ? importedSlices : [ ] ) ;
114+ setSelectedSlices ( checked ? fetchedSlices : [ ] ) ;
110115 } ;
111116
112117 const onSelect = ( slice : SliceImport ) => {
@@ -258,27 +263,28 @@ repositories and set a library for this project.`}
258263 icon = "alert"
259264 />
260265 ) ;
261- } else if ( importedSlices . length === 0 ) {
266+ } else if ( fetchedSlices . length === 0 ) {
262267 renderedContent = (
263268 < EmptyView
264269 title = "No slices found"
265- description = "This repository doesn't contain any Slice components."
270+ description = { `This repository doesn't contain any Slice components
271+ compatible with your project.` }
266272 icon = "viewDay"
267273 />
268274 ) ;
269275 } else {
270- const allSelected = importedSlices . every ( ( slice ) =>
276+ const allSelected = fetchedSlices . every ( ( slice ) =>
271277 selectedSlices . some ( ( s ) => s . model . id === slice . model . id ) ,
272278 ) ;
273- const someSelected = importedSlices . some ( ( slice ) =>
279+ const someSelected = fetchedSlices . some ( ( slice ) =>
274280 selectedSlices . some ( ( s ) => s . model . id === slice . model . id ) ,
275281 ) ;
276282
277283 let selectAllLabel = "Select all slices" ;
278284 if ( allSelected ) {
279285 selectAllLabel = `Selected all slices (${ selectedSlices . length } )` ;
280286 } else if ( someSelected ) {
281- selectAllLabel = `${ selectedSlices . length } of ${ importedSlices . length } selected` ;
287+ selectAllLabel = `${ selectedSlices . length } of ${ fetchedSlices . length } selected` ;
282288 }
283289
284290 renderedContent = (
@@ -300,7 +306,7 @@ repositories and set a library for this project.`}
300306 gap = { 16 }
301307 padding = { { inline : 16 , bottom : 16 } }
302308 >
303- { importedSlices . map ( ( slice ) => (
309+ { fetchedSlices . map ( ( slice ) => (
304310 < SliceCard
305311 key = { slice . model . id }
306312 model = { slice . model }
@@ -380,8 +386,12 @@ function RepositorySelector(props: RepositorySelectorProps) {
380386 ) ;
381387 } , [ integrations ] ) ;
382388
383- useEffect ( ( ) => {
389+ useStableEffect ( ( ) => {
384390 if ( isTabSelected && repositories . length > 0 ) {
391+ if ( repositories . length === 1 ) {
392+ onSelectRepository ( repositories [ 0 ] ) ;
393+ }
394+
385395 void telemetry . track ( {
386396 event : "slice-library:projects-listed" ,
387397 repositories_count : repositories . length ,
@@ -471,6 +481,20 @@ function RepositorySelector(props: RepositorySelectorProps) {
471481 ) ;
472482}
473483
484+ function usePrismicRepositoryDetails ( ) {
485+ const prismicRepositoryInformation = useRepositoryInformation ( ) ;
486+ const { data : framework } = useSuspenseQuery ( {
487+ queryKey : [ "getFrameworkFromAdapterName" ] ,
488+ queryFn : async ( ) => {
489+ return getFrameworkFromAdapter (
490+ AdapterSchema . parse ( await managerClient . project . getAdapterName ( ) ) ,
491+ ) ;
492+ } ,
493+ } ) ;
494+
495+ return { ...prismicRepositoryInformation , framework } ;
496+ }
497+
474498function ComboBoxItemContent ( props : {
475499 children : ReactNode ;
476500 disabled ?: boolean ;
0 commit comments