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

refactor(cluster): allow cluster pod header to be customized #4127

Merged
merged 2 commits into from
Sep 22, 2017
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
60 changes: 13 additions & 47 deletions app/scripts/modules/core/src/cluster/ClusterPod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import * as React from 'react';
import autoBindMethods from 'class-autobind-decorator';
import { orderBy } from 'lodash';

import { NgReact, ReactInjector } from 'core/reactShims';
import { ReactInjector } from 'core/reactShims';
import { ServerGroup } from 'core/serverGroup/ServerGroup';
import { Application } from 'core/application';
import { EntityNotifications } from 'core/entityTag/notifications/EntityNotifications';
import { HealthCounts } from 'core/healthCounts';
import { IServerGroup } from 'core/domain';
import { Tooltip } from 'core/presentation';
import { IClusterSubgroup, IServerGroupSubgroup } from './filter/clusterFilter.service';
import { ClusterPodTitleWrapper } from 'core/cluster/ClusterPodTitleWrapper';

export interface IClusterPodProps {
grouping: IClusterSubgroup;
Expand Down Expand Up @@ -43,12 +43,22 @@ export class ClusterPod extends React.Component<IClusterPodProps, IClusterPodSta

public render() {
const { grouping } = this.props;
const { showCloseButton } = this.state;

return (
<div className="row rollup-entry sub-group">
<div className="sticky-header">
<div className="rollup-summary">
{this.renderPodTitle()}
<ClusterPodTitleWrapper {...this.props} />
{showCloseButton && (
<div className="remove-button">
<Tooltip value="Remove cluster from view">
<button className="btn btn-link" onClick={this.close}>
<span className="glyphicon glyphicon-remove"/>
</button>
</Tooltip>
</div>
)}
</div>
</div>

Expand All @@ -59,50 +69,6 @@ export class ClusterPod extends React.Component<IClusterPodProps, IClusterPodSta
);
}

private renderPodTitle() {
const { AccountTag } = NgReact;
const { grouping, application, parentHeading } = this.props;
const { showCloseButton } = this.state;

return (
<div className="rollup-title-cell">
<div className="heading-tag">
<AccountTag account={parentHeading} />
</div>

<div className="pod-center">
<div>
<span className="glyphicon glyphicon-th"/>
{' ' + grouping.heading}
</div>

<EntityNotifications
entity={grouping}
application={application}
placement="top"
hOffsetPercent="90%"
entityType="cluster"
pageLocation="pod"
className="inverse"
onUpdate={application.serverGroups.refresh}
/>
</div>

<HealthCounts container={grouping.cluster.instanceCounts}/>

{showCloseButton && (
<div className="remove-button">
<Tooltip value="Remove cluster from view">
<button className="btn btn-link" onClick={this.close}>
<span className="glyphicon glyphicon-remove"/>
</button>
</Tooltip>
</div>
)}
</div>
)
}

private renderSubGroup(subgroup: IServerGroupSubgroup) {
const { grouping, application, sortFilter } = this.props;
const sortedServerGroups = orderBy(subgroup.serverGroups, ['name'], ['desc']);
Expand Down
24 changes: 24 additions & 0 deletions app/scripts/modules/core/src/cluster/ClusterPodTitleWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import autoBindMethods from 'class-autobind-decorator';

import { Application } from 'core/application/application.model';
import { ReactInjector } from 'core/reactShims';
import { DefaultClusterPodTitle } from './DefaultClusterPodTitle';
import { IClusterSubgroup } from './filter/clusterFilter.service';

export interface IClusterPodTitleProps {
grouping: IClusterSubgroup;
application: Application;
parentHeading: string;
}

@autoBindMethods
export class ClusterPodTitleWrapper extends React.Component<IClusterPodTitleProps> {
public render(): React.ReactElement<ClusterPodTitleWrapper> {
const { overrideRegistry } = ReactInjector;
const config = overrideRegistry.getComponent('clusterPodTitle');
const Title = config || DefaultClusterPodTitle;

return <Title {...this.props} />;
}
}
45 changes: 45 additions & 0 deletions app/scripts/modules/core/src/cluster/DefaultClusterPodTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as React from 'react';
import autoBindMethods from 'class-autobind-decorator';

import { NgReact } from 'core/reactShims';
import { EntityNotifications } from 'core/entityTag/notifications/EntityNotifications';
import { HealthCounts } from 'core/healthCounts';
import { IClusterPodTitleProps } from './ClusterPodTitleWrapper';

@autoBindMethods
export class DefaultClusterPodTitle extends React.Component<IClusterPodTitleProps> {

public render(): React.ReactElement<DefaultClusterPodTitle> {
const { AccountTag } = NgReact;
const { grouping, application, parentHeading } = this.props;

return (
<div className="rollup-title-cell">
<div className="heading-tag">
<AccountTag account={parentHeading} />
</div>

<div className="pod-center">
<div>
<span className="glyphicon glyphicon-th"/>
{' ' + grouping.heading}
</div>

<EntityNotifications
entity={grouping}
application={application}
placement="top"
hOffsetPercent="90%"
entityType="cluster"
pageLocation="pod"
className="inverse"
onUpdate={application.serverGroups.refresh}
/>
</div>

<HealthCounts container={grouping.cluster.instanceCounts}/>

</div>
)
}
}
2 changes: 2 additions & 0 deletions app/scripts/modules/core/src/cluster/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './ClusterPodTitleWrapper';
export * from './ClusterRuleMatcher';
export * from './cluster.service';
export * from './task.matcher';
export * from './filter/clusterFilter.service';
25 changes: 14 additions & 11 deletions app/scripts/modules/core/src/cluster/rollups.less
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ table.instances {
font-size: 110%;
margin: 0;
width: 100%;
display: flex;

.remove-button {
display: flex;
flex: 0 0 auto;
padding: 0 5px;
margin-left: 2px;
text-align: center;
button {
margin-right: 0;
}
background-color: var(--color-accent-g2);
}

.tooltip {
text-transform: none;
Expand All @@ -163,17 +176,7 @@ table.instances {
}

.rollup-title-cell {
.remove-button {
display: flex;
flex: 0 0 auto;
padding: 0 5px;
margin-left: 2px;
text-align: center;
button {
margin-right: 0;
}
background-color: var(--color-accent-g2);
}
flex: 1;
display: flex;
height: 36px;
line-height: 36px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { module } from 'angular';

import { ADD_ENTITY_TAG_LINKS_COMPONENT } from './addEntityTagLinks.component';
import { DATA_SOURCE_NOTIFICATIONS } from './notifications/DataSourceNotifications';
import { ENTITY_NOTIFICATIONS } from './notifications/EntityNotifications';
import { ENTITY_NOTIFICATIONS } from './notifications/entityNotifications.component';
import { ENTITY_SOURCE_COMPONENT } from './entitySource.component';
import { ENTITY_TAG_WRITER } from './entityTags.write.service';

Expand Down
1 change: 0 additions & 1 deletion app/scripts/modules/core/src/entityTag/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export * from './clusterTargetBuilder.service';
export * from './entityTags.read.service';
export * from './entityTags.write.service';
export * from './notifications';

Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { module } from 'angular';

import { react2angular } from 'react2angular';
import * as React from 'react';
import autoBindMethods from 'class-autobind-decorator';

Expand Down Expand Up @@ -98,37 +95,3 @@ export class EntityNotifications extends React.Component<IEntityNotificationsPro
);
}
}


export const ENTITY_NOTIFICATIONS = 'spinnaker.core.entityTag.alerts.entitynotifications';
const ngmodule = module(ENTITY_NOTIFICATIONS, []);

ngmodule.component('entityNotificationsWrapper', react2angular(EntityNotifications, [
'entity', 'application', 'placement', 'hOffsetPercent', 'className', 'pageLocation', 'entityType', 'onUpdate'
]));


ngmodule.component('entityNotifications', {
template: `
<entity-notifications-wrapper
entity="$ctrl.entity"
application="$ctrl.application"
placement="$ctrl.placement"
h-offset-percent="$ctrl.hOffsetPercent"
class-name="$ctrl.className"
entity-type="$ctrl.entityType"
page-location="$ctrl.pageLocation"
on-update="$ctrl.onUpdate"
></entity-notifications-wrapper>
`,
bindings: {
entity: '<',
application: '<',
placement: '@',
hOffsetPercent: '@',
className: '@',
entityType: '@',
pageLocation: '@',
onUpdate: '&',
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { module } from 'angular';

import { react2angular } from 'react2angular';

import { EntityNotifications } from './EntityNotifications';

export const ENTITY_NOTIFICATIONS = 'spinnaker.core.entityTag.alerts.entitynotifications';
const ngmodule = module(ENTITY_NOTIFICATIONS, []);

ngmodule.component('entityNotificationsWrapper', react2angular(EntityNotifications, [
'entity', 'application', 'placement', 'hOffsetPercent', 'className', 'pageLocation', 'entityType', 'onUpdate'
]));


ngmodule.component('entityNotifications', {
template: `
<entity-notifications-wrapper
entity="$ctrl.entity"
application="$ctrl.application"
placement="$ctrl.placement"
h-offset-percent="$ctrl.hOffsetPercent"
class-name="$ctrl.className"
entity-type="$ctrl.entityType"
page-location="$ctrl.pageLocation"
on-update="$ctrl.onUpdate"
></entity-notifications-wrapper>
`,
bindings: {
entity: '<',
application: '<',
placement: '@',
hOffsetPercent: '@',
className: '@',
entityType: '@',
pageLocation: '@',
onUpdate: '&',
}
});
3 changes: 3 additions & 0 deletions app/scripts/modules/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export * from './deploymentStrategy';
export * from './domain';

export * from './entityTag';
// TODO: try pushing this export back down; for some unknown reason, it causes grief with the library (the export
// is found by the TS compiler, but not at runtime)
export * from './entityTag/notifications/EntityNotifications';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: This is weird and I don't like it or understand it but I spent almost two hours trying to find a better workaround and I couldn't.


export * from './filterModel';

Expand Down
1 change: 1 addition & 0 deletions app/scripts/modules/core/src/widgets/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './cluster/clusterMatches.component';
export * from './CustomDropdown';
export * from './Keys';
export * from './notifier/notifier.service';
Expand Down