studiokit-scaffolding-js 5.1.1 → 5.1.2

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.
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
@@ -10,6 +21,10 @@ var react_2 = __importDefault(require("react"));
10
21
  var react_bootstrap_1 = require("react-bootstrap");
11
22
  var react_table_1 = __importDefault(require("react-table"));
12
23
  var table_1 = require("../constants/table");
24
+ var table_2 = require("../utils/table");
25
+ var ManageTableNoDataComponent_1 = require("./ManageTableNoDataComponent");
26
+ var PaginationNextButton_1 = require("./PaginationNextButton");
27
+ var PaginationPreviousButton_1 = require("./PaginationPreviousButton");
13
28
  var RefreshIndicator_1 = require("./RefreshIndicator");
14
29
  var ManageTable = function (_a) {
15
30
  //#region Data
@@ -62,33 +77,15 @@ var ManageTable = function (_a) {
62
77
  var SearchTabs = react_1.useMemo(function () { return (react_2.default.createElement(react_bootstrap_1.Tabs, { activeKey: selectedTab, id: "search-tabs", onSelect: onTabSelect }, tabs.map(function (tab) { return (react_2.default.createElement(react_bootstrap_1.Tab, { key: tab, eventKey: tab.toString(), title: getTabName(tab) + " (" + dataLengthByTab[tab] + ")", disabled: noResultsFound })); }))); }, [dataLengthByTab, getTabName, noResultsFound, onTabSelect, selectedTab, tabs]);
63
78
  //#endregion Tabs
64
79
  //#region Table
65
- var NoDataComponent = react_1.useMemo(function () {
66
- return hasSearched ? (react_2.default.createElement("p", { className: "pt4 tc" },
67
- "No ",
68
- entityName.toLocaleLowerCase(),
69
- " matched your search.",
70
- canQueryAll && !queryAll && (react_2.default.createElement(react_2.default.Fragment, null,
71
- " You might want to try again with \"Search All ",
72
- entityName,
73
- "\" checked.")))) : (react_2.default.createElement("p", { className: "pt4 tc" },
74
- "No ",
75
- getTabName(selectedTab).toLowerCase(),
76
- " ",
77
- entityName.toLocaleLowerCase(),
78
- ' ',
79
- isFiltered ? 'matched your search' : 'found',
80
- "."));
81
- }, [canQueryAll, entityName, getTabName, hasSearched, isFiltered, queryAll, selectedTab]);
80
+ var NoDataComponent = react_1.useMemo(function () { return (react_2.default.createElement(ManageTableNoDataComponent_1.ManageTableNoDataComponent, __assign({}, { canQueryAll: canQueryAll, entityName: entityName, getTabName: getTabName, hasSearched: hasSearched, isFiltered: isFiltered, queryAll: queryAll, selectedTab: selectedTab }))); }, [canQueryAll, entityName, getTabName, hasSearched, isFiltered, queryAll, selectedTab]);
82
81
  var NoDataComponentCallback = react_1.useCallback(function () { return NoDataComponent; }, [NoDataComponent]);
83
82
  var Table = react_1.useMemo(function () {
84
- var _a;
83
+ // show pagination if there are more rows than the default page size
85
84
  var showPagination = !!data && data.length > table_1.TABLE_DEFAULT_PAGE_SIZE;
86
85
  // if pagination is not enabled, or page is not set, ensure page is 0, the first page
87
86
  var pageForTab = showPagination && pageByTab && selectedTab ? pageByTab[selectedTab] : 0;
88
- // if there are less items to display than the page size, shrink the page size so there are not empty rows
89
- var currentPageSize = Math.min((_a = data === null || data === void 0 ? void 0 : data.length) !== null && _a !== void 0 ? _a : table_1.TABLE_DEFAULT_PAGE_SIZE, pageSize !== null && pageSize !== void 0 ? pageSize : table_1.TABLE_DEFAULT_PAGE_SIZE);
90
- var pageSizeOptions = table_1.TABLE_PAGE_SIZE_OPTIONS.filter(function (s) { return !(data === null || data === void 0 ? void 0 : data.length) || s <= (data === null || data === void 0 ? void 0 : data.length); });
91
- return (react_2.default.createElement(react_table_1.default, { "aria-describedby": "search-results-label", className: "manage-table -striped cb" + ((data === null || data === void 0 ? void 0 : data.length) === 1 ? ' single-row-action-button' : ''), data: data, showPagination: showPagination, showPaginationTop: true, sorted: sortingRules, pageSize: currentPageSize, page: pageForTab, pageSizeOptions: pageSizeOptions, columns: columns, onSortedChange: setSortingRules, onPageSizeChange: setPageSize, onPageChange: setPage, NoDataComponent: NoDataComponentCallback }));
87
+ var pageSizeOptions = table_2.getPageSizeOptions(data === null || data === void 0 ? void 0 : data.length);
88
+ return (react_2.default.createElement(react_table_1.default, { "aria-describedby": "search-results-label", className: "manage-table -striped cb" + ((data === null || data === void 0 ? void 0 : data.length) === 1 ? ' single-row-action-button' : ''), data: data, showPagination: showPagination, showPaginationTop: true, sorted: sortingRules, pageSize: pageSize, page: pageForTab, pageSizeOptions: pageSizeOptions, minRows: 0, columns: columns, onSortedChange: setSortingRules, onPageSizeChange: setPageSize, onPageChange: setPage, NextComponent: PaginationNextButton_1.PaginationNextButton, PreviousComponent: PaginationPreviousButton_1.PaginationPreviousButton, NoDataComponent: NoDataComponentCallback }));
92
89
  }, [
93
90
  NoDataComponentCallback,
94
91
  columns,
@@ -0,0 +1,11 @@
1
+ import { FunctionComponent } from 'react';
2
+ export interface ManageTableNoDataComponentProps {
3
+ entityName: string;
4
+ selectedTab?: number;
5
+ getTabName: (tab?: number) => string;
6
+ queryAll?: boolean;
7
+ canQueryAll?: boolean;
8
+ isFiltered?: boolean;
9
+ hasSearched?: boolean;
10
+ }
11
+ export declare const ManageTableNoDataComponent: FunctionComponent<ManageTableNoDataComponentProps>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ManageTableNoDataComponent = void 0;
7
+ var react_1 = __importDefault(require("react"));
8
+ var ManageTableNoDataComponent = function (_a) {
9
+ var entityName = _a.entityName, selectedTab = _a.selectedTab, getTabName = _a.getTabName, queryAll = _a.queryAll, canQueryAll = _a.canQueryAll, isFiltered = _a.isFiltered, hasSearched = _a.hasSearched;
10
+ return (react_1.default.createElement("p", { className: "pt4 tc" }, hasSearched ? (react_1.default.createElement(react_1.default.Fragment, null,
11
+ "No ",
12
+ entityName.toLocaleLowerCase(),
13
+ " matched your search.",
14
+ canQueryAll && !queryAll && (react_1.default.createElement(react_1.default.Fragment, null,
15
+ " You might want to try again with \"Search All ",
16
+ entityName,
17
+ "\" checked.")))) : (react_1.default.createElement(react_1.default.Fragment, null,
18
+ "No ",
19
+ getTabName(selectedTab).toLowerCase(),
20
+ " ",
21
+ entityName.toLocaleLowerCase(),
22
+ ' ',
23
+ isFiltered ? 'matched your search' : 'found',
24
+ "."))));
25
+ };
26
+ exports.ManageTableNoDataComponent = ManageTableNoDataComponent;
@@ -0,0 +1,3 @@
1
+ import { ButtonProps } from '@material-ui/core';
2
+ import { FunctionComponent } from 'react';
3
+ export declare const PaginationNextButton: FunctionComponent<ButtonProps>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.PaginationNextButton = void 0;
18
+ var core_1 = require("@material-ui/core");
19
+ var KeyboardArrowRight_1 = __importDefault(require("@material-ui/icons/KeyboardArrowRight"));
20
+ var react_1 = __importDefault(require("react"));
21
+ var PaginationNextButton = function (props) { return (react_1.default.createElement(core_1.Button, __assign({ className: "btn-text color-primary w-100" }, props),
22
+ "Next ",
23
+ react_1.default.createElement(KeyboardArrowRight_1.default, null))); };
24
+ exports.PaginationNextButton = PaginationNextButton;
@@ -0,0 +1,3 @@
1
+ import { ButtonProps } from '@material-ui/core';
2
+ import { FunctionComponent } from 'react';
3
+ export declare const PaginationPreviousButton: FunctionComponent<ButtonProps>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.PaginationPreviousButton = void 0;
18
+ var core_1 = require("@material-ui/core");
19
+ var KeyboardArrowLeft_1 = __importDefault(require("@material-ui/icons/KeyboardArrowLeft"));
20
+ var react_1 = __importDefault(require("react"));
21
+ var PaginationPreviousButton = function (props) { return (react_1.default.createElement(core_1.Button, __assign({ className: "btn-text color-primary w-100" }, props),
22
+ react_1.default.createElement(KeyboardArrowLeft_1.default, null),
23
+ " Previous")); };
24
+ exports.PaginationPreviousButton = PaginationPreviousButton;
@@ -25,7 +25,7 @@ var SearchControls = function (_a) {
25
25
  react_1.default.createElement(DateField_1.DateField, { id: "date", onChange: handleDateChange, label: "Date", "aria-label": "Active date", className: "fl-ns mw5-ns mr3-ns mb3 mb0-ns w-100-lt-xs date-align", value: dateString }))),
26
26
  react_1.default.createElement("div", { className: "fl-ns mt3-ns pt3-ns w-100-lt-xs" },
27
27
  canReadAnyGlobally && !!setQueryAll && (react_1.default.createElement(react_bootstrap_1.FormCheck, { name: "queryAll", id: "queryAll", checked: queryAll, disabled: canReadAnyGlobally && !canReadSome, onChange: setQueryAll, className: "fl-ns f6 mr2-ns mb3 mt2 w-100-lt-xs", label: react_1.default.createElement("span", { className: "b black" }, queryAllText || 'Search All') })),
28
- canReadAnyGlobally && queryAll && (react_1.default.createElement(Button_1.default, { className: "btn-primary fr-ns ml2-ns mb3 w-100-lt-xs search-button", onClick: handleSearchClick, color: "primary", disabled: !keywords || keywords.length < 3 || !!invalidKeywords },
28
+ canReadAnyGlobally && queryAll && (react_1.default.createElement(Button_1.default, { className: "btn-primary fr-ns ml2-ns mb3 w-100-lt-xs search-button", onClick: handleSearchClick, color: "primary", disabled: (!keywords || keywords.length < 3 || !!invalidKeywords) && !dateString },
29
29
  react_1.default.createElement(Search_1.default, null),
30
30
  "Search")),
31
31
  react_1.default.createElement(Button_1.default, { className: "btn-text color-pink fr-ns mb3 w-100-lt-xs", onClick: resetSearch },
@@ -62,6 +62,39 @@ th,
62
62
  * react table
63
63
  */
64
64
 
65
+ .table-container {
66
+ width: 100%;
67
+ overflow-x: auto;
68
+ }
69
+
70
+ .table-search-container {
71
+ padding: 0 !important;
72
+ text-align: left;
73
+ background: white;
74
+ border: 1px solid rgba(0, 0, 0, 0.1);
75
+ border-radius: 3px;
76
+ width: 100%;
77
+
78
+ & .MuiSvgIcon-root {
79
+ margin-top: 0.55rem;
80
+ }
81
+
82
+ & .table-search-input {
83
+ text-align: left;
84
+ outline: none !important;
85
+ border: none !important;
86
+ width: 100%;
87
+ }
88
+
89
+ & input[type=search] {
90
+ -webkit-appearance: none;
91
+ }
92
+
93
+ & input[type=search]::-webkit-search-cancel-button {
94
+ -webkit-appearance: searchfield-cancel-button;
95
+ }
96
+ }
97
+
65
98
  .ReactTable {
66
99
  & .rt-thead .rt-tr {
67
100
  background-color: var(--color-off-white);
@@ -88,10 +121,81 @@ th,
88
121
  overflow: visible;
89
122
  }
90
123
 
91
- & .-pagination .-btn[disabled] {
92
- opacity: 1 !important;
93
- background-color: var(--color-light-grey) !important;
94
- color: var(--color-dark-grey) !important;
124
+ & .pagination-top,
125
+ & .pagination-bottom {
126
+ background-color: var(--color-off-white);
127
+
128
+ & .-pagination {
129
+ padding: 0.5rem 0.6rem;
130
+ border-top: none;
131
+ }
132
+ }
133
+
134
+ & .pagination-top .-pagination {
135
+ border-bottom: 1px solid var(--color-light-grey);
136
+ }
137
+
138
+ & .pagination-bottom .-pagination {
139
+ border-top: 1px solid var(--color-light-grey);
140
+ }
141
+
142
+ & .-pagination .-previous,
143
+ & .-pagination .-next {
144
+ & .MuiButton-text {
145
+ background-color: var(--color-white);
146
+ border: 1px solid var(--color-light-grey);
147
+
148
+ &[disabled] {
149
+ background-color: var(--color-light-grey);
150
+ }
151
+
152
+ & .MuiButton-label .MuiSvgIcon-root {
153
+ margin: 0;
154
+ }
155
+ }
156
+ }
157
+
158
+ /* duplicate .form-control styles */
159
+ & .-pagination input,
160
+ .-pagination select {
161
+ display: block;
162
+ width: 100%;
163
+ height: calc(1.5em + 0.75rem + 2px);
164
+ font-size: 1rem;
165
+ font-weight: 400;
166
+ line-height: 1.5;
167
+ color: #495057;
168
+ background-color: #fff;
169
+ background-clip: padding-box;
170
+ border: 1px solid #ced4da;
171
+ border-radius: 0.25rem;
172
+ transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
173
+ font-family: var(--text-font-stack);
174
+ padding: 0.5rem;
175
+ border-color: var(--color-light-grey);
176
+ box-shadow: none;
177
+
178
+ &:focus {
179
+ border-color: #80bdff;
180
+ outline: 0;
181
+ -webkit-box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
182
+ box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
183
+ }
184
+
185
+ &::placeholder {
186
+ color: #6c757d;
187
+ opacity: 1;
188
+ }
189
+ }
190
+
191
+ & .-pagination .-pageSizeOptions.select {
192
+ padding: 0.375rem 0.75rem;
193
+ }
194
+
195
+ &.single-row-action-button {
196
+ & .rt-tbody {
197
+ padding-bottom: 108px;
198
+ }
95
199
  }
96
200
 
97
201
  & .rt-noData {
@@ -113,39 +217,6 @@ th,
113
217
  }
114
218
  }
115
219
 
116
- .table-container {
117
- width: 100%;
118
- overflow-x: auto;
119
- }
120
-
121
- .table-search-container {
122
- padding: 0 !important;
123
- text-align: left;
124
- background: white;
125
- border: 1px solid rgba(0, 0, 0, 0.1);
126
- border-radius: 3px;
127
- width: 100%;
128
-
129
- & .MuiSvgIcon-root {
130
- margin-top: 0.55rem;
131
- }
132
-
133
- & .table-search-input {
134
- text-align: left;
135
- outline: none !important;
136
- border: none !important;
137
- width: 100%;
138
- }
139
-
140
- & input[type=search] {
141
- -webkit-appearance: none;
142
- }
143
-
144
- & input[type=search]::-webkit-search-cancel-button {
145
- -webkit-appearance: searchfield-cancel-button;
146
- }
147
- }
148
-
149
220
  .striped-table tr:nth-child(even) {
150
221
  background-color: var(--color-light-blue) !important;
151
222
  }
@@ -0,0 +1,7 @@
1
+ export declare const getManageTableTabName: (selectedTab?: number | undefined) => "" | "Available" | "Deleted";
2
+ export declare const getGroupManageTableTabName: (selectedTab?: number | undefined) => "" | "Deleted" | "Current" | "Past";
3
+ /**
4
+ * return page size options that are less than or equal to the total data length,
5
+ * and one that is greater (if it exists) to allow viewing all data on one page.
6
+ * */
7
+ export declare const getPageSizeOptions: (dataLength?: number | undefined) => number[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGroupManageTableTabName = exports.getManageTableTabName = void 0;
3
+ exports.getPageSizeOptions = exports.getGroupManageTableTabName = exports.getManageTableTabName = void 0;
4
4
  var table_1 = require("../constants/table");
5
5
  var getManageTableTabName = function (selectedTab) {
6
6
  switch (selectedTab) {
@@ -26,3 +26,17 @@ var getGroupManageTableTabName = function (selectedTab) {
26
26
  }
27
27
  };
28
28
  exports.getGroupManageTableTabName = getGroupManageTableTabName;
29
+ /**
30
+ * return page size options that are less than or equal to the total data length,
31
+ * and one that is greater (if it exists) to allow viewing all data on one page.
32
+ * */
33
+ var getPageSizeOptions = function (dataLength) {
34
+ return table_1.TABLE_PAGE_SIZE_OPTIONS.reduce(function (options, option, currentIndex) {
35
+ var prevOption = currentIndex > 0 ? options[currentIndex - 1] : undefined;
36
+ if (!dataLength || option < dataLength || (prevOption && prevOption < dataLength)) {
37
+ options.push(option);
38
+ }
39
+ return options;
40
+ }, []);
41
+ };
42
+ exports.getPageSizeOptions = getPageSizeOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "studiokit-scaffolding-js",
3
- "version": "5.1.1",
3
+ "version": "5.1.2",
4
4
  "description": "Common scaffolding for Studio apps at Purdue",
5
5
  "repository": "https://gitlab.com/purdue-informatics/studiokit/studiokit-scaffolding-js",
6
6
  "license": "MIT",
@@ -1,2 +0,0 @@
1
- export declare const getManageTableTabName: (selectedTab?: number | undefined) => "" | "Available" | "Deleted";
2
- export declare const getGroupManageTableTabName: (selectedTab?: number | undefined) => "" | "Deleted" | "Current" | "Past";