From d12dac54502b00fcbc34c36076371f69289e8660 Mon Sep 17 00:00:00 2001 From: Maryam Khidir Date: Thu, 2 Nov 2023 20:07:36 +0100 Subject: [PATCH 1/5] enhancement: Create independent module dependency handling --- frontend/src/modules/Catalog/index.js | 11 +++++ frontend/src/modules/Glossaries/index.js | 11 +++++ frontend/src/modules/Shares/index.js | 9 ++++ frontend/src/modules/Worksheets/index.js | 11 +++++ frontend/src/modules/index.js | 4 ++ frontend/src/utils/helpers/moduleUtils.js | 54 +++++++++++------------ 6 files changed, 72 insertions(+), 28 deletions(-) create mode 100644 frontend/src/modules/Catalog/index.js create mode 100644 frontend/src/modules/Glossaries/index.js create mode 100644 frontend/src/modules/Worksheets/index.js create mode 100644 frontend/src/modules/index.js diff --git a/frontend/src/modules/Catalog/index.js b/frontend/src/modules/Catalog/index.js new file mode 100644 index 000000000..cad9cd2ba --- /dev/null +++ b/frontend/src/modules/Catalog/index.js @@ -0,0 +1,11 @@ +import { getModuleActiveStatus, ModuleNames } from 'utils'; + +export const CatalogsModule = { + name: 'catalog', + resolve_dependency: () => { + return ( + getModuleActiveStatus(ModuleNames.DATASETS) || + getModuleActiveStatus(ModuleNames.DASHBOARDS) + ); + } +}; diff --git a/frontend/src/modules/Glossaries/index.js b/frontend/src/modules/Glossaries/index.js new file mode 100644 index 000000000..b1b800ac5 --- /dev/null +++ b/frontend/src/modules/Glossaries/index.js @@ -0,0 +1,11 @@ +import { getModuleActiveStatus, ModuleNames } from 'utils'; + +export const GlossariesModule = { + name: 'glossaries', + resolve_dependency: () => { + return ( + getModuleActiveStatus(ModuleNames.DATASETS) || + getModuleActiveStatus(ModuleNames.DASHBOARDS) + ); + } +}; diff --git a/frontend/src/modules/Shares/index.js b/frontend/src/modules/Shares/index.js index 8c76e1369..803b1e250 100644 --- a/frontend/src/modules/Shares/index.js +++ b/frontend/src/modules/Shares/index.js @@ -1 +1,10 @@ +import { ModuleNames, getModuleActiveStatus } from 'utils'; + +export const SharesModule = { + name: 'shares', + resolve_dependency: () => { + return getModuleActiveStatus(ModuleNames.DATASETS); + } +}; + export { ShareInboxList } from './components'; diff --git a/frontend/src/modules/Worksheets/index.js b/frontend/src/modules/Worksheets/index.js new file mode 100644 index 000000000..635cb0b75 --- /dev/null +++ b/frontend/src/modules/Worksheets/index.js @@ -0,0 +1,11 @@ +import { getModuleActiveStatus, ModuleNames } from 'utils'; + +export const WorksheetsModule = { + name: 'worksheets', + resolve_dependency: () => { + return ( + getModuleActiveStatus(ModuleNames.DATASETS) && + getModuleActiveStatus(ModuleNames.WORKSHEETS) + ); + } +}; diff --git a/frontend/src/modules/index.js b/frontend/src/modules/index.js new file mode 100644 index 000000000..4ee86238f --- /dev/null +++ b/frontend/src/modules/index.js @@ -0,0 +1,4 @@ +export * from './Catalog'; +export * from './Glossaries'; +export * from './Shares'; +export * from './Worksheets'; diff --git a/frontend/src/utils/helpers/moduleUtils.js b/frontend/src/utils/helpers/moduleUtils.js index 827ca31aa..53fb71797 100644 --- a/frontend/src/utils/helpers/moduleUtils.js +++ b/frontend/src/utils/helpers/moduleUtils.js @@ -1,35 +1,12 @@ /* eslint-disable no-restricted-properties */ +import * as modules from 'modules'; import config from '../../generated/config.json'; -const ModuleNames = { - CATALOG: 'catalog', - DATASETS: 'datasets', - SHARES: 'shares', - GLOSSARIES: 'glossaries', - WORKSHEETS: 'worksheets', - NOTEBOOKS: 'notebooks', - MLSTUDIO: 'mlstudio', - PIPELINES: 'datapipelines', - DASHBOARDS: 'dashboards' -}; - function isModuleEnabled(module) { - if (module === ModuleNames.CATALOG || module === ModuleNames.GLOSSARIES) { - return ( - getModuleActiveStatus(ModuleNames.DATASETS) || - getModuleActiveStatus(ModuleNames.DASHBOARDS) - ); - } - if (module === ModuleNames.SHARES) { - return getModuleActiveStatus(ModuleNames.DATASETS); - } - if (module === ModuleNames.WORKSHEETS) { - return ( - getModuleActiveStatus(ModuleNames.DATASETS) && - getModuleActiveStatus(ModuleNames.WORKSHEETS) - ); + if (hasDependencyModule(module)) { + const resolvedModule = resolveModuleName(module); + return resolvedModule.resolve_dependency(); } - return getModuleActiveStatus(module); } @@ -44,4 +21,25 @@ function getModuleActiveStatus(moduleKey) { return false; } -export { ModuleNames, isModuleEnabled }; +function resolveModuleName(module) { + return Object.values(modules).find((_module) => _module.name === module); +} + +function hasDependencyModule(module) { + const resolvedModule = resolveModuleName(module); + return typeof resolvedModule?.resolve_dependency === 'function'; +} + +function configKeysMap(obj) { + const map = {}; + const otherModules = ['catalog', 'shares', 'glossaries']; + for (const module of [...Object.keys(obj), ...otherModules]) { + const upperCaseModule = module.toUpperCase(); + map[upperCaseModule] = module; + } + return map; +} + +const ModuleNames = configKeysMap(config.modules); + +export { ModuleNames, isModuleEnabled, getModuleActiveStatus }; From e4ff7b518781975bd6e404f39f845bacae7b4796 Mon Sep 17 00:00:00 2001 From: Maryam Khidir Date: Thu, 2 Nov 2023 20:09:40 +0100 Subject: [PATCH 2/5] Change module Pipelines to Datapipelines as declared in the config file --- frontend/src/design/components/layout/DefaultSidebar.js | 2 +- .../src/modules/Environments/components/EnvironmentFeatures.js | 2 +- frontend/src/routes.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/design/components/layout/DefaultSidebar.js b/frontend/src/design/components/layout/DefaultSidebar.js index 00ff51103..89e643985 100644 --- a/frontend/src/design/components/layout/DefaultSidebar.js +++ b/frontend/src/design/components/layout/DefaultSidebar.js @@ -84,7 +84,7 @@ export const DefaultSidebar = ({ openDrawer, onOpenDrawerChange }) => { title: 'Pipelines', path: '/console/pipelines', icon: , - active: isModuleEnabled(ModuleNames.PIPELINES) + active: isModuleEnabled(ModuleNames.DATAPIPELINES) }; const organizationsSection = { diff --git a/frontend/src/modules/Environments/components/EnvironmentFeatures.js b/frontend/src/modules/Environments/components/EnvironmentFeatures.js index 4c4fa2c25..d12d710f6 100644 --- a/frontend/src/modules/Environments/components/EnvironmentFeatures.js +++ b/frontend/src/modules/Environments/components/EnvironmentFeatures.js @@ -34,7 +34,7 @@ export const EnvironmentFeatures = (props) => { { title: 'Pipelines', enabledEnvVariableName: 'pipelinesEnabled', - active: isModuleEnabled(ModuleNames.PIPELINES) + active: isModuleEnabled(ModuleNames.DATAPIPELINES) } ]; diff --git a/frontend/src/routes.js b/frontend/src/routes.js index 22f9050b6..927ba60b9 100644 --- a/frontend/src/routes.js +++ b/frontend/src/routes.js @@ -327,7 +327,7 @@ const routes = [ } ] }, - isModuleEnabled(ModuleNames.PIPELINES) && { + isModuleEnabled(ModuleNames.DATAPIPELINES) && { children: [ { path: 'pipelines', From 531b20b31e4ff48d2a5b517519be27bfedcbaa2a Mon Sep 17 00:00:00 2001 From: dlpzx Date: Tue, 14 Nov 2023 13:29:34 +0100 Subject: [PATCH 3/5] Add notifications frontend index --- frontend/src/modules/Notifications/index.js | 10 ++++++++++ frontend/src/modules/index.js | 1 + 2 files changed, 11 insertions(+) create mode 100644 frontend/src/modules/Notifications/index.js diff --git a/frontend/src/modules/Notifications/index.js b/frontend/src/modules/Notifications/index.js new file mode 100644 index 000000000..a91a8d095 --- /dev/null +++ b/frontend/src/modules/Notifications/index.js @@ -0,0 +1,10 @@ +import { getModuleActiveStatus, ModuleNames } from 'utils'; + +export const NotificationsModule = { + name: 'notifications', + resolve_dependency: () => { + return ( + getModuleActiveStatus(ModuleNames.DATASETS) + ); + } +}; diff --git a/frontend/src/modules/index.js b/frontend/src/modules/index.js index 4ee86238f..a174dee89 100644 --- a/frontend/src/modules/index.js +++ b/frontend/src/modules/index.js @@ -2,3 +2,4 @@ export * from './Catalog'; export * from './Glossaries'; export * from './Shares'; export * from './Worksheets'; +export * from '/Notifications'; \ No newline at end of file From 5f85e2743fd099a2737b4659217e07781d9c1265 Mon Sep 17 00:00:00 2001 From: dlpzx Date: Tue, 14 Nov 2023 16:38:30 +0100 Subject: [PATCH 4/5] Modifying logic of moduleUtils. read from index files. Add v2.1 changes --- frontend/src/modules/Catalog/index.js | 2 + frontend/src/modules/Dashboards/index.js | 5 ++ frontend/src/modules/Datasets/index.js | 5 ++ .../views/EnvironmentCreateForm.js | 6 +- .../Environments/views/EnvironmentEditForm.js | 11 ++-- frontend/src/modules/Glossaries/index.js | 2 + frontend/src/modules/MLStudio/index.js | 5 ++ frontend/src/modules/Notebooks/index.js | 5 ++ frontend/src/modules/Notifications/index.js | 6 +- frontend/src/modules/Pipelines/index.js | 5 ++ frontend/src/modules/Shares/index.js | 2 + frontend/src/modules/Worksheets/index.js | 2 + frontend/src/modules/index.js | 7 +- frontend/src/utils/helpers/moduleUtils.js | 64 ++++++++++++++----- 14 files changed, 101 insertions(+), 26 deletions(-) create mode 100644 frontend/src/modules/Dashboards/index.js create mode 100644 frontend/src/modules/Datasets/index.js create mode 100644 frontend/src/modules/MLStudio/index.js create mode 100644 frontend/src/modules/Notebooks/index.js create mode 100644 frontend/src/modules/Pipelines/index.js diff --git a/frontend/src/modules/Catalog/index.js b/frontend/src/modules/Catalog/index.js index cad9cd2ba..fd3c9e6e9 100644 --- a/frontend/src/modules/Catalog/index.js +++ b/frontend/src/modules/Catalog/index.js @@ -1,7 +1,9 @@ import { getModuleActiveStatus, ModuleNames } from 'utils'; export const CatalogsModule = { + moduleDefinition: true, name: 'catalog', + isEnvironmentModule: false, resolve_dependency: () => { return ( getModuleActiveStatus(ModuleNames.DATASETS) || diff --git a/frontend/src/modules/Dashboards/index.js b/frontend/src/modules/Dashboards/index.js new file mode 100644 index 000000000..74d656587 --- /dev/null +++ b/frontend/src/modules/Dashboards/index.js @@ -0,0 +1,5 @@ +export const DashboardsModule = { + moduleDefinition: true, + name: 'dashboards', + isEnvironmentModule: true +}; diff --git a/frontend/src/modules/Datasets/index.js b/frontend/src/modules/Datasets/index.js new file mode 100644 index 000000000..0d306bebb --- /dev/null +++ b/frontend/src/modules/Datasets/index.js @@ -0,0 +1,5 @@ +export const DatasetsModule = { + moduleDefinition: true, + name: 'datasets', + isEnvironmentModule: false +}; diff --git a/frontend/src/modules/Environments/views/EnvironmentCreateForm.js b/frontend/src/modules/Environments/views/EnvironmentCreateForm.js index aeecc504d..7acf0052f 100644 --- a/frontend/src/modules/Environments/views/EnvironmentCreateForm.js +++ b/frontend/src/modules/Environments/views/EnvironmentCreateForm.js @@ -53,7 +53,7 @@ import { } from '../services'; import { AwsRegions, - isAnyFeatureModuleEnabled, + isAnyEnvironmentModuleEnabled, isModuleEnabled, ModuleNames } from 'utils'; @@ -604,7 +604,7 @@ const EnvironmentCreateForm = (props) => { - {isAnyFeatureModuleEnabled() && ( + {isAnyEnvironmentModuleEnabled() && ( @@ -710,7 +710,7 @@ const EnvironmentCreateForm = (props) => { )} - {isModuleEnabled(ModuleNames.PIPELINES) && ( + {isModuleEnabled(ModuleNames.DATAPIPELINES) && ( { const dispatch = useDispatch(); @@ -379,11 +383,10 @@ const EnvironmentEditForm = (props) => { - {isAnyFeatureModuleEnabled() && ( + {isAnyEnvironmentModuleEnabled() && ( - {isModuleEnabled(ModuleNames.DASHBOARDS) && ( @@ -494,7 +497,7 @@ const EnvironmentEditForm = (props) => { )} - {isModuleEnabled(ModuleNames.PIPELINES) && ( + {isModuleEnabled(ModuleNames.DATAPIPELINES) && ( { return ( getModuleActiveStatus(ModuleNames.DATASETS) || diff --git a/frontend/src/modules/MLStudio/index.js b/frontend/src/modules/MLStudio/index.js new file mode 100644 index 000000000..e3321c5ce --- /dev/null +++ b/frontend/src/modules/MLStudio/index.js @@ -0,0 +1,5 @@ +export const MLStudioModule = { + moduleDefinition: true, + name: 'mlstudio', + isEnvironmentModule: true +}; diff --git a/frontend/src/modules/Notebooks/index.js b/frontend/src/modules/Notebooks/index.js new file mode 100644 index 000000000..1d69d8cf6 --- /dev/null +++ b/frontend/src/modules/Notebooks/index.js @@ -0,0 +1,5 @@ +export const NotebooksModule = { + moduleDefinition: true, + name: 'notebooks', + isEnvironmentModule: true +}; diff --git a/frontend/src/modules/Notifications/index.js b/frontend/src/modules/Notifications/index.js index a91a8d095..996902fac 100644 --- a/frontend/src/modules/Notifications/index.js +++ b/frontend/src/modules/Notifications/index.js @@ -1,10 +1,10 @@ import { getModuleActiveStatus, ModuleNames } from 'utils'; export const NotificationsModule = { + moduleDefinition: true, name: 'notifications', + isEnvironmentModule: false, resolve_dependency: () => { - return ( - getModuleActiveStatus(ModuleNames.DATASETS) - ); + return getModuleActiveStatus(ModuleNames.DATASETS); } }; diff --git a/frontend/src/modules/Pipelines/index.js b/frontend/src/modules/Pipelines/index.js new file mode 100644 index 000000000..5572ecb98 --- /dev/null +++ b/frontend/src/modules/Pipelines/index.js @@ -0,0 +1,5 @@ +export const DataPipelinesModule = { + moduleDefinition: true, + name: 'datapipelines', + isEnvironmentModule: true +}; diff --git a/frontend/src/modules/Shares/index.js b/frontend/src/modules/Shares/index.js index 803b1e250..0fc3578e6 100644 --- a/frontend/src/modules/Shares/index.js +++ b/frontend/src/modules/Shares/index.js @@ -1,7 +1,9 @@ import { ModuleNames, getModuleActiveStatus } from 'utils'; export const SharesModule = { + moduleDefinition: true, name: 'shares', + isEnvironmentModule: false, resolve_dependency: () => { return getModuleActiveStatus(ModuleNames.DATASETS); } diff --git a/frontend/src/modules/Worksheets/index.js b/frontend/src/modules/Worksheets/index.js index 635cb0b75..d850e8f2b 100644 --- a/frontend/src/modules/Worksheets/index.js +++ b/frontend/src/modules/Worksheets/index.js @@ -1,7 +1,9 @@ import { getModuleActiveStatus, ModuleNames } from 'utils'; export const WorksheetsModule = { + moduleDefinition: true, name: 'worksheets', + isEnvironmentModule: false, resolve_dependency: () => { return ( getModuleActiveStatus(ModuleNames.DATASETS) && diff --git a/frontend/src/modules/index.js b/frontend/src/modules/index.js index a174dee89..873e5177d 100644 --- a/frontend/src/modules/index.js +++ b/frontend/src/modules/index.js @@ -1,5 +1,10 @@ export * from './Catalog'; +export * from './Dashboards'; +export * from './Datasets'; export * from './Glossaries'; +export * from './MLStudio'; +export * from './Notebooks'; +export * from './Notifications'; +export * from './Pipelines'; export * from './Shares'; export * from './Worksheets'; -export * from '/Notifications'; \ No newline at end of file diff --git a/frontend/src/utils/helpers/moduleUtils.js b/frontend/src/utils/helpers/moduleUtils.js index 53fb71797..525d4f222 100644 --- a/frontend/src/utils/helpers/moduleUtils.js +++ b/frontend/src/utils/helpers/moduleUtils.js @@ -2,9 +2,18 @@ import * as modules from 'modules'; import config from '../../generated/config.json'; +function _resolveModuleName(module) { + return Object.values(modules).find((_module) => _module.name === module); +} + +function _hasDependencyModule(module) { + const resolvedModule = _resolveModuleName(module); + return typeof resolvedModule?.resolve_dependency === 'function'; +} + function isModuleEnabled(module) { - if (hasDependencyModule(module)) { - const resolvedModule = resolveModuleName(module); + if (_hasDependencyModule(module)) { + const resolvedModule = _resolveModuleName(module); return resolvedModule.resolve_dependency(); } return getModuleActiveStatus(module); @@ -21,25 +30,50 @@ function getModuleActiveStatus(moduleKey) { return false; } -function resolveModuleName(module) { - return Object.values(modules).find((_module) => _module.name === module); +function isFeatureEnabled(moduleKey, featureKey) { + if ( + moduleKey === 'core' && + config.core.features !== undefined && + config.core.features[featureKey] !== undefined + ) { + return config.core.features[featureKey]; + } else if ( + getModuleActiveStatus(moduleKey) && + config.modules[moduleKey]['features'] !== undefined && + config.modules[moduleKey]['features'][featureKey] !== undefined + ) { + return config.modules[moduleKey]['features'][featureKey]; + } + return false; } -function hasDependencyModule(module) { - const resolvedModule = resolveModuleName(module); - return typeof resolvedModule?.resolve_dependency === 'function'; +function isAnyEnvironmentModuleEnabled() { + const env_modules = Object.values(modules).filter( + (_module) => + _module.isEnvironmentModule === true && isModuleEnabled(_module.name) + ); + return env_modules.length > 0 ? true : false; } -function configKeysMap(obj) { +function _modulesNameMap() { const map = {}; - const otherModules = ['catalog', 'shares', 'glossaries']; - for (const module of [...Object.keys(obj), ...otherModules]) { - const upperCaseModule = module.toUpperCase(); - map[upperCaseModule] = module; + for (const module of Object.values(modules).filter( + (_module) => _module.moduleDefinition === true + )) { + const upperCaseModule = module.name.toUpperCase(); + map[upperCaseModule] = module.name; } return map; } -const ModuleNames = configKeysMap(config.modules); - -export { ModuleNames, isModuleEnabled, getModuleActiveStatus }; +const ModuleNames = _modulesNameMap(); +/* eslint-disable no-console */ +console.log(ModuleNames); //no-console +/* eslint-enable no-console */ +export { + ModuleNames, + isModuleEnabled, + getModuleActiveStatus, + isFeatureEnabled, + isAnyEnvironmentModuleEnabled +}; From c029382ee188322d1f735a37c81f48da8a21a8ed Mon Sep 17 00:00:00 2001 From: dlpzx Date: Tue, 14 Nov 2023 16:46:58 +0100 Subject: [PATCH 5/5] Remove console.log --- frontend/src/utils/helpers/moduleUtils.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/frontend/src/utils/helpers/moduleUtils.js b/frontend/src/utils/helpers/moduleUtils.js index 525d4f222..648d675c0 100644 --- a/frontend/src/utils/helpers/moduleUtils.js +++ b/frontend/src/utils/helpers/moduleUtils.js @@ -67,9 +67,6 @@ function _modulesNameMap() { } const ModuleNames = _modulesNameMap(); -/* eslint-disable no-console */ -console.log(ModuleNames); //no-console -/* eslint-enable no-console */ export { ModuleNames, isModuleEnabled,