Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only construct an element when getFirst does not #885

Merged
merged 4 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from 3 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
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