From fc3cecf1ffa52bd91ef6eb22be641bd259dee057 Mon Sep 17 00:00:00 2001 From: Maksim Chervonnyi Date: Fri, 14 Jun 2024 18:12:39 +0200 Subject: [PATCH] Disable all actions by `actions = false` --- .../BucketPreferences.spec.ts | 8 +++ .../BucketPreferences/BucketPreferences.ts | 14 ++++- .../BucketPreferences.spec.ts.snap | 11 ++++ shared/schemas/bucketConfig.yml.json | 61 +++++++++++-------- 4 files changed, 66 insertions(+), 28 deletions(-) create mode 100644 catalog/app/utils/BucketPreferences/__snapshots__/BucketPreferences.spec.ts.snap diff --git a/catalog/app/utils/BucketPreferences/BucketPreferences.spec.ts b/catalog/app/utils/BucketPreferences/BucketPreferences.spec.ts index 49b4f93693c..17923b2714e 100644 --- a/catalog/app/utils/BucketPreferences/BucketPreferences.spec.ts +++ b/catalog/app/utils/BucketPreferences/BucketPreferences.spec.ts @@ -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', () => { diff --git a/catalog/app/utils/BucketPreferences/BucketPreferences.ts b/catalog/app/utils/BucketPreferences/BucketPreferences.ts index d2d5c53c170..00d23dc4f1f 100644 --- a/catalog/app/utils/BucketPreferences/BucketPreferences.ts +++ b/catalog/app/utils/BucketPreferences/BucketPreferences.ts @@ -79,7 +79,7 @@ export interface AthenaPreferences { } interface UiPreferencesInput { - actions?: Partial + actions?: Partial | false athena?: AthenaPreferences blocks?: Partial defaultSourceBucket?: DefaultSourceBucketInput @@ -175,6 +175,17 @@ function validate(data: unknown): asserts data is BucketPreferencesInput { if (errors.length) throw new bucketErrors.BucketPreferencesInvalid({ errors }) } +function parseActions(actions?: Partial | 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 { @@ -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( diff --git a/catalog/app/utils/BucketPreferences/__snapshots__/BucketPreferences.spec.ts.snap b/catalog/app/utils/BucketPreferences/__snapshots__/BucketPreferences.spec.ts.snap new file mode 100644 index 00000000000..c92e1ae57d3 --- /dev/null +++ b/catalog/app/utils/BucketPreferences/__snapshots__/BucketPreferences.spec.ts.snap @@ -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, +} +`; diff --git a/shared/schemas/bucketConfig.yml.json b/shared/schemas/bucketConfig.yml.json index cb211114f85..c30d7444f91 100644 --- a/shared/schemas/bucketConfig.yml.json +++ b/shared/schemas/bucketConfig.yml.json @@ -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",