-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
272 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
catalog/app/components/FileEditor/QuiltConfigEditor/BucketPreferences.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as React from 'react' | ||
|
||
import bucketPreferencesSchema from 'schemas/bucketConfig.yml.json' | ||
|
||
import type { JsonSchema } from 'utils/json-schema' | ||
|
||
interface BucketPreferencesProps { | ||
children: (props: { schema: JsonSchema }) => React.ReactElement | ||
} | ||
|
||
export default function BucketPreferences({ children }: BucketPreferencesProps) { | ||
return children({ schema: bucketPreferencesSchema }) | ||
} |
62 changes: 62 additions & 0 deletions
62
catalog/app/components/FileEditor/QuiltConfigEditor/QuiltConfigEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type { ErrorObject } from 'ajv' | ||
import * as React from 'react' | ||
import * as M from '@material-ui/core' | ||
|
||
import JsonEditor from 'components/JsonEditor' | ||
import JsonValidationErrors from 'components/JsonValidationErrors' | ||
import { JsonSchema, makeSchemaValidator } from 'utils/json-schema' | ||
import * as YAML from 'utils/yaml' | ||
|
||
const useStyles = M.makeStyles((t) => ({ | ||
root: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
width: '100%', | ||
}, | ||
errors: { | ||
marginTop: t.spacing(1), | ||
}, | ||
})) | ||
|
||
export interface QuiltConfigEditorProps { | ||
disabled?: boolean | ||
onChange: (value: string) => void | ||
initialValue?: string | ||
error: Error | null | ||
} | ||
|
||
export default function QuiltConfigEditorSuspended({ | ||
disabled, | ||
onChange, | ||
initialValue, | ||
error, | ||
schema, | ||
}: QuiltConfigEditorProps & { schema?: JsonSchema }) { | ||
const classes = useStyles() | ||
const validate = React.useMemo(() => makeSchemaValidator(schema), [schema]) | ||
const [errors, setErrors] = React.useState<(Error | ErrorObject)[]>( | ||
error ? [error] : [], | ||
) | ||
const [value, setValue] = React.useState(YAML.parse(initialValue)) | ||
const handleChange = React.useCallback( | ||
(json) => { | ||
setErrors(validate(json)) | ||
setValue(json) | ||
onChange(YAML.stringify(json)) | ||
}, | ||
[onChange, validate], | ||
) | ||
return ( | ||
<div className={classes.root}> | ||
<JsonEditor | ||
disabled={disabled} | ||
errors={errors} | ||
multiColumned | ||
onChange={handleChange} | ||
value={value} | ||
schema={schema} | ||
/> | ||
<JsonValidationErrors className={classes.errors} error={errors} /> | ||
</div> | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
catalog/app/components/FileEditor/QuiltConfigEditor/Workflows.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as React from 'react' | ||
|
||
import workflowsBaseSchema from 'schemas/workflows-config-1.1.0.json' | ||
|
||
import type { JsonSchema } from 'utils/json-schema' | ||
|
||
interface WorkflowsProps { | ||
children: (props: { schema: JsonSchema }) => React.ReactElement | ||
} | ||
|
||
export default function Workflows({ children }: WorkflowsProps) { | ||
return children({ schema: workflowsBaseSchema }) | ||
} |
44 changes: 44 additions & 0 deletions
44
catalog/app/components/FileEditor/QuiltConfigEditor/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as React from 'react' | ||
|
||
import * as quiltConfigs from 'constants/quiltConfigs' | ||
import type { S3HandleBase } from 'utils/s3paths' | ||
|
||
import Skeleton from '../Skeleton' | ||
|
||
import type { QuiltConfigEditorProps } from './QuiltConfigEditor' | ||
|
||
const BucketPreferences = React.lazy(() => import('./BucketPreferences')) | ||
const Workflows = React.lazy(() => import('./Workflows')) | ||
|
||
function DummySchemaFetcher({ | ||
children, | ||
}: { | ||
children: (props: { schema: undefined }) => React.ReactElement | ||
}) { | ||
return children({ schema: undefined }) | ||
} | ||
|
||
const QuiltConfigEditorSuspended = React.lazy(() => import('./QuiltConfigEditor')) | ||
|
||
function getSchemaFetcher(handle: S3HandleBase) { | ||
if ( | ||
quiltConfigs.bucketPreferences.some((quiltConfig) => quiltConfig.includes(handle.key)) | ||
) | ||
return BucketPreferences | ||
if (quiltConfigs.workflows.includes(handle.key)) return Workflows | ||
return DummySchemaFetcher | ||
} | ||
|
||
export default ({ | ||
handle, | ||
...props | ||
}: QuiltConfigEditorProps & { handle: S3HandleBase }) => { | ||
const SchemaFetcher = getSchemaFetcher(handle) | ||
return ( | ||
<React.Suspense fallback={<Skeleton />}> | ||
<SchemaFetcher> | ||
{({ schema }) => <QuiltConfigEditorSuspended {...props} schema={schema} />} | ||
</SchemaFetcher> | ||
</React.Suspense> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const bucketPreferences = [ | ||
'.quilt/catalog/config.yaml', | ||
'.quilt/catalog/config.yml', | ||
] | ||
|
||
export const esQueries = '.quilt/queries/config.yaml' | ||
|
||
// TODO: enable this when backend is ready | ||
// const workflows = [ | ||
// '.quilt/workflows/config.yaml', | ||
// '.quilt/workflows/config.yml', | ||
// ] | ||
export const workflows = '.quilt/workflows/config.yml' | ||
|
||
export const all = [...bucketPreferences, esQueries, workflows] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.