Skip to content

Commit 818bb95

Browse files
feat(ProjectSettingsForm): add project labels
1 parent c03d868 commit 818bb95

File tree

4 files changed

+47
-29
lines changed

4 files changed

+47
-29
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React, { Component } from 'react'
2+
import { Panel } from 'react-bootstrap'
3+
4+
import FeedLabel from '../../common/containers/FeedLabel'
5+
import { Project } from '../../types'
6+
7+
import LabelEditorModal from './LabelEditorModal'
8+
9+
export default class LabelPanel extends Component<{ project: Project; }> {
10+
_onClickNewLabel = () => this.refs.newLabelModal.open();
11+
12+
render () {
13+
const {large, project} = this.props
14+
const { labels, id: projectId } = project
15+
16+
let labelBody = (
17+
<div className='noLabelsMessage' >
18+
There are no labels in this project.
19+
</div>
20+
)
21+
if (labels.length > 0) {
22+
labelBody = labels.map((label) => (
23+
<FeedLabel key={label.id} label={label} />
24+
))
25+
}
26+
27+
return (
28+
<Panel header={<h3>Labels</h3>}>
29+
<div className={`feedLabelContainer ${large ? 'large' : ''}`}>
30+
<LabelEditorModal ref='newLabelModal' projectId={projectId} />
31+
<button className='newLabel' onClick={this._onClickNewLabel}>Add a new label</button>
32+
{labelBody}
33+
</div>
34+
</Panel>
35+
)
36+
}
37+
}

lib/manager/components/ProjectSettingsForm.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ import ConfirmModal from '../../common/components/ConfirmModal'
3030
import TimezoneSelect from '../../common/components/TimezoneSelect'
3131
import {getComponentMessages} from '../../common/util/config'
3232
import {parseBounds, validationState} from '../util'
33-
3433
import type {Bounds, Project} from '../../types'
3534

35+
import LabelPanel from './LabelPanel'
36+
3637
type ProjectModel = {
3738
autoFetchFeeds?: boolean,
3839
autoFetchHour?: number,
@@ -235,7 +236,7 @@ export default class ProjectSettingsForm extends Component<Props, State> {
235236
_getChanges = () => {
236237
const {model} = this.state
237238
const {project} = this.props
238-
let changes: any = {}
239+
const changes: any = {}
239240
Object.keys(model).map(k => {
240241
if (model[k] !== project[k]) {
241242
changes[k] = model[k]
@@ -252,7 +253,7 @@ export default class ProjectSettingsForm extends Component<Props, State> {
252253
}
253254

254255
render () {
255-
const {editDisabled, showDangerZone} = this.props
256+
const {editDisabled, showDangerZone, project} = this.props
256257
const {model, validation} = this.state
257258
const {autoFetchHour, autoFetchMinute} = model
258259
const autoFetchChecked = model.autoFetchFeeds
@@ -359,6 +360,7 @@ export default class ProjectSettingsForm extends Component<Props, State> {
359360
</ListGroupItem>
360361
</ListGroup>
361362
</Panel>
363+
<LabelPanel project={project} large />
362364
{showDangerZone &&
363365
<Panel bsStyle='danger' header={<h3>Danger zone</h3>}>
364366
<ListGroup fill>

lib/manager/components/ProjectViewer.js

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ import WatchButton from '../../common/containers/WatchButton'
2727
import {getComponentMessages, getConfigProperty, isModuleEnabled} from '../../common/util/config'
2828
import DeploymentsPanel from '../containers/DeploymentsPanel'
2929
import FeedSourceTable from '../containers/FeedSourceTable'
30-
import FeedLabel from '../../common/containers/FeedLabel'
3130
import type {Props as ContainerProps} from '../containers/ActiveProjectViewer'
3231
import type {Feed, Project} from '../../types'
3332
import type {ManagerUserState} from '../../types/reducers'
3433

35-
import LabelEditorModal from './LabelEditorModal'
3634
import CreateFeedSource from './CreateFeedSource'
3735
import ProjectSettings from './ProjectSettings'
36+
import LabelPanel from './LabelPanel'
3837

3938
type Props = ContainerProps & {
4039
activeComponent: ?string,
@@ -309,30 +308,6 @@ class ProjectSummaryPanel extends Component<{feedSources: Array<Feed>, project:
309308
}
310309
}
311310

312-
class LabelPanel extends Component<{project: Project}> {
313-
_onClickNewLabel = () => this.refs.newLabelModal.open()
314-
render () {
315-
const { labels, id: projectId } = this.props.project
316-
317-
let labelBody = 'There are no labels in this project.'
318-
if (labels.length > 0) {
319-
labelBody = labels.map((label) => (
320-
<FeedLabel key={label.id} label={label} />
321-
))
322-
}
323-
324-
return (
325-
<Panel header={<h3>Labels</h3>}>
326-
<div className='feedLabelContainer'>
327-
<LabelEditorModal ref='newLabelModal' projectId={projectId} />
328-
<button className='newLabel' onClick={this._onClickNewLabel}>Add a new label</button>
329-
{labelBody}
330-
</div>
331-
</Panel>
332-
)
333-
}
334-
}
335-
336311
const ExplanatoryPanel = ({ project }) => {
337312
// If user has more than 3 labels, hide the feed source instruction
338313
if (project.labels.length <= 3) {

lib/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ td.feed-source-info {
156156
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
157157
grid-gap: 15px;
158158
}
159+
.feedLabelContainer.large .noLabelsMessage {
160+
/* Match the margin of the new labels "button" */
161+
margin: 0 0 10px 0;
162+
}
159163
.feedSourceLabelRow {
160164
display: inline-flex;
161165
width: 100%;

0 commit comments

Comments
 (0)