Skip to content

Commit

Permalink
feature(core): Add ability to override application icon (#3917)
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Reynolds authored Jul 14, 2017
1 parent d9ae9a1 commit df1bb9f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import autoBindMethods from 'class-autobind-decorator';

import { Application } from 'core/application';
import { ApplicationIcon, IApplicationIconProps } from './ApplicationIcon';
import { NgReact, ReactInjector } from 'core/reactShims';
import { Refresher } from 'core/presentation/refresher/Refresher';
import { Tooltip } from 'core/presentation/Tooltip';
Expand Down Expand Up @@ -71,6 +72,9 @@ export class ApplicationComponent extends React.Component<IApplicationComponentP
}

public render() {
// Get overridden application icon renderer
const Icon: React.ComponentClass<IApplicationComponentProps> = ReactInjector.overrideRegistry.getComponent<IApplicationIconProps>('applicationIcon') || ApplicationIcon;

const { ApplicationNav, ApplicationNavSecondary } = NgReact;

const NotFound = this.props.app.notFound ? (
Expand All @@ -82,7 +86,7 @@ export class ApplicationComponent extends React.Component<IApplicationComponentP

const Found = !this.props.app.notFound ? (
<h2>
<i className="fa fa-window-maximize"/>
<Icon app={this.props.app} />
<span className="application-name">{this.props.app.name}</span>
<Refresher
refreshing={this.state.refreshing}
Expand Down
13 changes: 13 additions & 0 deletions app/scripts/modules/core/src/application/ApplicationIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';

import { Application } from 'core/application';

export interface IApplicationIconProps {
app: Application;
}

export class ApplicationIcon extends React.Component<IApplicationIconProps> {
public render() {
return <i className="fa fa-window-maximize"/>;
}
}
1 change: 1 addition & 0 deletions app/scripts/modules/core/src/application/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './ApplicationIcon';
export * from './application.model';
export * from './applicationModel.builder';
export * from './modal/validation/applicationName.validator';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import {module} from 'angular';
import { module } from 'angular';
import * as React from 'react';

export class OverrideRegistry {
private templateOverrides: Map<string, string> = new Map();
private componentOverrides: Map<string, React.ComponentClass> = new Map();
private controllerOverrides: Map<string, string> = new Map();

public overrideTemplate(key: string, val: string) {
this.templateOverrides.set(key, val);
}

public overrideComponent(key: string, val: React.ComponentClass) {
this.componentOverrides.set(key, val);
}

public overrideController(key: string, val: string) {
this.controllerOverrides.set(key, val);
}
Expand All @@ -16,6 +22,10 @@ export class OverrideRegistry {
return this.templateOverrides.get(key) || defaultVal;
}

public getComponent<T>(key: string) {
return this.componentOverrides.get(key) as React.ComponentClass<T>;
}

public getController(key: string) {
return this.controllerOverrides.get(key) || key;
}
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/modules/core/src/reactShims/react.injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { InfrastructureSearchService } from '../search/infrastructure/infrastruc
import { LoadBalancerFilterModel } from '../loadBalancer/filter/loadBalancerFilter.model';
import { LoadBalancerFilterService } from '../loadBalancer/filter/loadBalancer.filter.service';
import { ManualJudgmentService } from '../pipeline/config/stages/manualJudgment/manualJudgment.service';
import { OverrideRegistry } from '../overrideRegistry/override.registry';
import { PipelineConfigProvider } from '../pipeline/config/pipelineConfigProvider';
import { PipelineConfigService } from '../pipeline/config/services/pipelineConfig.service';
import { PipelineTemplateService } from '../pipeline/config/templates/pipelineTemplate.service';
Expand Down Expand Up @@ -77,6 +78,7 @@ export class CoreReactInject extends ReactInject {
public get loadBalancerFilterService() { return this.$injector.get('loadBalancerFilterService') as LoadBalancerFilterService; }
public get manualJudgmentService() { return this.$injector.get('manualJudgmentService') as ManualJudgmentService; }
public get modalService() { return this.$injector.get('$uibModal') as IModalService; }
public get overrideRegistry() { return this.$injector.get('overrideRegistry') as OverrideRegistry; }
public get pipelineConfig() { return this.$injector.get('pipelineConfig') as PipelineConfigProvider; }
public get pipelineConfigService() { return this.$injector.get('pipelineConfigService') as PipelineConfigService; }
public get pipelineTemplateService() { return this.$injector.get('pipelineTemplateService') as PipelineTemplateService; }
Expand Down

0 comments on commit df1bb9f

Please sign in to comment.