diff --git a/catalog/app/containers/Bucket/File.js b/catalog/app/containers/Bucket/File.js index 94233444620..5f44390cf0a 100644 --- a/catalog/app/containers/Bucket/File.js +++ b/catalog/app/containers/Bucket/File.js @@ -451,7 +451,9 @@ export default function File() { return ( - + {[path || 'Files', bucket]} @@ -509,15 +511,14 @@ export default function File() { {downloadable && ( )} - {cfg.qurator && - BucketPreferences.Result.match( - { - // XXX: only show this when the object exists? - Ok: ({ ui: { blocks } }) => (blocks.qurator ? : null), - _: () => null, - }, - prefs, - )} + {BucketPreferences.Result.match( + { + // XXX: only show this when the object exists? + Ok: ({ ui: { blocks } }) => (blocks.qurator ? : null), + _: () => null, + }, + prefs, + )} {objExistsData.case({ diff --git a/catalog/app/containers/Bucket/PackageTree/PackageTree.tsx b/catalog/app/containers/Bucket/PackageTree/PackageTree.tsx index f5f6fa98164..bc9f901c52c 100644 --- a/catalog/app/containers/Bucket/PackageTree/PackageTree.tsx +++ b/catalog/app/containers/Bucket/PackageTree/PackageTree.tsx @@ -6,6 +6,7 @@ import * as urql from 'urql' import * as M from '@material-ui/core' import * as Lab from '@material-ui/lab' +import * as Assistant from 'components/Assistant' import * as BreadCrumbs from 'components/BreadCrumbs' import * as Buttons from 'components/Buttons' import * as FileEditor from 'components/FileEditor' @@ -24,6 +25,7 @@ import * as GQL from 'utils/GraphQL' import * as LogicalKeyResolver from 'utils/LogicalKeyResolver' import MetaTitle from 'utils/MetaTitle' import * as NamedRoutes from 'utils/NamedRoutes' +import * as XML from 'utils/XML' import assertNever from 'utils/assertNever' import parseSearch from 'utils/parseSearch' import * as s3paths from 'utils/s3paths' @@ -544,6 +546,55 @@ const useFileDisplayStyles = M.makeStyles((t) => ({ }, })) +interface FileContextProps { + pkg: { + bucket: string + name: string + hash: string + } + file: Model.GQLTypes.PackageFile +} + +const FileContext = Assistant.Context.LazyContext(({ pkg, file }: FileContextProps) => { + const msg = React.useMemo(() => { + const s3loc = s3paths.parseS3Url(file.physicalKey) + return XML.tag('viewport') + .children( + 'You are currently viewing a file in a package.', + XML.tag( + 'package', + pkg, + XML.tag( + 'package-entry', + { path: file.path, size: file.size }, + 'You can use the physicalLocation to access the file in S3 (always provide version if available)', + XML.tag('physicalLocation', {}, JSON.stringify(s3loc, null, 2)), + file.metadata && + XML.tag('metadata', {}, JSON.stringify(file.metadata, null, 2)), + ), + ), + ) + .toString() + }, [file, pkg]) + + return { + messages: [msg], + } +}) + +function SummarizeButton() { + const assist = Assistant.use() + if (!assist) return null + const msg = 'Summarize this document' + return ( + assist(msg)} edge="end"> + + assistant + + + ) +} + interface FileDisplayProps extends FileDisplayQueryProps { file: Model.GQLTypes.PackageFile } @@ -626,6 +677,7 @@ function FileDisplay({ Ok: requests.ObjectExistence.case({ Exists: ({ archived, deleted, lastModified, size }: ObjectAttrs) => ( <> + - !cfg.noDownload && - !deleted && - !archived && - actions.downloadPackage && ( - - ), + Ok: ({ ui: { actions, blocks } }) => ( + <> + {!cfg.noDownload && + !deleted && + !archived && + actions.downloadPackage && ( + + )} + {blocks.qurator && !deleted && !archived && } + + ), Pending: () => ( ),