Skip to content

Commit

Permalink
Disable all actions by actions = false
Browse files Browse the repository at this point in the history
Co-authored-by: Alexei Mochalov <[email protected]>
  • Loading branch information
fiskus and nl0 committed Jun 18, 2024
1 parent 1b8d91d commit 82a7472
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 53 deletions.
28 changes: 20 additions & 8 deletions catalog/app/containers/Bucket/Dir.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,29 @@ interface DirectoryMenuProps {
}

function DirectoryMenu({ bucket, path, className }: DirectoryMenuProps) {
const prefs = BucketPreferences.use()

Check warning on line 40 in catalog/app/containers/Bucket/Dir.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/Dir.tsx#L40

Added line #L40 was not covered by tests
const prompt = FileEditor.useCreateFileInBucket(bucket, path)
const menuItems = React.useMemo(
() => [
{
onClick: prompt.open,
title: 'Create file',
},
],
[prompt.open],
() =>
BucketPreferences.Result.match(

Check warning on line 44 in catalog/app/containers/Bucket/Dir.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/Dir.tsx#L43-L44

Added lines #L43 - L44 were not covered by tests
{
Ok: ({ ui: { actions } }) => {
const menu = []

Check warning on line 47 in catalog/app/containers/Bucket/Dir.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/Dir.tsx#L46-L47

Added lines #L46 - L47 were not covered by tests
if (actions.writeFile) {
menu.push({

Check warning on line 49 in catalog/app/containers/Bucket/Dir.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/Dir.tsx#L49

Added line #L49 was not covered by tests
onClick: prompt.open,
title: 'Create file',
})
}
return menu

Check warning on line 54 in catalog/app/containers/Bucket/Dir.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/Dir.tsx#L54

Added line #L54 was not covered by tests
},
_: () => [],

Check warning on line 56 in catalog/app/containers/Bucket/Dir.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/Dir.tsx#L56

Added line #L56 was not covered by tests
},
prefs,
),
[prefs, prompt.open],
)

if (!menuItems.length) return null
return (
<>
{prompt.render()}
Expand Down
27 changes: 19 additions & 8 deletions catalog/app/containers/Bucket/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,18 @@ export default function File() {
onChange={onViewModeChange}
/>
)}
{FileEditor.isSupportedFileType(handle.key) && (
<FileEditor.Controls
{...editorState}
className={classes.button}
onSave={handleEditorSave}
/>
)}
{BucketPreferences.Result.match({
Ok: ({ ui: { actions } }) =>

Check warning on line 456 in catalog/app/containers/Bucket/File.js

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/File.js#L456

Added line #L456 was not covered by tests
actions.writeFile &&
FileEditor.isSupportedFileType(handle.key) && (
<FileEditor.Controls

Check warning on line 459 in catalog/app/containers/Bucket/File.js

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/File.js#L458-L459

Added lines #L458 - L459 were not covered by tests
{...editorState}
className={classes.button}
onSave={handleEditorSave}
/>
),
_: () => null,

Check warning on line 465 in catalog/app/containers/Bucket/File.js

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/File.js#L465

Added line #L465 was not covered by tests
})}
{bookmarks && (
<Buttons.Iconized
className={classes.button}
Expand Down Expand Up @@ -535,7 +540,13 @@ export default function File() {
) : (
<>
<Message headline="No Such Object">
<FileEditor.AddFileButton onClick={editorState.onEdit} />
{BucketPreferences.Result.match({
Ok: ({ ui: { actions } }) =>

Check warning on line 544 in catalog/app/containers/Bucket/File.js

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/File.js#L544

Added line #L544 was not covered by tests
actions.writeFile && (
<FileEditor.AddFileButton onClick={editorState.onEdit} />

Check warning on line 546 in catalog/app/containers/Bucket/File.js

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/File.js#L546

Added line #L546 was not covered by tests
),
_: () => null,

Check warning on line 548 in catalog/app/containers/Bucket/File.js

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/containers/Bucket/File.js#L548

Added line #L548 was not covered by tests
})}
</Message>
</>
),
Expand Down
2 changes: 1 addition & 1 deletion catalog/app/containers/Bucket/PackageTree/RevisionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function RevisionMenu({
{
Ok: ({ ui: { actions } }) => {
const menu = []
if (actions.revisePackage) {
if (actions.writeFile && actions.revisePackage) {
menu.push({
onClick: onCreateFile,
title: 'Create file',
Expand Down
35 changes: 28 additions & 7 deletions catalog/app/utils/BucketPreferences/BucketPreferences.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ const expectedDefaults = {
copyPackage: true,
createPackage: true,
deleteRevision: false,
openInDesktop: false,
revisePackage: true,
writeFile: true,
},
athena: {},
blocks: {
analytics: true,
browser: true,
Expand All @@ -22,6 +25,12 @@ const expectedDefaults = {
expanded: false,
},
},
gallery: {
files: true,
overview: true,
packages: true,
summarize: true,
},
},
nav: {
files: true,
Expand Down Expand Up @@ -54,7 +63,7 @@ describe('utils/BucketPreferences', () => {
actions:
copyPackage: False
`
expect(parse(config).ui.actions).toMatchObject({
expect(parse(config).ui.actions).toEqual({
...expectedDefaults.ui.actions,
copyPackage: false,
})
Expand All @@ -66,7 +75,7 @@ describe('utils/BucketPreferences', () => {
blocks:
analytics: False
`
expect(parse(config).ui.blocks).toMatchObject({
expect(parse(config).ui.blocks).toEqual({
...expectedDefaults.ui.blocks,
analytics: false,
})
Expand All @@ -78,19 +87,23 @@ describe('utils/BucketPreferences', () => {
nav:
queries: False
`
expect(parse(config).ui.nav).toMatchObject({
expect(parse(config).ui.nav).toEqual({
...expectedDefaults.ui.nav,
queries: false,
})
})

it('Additional config structures returns defaults', () => {
it('Additional config structures returns defaults and those additonal fields', () => {
const config = dedent`
ui:
blocks:
queries: QUERY
`
expect(parse(config)).toMatchObject(expectedDefaults)
expect(parse(config).ui.blocks).toEqual({
...expectedDefaults.ui.blocks,
queries: 'QUERY',
})
})

it('Invalid config values throws error', () => {
Expand All @@ -101,6 +114,14 @@ describe('utils/BucketPreferences', () => {
`
expect(() => parse(config)).toThrowError()
})

it('Actions = false disables all actions', () => {
const config = dedent`
ui:
actions: False
`
expect(parse(config).ui.actions).toMatchSnapshot()
})
})

describe('extendDefaults', () => {
Expand All @@ -116,7 +137,7 @@ describe('utils/BucketPreferences', () => {
},
},
}
expect(extendDefaults(config).ui.actions).toMatchObject({
expect(extendDefaults(config).ui.actions).toEqual({
...expectedDefaults.ui.actions,
deleteRevision: true,
})
Expand All @@ -130,7 +151,7 @@ describe('utils/BucketPreferences', () => {
},
},
}
expect(extendDefaults(config).ui.blocks).toMatchObject({
expect(extendDefaults(config).ui.blocks).toEqual({
...expectedDefaults.ui.blocks,
browser: false,
})
Expand All @@ -144,7 +165,7 @@ describe('utils/BucketPreferences', () => {
},
},
}
expect(extendDefaults(config).ui.nav).toMatchObject({
expect(extendDefaults(config).ui.nav).toEqual({
...expectedDefaults.ui.nav,
files: false,
})
Expand Down
22 changes: 20 additions & 2 deletions catalog/app/utils/BucketPreferences/BucketPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import * as tagged from 'utils/taggedV2'
import * as YAML from 'utils/yaml'

export type ActionPreferences = Record<
'copyPackage' | 'createPackage' | 'deleteRevision' | 'openInDesktop' | 'revisePackage',
| 'copyPackage'
| 'createPackage'
| 'deleteRevision'
| 'openInDesktop'
| 'revisePackage'
| 'writeFile',
boolean
>

Expand Down Expand Up @@ -79,7 +84,7 @@ export interface AthenaPreferences {
}

interface UiPreferencesInput {
actions?: Partial<ActionPreferences>
actions?: Partial<ActionPreferences> | false
athena?: AthenaPreferences
blocks?: Partial<BlocksPreferencesInput>
defaultSourceBucket?: DefaultSourceBucketInput
Expand Down Expand Up @@ -135,6 +140,7 @@ const defaultPreferences: BucketPreferences = {
deleteRevision: false,
openInDesktop: false,
revisePackage: true,
writeFile: true,
},
athena: {},
blocks: {
Expand Down Expand Up @@ -175,6 +181,17 @@ function validate(data: unknown): asserts data is BucketPreferencesInput {
if (errors.length) throw new bucketErrors.BucketPreferencesInvalid({ errors })
}

function parseActions(actions?: Partial<ActionPreferences> | false): ActionPreferences {
if (actions === false) {
return R.map(R.F, defaultPreferences.ui.actions)
}

return {
...defaultPreferences.ui.actions,
...actions,
}
}

function parseAthena(athena?: AthenaPreferencesInput): AthenaPreferences {
const { defaultWorkflow, ...rest } = { ...defaultPreferences.ui.athena, ...athena }
return {
Expand Down Expand Up @@ -266,6 +283,7 @@ export function extendDefaults(data: BucketPreferencesInput): BucketPreferences
return {
ui: {
...R.mergeDeepRight(defaultPreferences.ui, data?.ui || {}),
actions: parseActions(data?.ui?.actions),
athena: parseAthena(data?.ui?.athena),
blocks: parseBlocks(data?.ui?.blocks),
packageDescription: parsePackages(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`utils/BucketPreferences parse Actions = false disables all actions 1`] = `
{
"copyPackage": false,
"createPackage": false,
"deleteRevision": false,
"openInDesktop": false,
"revisePackage": false,
"writeFile": false,
}
`;
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Entries inside each section should be ordered by type:
* [Changed] Upload optimization check now tries to use S3 SHA-256 checksum and falls back to ETag ([#3968](https://github.com/quiltdata/quilt/pull/3968))

## Catalog, Lambdas
* [Added] Add `ui.actions = False` and `ui.actions.writeFile` for configuring visibility of buttons ([#4001](https://github.com/quiltdata/quilt/pull/4001))
* [Changed] Use promises for URLs in IGV to have fresh signing each time they used ([#3979](https://github.com/quiltdata/quilt/pull/3979))

# 6.0.0a3 - 2024-04-25
Expand Down
3 changes: 3 additions & 0 deletions docs/Catalog/Preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ui:
createPackage: True
deleteRevision: False
revisePackage: True
writeFile: True
blocks:
analytics: True
browser: True
Expand All @@ -46,11 +47,13 @@ ui:
* `ui.nav.files: False` - hide Files tab
* `ui.nav.packages: False` - hide Packages tab
* `ui.nav.queries: False` - hide Queries tab
* `ui.actions: False` - hide all buttons used to create and edit packages and files (make the catalog "read-only")
* `ui.actions.copyPackage: False` - hide buttons to push packages across buckets
* `ui.actions.createPackage: False` - hide buttons to create packages via
drag-and-drop or from folders in S3
* `ui.actions.deleteRevision: True` - show buttons to delete package revision
* `ui.actions.revisePackage: False` - hide the button to revise packages
* `ui.actions.writeFile: False` - hide buttons to create or edit files
* `ui.blocks.analytics: False` - hide Analytics block on file page
* `ui.blocks.browser: False` - hide files browser on both Bucket and Packages tab
* `ui.blocks.code: False` - hide Code block with quilt3 code boilerplate
Expand Down
71 changes: 44 additions & 27 deletions shared/schemas/bucketConfig.yml.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,51 @@
}
},
"actions": {
"type": "object",
"description": "Hide and show action buttons",
"properties": {
"createPackage": {
"default": true,
"description": "Hides buttons triggering Create Package dialog, both creating package from scratch and from directory",
"type": "boolean",
"examples": [true, false]
},
"deleteRevision": {
"default": true,
"description": "Hides buttons triggering Delete Package Revision dialog",
"type": "boolean",
"examples": [true, false]
},
"revisePackage": {
"default": true,
"description": "Hides button triggering Revise Package dialog",
"type": "boolean",
"examples": [true, false]
},
"copyPackage": {
"default": true,
"description": "Hides button triggering Push to Bucket dialog",
"type": "boolean",
"examples": [true, false]
"default": {
"createPackage": true,
"deleteRevision": true,
"revisePackage": true,
"copyPackage": true
},
"oneOf": [
{ "type": "boolean" },
{
"type": "object",
"description": "Hide and show action buttons",
"properties": {
"copyPackage": {
"description": "Hides button triggering Push to Bucket dialog",
"type": "boolean",
"examples": [true, false]
},
"createPackage": {
"description": "Hides buttons triggering Create Package dialog, both creating package from scratch and from directory",
"type": "boolean",
"examples": [true, false]
},
"deleteRevision": {
"description": "Hides buttons triggering Delete Package Revision dialog",
"type": "boolean",
"examples": [true, false]
},
"openInDesktop": {
"description": "Hides button to open current package in Quilt Desktop",
"type": "boolean",
"examples": [true, false]
},
"revisePackage": {
"description": "Hides button triggering Revise Package dialog",
"type": "boolean",
"examples": [true, false]
},
"writeFile": {
"description": "Hides button to create or edit file",
"type": "boolean",
"examples": [true, false]
}
}
}
}
]
},
"blocks": {
"description": "Hide and show UI blocks in package detail page",
Expand Down

0 comments on commit 82a7472

Please sign in to comment.