Skip to content

Commit 171da9e

Browse files
committed
refactor
1 parent ea9758f commit 171da9e

File tree

5 files changed

+36
-40
lines changed

5 files changed

+36
-40
lines changed

catalog/app/components/Assistant/Model/ContextFiles.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ function useBuildPathChain(path: string): string[] {
9393
}
9494

9595
function useContextFiles(
96+
marker: string,
9697
load: (path: string) => Promise<ContextFile | null>,
9798
paths: string[],
9899
limit?: number,
@@ -113,27 +114,40 @@ function useContextFiles(
113114
: r.map(format),
114115
[r],
115116
)
116-
return { ready, messages }
117+
return {
118+
markers: { [marker]: ready },
119+
messages,
120+
}
117121
}
118122

119123
export function useBucketRootContextFiles(bucket: string) {
120-
return useContextFiles(useLoadBucketContextFile(bucket), CONTEXT_FILE_NAMES)
124+
return useContextFiles(
125+
'bucketRootContextFilesReady',
126+
useLoadBucketContextFile(bucket),
127+
CONTEXT_FILE_NAMES,
128+
)
121129
}
122130

123131
export function useBucketDirContextFiles(bucket: string, path: string) {
124132
return useContextFiles(
133+
'bucketDirContextFilesReady',
125134
useLoadBucketContextFile(bucket),
126135
useBuildPathChain(path),
127136
MAX_NON_ROOT_FILES,
128137
)
129138
}
130139

131140
export function usePackageRootContextFiles(bucket: string, name: string) {
132-
return useContextFiles(useLoadPackageContextFile(bucket, name), CONTEXT_FILE_NAMES)
141+
return useContextFiles(
142+
'packageRootContextFilesReady',
143+
useLoadPackageContextFile(bucket, name),
144+
CONTEXT_FILE_NAMES,
145+
)
133146
}
134147

135148
export function usePackageDirContextFiles(bucket: string, name: string, path: string) {
136149
return useContextFiles(
150+
'packageDirContextFilesReady',
137151
useLoadPackageContextFile(bucket, name),
138152
useBuildPathChain(path),
139153
MAX_NON_ROOT_FILES,

catalog/app/containers/Bucket/AssistantContext.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ interface BucketContextProps {
55
bucket: string
66
}
77

8-
export const BucketContext = Assistant.Context.LazyContext(
9-
({ bucket }: BucketContextProps) => {
10-
const { ready, messages } = ContextFiles.useBucketRootContextFiles(bucket)
11-
return {
12-
markers: { bucketContextFilesReady: ready },
13-
messages,
14-
}
15-
},
8+
export const BucketContext = Assistant.Context.LazyContext<BucketContextProps>(
9+
({ bucket }) => ContextFiles.useBucketRootContextFiles(bucket),
1610
)

catalog/app/containers/Bucket/DirAssistantContext.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ interface DirContextFilesProps {
6262
path: string
6363
}
6464

65-
export const DirContextFiles = Assistant.Context.LazyContext(
66-
({ bucket, path }: DirContextFilesProps) => {
67-
const { ready, messages } = ContextFiles.useBucketDirContextFiles(bucket, path)
68-
return {
69-
markers: { dirContextFilesReady: ready },
70-
messages,
71-
}
72-
},
65+
export const DirContextFiles = Assistant.Context.LazyContext<DirContextFilesProps>(
66+
({ bucket, path }) => ContextFiles.useBucketDirContextFiles(bucket, path),
7367
)

catalog/app/containers/Bucket/File/AssistantContext.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,7 @@ interface FileContextFilesProps {
110110
path: string
111111
}
112112

113-
export const FileContextFiles = Assistant.Context.LazyContext(
114-
({ bucket, path }: FileContextFilesProps) => {
115-
const { ready, messages } = ContextFiles.useBucketDirContextFiles(
116-
bucket,
117-
S3Paths.getPrefix(path),
118-
)
119-
return {
120-
markers: { fileContextFilesReady: ready },
121-
messages,
122-
}
123-
},
113+
export const FileContextFiles = Assistant.Context.LazyContext<FileContextFilesProps>(
114+
({ bucket, path }) =>
115+
ContextFiles.useBucketDirContextFiles(bucket, S3Paths.getPrefix(path)),
124116
)

catalog/app/containers/Bucket/PackageTree/AssistantContext.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,13 @@ interface PackageContextProps {
5353
revision: RevisionData
5454
}
5555

56-
export const PackageContext = Assistant.Context.LazyContext(
57-
({ bucket, name, path, revision }: PackageContextProps) => {
58-
const dir = S3Paths.getPrefix(path)
59-
const dirCtx = ContextFiles.usePackageDirContextFiles(bucket, name, dir)
56+
export const PackageContext = Assistant.Context.LazyContext<PackageContextProps>(
57+
({ bucket, name, path, revision }) => {
58+
const dirCtx = ContextFiles.usePackageDirContextFiles(
59+
bucket,
60+
name,
61+
S3Paths.getPrefix(path),
62+
)
6063
const rootCtx = ContextFiles.usePackageRootContextFiles(bucket, name)
6164
const metadataMsg = useMetadataContext(bucket, name, revision)
6265

@@ -65,12 +68,11 @@ export const PackageContext = Assistant.Context.LazyContext(
6568
[metadataMsg, rootCtx.messages, dirCtx.messages],
6669
)
6770

68-
return {
69-
markers: {
70-
packageRootContextFilesReady: rootCtx.ready,
71-
packageDirContextFilesReady: dirCtx.ready,
72-
},
73-
messages,
71+
const markers = {
72+
...rootCtx.markers,
73+
...dirCtx.markers,
7474
}
75+
76+
return { markers, messages }
7577
},
7678
)

0 commit comments

Comments
 (0)