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

Perspective restore() config #2781

Merged
merged 22 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion catalog/app/components/Preview/loaders/summarize.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PerspectiveViewerConfig } from '@finos/perspective-viewer'

export type TypeShorthand =
| 'echarts'
| 'json'
Expand All @@ -13,7 +15,7 @@ export interface StyleOptions {
}

export interface PerspectiveOptions {
settings?: boolean
config?: PerspectiveViewerConfig
}

interface TypeExtendedEssentials {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ export default function Perspective({
handle,
onLoadMore,
truncated,
settings,
config,
...props
}: PerspectiveProps) {
const classes = useStyles()

const [root, setRoot] = React.useState<HTMLDivElement | null>(null)

const attrs = React.useMemo(() => ({ className: classes.viewer }), [classes])
const state = perspective.use(root, data, attrs, settings)
const state = perspective.use(root, data, attrs, config)

return (
<div className={cx(className, classes.root)} ref={setRoot} {...props}>
Expand Down
13 changes: 8 additions & 5 deletions catalog/app/utils/perspective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import 'utils/perspective-pollution'

import perspective from '@finos/perspective'
import type { Table } from '@finos/perspective'
import type { HTMLPerspectiveViewerElement } from '@finos/perspective-viewer'
import type {
HTMLPerspectiveViewerElement,
PerspectiveViewerConfig,
} from '@finos/perspective-viewer'

export interface State {
size: number | null
Expand Down Expand Up @@ -39,7 +42,7 @@ function usePerspective(
container: HTMLDivElement | null,
data: string | ArrayBuffer,
attrs: React.HTMLAttributes<HTMLDivElement>,
settings?: boolean,
config?: PerspectiveViewerConfig,
) {
const [state, setState] = React.useState<State | null>(null)

Expand All @@ -54,8 +57,8 @@ function usePerspective(
viewer = renderViewer(container, attrs)
table = await renderTable(data, viewer)

if (settings) {
await viewer.toggleConfig(true)
if (config) {
await viewer.restore(config)
}

const size = await table.size()
Expand All @@ -76,7 +79,7 @@ function usePerspective(
return () => {
disposeTable()
}
}, [attrs, container, data, settings])
}, [attrs, config, container, data])

return state
}
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
## Catalog, Lambdas
* [Added] Use `quilt_summarize.json` to control Perspective menu ([#2744](https://github.com/quiltdata/quilt/pull/2744))
* [Added] Show bucket collaborators ([#2756](https://github.com/quiltdata/quilt/pull/2756))
* [Added] Add `config` field to Perspective scope of `quilt_summarize.json` ([#2781](https://github.com/quiltdata/quilt/pull/2781))
* [Fixed] Fix package creation in S3 buckets with SSE-KMS enabled ([#2754](https://github.com/quiltdata/quilt/pull/2754))
* [Changed] Clean up home page ([#2780](https://github.com/quiltdata/quilt/pull/2780)).

Expand Down
4 changes: 4 additions & 0 deletions shared/schemas/quilt_summarize.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
}
}
},
"config": {
"description": "Perspctive specific option. Restores config from .save()",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akarve pls wordsmith

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akarve I'm going to merge it, feel free to point me out to different wording here on in Slack

"type": "object"
},
"settings": {
"description": "Perspctive specific option. Sets config opened",
"type": "boolean"
Expand Down