@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.
@@ -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 pageSize = page?.length || rows?.length;
16
- if (!pageSize) {
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 {pageSize} of {itemCount}.",
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
- pageSize
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","pageSize","length","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 { page, rows, itemCount } = useContext(DataTableContext);\n const pageSize = page?.length || rows?.length;\n\n if (!pageSize) {\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 {pageSize} of {itemCount}.\"\n description=\"A text describing how many rows is shown in the table\"\n values={{ itemCount, pageSize }}\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;EAAW,CAAC,GAAAF,IAAA;EAC1C,MAAM;IAAEG,IAAI;IAAEC,IAAI;IAAEC;EAAU,CAAC,GAAGV,UAAU,CAACG,gBAAgB,CAAC;EAC9D,MAAMQ,QAAQ,GAAGH,IAAI,EAAEI,MAAM,IAAIH,IAAI,EAAEG,MAAM;EAE7C,IAAI,CAACD,QAAQ,EAAE;IACb,OAAO,IAAI;EACb;EACA,oBACEZ,KAAA,CAAAc,aAAA;IAAKP,SAAS,EAAEA,SAAU;IAAC,eAAY;EAAY,GAChDC,UAAU,iBACTR,KAAA,CAAAc,aAAA,CAACX,gBAAgB;IACfY,EAAE,EAAC,oCAAoC;IACvCC,cAAc,EAAC,oCAAoC;IACnDC,WAAW,EAAC,uDAAuD;IACnEC,MAAM,EAAE;MAAEP,SAAS;MAAEC;IAAS;EAAE,CACjC,CAEA,CAAC;AAEV;AAEAP,SAAS,CAACc,SAAS,GAAG;EACpB;EACAZ,SAAS,EAAEL,SAAS,CAACkB,MAAM;EAC3B;EACAZ,UAAU,EAAEN,SAAS,CAACmB,SAAS,CAAC,CAACnB,SAAS,CAACkB,MAAM,EAAElB,SAAS,CAACoB,OAAO,CAAC;AACvE,CAAC;AAEDjB,SAAS,CAACkB,YAAY,GAAG;EACvBhB,SAAS,EAAEiB,SAAS;EACpBhB,UAAU,EAAEgB;AACd,CAAC;AAED,eAAenB,SAAS"}
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;AA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,SAAS"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openedx/paragon",
3
- "version": "21.7.3",
3
+ "version": "21.8.0",
4
4
  "description": "Accessible, responsive UI component library based on Bootstrap.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -4,10 +4,16 @@ import { FormattedMessage } from 'react-intl';
4
4
  import DataTableContext from './DataTableContext';
5
5
 
6
6
  function RowStatus({ className, statusText }) {
7
- const { page, rows, itemCount } = useContext(DataTableContext);
8
- const pageSize = page?.length || rows?.length;
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 (!pageSize) {
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 {pageSize} of {itemCount}."
24
+ defaultMessage="Showing {firstRow} - {lastRow} of {itemCount}."
19
25
  description="A text describing how many rows is shown in the table"
20
- values={{ itemCount, pageSize }}
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';