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

quilt_summarize.json editor #4254

Merged
merged 54 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
4a02092
modify array placeholder
fiskus Dec 3, 2024
fdca225
quilt summarize editor
fiskus Dec 3, 2024
a11ecf1
Merge branch 'master' of github.com:quiltdata/quilt into quilt_summar…
fiskus Dec 3, 2024
ffb9a36
sync types with JSON Schema
fiskus Dec 4, 2024
39d784e
wip: use custom form as quilt_summarize editor
fiskus Dec 4, 2024
631e20b
wip: use custom editor, it works though very unperformant
fiskus Dec 5, 2024
f9d0ffc
basic optimisations
fiskus Dec 5, 2024
61b9a93
use pseudo-ids to make room for changing the order
fiskus Dec 5, 2024
7a5f93b
use pseudo-ids to make room for changing the order
fiskus Dec 5, 2024
eccbd5d
polish styles
fiskus Dec 5, 2024
49c3f4a
remove column or row
fiskus Dec 5, 2024
1ae67dc
add file picker
fiskus Dec 9, 2024
890e242
switch to quilt_summarize editor earlier
fiskus Dec 9, 2024
b077db8
debounce internal value and call onChange
fiskus Dec 9, 2024
cb4a986
multiple minor improvements
fiskus Dec 9, 2024
be4ffd3
Merge branch 'master' of github.com:quiltdata/quilt into quilt_summar…
fiskus Dec 9, 2024
a28b425
revert unnecessary change
fiskus Dec 9, 2024
c49c774
revert unrelated changes
fiskus Dec 9, 2024
28f57d4
downgrade nanoid to sync with postcss
fiskus Dec 9, 2024
3f1e1b1
reuse props object
fiskus Dec 9, 2024
4172334
if delete last row
fiskus Dec 9, 2024
cac80b8
add some tests
fiskus Dec 10, 2024
ecb932b
return promises in tests
fiskus Dec 10, 2024
2892de8
add link to documentation
fiskus Dec 10, 2024
cfe0bc7
order imports
fiskus Dec 10, 2024
96a2e0b
validate with JSON schema
fiskus Dec 10, 2024
c397bf5
move to dir
fiskus Dec 10, 2024
0ab9a94
move state manipulation to individual file
fiskus Dec 10, 2024
eebb3f1
use crypto instead of nanoid
fiskus Dec 10, 2024
b1f4302
add tests for State
fiskus Dec 10, 2024
1b38c2d
save vim buffer
fiskus Dec 10, 2024
a64ff3d
set initial path for popup listing
fiskus Dec 10, 2024
221c709
changelog entry
fiskus Dec 10, 2024
37c5ef5
fix adding files from nested directories
fiskus Dec 11, 2024
50ea984
some tests to pass codecov treshold
fiskus Dec 11, 2024
089ead1
some tests to pass codecov treshold
fiskus Dec 11, 2024
71487e8
reuse JsonValidationErrors
fiskus Dec 11, 2024
2c61c39
wrap throw with brackets
fiskus Dec 11, 2024
3548c54
add simple smoke tests for FileEditor
fiskus Dec 11, 2024
9832505
cosmetic change
fiskus Dec 12, 2024
7d34edd
more tests
fiskus Dec 12, 2024
81ba9f4
fix [].length react condition
fiskus Dec 12, 2024
caad40f
dont go up outside package
fiskus Dec 12, 2024
e1dcc6f
make listing constant height
fiskus Dec 12, 2024
04d64b9
add tests for QuiltSummarize
fiskus Dec 12, 2024
b31709a
Merge branch 'master' into quilt_summarize_editor
fiskus Dec 16, 2024
21b2461
Update catalog/CHANGELOG.md
fiskus Dec 16, 2024
74fb03f
Update catalog/app/components/FileEditor/QuiltConfigEditor/QuiltSumma…
fiskus Dec 16, 2024
5a4de6d
Update catalog/app/components/FileEditor/QuiltConfigEditor/QuiltSumma…
fiskus Dec 16, 2024
ef70d7e
memoize random widths
fiskus Dec 16, 2024
f684afd
remove TODO note
fiskus Dec 16, 2024
ea943c6
show JSON.parse errors
fiskus Dec 16, 2024
e85ce4d
use wildcard import
fiskus Dec 16, 2024
8645b72
merge with remote
fiskus Dec 16, 2024
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
1 change: 1 addition & 0 deletions catalog/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ where verb is one of

## Changes

- [Added] Visual editor for `quilt_summarize.json` ([#4254](https://github.com/quiltdata/quilt/pull/4254))
- [Added] Support "html" type in `quilt_summarize.json` ([#4252](https://github.com/quiltdata/quilt/pull/4252))
- [Fixed] Resolve caching issues where changes in `.quilt/{workflows,catalog}` were not applied ([#4245](https://github.com/quiltdata/quilt/pull/4245))
- [Added] A shortcut to enable adding files to a package from the current bucket ([#4245](https://github.com/quiltdata/quilt/pull/4245))
Expand Down
2 changes: 2 additions & 0 deletions catalog/app/components/FileEditor/CreateFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function useCreateFileInBucket(bucket: string, path: string) {
const { urls } = NamedRoutes.use()
const history = RRDom.useHistory()

// TODO: put this into FileEditor/routes
const toFile = React.useCallback(
(name: string) => urls.bucketFile(bucket, join(path, name), { edit: true }),
[bucket, path, urls],
Expand All @@ -48,6 +49,7 @@ export function useCreateFileInPackage({ bucket, name }: PackageHandle, prefix?:
const { urls } = NamedRoutes.use()
const history = RRDom.useHistory()

// TODO: put this into FileEditor/routes
const toFile = React.useCallback(
(fileName: string) => {
const next = urls.bucketPackageDetail(bucket, name, { action: 'revisePackage' })
Expand Down
159 changes: 159 additions & 0 deletions catalog/app/components/FileEditor/FileEditor.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import * as React from 'react'
import renderer from 'react-test-renderer'
import { renderHook } from '@testing-library/react-hooks'

import AsyncResult from 'utils/AsyncResult'

import { useState } from './State'
import { Editor } from './FileEditor'

jest.mock('utils/AWS', () => ({ S3: { use: () => {} } }))

jest.mock('./Skeleton', () => () => <div id="Skeleton" />)

jest.mock('utils/NamedRoutes', () => ({
...jest.requireActual('utils/NamedRoutes'),
use: jest.fn(() => ({ urls: {} })),
}))

jest.mock(
'react-router-dom',
jest.fn(() => ({
...jest.requireActual('react-router-dom'),
useParams: jest.fn(() => ({ bucket: 'b', key: 'k' })),
useLocation: jest.fn(() => ({ search: '?edit=true' })),
})),
)

jest.mock(
'components/Preview/Display',
jest.fn(() => () => <div id="error" />),
)

const getObjectData = jest.fn((cases: any) =>
AsyncResult.case(cases, AsyncResult.Ok({ Body: 'body' })),
)

jest.mock(
'components/Preview/loaders/utils',
jest.fn(() => ({
...jest.requireActual('components/Preview/loaders/utils'),
useObjectGetter: () => ({
case: getObjectData,
}),
})),
)

jest.mock(
'./TextEditor',
jest.fn(() => ({ initialValue }: { initialValue: string }) => (
<div id="Text Editor">
<span id="initialValue">{initialValue}</span>
</div>
)),
)

jest.mock(
'constants/config',
jest.fn(() => ({})),
)

const loadMode = jest.fn(() => 'fulfilled')

jest.mock(
'./loader',
jest.fn(() => ({
loadMode: jest.fn(() => loadMode()),
detect: () => 'text',
useWriteData: () => {},
})),
)

describe('components/FileEditor/FileEditor', () => {
describe('Editor', () => {
const handle = { bucket: 'b', key: 'k' }
const hookData = renderHook(() => useState(handle))
const state = hookData.result.current
it('shows skeleton when loadMode is not resolved yet', () => {
loadMode.mockImplementationOnce(() => {
throw Promise.resolve(null)
})
const tree = renderer
.create(
<Editor
{...state}
className="root"
editing={{ brace: 'json' }}
handle={handle}
/>,
)
.toJSON()
expect(tree).toMatchSnapshot()
})

it('shows TextEditor', () => {
const tree = renderer
.create(
<Editor
{...state}
className="root"
editing={{ brace: 'json' }}
handle={handle}
/>,
)
.toJSON()
expect(tree).toMatchSnapshot()
})

it('shows an empty TextEditor', () => {
const tree = renderer
.create(
<Editor
{...state}
empty
className="root"
editing={{ brace: 'json' }}
handle={handle}
/>,
)
.toJSON()
expect(tree).toMatchSnapshot()
})

it('shows Skeleton while loading data', () => {
getObjectData.mockImplementationOnce((cases: any) =>
AsyncResult.case(cases, AsyncResult.Pending()),
)
const { result } = renderHook(() => useState(handle))
const tree = renderer
.create(
<Editor
{...result.current}
className="root"
editing={{ brace: 'json' }}
handle={handle}
/>,
)
.toJSON()
expect(tree).toMatchSnapshot()
})

it('shows Error when loading failed', () => {
getObjectData.mockImplementationOnce((cases: any) =>
AsyncResult.case(cases, AsyncResult.Err(new Error('Fail'))),
)
const { result } = renderHook(() => useState(handle))
const tree = renderer
.create(
<Editor
{...result.current}
className="root"
editing={{ brace: 'json' }}
handle={handle}
/>,
)
.toJSON()
expect(tree).toMatchSnapshot()
})
})
})
76 changes: 31 additions & 45 deletions catalog/app/components/FileEditor/FileEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

export { detect, isSupportedFileType } from './loader'

const QuiltSummarize = React.lazy(() => import('./QuiltConfigEditor/QuiltSummarize'))

interface EditorProps extends EditorState {
className: string
editing: EditorInputType
Expand All @@ -26,39 +28,34 @@

function EditorSuspended({
className,
saving,
saving: disabled,
empty,
error,
handle,
onChange,
editing,
}: EditorProps) {
const disabled = saving
if (editing.brace !== '__quiltConfig') {
if (editing.brace !== '__quiltConfig' && editing.brace !== '__quiltSummarize') {
loadMode(editing.brace || 'plain_text') // TODO: loaders#typeText.brace
}

const data = PreviewUtils.useObjectGetter(handle, { noAutoFetch: empty })
const initialProps = {
className,
disabled,
error,
onChange,
initialValue: '',
}
if (empty)
return editing.brace === '__quiltConfig' ? (
<QuiltConfigEditor
className={className}
handle={handle}
disabled={disabled}
error={error}
onChange={onChange}
initialValue=""
/>
) : (
<TextEditor
autoFocus
className={className}
error={error}
initialValue=""
onChange={onChange}
type={editing}
/>
)
switch (editing.brace) {
case '__quiltConfig':
return <QuiltConfigEditor {...initialProps} handle={handle} />
case '__quiltSummarize':
return <QuiltSummarize {...initialProps} />

Check warning on line 55 in catalog/app/components/FileEditor/FileEditor.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/components/FileEditor/FileEditor.tsx#L52-L55

Added lines #L52 - L55 were not covered by tests
default:
return <TextEditor {...initialProps} autoFocus type={editing} />
}
return data.case({
_: () => <Skeleton />,
Err: (
Expand All @@ -70,30 +67,19 @@
</div>
),
Ok: (response: { Body: Buffer }) => {
const value = response.Body.toString('utf-8')
if (editing.brace === '__quiltConfig') {
return (
<QuiltConfigEditor
className={className}
handle={handle}
disabled={disabled}
error={error}
onChange={onChange}
initialValue={value}
/>
)
const initialValue = response.Body.toString('utf-8')
const props = {
...initialProps,
initialValue,
}
switch (editing.brace) {
case '__quiltConfig':
return <QuiltConfigEditor {...props} handle={handle} />
case '__quiltSummarize':
return <QuiltSummarize {...props} />

Check warning on line 79 in catalog/app/components/FileEditor/FileEditor.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/components/FileEditor/FileEditor.tsx#L76-L79

Added lines #L76 - L79 were not covered by tests
default:
return <TextEditor {...props} autoFocus type={editing} />
}
return (
<TextEditor
autoFocus
className={className}
disabled={disabled}
error={error}
onChange={onChange}
type={editing}
initialValue={value}
/>
)
},
})
}
Expand Down
1 change: 1 addition & 0 deletions catalog/app/components/FileEditor/HelpLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import * as NamedRoutes from 'utils/NamedRoutes'
import StyledLink from 'utils/StyledLink'
import StyledTooltip from 'utils/StyledTooltip'

// TODO: put this into FileEditor/routes
function useRouteToEditFile(handle: Model.S3.S3ObjectLocation) {
const { urls } = NamedRoutes.use()
const { pathname, search } = RRDom.useLocation()
Expand Down
Loading
Loading