Skip to content
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
20 changes: 10 additions & 10 deletions __tests__/tests/components/StateBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('<StateBadge />', () => {
.childAt(0)
.text()
).toEqual('Open');
expect(wrapper.prop('style')[2].backgroundColor).toEqual(colors.green);
expect(wrapper.prop('color')).toEqual(colors.green);
});

it('correctly renders with closed issue', () => {
Expand All @@ -33,7 +33,7 @@ describe('<StateBadge />', () => {
.childAt(0)
.text()
).toEqual('Closed');
expect(wrapper.prop('style')[2].backgroundColor).toEqual(colors.red);
expect(wrapper.prop('color')).toEqual(colors.red);
});

it('correctly renders with open pull request', () => {
Expand All @@ -45,7 +45,7 @@ describe('<StateBadge />', () => {
.childAt(0)
.text()
).toEqual('Open');
expect(wrapper.prop('style')[2].backgroundColor).toEqual(colors.green);
expect(wrapper.prop('color')).toEqual(colors.green);
});

it('correctly renders with closed pull request', () => {
Expand All @@ -57,7 +57,7 @@ describe('<StateBadge />', () => {
.childAt(0)
.text()
).toEqual('Closed');
expect(wrapper.prop('style')[2].backgroundColor).toEqual(colors.red);
expect(wrapper.prop('color')).toEqual(colors.red);
});

it('correctly renders with merged pull request', () => {
Expand All @@ -71,7 +71,7 @@ describe('<StateBadge />', () => {
.childAt(0)
.text()
).toEqual('Merged');
expect(wrapper.prop('style')[2].backgroundColor).toEqual(colors.purple);
expect(wrapper.prop('color')).toEqual(colors.purple);
});

it('correctly renders without issue', () => {
Expand All @@ -83,7 +83,7 @@ describe('<StateBadge />', () => {
.childAt(0)
.text()
).toEqual('Merged');
expect(wrapper.prop('style')[2].backgroundColor).toEqual(colors.purple);
expect(wrapper.prop('color')).toEqual(colors.purple);
});

it('correctly renders with open type', () => {
Expand All @@ -95,7 +95,7 @@ describe('<StateBadge />', () => {
.childAt(0)
.text()
).toEqual('');
expect(wrapper.prop('style')[2].backgroundColor).toEqual(colors.green);
expect(wrapper.prop('color')).toEqual(colors.green);
});

it('correctly renders with closed type', () => {
Expand All @@ -107,7 +107,7 @@ describe('<StateBadge />', () => {
.childAt(0)
.text()
).toEqual('');
expect(wrapper.prop('style')[2].backgroundColor).toEqual(colors.red);
expect(wrapper.prop('color')).toEqual(colors.red);
});

it('correctly renders with closed type', () => {
Expand All @@ -119,7 +119,7 @@ describe('<StateBadge />', () => {
.childAt(0)
.text()
).toEqual('');
expect(wrapper.prop('style')[2].backgroundColor).toEqual(colors.purple);
expect(wrapper.prop('color')).toEqual(colors.purple);
});

it('correctly renders with custom text', () => {
Expand All @@ -133,6 +133,6 @@ describe('<StateBadge />', () => {
.childAt(0)
.text()
).toEqual('test text');
expect(wrapper.prop('style')[2].backgroundColor).toEqual(colors.green);
expect(wrapper.prop('color')).toEqual(colors.green);
});
});
10 changes: 1 addition & 9 deletions src/components/issue-description.component.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { StyleSheet, ActivityIndicator } from 'react-native';
import { ActivityIndicator } from 'react-native';
import { ListItem } from 'react-native-elements';
import Parse from 'parse-diff';
import styled from 'styled-components';
Expand All @@ -15,13 +15,6 @@ import { translate, relativeTimeToNow } from 'utils';
import { colors, fonts, normalize } from 'config';
import { v3 } from 'api';

const styles = StyleSheet.create({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why was this removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was used just for the Badge styles so I removed it. I don't think is needed here, also styled-components are already imported.
Also the styles defined for the Badge don't change the UI so they are useless for what I can saw.

badge: {
alignItems: 'flex-end',
justifyContent: 'center',
},
});

const HeaderContainer = styled.View`
flex-direction: row;
align-items: center;
Expand Down Expand Up @@ -164,7 +157,6 @@ export class IssueDescription extends Component {
(issue.pull_request &&
!isPendingCheckMerge && (
<StateBadge
style={styles.badge}
issue={issue}
isMerged={isMerged && issue.pull_request}
locale={locale}
Expand Down
58 changes: 23 additions & 35 deletions src/components/state-badge.component.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import styled from 'styled-components';

import { colors, fonts, normalize } from 'config';
import { translate } from 'utils';
Expand All @@ -13,28 +13,17 @@ type Props = {
locale: string,
};

const styles = StyleSheet.create({
badge: {
padding: 12,
paddingTop: 3,
paddingBottom: 3,
borderRadius: 20,
},
mergedIssue: {
backgroundColor: colors.purple,
},
openIssue: {
backgroundColor: colors.green,
},
closedIssue: {
backgroundColor: colors.red,
},
text: {
fontSize: normalize(12),
...fonts.fontPrimarySemiBold,
color: colors.white,
},
});
const Badge = styled.View`
padding: 3px 12px;
border-radius: 20px;
background-color: ${props => props.color};
`;

const BadgeText = styled.Text`
color: ${colors.white};
font-size: ${normalize(12)};
${fonts.fontPrimarySemiBold};
`;

export const StateBadge = ({
issue,
Expand All @@ -58,19 +47,18 @@ export const StateBadge = ({
issueText = translate('issue.main.states.closed', locale);
}

let issueStyle = {};

if (issueState === 'merged') {
issueStyle = styles.mergedIssue;
} else if (issueState === 'open') {
issueStyle = styles.openIssue;
} else if (issueState === 'closed') {
issueStyle = styles.closedIssue;
}
const stateColor = {
merged: colors.purple,
open: colors.green,
closed: colors.red,
};
const issueStateColor = stateColor[issueState]
? stateColor[issueState]
: colors.gray;

return (
<View style={[styles.badge, style, issueStyle]}>
<Text style={styles.text}>{issueText}</Text>
</View>
<Badge color={issueStateColor} style={style}>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You are not passing style anymore from issue-description.component.js, but you're still using the prop here .. Could you give it a second look?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I thought to get completely rid of the style prop but it could still be useful in case there is a need to override something from a parent component without modifying again this one instead.

But it's up for discussion, don't know if it is really needed or not so I left it there 😆

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Prop style is also used in repository-section-title.component.js, which is a useless component. I remembered @housseindjirdeh confirmed that in somewhere, but I forgot the detail issue/pr number. I will collect feedbacks in #725.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it was on Gitter, I added the relevant screenshot in the issue you opened.

<BadgeText>{issueText}</BadgeText>
</Badge>
);
};