Skip to content

Commit

Permalink
instrument directory route
Browse files Browse the repository at this point in the history
  • Loading branch information
nl0 committed Aug 16, 2024
1 parent cb21ebc commit d5e84a0
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -630,20 +630,36 @@ exports[`components/Assistant/Model/GlobalTools/navigation NavigateSchema produc
},
{
"additionalProperties": false,
"description": "Bucket overview page",
"description": "S3 Object (aka File) page",
"properties": {
"name": {
"const": "bucket.overview",
"const": "bucket.object",
},
"params": {
"additionalProperties": false,
"properties": {
"bucket": {
"type": "string",
},
"mode": {
"description": "Contents preview mode",
"title": "Viewing Mode",
"type": "string",
},
"path": {
"description": "S3 Object Key aka File Path",
"title": "Path",
"type": "string",
},
"version": {
"description": "S3 Object Version ID (omit for latest version)",
"title": "Version ID",
"type": "string",
},
},
"required": [
"bucket",
"path",
],
"type": "object",
},
Expand All @@ -656,36 +672,52 @@ exports[`components/Assistant/Model/GlobalTools/navigation NavigateSchema produc
},
{
"additionalProperties": false,
"description": "S3 Object (aka File) Detail page",
"description": "S3 Prefix (aka Directory) page",
"properties": {
"name": {
"const": "bucket.object",
"const": "bucket.prefix",
},
"params": {
"additionalProperties": false,
"properties": {
"bucket": {
"type": "string",
},
"mode": {
"description": "Contents preview mode",
"title": "Viewing Mode",
"type": "string",
},
"path": {
"description": "a string",
"title": "string & Brand<"S3Path">",
"description": "S3 Prefix aka Directory Path",
"title": "Path",
"type": "string",
},
"version": {
"description": "S3 Object Version ID (omit for latest version)",
"title": "Version ID",
},
"required": [
"bucket",
"path",
],
"type": "object",
},
},
"required": [
"name",
"params",
],
"type": "object",
},
{
"additionalProperties": false,
"description": "Bucket overview page",
"properties": {
"name": {
"const": "bucket.overview",
},
"params": {
"additionalProperties": false,
"properties": {
"bucket": {
"type": "string",
},
},
"required": [
"bucket",
"path",
],
"type": "object",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ describe('components/Assistant/Model/GlobalTools/navigation', () => {
hash: '',
},
},
{
route: {
name: 'bucket.prefix',
params: {
bucket: 'quilt-example',
path: 'data/random-data-benchmark/100kb/',
},
},
loc: {
pathname: '/b/quilt-example/tree/data/random-data-benchmark/100kb/',
search: '',
hash: '',
},
},
]

const encode = Eff.flow(
Expand All @@ -70,14 +84,15 @@ describe('components/Assistant/Model/GlobalTools/navigation', () => {
Eff.Effect.runPromise,
)

for (let i in TEST_CASES) {
const tc = TEST_CASES[i]
TEST_CASES.forEach((tc, i) => {
describe(`${i + 1}: ${tc.route.name}`, () => {
it('should encode', async () => {
const loc = await encode(tc.route)
expect(loc).toEqual(tc.loc)
expect(await encode(tc.route)).toEqual(tc.loc)
})
it('should decode', async () => {
expect(nav.matchLocation(tc.loc)?.decoded).toEqual(tc.route)
})
})
}
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ const navigate = (
),
)

interface Match {
export interface Match {
descriptor: KnownRoute
decoded: NavigableRoute | null
}

const matchLocation = (loc: typeof Nav.Location.Type): Match | null =>
export const matchLocation = (loc: typeof Nav.Location.Type): Match | null =>
Eff.pipe(
Eff.Array.findFirst(routeList, (route) =>
RR.matchPath(loc.pathname, {
Expand Down
3 changes: 3 additions & 0 deletions catalog/app/containers/Bucket/Dir.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as s3paths from 'utils/s3paths'
import type * as workflows from 'utils/workflows'

import DirCodeSamples from './CodeSamples/Dir'
import * as AssistantContext from './DirAssistantContext'

Check warning on line 23 in catalog/app/containers/Bucket/Dir.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/Dir.tsx#L23

Added line #L23 was not covered by tests
import * as FileView from './FileView'
import * as Listing from './Listing'
import Menu from './Menu'
Expand Down Expand Up @@ -268,6 +269,8 @@ export default function Dir() {
prev,
})

AssistantContext.useListingContext(data)

Check warning on line 272 in catalog/app/containers/Bucket/Dir.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/Dir.tsx#L272

Added line #L272 was not covered by tests

const loadMore = React.useCallback(() => {
AsyncResult.case(
{
Expand Down
51 changes: 51 additions & 0 deletions catalog/app/containers/Bucket/DirAssistantContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as Eff from 'effect'
import * as React from 'react'

Check warning on line 2 in catalog/app/containers/Bucket/DirAssistantContext.ts

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/DirAssistantContext.ts#L1-L2

Added lines #L1 - L2 were not covered by tests

import * as Assistant from 'components/Assistant'
import * as XML from 'utils/XML'

Check warning on line 5 in catalog/app/containers/Bucket/DirAssistantContext.ts

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/DirAssistantContext.ts#L4-L5

Added lines #L4 - L5 were not covered by tests

import type { BucketListingResult } from './requests'

export function useListingContext(data: $TSFixMe) {
const msg = React.useMemo(
() =>
Eff.pipe(

Check warning on line 12 in catalog/app/containers/Bucket/DirAssistantContext.ts

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/DirAssistantContext.ts#L9-L12

Added lines #L9 - L12 were not covered by tests
data.case({
Ok: (res: BucketListingResult) => Eff.Option.some(Eff.Either.right(res)),
Err: () => Eff.Option.some(Eff.Either.left('Error fetching listing data')),
_: () => Eff.Option.none(),

Check warning on line 16 in catalog/app/containers/Bucket/DirAssistantContext.ts

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/DirAssistantContext.ts#L14-L16

Added lines #L14 - L16 were not covered by tests
}) as Eff.Option.Option<Eff.Either.Either<BucketListingResult, string>>,
Eff.Option.map(
Eff.Either.match({
onLeft: (err) => [err],
onRight: (res) => [

Check warning on line 21 in catalog/app/containers/Bucket/DirAssistantContext.ts

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/DirAssistantContext.ts#L20-L21

Added lines #L20 - L21 were not covered by tests
res.truncated ? 'The listing is truncated' : null,
res.dirs.length ? XML.tag('prefixes', {}, ...res.dirs) : null,
res.files.length
? XML.tag(

Check warning on line 25 in catalog/app/containers/Bucket/DirAssistantContext.ts

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/DirAssistantContext.ts#L25

Added line #L25 was not covered by tests
'objects',
{},
...res.files.map((o) =>
JSON.stringify({

Check warning on line 29 in catalog/app/containers/Bucket/DirAssistantContext.ts

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/DirAssistantContext.ts#L28-L29

Added lines #L28 - L29 were not covered by tests
key: o.key,
size: o.size,
modified: o.modified.toISOString(),
}),
),
)
: null,

Check warning on line 36 in catalog/app/containers/Bucket/DirAssistantContext.ts

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/DirAssistantContext.ts#L36

Added line #L36 was not covered by tests
],
}),
),
Eff.Option.map((children: XML.Children) =>
XML.tag('listing-data', {}, ...children).toString(),

Check warning on line 41 in catalog/app/containers/Bucket/DirAssistantContext.ts

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/DirAssistantContext.ts#L40-L41

Added lines #L40 - L41 were not covered by tests
),
),
[data],
)

Assistant.Context.usePushContext({

Check warning on line 47 in catalog/app/containers/Bucket/DirAssistantContext.ts

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/DirAssistantContext.ts#L47

Added line #L47 was not covered by tests
markers: { listingReady: Eff.Option.isSome(msg) },
messages: Eff.Option.toArray(msg),
})
}
46 changes: 30 additions & 16 deletions catalog/app/containers/Bucket/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,28 @@ const mapSegments = (separator: string, map: (s: string) => string) =>

const S3Path = S.brand('S3Path')(S.String)

const S3PathFromString = S.transform(S.String, S3Path, {
encode: mapSegments(PATH_SEP, encodeURIComponent),
decode: mapSegments(PATH_SEP, decodeURIComponent),
})
const S3PathFromString = (S3PathSchema: typeof S3Path) =>
S.transform(S.String, S3PathSchema, {
encode: mapSegments(PATH_SEP, encodeURIComponent),
strict: true,
decode: mapSegments(PATH_SEP, decodeURIComponent),
})

export const s3Object = Nav.makeRoute({
name: 'bucket.object',
path: routes.bucketFile.path,
exact: true,
strict: true,
description: 'S3 Object (aka File) Detail page',
description: 'S3 Object (aka File) page',
waitForMarkers: ['versionsReady', 'currentVersionReady'],
pathParams: Nav.fromPathParams(
S.extend(
BucketPathParams,
S.Struct({
path: S3PathFromString.annotations({
title: 'Object Key',
path: S3Path.annotations({
title: 'Path',
description: 'S3 Object Key aka File Path',
}),
}).pipe(S3PathFromString),
}),
),
),
Expand All @@ -63,13 +65,25 @@ export const s3Object = Nav.makeRoute({
}),
})

// export const bucketDir = route(
// '/b/:bucket/tree/:path(.+/)?',
// (bucket: string, path: string = '', prefix?: string) =>
// `/b/${bucket}/tree/${encode(path)}${mkSearch({ prefix: prefix || undefined })}`,
// )
// export type BucketDirArgs = Parameters<typeof bucketDir.url>
//
export const s3Prefix = Nav.makeRoute({
name: 'bucket.prefix',
path: routes.bucketDir.path,
exact: true,
description: 'S3 Prefix (aka Directory) page',
waitForMarkers: ['listingReady'],
pathParams: Nav.fromPathParams(
S.extend(
BucketPathParams,
S.Struct({
path: S3Path.annotations({
title: 'Path',
description: 'S3 Prefix aka Directory Path',
}).pipe(S3PathFromString),
}),
),
),
})

// interface BucketPackageListOpts {
// filter?: string
// sort?: string
Expand Down Expand Up @@ -140,4 +154,4 @@ export const s3Object = Nav.makeRoute({
// (bucket: string, workgroup: string, queryExecutionId: string) =>
// `/b/${bucket}/queries/athena/${workgroup}/${queryExecutionId}`,

export default [overview, s3Object]
export default [s3Object, s3Prefix, overview]

0 comments on commit d5e84a0

Please sign in to comment.