Skip to content

Commit

Permalink
Merge pull request #885 from jhsu/getFirst
Browse files Browse the repository at this point in the history
only construct an element when getFirst does not
  • Loading branch information
ogupte authored Jan 30, 2018
2 parents 4d6e621 + c9e50c8 commit 6ad6cdd
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 37 deletions.
8 changes: 3 additions & 5 deletions src/components/BarChart/BarChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,9 @@ const BarChart = createClass({
: yAxisFinalFormatter;

if (_.isEmpty(data) || width < 1 || height < 1 || isLoading) {
const emptyStateWrapper = getFirst(
this.props,
BarChart.EmptyStateWrapper,
<BarChart.EmptyStateWrapper Title="You have no data." />
);
const emptyStateWrapper =
getFirst(this.props, BarChart.EmptyStateWrapper) ||
<BarChart.EmptyStateWrapper Title="You have no data." />;

return (
<EmptyStateWrapper
Expand Down
8 changes: 3 additions & 5 deletions src/components/DataTable/DataTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,12 @@ const DataTable = createClass({
childComponentElement.type === DataTable.ColumnGroup
);

const emptyStateWrapper = getFirst(
this.props,
DataTable.EmptyStateWrapper,
const emptyStateWrapper =
getFirst(this.props, DataTable.EmptyStateWrapper) ||
<DataTable.EmptyStateWrapper
Title="No items found."
Body="Try creating a new object or removing a filter."
/>
);
/>;

const fillerRowCount = _.clamp(minRows - _.size(data), 0, Infinity);

Expand Down
8 changes: 3 additions & 5 deletions src/components/DateSelect/DateSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,9 @@ const DateSelect = createClass({
const { cursor } = this.state;
const isRangeSameDay = DateUtils.isSameDay(from, to);

const calendarMonth = getFirst(
this.props,
DateSelect.CalendarMonth,
<DateSelect.CalendarMonth />
);
const calendarMonth =
getFirst(this.props, DateSelect.CalendarMonth) ||
<DateSelect.CalendarMonth />;
const monthsShown = clampMonthsShown(monthsShownRaw);

/* istanbul ignore next */
Expand Down
8 changes: 3 additions & 5 deletions src/components/InfiniteSlidePanel/InfiniteSlidePanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,9 @@ const InfiniteSlidePanel = createClass({
...passThroughs
} = this.props;

const slide = getFirst(
this.props,
InfiniteSlidePanel.Slide,
<InfiniteSlidePanel.Slide>{children}</InfiniteSlidePanel.Slide>
);
const slide =
getFirst(this.props, InfiniteSlidePanel.Slide) ||
<InfiniteSlidePanel.Slide>{children}</InfiniteSlidePanel.Slide>;
const slideChildRenderFunction = slide.props.children;
if (!_.isFunction(slideChildRenderFunction)) {
throw new Error(
Expand Down
8 changes: 3 additions & 5 deletions src/components/LineChart/LineChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,9 @@ const LineChart = createClass({
const xPoints = _.map(_.keys(xPointMap), _.toNumber);

if (_.isEmpty(data) || width < 1 || height < 1 || isLoading) {
const emptyStateWrapper = getFirst(
this.props,
LineChart.EmptyStateWrapper,
<LineChart.EmptyStateWrapper Title="You have no data." />
);
const emptyStateWrapper =
getFirst(this.props, LineChart.EmptyStateWrapper) ||
<LineChart.EmptyStateWrapper Title="You have no data." />;

return (
<EmptyStateWrapper
Expand Down
3 changes: 2 additions & 1 deletion src/components/LoadingIndicator/LoadingIndicator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const LoadingIndicator = createClass({

const { LoadingMessage } = LoadingIndicator;

const messageElement = getFirst(props, LoadingMessage, <LoadingMessage />);
const messageElement =
getFirst(props, LoadingMessage) || <LoadingMessage />;
const otherChildren = rejectTypes(children, LoadingMessage);

return (
Expand Down
7 changes: 2 additions & 5 deletions src/components/SearchField/SearchField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,8 @@ const SearchField = createClass({
value,
};

const textFieldElement = getFirst(
props,
TextField,
<TextField {...textFieldProps} />
);
const textFieldElement =
getFirst(props, TextField) || <TextField {...textFieldProps} />;
const isIconActive = _.isUndefined(isValid)
? !_.isEmpty(_.get(textFieldElement, 'props.value'))
: isValid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,11 @@ const SearchableMultiSelect = createClass({
'props',
{}
);
const selectionLabel = getFirst(
props,
SearchableMultiSelect.SelectionLabel,
const selectionLabel =
getFirst(props, SearchableMultiSelect.SelectionLabel) ||
<SearchableMultiSelect.SelectionLabel>
Selected
</SearchableMultiSelect.SelectionLabel>
);
</SearchableMultiSelect.SelectionLabel>;
const isSmall = responsiveMode === 'small';

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/SearchableSelect/SearchableSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ const SearchableSelect = createClass({
const { flattenedOptionsData } = this.state;

const searchFieldProps = _.get(
getFirst(props, SearchField, <SearchField />),
getFirst(props, SearchField) || <SearchField />,
'props'
);
const placeholderProps = _.first(
Expand Down

0 comments on commit 6ad6cdd

Please sign in to comment.