Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iframe browsing frontend #3198

Merged
merged 133 commits into from Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 119 commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
ac067fa
put environment variables to iframe
fiskus Nov 24, 2022
e5fca53
allow same origin for iframe
fiskus Nov 24, 2022
b197d0a
wip: hardcode json loader
fiskus Nov 24, 2022
a7f090e
linting
fiskus Nov 24, 2022
8fc5019
wip: split to functions
fiskus Nov 24, 2022
5110f1e
wip: use asyncresult
fiskus Nov 24, 2022
65fff52
type fixes
fiskus Nov 24, 2022
d20146b
remove credentials
fiskus Nov 25, 2022
8e6af91
remove extra type
fiskus Nov 25, 2022
491860b
iframe message bus
fiskus Nov 25, 2022
3d38e85
polishing event listeners
fiskus Nov 25, 2022
cb4abf9
Merge branch 'master' of github.com:quiltdata/quilt into iframe-loade…
fiskus Nov 25, 2022
2aa10ac
add fetchFile and onReady
fiskus Nov 26, 2022
baa9a5f
rename event names
fiskus Nov 26, 2022
2913d53
use constants instead of strings
fiskus Nov 26, 2022
662d869
prettify
fiskus Nov 26, 2022
a6880ff
move onMessage to hook and remove unused code
fiskus Nov 28, 2022
6f7f4d9
use constatnts
fiskus Nov 28, 2022
a921f79
fix listener in Chrome, remove debug code
fiskus Nov 28, 2022
12cd3fd
Merge branch 'master' of github.com:quiltdata/quilt into iframe-loade…
fiskus Nov 28, 2022
17c490c
add docs
fiskus Nov 28, 2022
af02478
Merge branch 'master' of github.com:quiltdata/quilt into iframe-loade…
fiskus Nov 29, 2022
71f95fd
fix parallel requests
fiskus Nov 29, 2022
91ae503
dry
fiskus Nov 29, 2022
e922fec
use config
fiskus Nov 29, 2022
e525791
todo note
fiskus Nov 29, 2022
067e8ad
update docs
fiskus Nov 29, 2022
6d77660
update docs with more real life and full example
fiskus Nov 30, 2022
141fb30
improve docs
fiskus Nov 30, 2022
0ff41dc
example of text fetching
fiskus Nov 30, 2022
7a390ec
better error handling
fiskus Nov 30, 2022
be256b8
Merge branch 'master' of github.com:quiltdata/quilt into iframe-loade…
fiskus Nov 30, 2022
a856f0d
closing tag
fiskus Nov 30, 2022
c70bdcf
small note about fetch
fiskus Nov 30, 2022
02a1ea9
fix typos
fiskus Nov 30, 2022
0d4408f
fix typos
fiskus Nov 30, 2022
d9c1c97
fix typos
fiskus Nov 30, 2022
dadf291
note that you need to import libs
fiskus Nov 30, 2022
a875832
add __iframe page with injectable scripts
fiskus Dec 1, 2022
38ddef3
add types for iframe sdk
fiskus Dec 1, 2022
a81e515
make iframe sdk buildable
fiskus Dec 1, 2022
b4b82ff
merge with master
fiskus Dec 1, 2022
ac752cc
linting
fiskus Dec 1, 2022
4cce0ec
move to utils
fiskus Dec 5, 2022
0e2a046
move to utils
fiskus Dec 5, 2022
1b0e743
add scrpits and styles as dependencies
fiskus Dec 5, 2022
4a85dce
remove accidentally commited
fiskus Dec 5, 2022
e7a3206
list available libraries
fiskus Dec 5, 2022
1fd02a3
add docs for list/import
fiskus Dec 5, 2022
a09a094
add docs for list and install
fiskus Dec 5, 2022
c54d1de
enable javascript only in specific buckets
fiskus Dec 6, 2022
43848e0
Merge branch 'master' of github.com:quiltdata/quilt into iframe-loade…
fiskus Dec 6, 2022
70fe82f
linting
fiskus Dec 6, 2022
b34602c
add signer.igv method
fiskus Dec 7, 2022
42a049c
refactor
fiskus Dec 7, 2022
249a472
refactor
fiskus Dec 7, 2022
451b2c5
split iframe loaders to simple and with js
fiskus Dec 7, 2022
4899a9f
move iframe sdk to loaders/IFrame
fiskus Dec 7, 2022
b5bac2e
message bus
fiskus Dec 7, 2022
16c5985
add sign url method
fiskus Dec 7, 2022
fdd51d9
move quilt init to top
fiskus Dec 7, 2022
09b0f5c
add echarts signer
fiskus Dec 7, 2022
79ed051
fix types
fiskus Dec 7, 2022
63621b5
merge with master
fiskus Feb 7, 2023
e52f580
wip: remove SDK
fiskus Feb 8, 2023
defb79d
wip: merge with Alexei frontend
fiskus Feb 8, 2023
73cafd6
move usePolling to module
fiskus Feb 8, 2023
874693a
move to loaders/IFrame namespace
fiskus Feb 8, 2023
b04cc1a
add expires and add other session mutations
fiskus Feb 8, 2023
adb8f84
wip: refresh session
fiskus Feb 8, 2023
63cde39
use loading state and AsyncResult
fiskus Feb 8, 2023
00e2024
catch errors
fiskus Feb 8, 2023
8a332bc
format
fiskus Feb 8, 2023
6831d8c
remove cruft from prev design iteration
fiskus Feb 8, 2023
b569341
disable extended iframe
fiskus Feb 9, 2023
005ed1f
fix syntax error
fiskus Feb 9, 2023
a6c7e02
revert changes from prev design iteration
fiskus Feb 9, 2023
7da5eab
enable beta and clear timeout
fiskus Feb 9, 2023
0480201
increse ttl to 60 minutes
fiskus Feb 9, 2023
43e175b
add Expired error
fiskus Feb 9, 2023
724e3b2
add retry button
fiskus Feb 9, 2023
a8f5f59
Merge branch 'master' of github.com:quiltdata/quilt into iframe-loade…
fiskus Feb 9, 2023
38c2620
add Forbidden error
fiskus Feb 9, 2023
0c98534
add browsable checkbox
fiskus Feb 9, 2023
eaad52d
browsable switch
fiskus Feb 9, 2023
e4a9e7b
simplify
fiskus Feb 9, 2023
c13f259
optimize laziness
fiskus Feb 9, 2023
085b593
rename extended to browsable
fiskus Feb 9, 2023
fdad420
get initial browsable
fiskus Feb 9, 2023
d4b9ee6
cosmetic
fiskus Feb 10, 2023
c7c5976
fix types
fiskus Feb 10, 2023
558a0d3
fix missing argument
fiskus Feb 10, 2023
3d614da
reset session too
fiskus Feb 10, 2023
ba12d52
Merge branch 'master' of github.com:quiltdata/quilt into iframe-loade…
fiskus Feb 10, 2023
5933076
describe error arguments
fiskus Feb 10, 2023
4a6f32e
move to the new file preview section
fiskus Feb 10, 2023
d6bfbec
add checkbox hint
fiskus Feb 10, 2023
0d246c4
use styledtooltip with more readable fonts and background
fiskus Feb 10, 2023
a4d1781
added changelog entry
fiskus Feb 10, 2023
1af2165
cosmetic: ternary operator
fiskus Feb 10, 2023
bfec1cb
import type only
fiskus Feb 10, 2023
15846f5
cosmetic changes
fiskus Feb 10, 2023
662f02a
add brief notes on how browsable iframe works
fiskus Feb 10, 2023
f3917c9
lint markdown file
fiskus Feb 10, 2023
5dd516f
fix tooltip arrow
fiskus Feb 10, 2023
2d663f8
Merge branch 'master' of github.com:quiltdata/quilt into iframe-loade…
fiskus Feb 13, 2023
e1cfa20
prettify
fiskus Feb 13, 2023
9491b14
fix ttl
fiskus Feb 13, 2023
2b42907
add error names
fiskus Feb 14, 2023
adfbab4
use error.name
fiskus Feb 14, 2023
3652787
use AsyncResult.mapCase
fiskus Feb 14, 2023
3a315a5
use setInterval to simplify algorithm
fiskus Feb 14, 2023
4bd9e51
use asyncresult to store state
fiskus Feb 14, 2023
acdbc68
clear on effect dispose
fiskus Feb 14, 2023
15f4153
use session id instead of session object
fiskus Feb 14, 2023
c2dbc39
remove unused expires field
fiskus Feb 14, 2023
4ceb902
call sentry
fiskus Feb 14, 2023
6d54b31
Merge branch 'master' of github.com:quiltdata/quilt into iframe-loade…
fiskus Feb 14, 2023
8de4b35
rename iframe loaders consistently
fiskus Feb 14, 2023
6bf75ec
remove setState call from cleanup callback
fiskus Feb 14, 2023
cc5e479
format
fiskus Feb 14, 2023
7bc60a7
check ignore after all await calls
fiskus Feb 14, 2023
120714b
prettify
fiskus Feb 15, 2023
bc61153
Merge branch 'master' into iframe-loader-with-environment
fiskus Feb 21, 2023
5e594fd
merge with master, resolve conflict
fiskus Feb 23, 2023
1eb9e64
Apply suggestions from code review
fiskus Feb 24, 2023
b137726
Merge branch 'master' of github.com:quiltdata/quilt into iframe-loade…
fiskus Feb 24, 2023
df2683a
lint docs
fiskus Feb 24, 2023
8fce1c5
Merge branch 'master' into iframe-loader-with-environment
fiskus Mar 2, 2023
02fc138
merge with master, resolve conflict
fiskus Mar 9, 2023
0856c4f
apply text suggestion
fiskus Mar 9, 2023
a17b1e8
Merge branch 'master' into iframe-loader-with-environment
nl0 Mar 17, 2023
c16328f
Merge branch 'master' into iframe-loader-with-environment
fiskus Mar 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions catalog/app/components/Preview/Display.js
Expand Up @@ -125,6 +125,12 @@ export default function PreviewDisplay({
heading: 'Malformed JSON',
body: message,
}),
Expired: ({ retry }) =>
renderMessage({
heading: 'Session is expired',
body: 'Try to reload the page',
action: !!retry && renderAction({ label: 'Retry', onClick: retry }),
}),
Unexpected: ({ retry }) =>
renderMessage({
heading: 'Unexpected Error',
Expand Down
50 changes: 29 additions & 21 deletions catalog/app/components/Preview/loaders/Html.js
@@ -1,41 +1,49 @@
import * as React from 'react'

import cfg from 'constants/config'
import * as AWS from 'utils/AWS'
import AsyncResult from 'utils/AsyncResult'
import { useIsInStack } from 'utils/BucketConfig'
import { useStatusReportsBucket } from 'utils/StatusReportsBucket'
import useMemoEq from 'utils/useMemoEq'

import { PreviewData } from '../types'
import useQuery from 'utils/useQuery'

import * as IFrame from './IFrame'
import * as Text from './Text'
import FileType from './fileType'
import * as utils from './utils'

import BUCKET_CONFIG_QUERY from './IFrame/BrowsableBucketConfig.generated'

export const detect = utils.extIn(['.htm', '.html'])

export const FILE_TYPE = FileType.Html

function IFrameLoader({ handle, children }) {
const sign = AWS.Signer.useS3Signer()
const src = useMemoEq([handle, sign], () =>
sign(handle, { ResponseContentType: 'text/html' }),
)
// TODO: issue a head request to ensure existence and get storage class
return children(
AsyncResult.Ok(PreviewData.IFrame({ src, modes: [FileType.Html, FileType.Text] })),
// It's unsafe to render HTML in these conditions
function useHtmlAsText(handle) {
const isInStack = useIsInStack()
const statusReportsBucket = useStatusReportsBucket()
return (
cfg.mode !== 'LOCAL' &&
!isInStack(handle.bucket) &&
handle.bucket !== statusReportsBucket
)
}

export const Loader = function HtmlLoader({ handle, children }) {
const isInStack = useIsInStack()
const statusReportsBucket = useStatusReportsBucket()
return cfg.mode === 'LOCAL' ||
isInStack(handle.bucket) ||
handle.bucket === statusReportsBucket ? (
<IFrameLoader {...{ handle, children }} />
) : (
<Text.Loader {...{ handle, children }} />
)
const renderHtmlAsText = useHtmlAsText(handle)
const bucketData = useQuery({
query: BUCKET_CONFIG_QUERY,
variables: { bucket: handle.bucket },
pause: renderHtmlAsText,
})
if (renderHtmlAsText) return <Text.Loader {...{ handle, children }} />
return bucketData.case({
fetching: () => children(AsyncResult.Pending()),
error: (e) => children(AsyncResult.Err(e)),
data: ({ bucketConfig: { browsable } }) =>
browsable ? (
<IFrame.LoaderBrowsable {...{ handle, children }} />
) : (
<IFrame.LoaderSigned {...{ handle, children }} />
),
})
}
@@ -0,0 +1,71 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'
import * as Types from '../../../../model/graphql/types.generated'

export type components_Preview_loaders_IFrame_BrowsableBucketConfigQueryVariables =
Types.Exact<{
bucket: Types.Scalars['String']
}>

export type components_Preview_loaders_IFrame_BrowsableBucketConfigQuery = {
readonly __typename: 'Query'
} & {
readonly bucketConfig: Types.Maybe<
{ readonly __typename: 'BucketConfig' } & Pick<
Types.BucketConfig,
'name' | 'browsable'
>
>
}

export const components_Preview_loaders_IFrame_BrowsableBucketConfigDocument = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'query',
name: {
kind: 'Name',
value: 'components_Preview_loaders_IFrame_BrowsableBucketConfig',
},
variableDefinitions: [
{
kind: 'VariableDefinition',
variable: { kind: 'Variable', name: { kind: 'Name', value: 'bucket' } },
type: {
kind: 'NonNullType',
type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } },
},
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'bucketConfig' },
arguments: [
{
kind: 'Argument',
name: { kind: 'Name', value: 'name' },
value: { kind: 'Variable', name: { kind: 'Name', value: 'bucket' } },
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
{ kind: 'Field', name: { kind: 'Name', value: 'browsable' } },
],
},
},
],
},
},
],
} as unknown as DocumentNode<
components_Preview_loaders_IFrame_BrowsableBucketConfigQuery,
components_Preview_loaders_IFrame_BrowsableBucketConfigQueryVariables
>

export { components_Preview_loaders_IFrame_BrowsableBucketConfigDocument as default }
@@ -0,0 +1,6 @@
query ($bucket: String!) {
bucketConfig(name: $bucket) {
name
browsable
}
}
@@ -0,0 +1,138 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'
import * as Types from '../../../../model/graphql/types.generated'

export type components_Preview_loaders_IFrame_CreateBrowsingSessionMutationVariables =
Types.Exact<{
scope: Types.Scalars['String']
ttl: Types.Maybe<Types.Scalars['Int']>
}>

export type components_Preview_loaders_IFrame_CreateBrowsingSessionMutation = {
readonly __typename: 'Mutation'
} & {
readonly browsingSessionCreate:
| ({ readonly __typename: 'BrowsingSession' } & Pick<Types.BrowsingSession, 'id'>)
| ({ readonly __typename: 'InvalidInput' } & {
readonly errors: ReadonlyArray<
{ readonly __typename: 'InputError' } & Pick<
Types.InputError,
'name' | 'path' | 'message'
>
>
})
| ({ readonly __typename: 'OperationError' } & Pick<
Types.OperationError,
'name' | 'message'
>)
}

export const components_Preview_loaders_IFrame_CreateBrowsingSessionDocument = {
kind: 'Document',
definitions: [
{
kind: 'OperationDefinition',
operation: 'mutation',
name: {
kind: 'Name',
value: 'components_Preview_loaders_IFrame_CreateBrowsingSession',
},
variableDefinitions: [
{
kind: 'VariableDefinition',
variable: { kind: 'Variable', name: { kind: 'Name', value: 'scope' } },
type: {
kind: 'NonNullType',
type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } },
},
},
{
kind: 'VariableDefinition',
variable: { kind: 'Variable', name: { kind: 'Name', value: 'ttl' } },
type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } },
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'browsingSessionCreate' },
arguments: [
{
kind: 'Argument',
name: { kind: 'Name', value: 'scope' },
value: { kind: 'Variable', name: { kind: 'Name', value: 'scope' } },
},
{
kind: 'Argument',
name: { kind: 'Name', value: 'ttl' },
value: { kind: 'Variable', name: { kind: 'Name', value: 'ttl' } },
},
],
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{
kind: 'InlineFragment',
typeCondition: {
kind: 'NamedType',
name: { kind: 'Name', value: 'BrowsingSession' },
},
selectionSet: {
kind: 'SelectionSet',
selections: [{ kind: 'Field', name: { kind: 'Name', value: 'id' } }],
},
},
{
kind: 'InlineFragment',
typeCondition: {
kind: 'NamedType',
name: { kind: 'Name', value: 'InvalidInput' },
},
selectionSet: {
kind: 'SelectionSet',
selections: [
{
kind: 'Field',
name: { kind: 'Name', value: 'errors' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
{ kind: 'Field', name: { kind: 'Name', value: 'path' } },
{ kind: 'Field', name: { kind: 'Name', value: 'message' } },
],
},
},
],
},
},
{
kind: 'InlineFragment',
typeCondition: {
kind: 'NamedType',
name: { kind: 'Name', value: 'OperationError' },
},
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
{ kind: 'Field', name: { kind: 'Name', value: 'message' } },
],
},
},
],
},
},
],
},
},
],
} as unknown as DocumentNode<
components_Preview_loaders_IFrame_CreateBrowsingSessionMutation,
components_Preview_loaders_IFrame_CreateBrowsingSessionMutationVariables
>

export { components_Preview_loaders_IFrame_CreateBrowsingSessionDocument as default }
@@ -0,0 +1,19 @@
mutation ($scope: String!, $ttl: Int) {
browsingSessionCreate(scope: $scope, ttl: $ttl) {
__typename
... on BrowsingSession {
id
}
... on InvalidInput {
errors {
name
path
message
}
}
... on OperationError {
name
message
fiskus marked this conversation as resolved.
Show resolved Hide resolved
}
}
}