Skip to content

Commit

Permalink
only construct an element when getFirst does not, closes #879.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Hsu committed Jan 22, 2018
1 parent 3486f6e commit dfcaa0c
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 @@ -335,11 +335,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 @@ -226,14 +226,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 @@ -306,11 +306,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 @@ -91,11 +91,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 @@ -500,11 +500,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 @@ -58,7 +58,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 @@ -135,11 +135,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 @@ -470,13 +470,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 @@ -321,7 +321,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 dfcaa0c

Please sign in to comment.