Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UD] Make some features togglable, add optional FAQ button #15907

Merged
merged 4 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,17 @@ The `"configuration.prefetch"` section allows to define resources that UD should
...
]
```

The `"configuration.features.disabled"` field defines features that should be disabled and not displayed in User Dashboard. Available values are `"workspaceSharing"`, `"kubernetesNamespaceSelector"`.

For example, this config disables kubernetes namespace selector:

```json
{
"configuration": {
"features": {
"disabled": ["kubernetesNamespaceSelector"]
}
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {RandomSvc} from '../../../../components/utils/random.service';
import {NamespaceSelectorSvc} from '../ready-to-go-stacks/namespace-selector/namespace-selector.service';
import { CheKubernetesNamespace } from '../../../../components/api/che-kubernetes-namespace.factory';
import { CheWorkspace } from '../../../../components/api/workspace/che-workspace.factory';
import { CheDashboardConfigurationService } from '../../../../components/branding/che-dashboard-configuration.service';
import { TogglableFeature } from '../../../../components/branding/che-branding.factory';

/**
* This class is handling the controller for stack importing directive.
Expand All @@ -26,18 +28,18 @@ import { CheWorkspace } from '../../../../components/api/workspace/che-workspace
export class ImportStackController implements IImportStackScopeBindings {

static $inject = [
'cheDashboardConfigurationService',
'cheKubernetesNamespace',
'cheWorkspace',
'createWorkspaceSvc',
'namespaceSelectorSvc',
'randomSvc'
'randomSvc',
];

onChange: IImportStackScopeOnChange;

infrastructureNamespaceHint: string;

ephemeralMode: boolean;
enabledKubernetesNamespaceSelector: boolean = false;

/**
* Kubernetes Namespace API interaction.
Expand All @@ -59,6 +61,10 @@ export class ImportStackController implements IImportStackScopeBindings {
* Workspace creation service.
*/
private createWorkspaceSvc: CreateWorkspaceSvc;
/**
* Dashboard configuration service.
*/
private cheDashboardConfigurationService: CheDashboardConfigurationService;
/**
* The selected source for devfile importing(URL or YAML).
*/
Expand Down Expand Up @@ -88,12 +94,14 @@ export class ImportStackController implements IImportStackScopeBindings {
* Default constructor that is using resource injection
*/
constructor(
cheDashboardConfigurationService: CheDashboardConfigurationService,
cheKubernetesNamespace: CheKubernetesNamespace,
cheWorkspace: CheWorkspace,
createWorkspaceSvc: CreateWorkspaceSvc,
namespaceSelectorSvc: NamespaceSelectorSvc,
randomSvc: RandomSvc
randomSvc: RandomSvc,
) {
this.cheDashboardConfigurationService = cheDashboardConfigurationService;
this.cheKubernetesNamespace = cheKubernetesNamespace;
this.cheWorkspace = cheWorkspace;
this.createWorkspaceSvc = createWorkspaceSvc;
Expand All @@ -106,6 +114,9 @@ export class ImportStackController implements IImportStackScopeBindings {
this.cheWorkspace.fetchWorkspaceSettings().then((settings: che.IWorkspaceSettings) => {
this.ephemeralMode = settings['che.workspace.persist_volumes.default'] === 'false';
});
this.cheDashboardConfigurationService.ready.then(() => {
this.enabledKubernetesNamespaceSelector = this.cheDashboardConfigurationService.enabledFeature(TogglableFeature.KUBERNETES_NAMESPACE_SELECTOR);
});
}

updateDevfileFromRemote(devfile: che.IWorkspaceDevfile, attrs: { factoryurl?: string } | undefined): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
</che-label-container>

<!-- Kubernetes namespace selector -->
<che-label-container che-label-name="Kubernetes Namespace" che-label-description="{{importStackController.infrastructureNamespaceHint}}">
<che-label-container
ng-if="importStackController.enabledKubernetesNamespaceSelector"
che-label-name="Kubernetes Namespace"
che-label-description="{{importStackController.infrastructureNamespaceHint}}">
<kubernetes-namespace-selector on-change="importStackController.onInfrastructureNamespaceChange(namespaceId)"></kubernetes-namespace-selector>
</che-label-container>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { IReadyToGoStacksScopeBindings, IReadyToGoStacksScopeOnChange } from './
import { ProjectSourceSelectorService } from './project-source-selector/project-source-selector.service';
import { CheKubernetesNamespace } from '../../../../components/api/che-kubernetes-namespace.factory';
import { CheWorkspace } from '../../../../components/api/workspace/che-workspace.factory';
import { CheDashboardConfigurationService } from '../../../../components/branding/che-dashboard-configuration.service';
import { TogglableFeature } from '../../../../components/branding/che-branding.factory';

/**
* This class is handling the controller for predefined stacks.
Expand All @@ -27,12 +29,13 @@ import { CheWorkspace } from '../../../../components/api/workspace/che-workspace
export class ReadyToGoStacksController implements IReadyToGoStacksScopeBindings {

static $inject = [
'cheDashboardConfigurationService',
'cheKubernetesNamespace',
'cheWorkspace',
'createWorkspaceSvc',
'namespaceSelectorSvc',
'projectSourceSelectorService',
'randomSvc'
'randomSvc',
];

/**
Expand All @@ -53,10 +56,12 @@ export class ReadyToGoStacksController implements IReadyToGoStacksScopeBindings
WORKSPACE_NAME_FORM = 'workspaceName';
infrastructureNamespaceHint: string = '';
ephemeralMode: boolean;
enabledKubernetesNamespaceSelector: boolean = false;

/**
* Injected dependencies.
*/
private cheDashboardConfigurationService: CheDashboardConfigurationService;
private cheKubernetesNamespace: CheKubernetesNamespace;
private cheWorkspace: CheWorkspace;
private createWorkspaceSvc: CreateWorkspaceSvc;
Expand Down Expand Up @@ -101,13 +106,15 @@ export class ReadyToGoStacksController implements IReadyToGoStacksScopeBindings
* Default constructor that is using resource injection
*/
constructor(
cheDashboardConfigurationService: CheDashboardConfigurationService,
cheKubernetesNamespace: CheKubernetesNamespace,
cheWorkspace: CheWorkspace,
createWorkspaceSvc: CreateWorkspaceSvc,
namespaceSelectorSvc: NamespaceSelectorSvc,
projectSourceSelectorService: ProjectSourceSelectorService,
randomSvc: RandomSvc
randomSvc: RandomSvc,
) {
this.cheDashboardConfigurationService = cheDashboardConfigurationService;
this.cheKubernetesNamespace = cheKubernetesNamespace;
this.cheWorkspace = cheWorkspace;
this.createWorkspaceSvc = createWorkspaceSvc;
Expand All @@ -131,6 +138,9 @@ export class ReadyToGoStacksController implements IReadyToGoStacksScopeBindings
this.cheWorkspace.fetchWorkspaceSettings().then((settings: che.IWorkspaceSettings) => {
this.ephemeralMode = settings['che.workspace.persist_volumes.default'] === 'false';
});
this.cheDashboardConfigurationService.ready.then(() => {
this.enabledKubernetesNamespaceSelector = this.cheDashboardConfigurationService.enabledFeature(TogglableFeature.KUBERNETES_NAMESPACE_SELECTOR);
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
</che-label-container>

<!-- Kubernetes namespace selector -->
<che-label-container che-label-name="Kubernetes Namespace" che-label-description="{{readyToGoStacksController.infrastructureNamespaceHint}}">
<che-label-container
ng-if="readyToGoStacksController.enabledKubernetesNamespaceSelector"
che-label-name="Kubernetes Namespace"
che-label-description="{{readyToGoStacksController.infrastructureNamespaceHint}}">
<kubernetes-namespace-selector on-change="readyToGoStacksController.onInfrastructureNamespaceChanged(namespaceId)"></kubernetes-namespace-selector>
</che-label-container>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ describe(`WorkspaceDetailsController >`, () => {
menu: {
disabled: []
},
prefetch: {}
prefetch: {},
features: {
disabled: []
}
};
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {CheService} from '../../../components/api/che-service.factory';
import {PluginRegistry} from '../../../components/api/plugin-registry.factory';
import {WorkspaceDataManager} from '../../../components/api/workspace/workspace-data-manager';
import { ConfirmDialogService } from '../../../components/service/confirm-dialog/confirm-dialog.service';
import { CheDashboardConfigurationService } from '../../../components/branding/che-dashboard-configuration.service';
import { TogglableFeature } from '../../../components/branding/che-branding.factory';

interface IPage {
title: string;
Expand Down Expand Up @@ -84,14 +86,15 @@ export class WorkspaceDetailsService {
static $inject = [
'$log',
'$q',
'cheWorkspace',
'cheDashboardConfigurationService',
'cheNotification',
'ideSvc',
'workspaceDetailsProjectsService',
'cheService',
'chePermissions',
'cheService',
'cheWorkspace',
'confirmDialogService',
'pluginRegistry'
'ideSvc',
'pluginRegistry',
'workspaceDetailsProjectsService',
];

/**
Expand All @@ -102,6 +105,10 @@ export class WorkspaceDetailsService {
* Promises service.
*/
private $q: ng.IQService;
/**
* Dashboard configuration service.
*/
private cheDashboardConfigurationService: CheDashboardConfigurationService;
/**
* Workspace API interaction.
*/
Expand Down Expand Up @@ -156,23 +163,25 @@ export class WorkspaceDetailsService {
constructor (
$log: ng.ILogService,
$q: ng.IQService,
cheWorkspace: CheWorkspace,
cheDashboardConfigurationService: CheDashboardConfigurationService,
cheNotification: CheNotification,
ideSvc: IdeSvc,
workspaceDetailsProjectsService: WorkspaceDetailsProjectsService,
cheService: CheService,
chePermissions: che.api.IChePermissions,
cheService: CheService,
cheWorkspace: CheWorkspace,
confirmDialogService: ConfirmDialogService,
pluginRegistry: PluginRegistry
ideSvc: IdeSvc,
pluginRegistry: PluginRegistry,
workspaceDetailsProjectsService: WorkspaceDetailsProjectsService,
) {
this.$log = $log;
this.$q = $q;
this.cheWorkspace = cheWorkspace;
this.cheDashboardConfigurationService = cheDashboardConfigurationService;
this.cheNotification = cheNotification;
this.cheWorkspace = cheWorkspace;
this.confirmDialogService = confirmDialogService;
this.ideSvc = ideSvc;
this.pluginRegistry = pluginRegistry;
this.workspaceDetailsProjectsService = workspaceDetailsProjectsService;
this.confirmDialogService = confirmDialogService;

this.observable = new Observable<any>();

Expand All @@ -181,7 +190,9 @@ export class WorkspaceDetailsService {
this.observable = new Observable();

cheService.fetchServices().finally(() => {
if (cheService.isServiceAvailable(chePermissions.getPermissionsServicePath())) {
const sharingEnabled = this.cheDashboardConfigurationService.enabledFeature(TogglableFeature.WORKSPACE_SHARING);
const permissionServiceAvailable = cheService.isServiceAvailable(chePermissions.getPermissionsServicePath());
if (sharingEnabled && permissionServiceAvailable) {
this.addPage('Share', '<share-workspace></share-workspace>', 'icon-ic_folder_shared_24px');
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {ConfirmDialogService} from '../../../../components/service/confirm-dialo
import {NamespaceSelectorSvc} from '../../create-workspace/ready-to-go-stacks/namespace-selector/namespace-selector.service';
import {WorkspaceDetailsService} from '../workspace-details.service';
import { CheKubernetesNamespace } from '../../../../components/api/che-kubernetes-namespace.factory';
import { CheDashboardConfigurationService } from '../../../../components/branding/che-dashboard-configuration.service';
import { TogglableFeature } from '../../../../components/branding/che-branding.factory';

const STARTING = WorkspaceStatus[WorkspaceStatus.STARTING];
const RUNNING = WorkspaceStatus[WorkspaceStatus.RUNNING];
Expand All @@ -35,6 +37,7 @@ export class WorkspaceDetailsOverviewController {
'$route',
'$scope',
'$timeout',
'cheDashboardConfigurationService',
'cheKubernetesNamespace',
'cheNotification',
'cheWorkspace',
Expand All @@ -49,12 +52,14 @@ export class WorkspaceDetailsOverviewController {
* Displaying name of infrastructure namespace.
*/
infrastructureNamespace: string;
enabledKubernetesNamespaceSelector: boolean = false;

private $location: ng.ILocationService;
private $q: ng.IQService;
private $route: ng.route.IRouteService;
private $scope: ng.IScope;
private $timeout: ng.ITimeoutService;
private cheDashboardConfigurationService: CheDashboardConfigurationService;
private cheKubernetesNamespace: CheKubernetesNamespace;
private cheNotification: CheNotification;
private cheWorkspace: CheWorkspace;
Expand Down Expand Up @@ -83,6 +88,7 @@ export class WorkspaceDetailsOverviewController {
$route: ng.route.IRouteService,
$scope: ng.IScope,
$timeout: ng.ITimeoutService,
cheDashboardConfigurationService: CheDashboardConfigurationService,
cheKubernetesNamespace: CheKubernetesNamespace,
cheNotification: CheNotification,
cheWorkspace: CheWorkspace,
Expand All @@ -95,6 +101,7 @@ export class WorkspaceDetailsOverviewController {
this.$route = $route;
this.$scope = $scope;
this.$timeout = $timeout;
this.cheDashboardConfigurationService = cheDashboardConfigurationService;
this.cheKubernetesNamespace = cheKubernetesNamespace;
this.cheNotification = cheNotification;
this.cheWorkspace = cheWorkspace;
Expand All @@ -121,6 +128,10 @@ export class WorkspaceDetailsOverviewController {
deRegistrationFn();
});

this.cheDashboardConfigurationService.ready.then(() => {
this.enabledKubernetesNamespaceSelector = this.cheDashboardConfigurationService.enabledFeature(TogglableFeature.KUBERNETES_NAMESPACE_SELECTOR);
});

this.init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
<div che-compile="section.content"></div>
</che-label-container>
<!-- Infrastructure Namespace -->
<che-label-container class="infrastructure-namespace-input-container"
<che-label-container
ng-if="workspaceDetailsOverviewController.enabledKubernetesNamespaceSelector"
class="infrastructure-namespace-input-container"
che-label-name="Kubernetes Namespace"
ng-if="workspaceDetailsOverviewController.infrastructureNamespace">
<che-input
Expand Down
22 changes: 20 additions & 2 deletions dashboard/src/components/branding/che-branding.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface IBrandingDocs {
organization?: string;
general?: string;
converting?: string;
faq?: string;
}
interface IBrandingWorkspace {
priorityStacks?: Array<string>;
Expand All @@ -60,6 +61,14 @@ interface IBrandingConfiguration {
cheCDN: string;
resources: string[];
};
features: {
disabled: TogglableFeature[];
};
}

export enum TogglableFeature {
WORKSPACE_SHARING = 'workspaceSharing',
KUBERNETES_NAMESPACE_SELECTOR = 'kubernetesNamespaceSelector',
}

const ASSET_PREFIX = 'assets/branding/';
Expand Down Expand Up @@ -321,7 +330,8 @@ export class CheBranding {
factory: this.branding.docs && this.branding.docs.factory ? this.branding.docs.factory : DEFAULT_DOCS_FACTORY,
organization: this.branding.docs && this.branding.docs.organization ? this.branding.docs.organization : DEFAULT_DOCS_ORGANIZATION,
general: this.branding.docs && this.branding.docs.general ? this.branding.docs.general : DEFAULT_DOCS_GENERAL,
converting: this.branding.docs && this.branding.docs.converting ? this.branding.docs.converting : DEFAULT_DOCS_CONVERTING
converting: this.branding.docs && this.branding.docs.converting ? this.branding.docs.converting : DEFAULT_DOCS_CONVERTING,
faq: this.branding.docs && this.branding.docs.faq ? this.branding.docs.faq : undefined
};
}

Expand All @@ -344,10 +354,18 @@ export class CheBranding {
menu: {
disabled:
this.branding.configuration &&
this.branding.configuration.menu && this.branding.configuration.menu.disabled
this.branding.configuration.menu && this.branding.configuration.menu.disabled
? this.branding.configuration.menu.disabled
: []
},
features: {
disabled:
this.branding.configuration &&
this.branding.configuration.features &&
this.branding.configuration.features.disabled
? this.branding.configuration.features.disabled
: []
},
prefetch: {
cheCDN: this.branding.configuration &&
this.branding.configuration.prefetch &&
Expand Down
Loading