Skip to content

Commit

Permalink
Fixed #2337 - Support locale for emptyMessage default value
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Nov 4, 2021
1 parent 9c360d7 commit 0cc35e5
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/components/datascroller/DataScroller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { classNames, ObjectUtils } from '../utils/Utils';
import { localeOption } from '../api/Api';

export class DataScroller extends Component {

Expand All @@ -15,7 +16,7 @@ export class DataScroller extends Component {
style: null,
className: null,
onLazyLoad: null,
emptyMessage: 'No records found',
emptyMessage: null,
itemTemplate: null,
header: null,
footer: null,
Expand Down Expand Up @@ -203,7 +204,7 @@ export class DataScroller extends Component {
}

renderEmptyMessage() {
const content = ObjectUtils.getJSXElement(this.props.emptyMessage, this.props);
const content = ObjectUtils.getJSXElement(this.props.emptyMessage, this.props) || localeOption('emptyMessage');

return <li>{content}</li>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/datatable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class DataTable extends Component {
sortMode: 'single',
defaultSortOrder: 1,
removableSort: false,
emptyMessage: 'No records found',
emptyMessage: null,
selectionMode: null,
dragSelection: false,
cellSelection: false,
Expand Down
3 changes: 2 additions & 1 deletion src/components/datatable/TableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
import { BodyRow } from './BodyRow';
import { classNames, DomHandler, ObjectUtils } from '../utils/Utils';
import { RowTogglerButton } from './RowTogglerButton';
import { localeOption } from '../api/Api';

export class TableBody extends Component {

Expand Down Expand Up @@ -804,7 +805,7 @@ export class TableBody extends Component {
renderEmptyContent() {
if (!this.props.loading) {
const colSpan = this.getColumnsLength();
const content = ObjectUtils.getJSXElement(this.props.emptyMessage, { props: this.props, frozen: this.props.frozenRow });
const content = ObjectUtils.getJSXElement(this.props.emptyMessage, { props: this.props, frozen: this.props.frozenRow }) || localeOption('emptyMessage');

return (
<tr className="p-datatable-emptymessage" role="row">
Expand Down
7 changes: 5 additions & 2 deletions src/components/dataview/DataView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import { Paginator } from '../paginator/Paginator';
import { ObjectUtils, classNames } from '../utils/Utils';
import { Ripple } from '../ripple/Ripple';
import { localeOption } from '../api/Api';

export class DataViewLayoutOptions extends Component {

Expand Down Expand Up @@ -98,7 +99,7 @@ export class DataView extends Component {
pageLinkSize: 5,
rowsPerPageOptions: null,
currentPageReportTemplate: '({currentPage} of {totalPages})',
emptyMessage: 'No records found',
emptyMessage: null,
sortField: null,
sortOrder: null,
style: null,
Expand Down Expand Up @@ -259,7 +260,9 @@ export class DataView extends Component {

renderEmptyMessage() {
if (!this.props.loading) {
return <div className="p-col-12 col-12 p-dataview-emptymessage">{this.props.emptyMessage}</div>;
const content = this.props.emptyMessage || localeOption('emptyMessage');

return <div className="p-col-12 col-12 p-dataview-emptymessage">{content}</div>;
}

return null;
Expand Down
4 changes: 2 additions & 2 deletions src/components/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export class Dropdown extends Component {
filterMatchMode: 'contains',
filterPlaceholder: null,
filterLocale: undefined,
emptyMessage: 'No records found',
emptyFilterMessage: 'No results found',
emptyMessage: null,
emptyFilterMessage: null,
editable: false,
placeholder: null,
required: false,
Expand Down
8 changes: 5 additions & 3 deletions src/components/dropdown/DropdownPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DropdownItem } from './DropdownItem';
import { CSSTransition } from '../csstransition/CSSTransition';
import { Portal } from '../portal/Portal';
import { VirtualScroller } from '../virtualscroller/VirtualScroller';
import { localeOption } from '../api/Api';

class DropdownPanelComponent extends Component {

Expand Down Expand Up @@ -61,8 +62,9 @@ class DropdownPanelComponent extends Component {
)
}

renderEmptyMessage(emptyMessage) {
const message = ObjectUtils.getJSXElement(emptyMessage, this.props);
renderEmptyMessage(emptyMessage, isFilter) {
const message = ObjectUtils.getJSXElement(emptyMessage, this.props) || localeOption(isFilter ? 'emptyFilterMessage' : 'emptyMessage');

return (
<li className="p-dropdown-empty-message">
{message}
Expand Down Expand Up @@ -101,7 +103,7 @@ class DropdownPanelComponent extends Component {
return this.props.visibleOptions.map((option, index) => this.renderItem(option, index));
}
else if (this.props.hasFilter()) {
return this.renderEmptyMessage(this.props.emptyFilterMessage);
return this.renderEmptyMessage(this.props.emptyFilterMessage, true);
}

return this.renderEmptyMessage(this.props.emptyMessage);
Expand Down
2 changes: 1 addition & 1 deletion src/components/multiselect/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class MultiSelect extends Component {
filterMatchMode: 'contains',
filterPlaceholder: null,
filterLocale: undefined,
emptyFilterMessage: 'No results found',
emptyFilterMessage: null,
resetFilterOnHide: false,
tabIndex: 0,
dataKey: null,
Expand Down
3 changes: 2 additions & 1 deletion src/components/multiselect/MultiSelectPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Portal } from '../portal/Portal';
import { MultiSelectHeader } from './MultiSelectHeader';
import { MultiSelectItem } from './MultiSelectItem';
import { VirtualScroller } from '../virtualscroller/VirtualScroller';
import { localeOption } from '../api/Api';

class MultiSelectPanelComponent extends Component {

Expand Down Expand Up @@ -77,7 +78,7 @@ class MultiSelectPanelComponent extends Component {
}

renderEmptyFilter() {
const emptyFilterMessage = ObjectUtils.getJSXElement(this.props.emptyFilterMessage, this.props);
const emptyFilterMessage = ObjectUtils.getJSXElement(this.props.emptyFilterMessage, this.props) || localeOption('emptyFilterMessage');
return (
<li className="p-multiselect-empty-message">
{emptyFilterMessage}
Expand Down
4 changes: 2 additions & 2 deletions src/components/treeselect/TreeSelect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component, createRef } from 'react';
import PropTypes from 'prop-types';
import { DomHandler, ObjectUtils, classNames, ZIndexUtils, ConnectedOverlayScrollHandler } from '../utils/Utils';
import PrimeReact from '../api/Api';
import PrimeReact, { localeOption } from '../api/Api';
import { OverlayService } from '../overlayservice/OverlayService';
import { Tree } from '../tree/Tree';
import { TreeSelectPanel } from './TreeSelectPanel';
Expand Down Expand Up @@ -582,7 +582,7 @@ export class TreeSelect extends Component {
{
this.hasNoOptions() && (
<div className="p-treeselect-empty-message">
{this.props.emptyMessage}
{this.props.emptyMessage || localeOption('emptyMessage')}
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/treetable/TreeTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class TreeTable extends Component {
frozenWidth: null,
resizableColumns: false,
columnResizeMode: 'fit',
emptyMessage: "No records found",
emptyMessage: null,
filters: null,
globalFilter: null,
filterMode: 'lenient',
Expand Down
7 changes: 5 additions & 2 deletions src/components/treetable/TreeTableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import DomHandler from '../utils/DomHandler';
import { TreeTableRow } from './TreeTableRow';
import { localeOption } from '../api/Api';

export class TreeTableBody extends Component {

Expand All @@ -20,7 +21,7 @@ export class TreeTableBody extends Component {
propagateSelectionDown: true,
lazy: false,
rowClassName: null,
emptyMessage: "No records found",
emptyMessage: null,
loading: false,
onExpand: null,
onCollapse: null,
Expand Down Expand Up @@ -277,9 +278,11 @@ export class TreeTableBody extends Component {
}
else {
const colSpan = this.props.columns ? this.props.columns.length : null;
const content = this.props.emptyMessage || localeOption('emptyMessage');

return (
<tr>
<td className="p-treetable-emptymessage" colSpan={colSpan}>{this.props.emptyMessage}</td>
<td className="p-treetable-emptymessage" colSpan={colSpan}>{content}</td>
</tr>
);
}
Expand Down

0 comments on commit 0cc35e5

Please sign in to comment.