Skip to content

Commit

Permalink
Disable all actions by actions = false
Browse files Browse the repository at this point in the history
  • Loading branch information
fiskus committed Jun 14, 2024
1 parent f7d45ba commit fc3cecf
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 28 deletions.
8 changes: 8 additions & 0 deletions catalog/app/utils/BucketPreferences/BucketPreferences.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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 Down
14 changes: 13 additions & 1 deletion catalog/app/utils/BucketPreferences/BucketPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface AthenaPreferences {
}

interface UiPreferencesInput {
actions?: Partial<ActionPreferences>
actions?: Partial<ActionPreferences> | false
athena?: AthenaPreferences
blocks?: Partial<BlocksPreferencesInput>
defaultSourceBucket?: DefaultSourceBucketInput
Expand Down Expand Up @@ -175,6 +175,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 +277,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,11 @@
// 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,
}
`;
61 changes: 34 additions & 27 deletions shared/schemas/bucketConfig.yml.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,41 @@
}
},
"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": {
"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]
},
"revisePackage": {
"description": "Hides button triggering Revise Package dialog",
"type": "boolean",
"examples": [true, false]
},
"copyPackage": {
"description": "Hides button triggering Push to Bucket dialog",
"type": "boolean",
"examples": [true, false]
}
}
}
}
]
},
"blocks": {
"description": "Hide and show UI blocks in package detail page",
Expand Down

0 comments on commit fc3cecf

Please sign in to comment.