Skip to content

Commit

Permalink
Display port names in task view (#24)
Browse files Browse the repository at this point in the history
Display port names in task view
  • Loading branch information
kamaradclimber authored Jul 17, 2019
2 parents 276f74a + 4760286 commit c30acc6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/js/components/AppPageComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ var AppPageComponent = React.createClass({
fetchState={state.fetchState}
getTaskHealthMessage={this.getTaskHealthMessage}
hasHealth={Object.keys(model.healthChecks).length > 0}
portDefinitions={model.portDefinitions}
labels={model.labels}
tasks={model.tasks} />
</TabPaneComponent>
Expand Down
2 changes: 2 additions & 0 deletions src/js/components/TaskListComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var TaskListComponent = React.createClass({
itemsPerPage: React.PropTypes.number.isRequired,
labels: React.PropTypes.object.isRequired,
onTaskToggle: React.PropTypes.func.isRequired,
portDefinitions: React.PropTypes.object.isRequired,
selectedTasks: React.PropTypes.object.isRequired,
tasks: React.PropTypes.array.isRequired,
toggleAllTasks: React.PropTypes.func.isRequired
Expand Down Expand Up @@ -71,6 +72,7 @@ var TaskListComponent = React.createClass({
onToggle={props.onTaskToggle}
sortKey={sortKey}
task={task}
portDefinitions={props.portDefinitions}
labels={props.labels}
taskHealthMessage={props.getTaskHealthMessage(task.id)} />
);
Expand Down
19 changes: 17 additions & 2 deletions src/js/components/TaskListItemComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ function joinNodes(nodes, separator = ", ") {
});
}

function getPortDecoration(portDefinitions, index, port) {
const LABEL_NAME = "name";
if (portDefinitions == null || portDefinitions[index] == null) {
return port;
}
if (LABEL_NAME in portDefinitions[index]) {
return portDefinitions[index][LABEL_NAME];
} else {
return port;
}
}

var TaskListItemComponent = React.createClass({
displayName: "TaskListItemComponent",

Expand All @@ -33,6 +45,7 @@ var TaskListItemComponent = React.createClass({
isActive: React.PropTypes.bool.isRequired,
labels: React.PropTypes.object.isRequired,
onToggle: React.PropTypes.func.isRequired,
portDefinitions: React.PropTypes.object.isRequired,
sortKey: React.PropTypes.string,
task: React.PropTypes.object.isRequired,
taskHealthMessage: React.PropTypes.string
Expand All @@ -50,11 +63,12 @@ var TaskListItemComponent = React.createClass({
if (ports != null && ports.length === 1) {
const scheme = ServiceSchemeUtil
.getServiceSchemeFromLabels(props.labels, 0);
const name = getPortDecoration(props.portDefinitions, 0, ports[0]);
return (
<a className="text-muted"
href={`${scheme}://${task.host}:${ports[0]}`}
target="_blank">
{`${task.host}:${ports[0]}`}
{`${task.host}:${name}`}
</a>
);
}
Expand All @@ -63,12 +77,13 @@ var TaskListItemComponent = React.createClass({
let portNodes = ports.map(function (port, i) {
const scheme = ServiceSchemeUtil
.getServiceSchemeFromLabels(props.labels, i);
const name = getPortDecoration(props.portDefinitions, i, port);
return (
<a key={`${task.host}:${port}`}
className="text-muted"
href={`${scheme}://${task.host}:${port}`}
target="_blank">
{port}
{name}
</a>
);
});
Expand Down
2 changes: 2 additions & 0 deletions src/js/components/TaskViewComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var TaskViewComponent = React.createClass({
getTaskHealthMessage: React.PropTypes.func.isRequired,
hasHealth: React.PropTypes.bool,
labels: React.PropTypes.object.isRequired,
portDefinitions: React.PropTypes.object.isRequired,
tasks: React.PropTypes.array.isRequired
},

Expand Down Expand Up @@ -231,6 +232,7 @@ var TaskViewComponent = React.createClass({
onTaskToggle={this.onTaskToggle}
itemsPerPage={this.state.itemsPerPage}
labels={this.props.labels}
portDefinitions={this.props.portDefinitions}
selectedTasks={this.state.selectedTasks}
tasks={this.props.tasks}
toggleAllTasks={this.toggleAllTasks} />
Expand Down

0 comments on commit c30acc6

Please sign in to comment.