@openedx/paragon 21.7.3 → 21.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DataTable/RowStatus.js +11 -5
- package/dist/DataTable/RowStatus.js.map +1 -1
- package/package.json +1 -1
- package/src/DataTable/RowStatus.jsx +11 -5
- package/src/DataTable/tests/DataTable.test.jsx +1 -1
- package/src/DataTable/tests/RowStatus.test.jsx +2 -2
- package/src/DataTable/tests/SmartStatus.test.jsx +2 -2
|
@@ -10,10 +10,15 @@ function RowStatus(_ref) {
|
|
|
10
10
|
const {
|
|
11
11
|
page,
|
|
12
12
|
rows,
|
|
13
|
-
itemCount
|
|
13
|
+
itemCount,
|
|
14
|
+
state
|
|
14
15
|
} = useContext(DataTableContext);
|
|
15
|
-
const
|
|
16
|
-
|
|
16
|
+
const rowCount = page?.length || rows?.length;
|
|
17
|
+
const pageSize = state?.pageSize || 0;
|
|
18
|
+
const pageIndex = state?.pageIndex || 0;
|
|
19
|
+
const firstRow = pageSize * pageIndex + 1;
|
|
20
|
+
const lastRow = firstRow + rowCount - 1;
|
|
21
|
+
if (!rowCount) {
|
|
17
22
|
return null;
|
|
18
23
|
}
|
|
19
24
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -21,11 +26,12 @@ function RowStatus(_ref) {
|
|
|
21
26
|
"data-testid": "row-status"
|
|
22
27
|
}, statusText || /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
23
28
|
id: "pgn.DataTable.RowStatus.statusText",
|
|
24
|
-
defaultMessage: "Showing {
|
|
29
|
+
defaultMessage: "Showing {firstRow} - {lastRow} of {itemCount}.",
|
|
25
30
|
description: "A text describing how many rows is shown in the table",
|
|
26
31
|
values: {
|
|
27
32
|
itemCount,
|
|
28
|
-
|
|
33
|
+
firstRow,
|
|
34
|
+
lastRow
|
|
29
35
|
}
|
|
30
36
|
}));
|
|
31
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RowStatus.js","names":["React","useContext","PropTypes","FormattedMessage","DataTableContext","RowStatus","_ref","className","statusText","page","rows","itemCount","
|
|
1
|
+
{"version":3,"file":"RowStatus.js","names":["React","useContext","PropTypes","FormattedMessage","DataTableContext","RowStatus","_ref","className","statusText","page","rows","itemCount","state","rowCount","length","pageSize","pageIndex","firstRow","lastRow","createElement","id","defaultMessage","description","values","propTypes","string","oneOfType","element","defaultProps","undefined"],"sources":["../../src/DataTable/RowStatus.jsx"],"sourcesContent":["import React, { useContext } from 'react';\nimport PropTypes from 'prop-types';\nimport { FormattedMessage } from 'react-intl';\nimport DataTableContext from './DataTableContext';\n\nfunction RowStatus({ className, statusText }) {\n const {\n page, rows, itemCount, state,\n } = useContext(DataTableContext);\n const rowCount = page?.length || rows?.length;\n const pageSize = state?.pageSize || 0;\n const pageIndex = state?.pageIndex || 0;\n const firstRow = pageSize * pageIndex + 1;\n const lastRow = firstRow + rowCount - 1;\n\n if (!rowCount) {\n return null;\n }\n return (\n <div className={className} data-testid=\"row-status\">\n {statusText || (\n <FormattedMessage\n id=\"pgn.DataTable.RowStatus.statusText\"\n defaultMessage=\"Showing {firstRow} - {lastRow} of {itemCount}.\"\n description=\"A text describing how many rows is shown in the table\"\n values={{ itemCount, firstRow, lastRow }}\n />\n )}\n </div>\n );\n}\n\nRowStatus.propTypes = {\n /** Specifies class name to append to the base element. */\n className: PropTypes.string,\n /** A text describing how many rows is shown in the table. */\n statusText: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),\n};\n\nRowStatus.defaultProps = {\n className: undefined,\n statusText: undefined,\n};\n\nexport default RowStatus;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,UAAU,QAAQ,OAAO;AACzC,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,gBAAgB,QAAQ,YAAY;AAC7C,OAAOC,gBAAgB,MAAM,oBAAoB;AAEjD,SAASC,SAASA,CAAAC,IAAA,EAA4B;EAAA,IAA3B;IAAEC,SAAS;IAAEC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
|
5
5
|
|
|
6
6
|
function RowStatus({ className, statusText }) {
|
|
7
|
-
const {
|
|
8
|
-
|
|
7
|
+
const {
|
|
8
|
+
page, rows, itemCount, state,
|
|
9
|
+
} = useContext(DataTableContext);
|
|
10
|
+
const rowCount = page?.length || rows?.length;
|
|
11
|
+
const pageSize = state?.pageSize || 0;
|
|
12
|
+
const pageIndex = state?.pageIndex || 0;
|
|
13
|
+
const firstRow = pageSize * pageIndex + 1;
|
|
14
|
+
const lastRow = firstRow + rowCount - 1;
|
|
9
15
|
|
|
10
|
-
if (!
|
|
16
|
+
if (!rowCount) {
|
|
11
17
|
return null;
|
|
12
18
|
}
|
|
13
19
|
return (
|
|
@@ -15,9 +21,9 @@ function RowStatus({ className, statusText }) {
|
|
|
15
21
|
{statusText || (
|
|
16
22
|
<FormattedMessage
|
|
17
23
|
id="pgn.DataTable.RowStatus.statusText"
|
|
18
|
-
defaultMessage="Showing {
|
|
24
|
+
defaultMessage="Showing {firstRow} - {lastRow} of {itemCount}."
|
|
19
25
|
description="A text describing how many rows is shown in the table"
|
|
20
|
-
values={{ itemCount,
|
|
26
|
+
values={{ itemCount, firstRow, lastRow }}
|
|
21
27
|
/>
|
|
22
28
|
)}
|
|
23
29
|
</div>
|
|
@@ -135,7 +135,7 @@ describe('<DataTable />', () => {
|
|
|
135
135
|
it('displays a control bar', () => {
|
|
136
136
|
render(<DataTableWrapper {...props} />);
|
|
137
137
|
expect(screen.getByTestId('table-control-bar')).toBeInTheDocument();
|
|
138
|
-
expect(screen.getAllByText('Showing 7 of 7.')[0]).toBeInTheDocument();
|
|
138
|
+
expect(screen.getAllByText('Showing 1 - 7 of 7.')[0]).toBeInTheDocument();
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
it('displays a table', () => {
|
|
@@ -32,13 +32,13 @@ describe('<RowStatus />', () => {
|
|
|
32
32
|
it('displays the row status with pagination', () => {
|
|
33
33
|
const pageSize = 10;
|
|
34
34
|
const { getByText } = render(<RowStatusWrapper value={{ ...instance, page: Array(pageSize) }} />);
|
|
35
|
-
const statusText = getByText(`Showing ${pageSize} of ${instance.itemCount}.`);
|
|
35
|
+
const statusText = getByText(`Showing 1 - ${pageSize} of ${instance.itemCount}.`);
|
|
36
36
|
expect(statusText).toBeInTheDocument();
|
|
37
37
|
});
|
|
38
38
|
it('displays the row status without pagination', () => {
|
|
39
39
|
const pageSize = 10;
|
|
40
40
|
const { getByText } = render(<RowStatusWrapper value={{ ...instance, rows: Array(pageSize) }} />);
|
|
41
|
-
const statusText = getByText(`Showing ${pageSize} of ${instance.itemCount}.`);
|
|
41
|
+
const statusText = getByText(`Showing 1 - ${pageSize} of ${instance.itemCount}.`);
|
|
42
42
|
expect(statusText).toBeInTheDocument();
|
|
43
43
|
});
|
|
44
44
|
it('sets class names on the parent', () => {
|
|
@@ -67,13 +67,13 @@ describe('<SmartStatus />', () => {
|
|
|
67
67
|
const { getByText } = render(
|
|
68
68
|
<SmartStatusWrapper value={instance} />,
|
|
69
69
|
);
|
|
70
|
-
expect(getByText(`Showing ${instance.page.length} of ${itemCount}.`)).toBeInTheDocument();
|
|
70
|
+
expect(getByText(`Showing 1 - ${instance.page.length} of ${itemCount}.`)).toBeInTheDocument();
|
|
71
71
|
});
|
|
72
72
|
it('Shows the number of items on the page if selection is off and there are no filters', () => {
|
|
73
73
|
const { getByText } = render(
|
|
74
74
|
<SmartStatusWrapper value={instance} />,
|
|
75
75
|
);
|
|
76
|
-
expect(getByText(`Showing ${instance.page.length} of ${itemCount}.`)).toBeInTheDocument();
|
|
76
|
+
expect(getByText(`Showing 1 - ${instance.page.length} of ${itemCount}.`)).toBeInTheDocument();
|
|
77
77
|
});
|
|
78
78
|
it('shows an alternate selection status', () => {
|
|
79
79
|
const altStatusText = 'horses R cool';
|