@kaspernj/api-maker 1.0.400 → 1.0.402
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/package.json +2 -2
- package/src/bootstrap/paginate.jsx +15 -14
- package/src/bootstrap/sort-link.jsx +10 -12
- package/src/data-set-to-attributes.mjs +13 -0
- package/src/link.jsx +44 -10
- package/src/router/route.jsx +32 -13
- package/src/super-admin/index.jsx +15 -10
- package/src/super-admin/layout/menu/index.jsx +5 -3
- package/src/super-admin/layout/menu/menu-item/index.jsx +42 -5
- package/src/super-admin/layout/menu/menu-item/style.scss +1 -21
- package/src/super-admin/show-nav.jsx +4 -2
- package/src/super-admin/show-page/belongs-to-attribute-row.jsx +5 -2
- package/src/super-admin/show-reflection-actions.jsx +1 -1
- package/src/super-admin/show-reflection-link.jsx +4 -1
- package/src/table/components/column.jsx +12 -0
- package/src/table/components/flat-list.jsx +18 -0
- package/src/table/components/header.jsx +12 -0
- package/src/table/components/row.jsx +20 -0
- package/src/table/header-column.jsx +36 -38
- package/src/table/model-row.jsx +76 -51
- package/src/table/settings/column-row.jsx +1 -1
- package/src/table/settings/index.jsx +0 -12
- package/src/table/style.scss +0 -4
- package/src/table/table.jsx +99 -82
- package/src/table/widths.mjs +77 -0
- package/src/table/worker-plugins-check-all-checkbox.jsx +6 -4
- package/src/table/worker-plugins-checkbox.jsx +5 -3
- package/src/use-model.mjs +25 -23
- package/src/use-screen-layout.mjs +2 -2
- package/src/bootstrap/live-table/model-row.jsx +0 -149
- package/src/bootstrap/live-table.jsx +0 -399
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import {digg, digs} from "diggerize"
|
|
2
|
-
import * as inflection from "inflection"
|
|
3
|
-
import Link from "../../link"
|
|
4
|
-
import MoneyFormatter from "../../money-formatter"
|
|
5
|
-
import PropTypes from "prop-types"
|
|
6
|
-
|
|
7
|
-
export default class ApiMakerBootStrapLiveTableModelRow extends React.PureComponent {
|
|
8
|
-
static propTypes = {
|
|
9
|
-
model: PropTypes.object.isRequired,
|
|
10
|
-
liveTable: PropTypes.object.isRequired
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
modelCallbackArgs = this._modelCallbackArgs()
|
|
14
|
-
|
|
15
|
-
render() {
|
|
16
|
-
const {model} = digs(this.props, "model")
|
|
17
|
-
const {modelClass} = digs(this.props.liveTable.props, "modelClass")
|
|
18
|
-
const {actionsContent, columnsContent, destroyEnabled, editModelPath, viewModelPath} = digg(this, "props", "liveTable", "props")
|
|
19
|
-
const {columns} = digg(this, "props", "liveTable", "shape")
|
|
20
|
-
|
|
21
|
-
let editPath, viewPath
|
|
22
|
-
|
|
23
|
-
if (editModelPath && model.can("edit")) editPath = editModelPath(this.modelCallbackArgs)
|
|
24
|
-
if (viewModelPath && model.can("show")) viewPath = viewModelPath(this.modelCallbackArgs)
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<tr className={`${inflection.dasherize(modelClass.modelClassData().paramKey)}-row`} data-model-id={model.id()}>
|
|
28
|
-
{columns && this.columnsContentFromColumns(model)}
|
|
29
|
-
{!columns && columnsContent && columnsContent(this.modelCallbackArgs)}
|
|
30
|
-
<td className="actions-column text-end text-nowrap text-right">
|
|
31
|
-
{actionsContent && actionsContent(this.modelCallbackArgs)}
|
|
32
|
-
{viewPath &&
|
|
33
|
-
<Link className="view-button" to={viewPath}>
|
|
34
|
-
<i className="fa fa-search la la-search" />
|
|
35
|
-
</Link>
|
|
36
|
-
}
|
|
37
|
-
{editPath &&
|
|
38
|
-
<Link className="edit-button" to={editPath}>
|
|
39
|
-
<i className="fa fa-edit la la-edit" />
|
|
40
|
-
</Link>
|
|
41
|
-
}
|
|
42
|
-
{destroyEnabled && model.can("destroy") &&
|
|
43
|
-
<a className="destroy-button" href="#" onClick={this.onDestroyClicked}>
|
|
44
|
-
<i className="fa fa-trash la la-trash" />
|
|
45
|
-
</a>
|
|
46
|
-
}
|
|
47
|
-
</td>
|
|
48
|
-
</tr>
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
columnClassNamesForColumn (column) {
|
|
53
|
-
const classNames = ["live-table-column"]
|
|
54
|
-
|
|
55
|
-
if (column.commonProps && column.commonProps.className) classNames.push(column.commonProps.className)
|
|
56
|
-
if (column.columnProps && column.columnProps.className) classNames.push(column.columnProps.className)
|
|
57
|
-
if (column.textCenter) classNames.push("text-center")
|
|
58
|
-
if (column.textRight) classNames.push("text-end text-right")
|
|
59
|
-
|
|
60
|
-
return classNames
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
columnsContentFromColumns (model) {
|
|
64
|
-
const {columns} = digs(this.props.liveTable.shape, "columns")
|
|
65
|
-
|
|
66
|
-
return columns.map((column) =>
|
|
67
|
-
<td
|
|
68
|
-
className={classNames(this.columnClassNamesForColumn(column))}
|
|
69
|
-
data-identifier={this.props.liveTable.identifierForColumn(column)}
|
|
70
|
-
key={this.props.liveTable.identifierForColumn(column)}
|
|
71
|
-
>
|
|
72
|
-
{column.content && this.columnContentFromContentArg(column, model)}
|
|
73
|
-
{!column.content && column.attribute && this.columnsContentFromAttributeAndPath(column, model)}
|
|
74
|
-
</td>
|
|
75
|
-
)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
columnContentFromContentArg (column, model) {
|
|
79
|
-
const value = column.content(this.modelCallbackArgs)
|
|
80
|
-
|
|
81
|
-
return this.presentColumnValue(value)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
columnsContentFromAttributeAndPath (column, model) {
|
|
85
|
-
const {attribute} = digs(column, "attribute")
|
|
86
|
-
const currentModelClass = this.props.modelClass
|
|
87
|
-
const path = column.path || []
|
|
88
|
-
|
|
89
|
-
if (path.length > 0) throw new Error("'path' support not implemented")
|
|
90
|
-
|
|
91
|
-
if (!(attribute in model)) throw new Error(`${currentModelClass.modelName().name} doesn't respond to ${attribute}`)
|
|
92
|
-
|
|
93
|
-
const value = model[attribute]()
|
|
94
|
-
|
|
95
|
-
return this.presentColumnValue(value)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
_modelCallbackArgs () {
|
|
99
|
-
const {model} = digs(this.props, "model")
|
|
100
|
-
const modelArgName = inflection.camelize(this.props.liveTable.props.modelClass.modelClassData().name, true)
|
|
101
|
-
const modelCallbackArgs = {}
|
|
102
|
-
|
|
103
|
-
modelCallbackArgs[modelArgName] = model
|
|
104
|
-
|
|
105
|
-
return modelCallbackArgs
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
onDestroyClicked = async (e) => {
|
|
109
|
-
e.preventDefault()
|
|
110
|
-
|
|
111
|
-
const {destroyMessage} = digg(this, "props", "liveTable", "props")
|
|
112
|
-
const {model} = digs(this.props, "model")
|
|
113
|
-
|
|
114
|
-
if (!confirm(I18n.t("js.shared.are_you_sure"))) {
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
try {
|
|
119
|
-
await model.destroy()
|
|
120
|
-
|
|
121
|
-
if (destroyMessage) {
|
|
122
|
-
FlashMessage.success(destroyMessage)
|
|
123
|
-
}
|
|
124
|
-
} catch (error) {
|
|
125
|
-
FlashMessage.errorResponse(error)
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
presentColumnValue (value) {
|
|
130
|
-
if (value instanceof Date) {
|
|
131
|
-
return I18n.l("time.formats.default", value)
|
|
132
|
-
} else if (MoneyFormatter.isMoney(value)) {
|
|
133
|
-
return MoneyFormatter.format(value)
|
|
134
|
-
} else if (typeof value == "boolean") {
|
|
135
|
-
if (value) {
|
|
136
|
-
return I18n.t("js.shared.yes")
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return I18n.t("js.shared.no")
|
|
140
|
-
} else if (Array.isArray(value)) {
|
|
141
|
-
return value
|
|
142
|
-
.map((valuePart) => this.presentColumnValue(valuePart))
|
|
143
|
-
.filter((valuePart) => Boolean(valuePart))
|
|
144
|
-
.join(", ")
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return value
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
import BaseComponent from "../base-component"
|
|
2
|
-
import Card from "./card"
|
|
3
|
-
import classNames from "classnames"
|
|
4
|
-
import Collection from "../collection"
|
|
5
|
-
import CollectionLoader from "../collection-loader"
|
|
6
|
-
import debounce from "debounce"
|
|
7
|
-
import {digg, digs} from "diggerize"
|
|
8
|
-
import instanceOfClassName from "../instance-of-class-name"
|
|
9
|
-
import ModelRow from "./live-table/model-row"
|
|
10
|
-
import Paginate from "./paginate"
|
|
11
|
-
import Params from "../params"
|
|
12
|
-
import PropTypes from "prop-types"
|
|
13
|
-
import {memo} from "react"
|
|
14
|
-
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
15
|
-
import SortLink from "./sort-link"
|
|
16
|
-
|
|
17
|
-
export default memo(shapeComponent(class ApiMakerBootstrapLiveTable extends BaseComponent {
|
|
18
|
-
static defaultProps = {
|
|
19
|
-
card: true,
|
|
20
|
-
destroyEnabled: true,
|
|
21
|
-
filterCard: true,
|
|
22
|
-
filterSubmitButton: true,
|
|
23
|
-
noRecordsAvailableContent: undefined,
|
|
24
|
-
noRecordsFoundContent: undefined,
|
|
25
|
-
preloads: [],
|
|
26
|
-
select: {}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static propTypes = {
|
|
30
|
-
abilities: PropTypes.object,
|
|
31
|
-
actionsContent: PropTypes.func,
|
|
32
|
-
appHistory: PropTypes.object,
|
|
33
|
-
card: PropTypes.bool.isRequired,
|
|
34
|
-
className: PropTypes.string,
|
|
35
|
-
collection: PropTypes.oneOfType([
|
|
36
|
-
instanceOfClassName("ApiMakerCollection"),
|
|
37
|
-
PropTypes.instanceOf(Collection)
|
|
38
|
-
]),
|
|
39
|
-
columns: PropTypes.oneOfType([PropTypes.array, PropTypes.func]),
|
|
40
|
-
columnsContent: PropTypes.func,
|
|
41
|
-
controls: PropTypes.func,
|
|
42
|
-
defaultParams: PropTypes.object,
|
|
43
|
-
destroyEnabled: PropTypes.bool.isRequired,
|
|
44
|
-
destroyMessage: PropTypes.string,
|
|
45
|
-
editModelPath: PropTypes.func,
|
|
46
|
-
filterCard: PropTypes.bool.isRequired,
|
|
47
|
-
filterContent: PropTypes.func,
|
|
48
|
-
filterSubmitButton: PropTypes.bool.isRequired,
|
|
49
|
-
filterSubmitLabel: PropTypes.node,
|
|
50
|
-
headersContent: PropTypes.func,
|
|
51
|
-
header: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
|
|
52
|
-
groupBy: PropTypes.array,
|
|
53
|
-
modelClass: PropTypes.func.isRequired,
|
|
54
|
-
noRecordsAvailableContent: PropTypes.func,
|
|
55
|
-
noRecordsFoundContent: PropTypes.func,
|
|
56
|
-
onModelsLoaded: PropTypes.func,
|
|
57
|
-
paginateContent: PropTypes.func,
|
|
58
|
-
paginationComponent: PropTypes.func,
|
|
59
|
-
preloads: PropTypes.array.isRequired,
|
|
60
|
-
queryName: PropTypes.string,
|
|
61
|
-
select: PropTypes.object,
|
|
62
|
-
selectColumns: PropTypes.object,
|
|
63
|
-
viewModelPath: PropTypes.func
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
setup() {
|
|
67
|
-
let queryName = this.props.queryName
|
|
68
|
-
|
|
69
|
-
if (!queryName) {
|
|
70
|
-
queryName = digg(this.props.modelClass.modelClassData(), "collectionKey")
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this.useStates({
|
|
74
|
-
columns: () => this.columnsAsArray(),
|
|
75
|
-
models: undefined,
|
|
76
|
-
overallCount: undefined,
|
|
77
|
-
query: undefined,
|
|
78
|
-
queryName,
|
|
79
|
-
queryQName: `${queryName}_q`,
|
|
80
|
-
queryPageName: `${queryName}_page`,
|
|
81
|
-
qParams: undefined,
|
|
82
|
-
result: undefined,
|
|
83
|
-
showNoRecordsAvailableContent: false,
|
|
84
|
-
showNoRecordsFoundContent: false
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
columnsAsArray () {
|
|
89
|
-
if (typeof this.props.columns == "function") {
|
|
90
|
-
return this.props.columns()
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return this.props.columns
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
render () {
|
|
97
|
-
const {modelClass, noRecordsAvailableContent, noRecordsFoundContent} = digs(this.props, "modelClass", "noRecordsAvailableContent", "noRecordsFoundContent")
|
|
98
|
-
const {collection, defaultParams, onModelsLoaded, preloads, select, selectColumns} = this.props
|
|
99
|
-
const {
|
|
100
|
-
overallCount,
|
|
101
|
-
qParams,
|
|
102
|
-
query,
|
|
103
|
-
result,
|
|
104
|
-
models,
|
|
105
|
-
showNoRecordsAvailableContent,
|
|
106
|
-
showNoRecordsFoundContent
|
|
107
|
-
} = digs(
|
|
108
|
-
this.state,
|
|
109
|
-
"overallCount",
|
|
110
|
-
"qParams",
|
|
111
|
-
"query",
|
|
112
|
-
"result",
|
|
113
|
-
"models",
|
|
114
|
-
"showNoRecordsAvailableContent",
|
|
115
|
-
"showNoRecordsFoundContent"
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
return (
|
|
119
|
-
<div className={this.className()}>
|
|
120
|
-
<CollectionLoader
|
|
121
|
-
abilities={this.abilitiesToLoad()}
|
|
122
|
-
defaultParams={defaultParams}
|
|
123
|
-
collection={collection}
|
|
124
|
-
component={this}
|
|
125
|
-
modelClass={modelClass}
|
|
126
|
-
noRecordsAvailableContent={noRecordsAvailableContent}
|
|
127
|
-
noRecordsFoundContent={noRecordsFoundContent}
|
|
128
|
-
onModelsLoaded={onModelsLoaded}
|
|
129
|
-
pagination
|
|
130
|
-
preloads={preloads}
|
|
131
|
-
select={select}
|
|
132
|
-
selectColumns={selectColumns}
|
|
133
|
-
/>
|
|
134
|
-
{showNoRecordsAvailableContent &&
|
|
135
|
-
<div className="live-table--no-records-available-content">
|
|
136
|
-
{noRecordsAvailableContent({models, qParams, overallCount})}
|
|
137
|
-
</div>
|
|
138
|
-
}
|
|
139
|
-
{showNoRecordsFoundContent &&
|
|
140
|
-
<div className="live-table--no-records-found-content">
|
|
141
|
-
{noRecordsFoundContent({models, qParams, overallCount})}
|
|
142
|
-
</div>
|
|
143
|
-
}
|
|
144
|
-
{qParams && query && result && models && !showNoRecordsAvailableContent && !showNoRecordsFoundContent &&
|
|
145
|
-
this.cardOrTable()
|
|
146
|
-
}
|
|
147
|
-
</div>
|
|
148
|
-
)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
abilitiesToLoad () {
|
|
152
|
-
const abilitiesToLoad = {}
|
|
153
|
-
const {abilities, modelClass} = this.props
|
|
154
|
-
const ownAbilities = []
|
|
155
|
-
|
|
156
|
-
if (this.props.destroyEnabled) {
|
|
157
|
-
ownAbilities.push("destroy")
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (this.props.editModelPath) {
|
|
161
|
-
ownAbilities.push("edit")
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (this.props.viewModelPath) {
|
|
165
|
-
ownAbilities.push("show")
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (ownAbilities.length > 0) {
|
|
169
|
-
const modelClassName = digg(modelClass.modelClassData(), "name")
|
|
170
|
-
|
|
171
|
-
abilitiesToLoad[modelClassName] = ownAbilities
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (abilities) {
|
|
175
|
-
for (const modelName in abilities) {
|
|
176
|
-
if (!(modelName in abilitiesToLoad)) {
|
|
177
|
-
abilitiesToLoad[modelName] = []
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
for (const ability of abilities[modelName]) {
|
|
181
|
-
abilitiesToLoad[modelName].push(ability)
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return abilitiesToLoad
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
cardOrTable () {
|
|
190
|
-
const {
|
|
191
|
-
abilities,
|
|
192
|
-
actionsContent,
|
|
193
|
-
appHistory,
|
|
194
|
-
card,
|
|
195
|
-
className,
|
|
196
|
-
collection,
|
|
197
|
-
columns,
|
|
198
|
-
columnsContent,
|
|
199
|
-
controls,
|
|
200
|
-
defaultParams,
|
|
201
|
-
destroyEnabled,
|
|
202
|
-
destroyMessage,
|
|
203
|
-
editModelPath,
|
|
204
|
-
filterCard,
|
|
205
|
-
filterContent,
|
|
206
|
-
filterSubmitButton,
|
|
207
|
-
filterSubmitLabel,
|
|
208
|
-
headersContent,
|
|
209
|
-
header,
|
|
210
|
-
groupBy,
|
|
211
|
-
modelClass,
|
|
212
|
-
noRecordsAvailableContent,
|
|
213
|
-
noRecordsFoundContent,
|
|
214
|
-
onModelsLoaded,
|
|
215
|
-
paginateContent,
|
|
216
|
-
paginationComponent,
|
|
217
|
-
preloads,
|
|
218
|
-
queryName,
|
|
219
|
-
select,
|
|
220
|
-
selectColumns,
|
|
221
|
-
viewModelPath,
|
|
222
|
-
...restProps
|
|
223
|
-
} = this.props
|
|
224
|
-
const {models, qParams, query, result} = digs(this.state, "models", "qParams", "query", "result")
|
|
225
|
-
|
|
226
|
-
let controlsContent, headerContent, PaginationComponent
|
|
227
|
-
|
|
228
|
-
if (controls) {
|
|
229
|
-
controlsContent = controls({models, qParams, query, result})
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (typeof header == "function") {
|
|
233
|
-
headerContent = header({models, qParams, query, result})
|
|
234
|
-
} else if (header) {
|
|
235
|
-
headerContent = header
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (!paginateContent) {
|
|
239
|
-
if (paginationComponent) {
|
|
240
|
-
PaginationComponent = paginationComponent
|
|
241
|
-
} else {
|
|
242
|
-
PaginationComponent = Paginate
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return (
|
|
247
|
-
<>
|
|
248
|
-
{filterContent && filterCard &&
|
|
249
|
-
<Card className="live-table--filter-card mb-4">
|
|
250
|
-
{this.filterForm()}
|
|
251
|
-
</Card>
|
|
252
|
-
}
|
|
253
|
-
{filterContent && !filterCard &&
|
|
254
|
-
this.filterForm()
|
|
255
|
-
}
|
|
256
|
-
{card &&
|
|
257
|
-
<Card className={classNames("mb-4", className)} controls={controlsContent} header={headerContent} table {...restProps}>
|
|
258
|
-
{this.tableContent()}
|
|
259
|
-
</Card>
|
|
260
|
-
}
|
|
261
|
-
{!card &&
|
|
262
|
-
<table className={className} {...restProps}>
|
|
263
|
-
{this.tableContent()}
|
|
264
|
-
</table>
|
|
265
|
-
}
|
|
266
|
-
{result && PaginationComponent &&
|
|
267
|
-
<PaginationComponent result={result} />
|
|
268
|
-
}
|
|
269
|
-
{result && paginateContent &&
|
|
270
|
-
paginateContent({result})
|
|
271
|
-
}
|
|
272
|
-
</>
|
|
273
|
-
)
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
filterForm = () => {
|
|
277
|
-
const {submitFilterDebounce} = digs(this, "submitFilterDebounce")
|
|
278
|
-
const {filterContent, filterSubmitButton} = digs(this.props, "filterContent", "filterSubmitButton")
|
|
279
|
-
const {filterSubmitLabel} = this.props
|
|
280
|
-
const {qParams} = digs(this.state, "qParams")
|
|
281
|
-
|
|
282
|
-
return (
|
|
283
|
-
<form className="live-table--filter-form" onSubmit={this.onFilterFormSubmit} ref="filterForm">
|
|
284
|
-
{filterContent({
|
|
285
|
-
onFilterChanged: this.submitFilter,
|
|
286
|
-
onFilterChangedWithDelay: submitFilterDebounce,
|
|
287
|
-
qParams
|
|
288
|
-
})}
|
|
289
|
-
{filterSubmitButton &&
|
|
290
|
-
<input
|
|
291
|
-
className="btn btn-primary live-table--submit-filter-button"
|
|
292
|
-
type="submit"
|
|
293
|
-
value={filterSubmitLabel || I18n.t("js.api_maker_bootstrap.live_table.filter")}
|
|
294
|
-
/>
|
|
295
|
-
}
|
|
296
|
-
</form>
|
|
297
|
-
)
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
tableContent () {
|
|
301
|
-
const {query, models} = this.state
|
|
302
|
-
|
|
303
|
-
return (
|
|
304
|
-
<>
|
|
305
|
-
<thead>
|
|
306
|
-
<tr>
|
|
307
|
-
{this.state.columns && this.headersContentFromColumns()}
|
|
308
|
-
{this.props.headersContent && this.props.headersContent({query})}
|
|
309
|
-
<th />
|
|
310
|
-
</tr>
|
|
311
|
-
</thead>
|
|
312
|
-
<tbody>
|
|
313
|
-
{models.map((model) =>
|
|
314
|
-
<ModelRow key={model.id()} liveTable={this} model={model} />
|
|
315
|
-
)}
|
|
316
|
-
</tbody>
|
|
317
|
-
</>
|
|
318
|
-
)
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
className () {
|
|
322
|
-
const classNames = ["component-api-maker-live-table"]
|
|
323
|
-
|
|
324
|
-
if (this.props.className)
|
|
325
|
-
classNames.push(this.props.className)
|
|
326
|
-
|
|
327
|
-
return classNames.join(" ")
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
headersContentFromColumns () {
|
|
331
|
-
const {columns} = digs(this.state, "columns")
|
|
332
|
-
|
|
333
|
-
return columns.map((column) =>
|
|
334
|
-
<th
|
|
335
|
-
className={classNames(...this.headerClassNameForColumn(column))}
|
|
336
|
-
data-identifier={this.identifierForColumn(column)}
|
|
337
|
-
key={this.identifierForColumn(column)}
|
|
338
|
-
>
|
|
339
|
-
{column.sortKey && this.state.query &&
|
|
340
|
-
<SortLink attribute={column.sortKey} query={this.state.query} title={this.headerLabelForColumn(column)} />
|
|
341
|
-
}
|
|
342
|
-
{(!column.sortKey || !this.state.query) &&
|
|
343
|
-
this.headerLabelForColumn(column)
|
|
344
|
-
}
|
|
345
|
-
</th>
|
|
346
|
-
)
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
headerClassNameForColumn (column) {
|
|
350
|
-
const classNames = ["live-table-header"]
|
|
351
|
-
|
|
352
|
-
if (column.commonProps && column.commonProps.className) classNames.push(column.commonProps.className)
|
|
353
|
-
if (column.headerProps && column.headerProps.className) classNames.push(column.headerProps.className)
|
|
354
|
-
if (column.textCenter) classNames.push("text-center")
|
|
355
|
-
if (column.textRight) classNames.push("text-end text-right")
|
|
356
|
-
|
|
357
|
-
return classNames
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
headerLabelForColumn (column) {
|
|
361
|
-
if ("label" in column) {
|
|
362
|
-
if (typeof column.label == "function") {
|
|
363
|
-
return column.label()
|
|
364
|
-
} else {
|
|
365
|
-
return column.label
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
if (column.attribute) return this.props.modelClass.humanAttributeName(column.attribute)
|
|
370
|
-
|
|
371
|
-
throw new Error("No 'label' or 'attribute' was given")
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
identifierForColumn (column) {
|
|
375
|
-
if (column.identifier) return column.identifier
|
|
376
|
-
if (column.attribute) return `attribute-${column.attribute}`
|
|
377
|
-
if (column.sortKey) return `sort-key-${column.sortKey}`
|
|
378
|
-
|
|
379
|
-
throw new Error("No 'attribute', 'identifier' or 'sortKey' was given")
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
onFilterFormSubmit = (e) => {
|
|
383
|
-
e.preventDefault()
|
|
384
|
-
this.submitFilter()
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
submitFilter = () => {
|
|
388
|
-
const {appHistory} = this.props
|
|
389
|
-
const qParams = Params.serializeForm(this.refs.filterForm)
|
|
390
|
-
const {queryQName} = this.state
|
|
391
|
-
|
|
392
|
-
const changeParamsParams = {}
|
|
393
|
-
changeParamsParams[queryQName] = JSON.stringify(qParams)
|
|
394
|
-
|
|
395
|
-
Params.changeParams(changeParamsParams, {appHistory})
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
submitFilterDebounce = debounce(digg(this, "submitFilter"))
|
|
399
|
-
}))
|