@kaspernj/api-maker 1.0.2011 → 1.0.2012
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/{.eslintrc.cjs → .eslintrc.js} +10 -1
- package/README.md +35 -0
- package/android/build.gradle +43 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/api_maker/ApiMakerModule.kt +50 -0
- package/android/src/main/java/expo/modules/api_maker/ApiMakerView.kt +30 -0
- package/build/api.js +120 -0
- package/build/attribute-not-loaded-error.js +2 -0
- package/build/base-component.js +5 -0
- package/build/base-error.js +33 -0
- package/build/base-model/attribute.js +25 -0
- package/build/base-model/column.js +11 -0
- package/build/base-model/reflection.js +14 -0
- package/build/base-model/scope.js +11 -0
- package/build/base-model.js +828 -0
- package/build/bootstrap/attribute-row.js +135 -0
- package/build/bootstrap/attribute-rows.js +31 -0
- package/build/bootstrap/card.js +138 -0
- package/build/bootstrap/checkbox.js +97 -0
- package/build/bootstrap/checkboxes.js +183 -0
- package/build/bootstrap/index.js +2 -0
- package/build/bootstrap/input.js +129 -0
- package/build/bootstrap/invalid-feedback.js +27 -0
- package/build/bootstrap/paginate.js +150 -0
- package/build/bootstrap/radio-buttons.js +72 -0
- package/build/bootstrap/select.js +88 -0
- package/build/bootstrap/sort-link.js +131 -0
- package/build/cable-connection-pool.js +128 -0
- package/build/cable-subscription-pool.js +207 -0
- package/build/cable-subscription.js +21 -0
- package/build/cache-key-generator.js +81 -0
- package/build/can-can.js +134 -0
- package/build/channels-consumer.js +9 -0
- package/build/collection-loader.js +48 -0
- package/build/collection.js +280 -0
- package/build/command-submit-data.js +81 -0
- package/build/commands-pool.js +195 -0
- package/build/compose.js +9 -0
- package/build/config.js +62 -0
- package/build/custom-error.js +5 -0
- package/build/data-set-to-attributes.js +10 -0
- package/build/deserializer.js +56 -0
- package/build/destroy-error.js +5 -0
- package/build/devise.js +112 -0
- package/build/draggable-sort/controller.js +136 -0
- package/build/draggable-sort/index.js +114 -0
- package/build/draggable-sort/item.js +188 -0
- package/build/error-logger.js +101 -0
- package/build/error-messages.js +13 -0
- package/build/event-connection.js +32 -0
- package/build/event-emitter-listener.js +15 -0
- package/build/event-model-class.js +24 -0
- package/build/events.js +5 -0
- package/build/flash-message.js +79 -0
- package/build/form.js +83 -0
- package/build/history-expo.js +20 -0
- package/build/history-react-native.js +20 -0
- package/build/history.js +3 -0
- package/build/index.js +3 -0
- package/build/inputs/attachment.js +133 -0
- package/build/inputs/auto-submit.js +36 -0
- package/build/inputs/checkbox.js +138 -0
- package/build/inputs/checkboxes.js +112 -0
- package/build/inputs/id-for-component.js +15 -0
- package/build/inputs/input-wrapper.js +19 -0
- package/build/inputs/input.js +243 -0
- package/build/inputs/money.js +179 -0
- package/build/inputs/name-for-component.js +13 -0
- package/build/inputs/select.js +93 -0
- package/build/instance-of-class-name.js +23 -0
- package/build/key-value-store.js +53 -0
- package/build/link.js +73 -0
- package/build/logger.js +30 -0
- package/build/modal.js +38 -0
- package/build/model-class-require.js +13 -0
- package/build/model-events.js +30 -0
- package/build/model-name.js +28 -0
- package/build/model-prop-type.js +101 -0
- package/build/model-recipes-loader.js +32 -0
- package/build/model-recipes-model-loader.js +357 -0
- package/build/models-response-reader.js +40 -0
- package/build/models.js +8 -0
- package/build/money-formatter.js +78 -0
- package/build/not-loaded-error.js +2 -0
- package/build/params.js +61 -0
- package/build/preloaded.js +38 -0
- package/build/resize-observer.js +11 -0
- package/build/result.js +13 -0
- package/build/router/route.js +270 -0
- package/build/router/switch.js +72 -0
- package/build/router.js +59 -0
- package/build/routes-native.js +202 -0
- package/build/routes.js +50 -0
- package/build/run-last.js +35 -0
- package/build/serializer.js +63 -0
- package/build/services.js +20 -0
- package/build/session-status-updater.js +134 -0
- package/build/source-maps-loader.js +184 -0
- package/build/super-admin/config-reader.js +85 -0
- package/build/super-admin/edit-page/edit-attribute-checkbox.js +85 -0
- package/build/super-admin/edit-page/edit-attribute-content.js +55 -0
- package/build/super-admin/edit-page/edit-attribute-input.js +79 -0
- package/build/super-admin/edit-page/edit-attribute.js +77 -0
- package/build/super-admin/edit-page.js +123 -0
- package/build/super-admin/has-edit-config.js +12 -0
- package/build/super-admin/index-page.js +25 -0
- package/build/super-admin/index.js +181 -0
- package/build/super-admin/layout/header/index.js +161 -0
- package/build/super-admin/layout/index.js +164 -0
- package/build/super-admin/layout/menu/index.js +206 -0
- package/build/super-admin/layout/menu/menu-content.js +46 -0
- package/build/super-admin/layout/menu/menu-item.js +84 -0
- package/build/super-admin/layout/no-access.js +27 -0
- package/build/super-admin/model-class-table.js +61 -0
- package/build/super-admin/models.js +8 -0
- package/build/super-admin/show-nav.js +51 -0
- package/build/super-admin/show-page/belongs-to-attribute-row.js +29 -0
- package/build/super-admin/show-page/index.js +141 -0
- package/build/super-admin/show-reflection-actions.js +47 -0
- package/build/super-admin/show-reflection-link.js +48 -0
- package/build/super-admin/show-reflection-page.js +48 -0
- package/build/table/column-content.js +117 -0
- package/build/table/column-identifier.js +18 -0
- package/build/table/column-visible.js +7 -0
- package/build/table/components/column.js +21 -0
- package/build/table/components/flat-list.js +21 -0
- package/build/table/components/header.js +26 -0
- package/build/table/components/row.js +26 -0
- package/build/table/filters/attribute-element.js +44 -0
- package/build/table/filters/filter-form.js +402 -0
- package/build/table/filters/filter.js +90 -0
- package/build/table/filters/index.js +184 -0
- package/build/table/filters/load-search-modal.js +175 -0
- package/build/table/filters/reflection-element.js +37 -0
- package/build/table/filters/save-search-modal.js +88 -0
- package/build/table/filters/scope-element.js +42 -0
- package/build/table/header-column-content.js +68 -0
- package/build/table/header-column.js +144 -0
- package/build/table/header-select.js +105 -0
- package/build/table/model-callback-args.js +10 -0
- package/build/table/model-column.js +97 -0
- package/build/table/model-row.js +193 -0
- package/build/table/select-calculator.js +63 -0
- package/build/table/settings/column-row.js +97 -0
- package/build/table/settings/download-action.js +79 -0
- package/build/table/settings/index.js +92 -0
- package/build/table/table-settings.js +219 -0
- package/build/table/table.js +972 -0
- package/build/table/use-sorting.js +34 -0
- package/build/table/widths.js +75 -0
- package/build/table/worker-plugins-check-all-checkbox.js +125 -0
- package/build/table/worker-plugins-checkbox.js +115 -0
- package/build/translated-attributes.js +10 -0
- package/build/translated-collections.js +12 -0
- package/build/updated-attribute.js +76 -0
- package/build/url-encode.js +15 -0
- package/build/use-breakpoint.js +62 -0
- package/build/use-can-can.js +55 -0
- package/build/use-collection.js +225 -0
- package/build/use-created-event.js +52 -0
- package/build/use-current-user.js +76 -0
- package/build/use-destroyed-event.js +60 -0
- package/build/use-event-emitter.js +13 -0
- package/build/use-event-listener.js +16 -0
- package/build/use-input.js +137 -0
- package/build/use-model-event.js +60 -0
- package/build/use-model.js +169 -0
- package/build/use-resize-observer.js +23 -0
- package/build/use-router.js +104 -0
- package/build/use-screen-layout.js +39 -0
- package/build/use-updated-event.js +60 -0
- package/build/use-validation-errors.js +30 -0
- package/build/utils/card.js +51 -0
- package/build/utils/checkbox.js +78 -0
- package/build/utils/checkboxes.js +163 -0
- package/build/utils/default-style.js +18 -0
- package/build/utils/icon.js +23 -0
- package/build/utils/invalid-feedback.js +19 -0
- package/build/utils/modal.js +62 -0
- package/build/utils/text.js +19 -0
- package/build/validation-error.js +28 -0
- package/build/validation-errors.js +98 -0
- package/build/with-api-maker.js +29 -0
- package/build/with-collection.js +14 -0
- package/build/with-current-user.js +10 -0
- package/build/with-model.js +15 -0
- package/build/with-router.js +22 -0
- package/expo-module.config.json +17 -0
- package/ios/ApiMaker.podspec +29 -0
- package/ios/ApiMakerModule.swift +48 -0
- package/ios/ApiMakerView.swift +38 -0
- package/link.sh +8 -0
- package/package.json +49 -46
- package/src/{api.mjs → api.js} +38 -37
- package/src/base-component.jsx +5 -0
- package/src/{base-error.mjs → base-error.js} +4 -6
- package/src/base-model/attribute.js +33 -0
- package/src/base-model/column.js +13 -0
- package/src/base-model/reflection.js +15 -0
- package/src/base-model/scope.js +12 -0
- package/src/{base-model.mjs → base-model.js} +302 -144
- package/src/bootstrap/attribute-row.jsx +135 -0
- package/src/bootstrap/attribute-rows.jsx +27 -0
- package/src/bootstrap/card.jsx +149 -0
- package/src/bootstrap/checkbox.jsx +86 -0
- package/src/bootstrap/checkboxes.jsx +185 -0
- package/src/bootstrap/index.js +0 -0
- package/src/bootstrap/input.jsx +173 -0
- package/src/bootstrap/invalid-feedback.jsx +31 -0
- package/src/bootstrap/paginate.jsx +187 -0
- package/src/bootstrap/radio-buttons.jsx +87 -0
- package/src/bootstrap/select.jsx +110 -0
- package/src/bootstrap/sort-link.jsx +106 -0
- package/src/{cable-connection-pool.mjs → cable-connection-pool.js} +16 -36
- package/src/{cable-subscription-pool.mjs → cable-subscription-pool.js} +26 -21
- package/src/{cable-subscription.mjs → cable-subscription.js} +6 -4
- package/src/cache-key-generator.js +100 -0
- package/src/{can-can.mjs → can-can.js} +13 -12
- package/src/channels-consumer.js +10 -0
- package/src/collection-loader.jsx +58 -224
- package/src/{collection.mjs → collection.js} +98 -44
- package/src/{command-submit-data.mjs → command-submit-data.js} +2 -7
- package/src/{commands-pool.mjs → commands-pool.js} +57 -41
- package/src/compose.js +11 -0
- package/src/{config.mjs → config.js} +6 -2
- package/src/{custom-error.mjs → custom-error.js} +1 -1
- package/src/data-set-to-attributes.js +13 -0
- package/src/{deserializer.mjs → deserializer.js} +3 -3
- package/src/destroy-error.js +7 -0
- package/src/devise.js +129 -0
- package/src/draggable-sort/controller.js +137 -0
- package/src/draggable-sort/index.jsx +108 -0
- package/src/draggable-sort/item.jsx +174 -0
- package/src/{error-logger.mjs → error-logger.js} +12 -7
- package/src/{error-messages.mjs → error-messages.js} +1 -0
- package/src/event-connection.jsx +1 -1
- package/src/event-emitter-listener.jsx +8 -27
- package/src/event-model-class.jsx +2 -4
- package/src/events.js +7 -0
- package/src/flash-message.js +70 -0
- package/src/form.jsx +91 -0
- package/src/history-expo.js +23 -0
- package/src/history-react-native.js +25 -0
- package/src/history.js +3 -0
- package/src/index.js +3 -0
- package/src/inputs/attachment.jsx +108 -0
- package/src/inputs/auto-submit.js +37 -0
- package/src/inputs/checkbox.jsx +125 -0
- package/src/inputs/checkboxes.jsx +116 -0
- package/src/inputs/id-for-component.js +15 -0
- package/src/inputs/input-wrapper.jsx +16 -0
- package/src/inputs/input.jsx +260 -0
- package/src/inputs/money.jsx +187 -0
- package/src/inputs/name-for-component.js +15 -0
- package/src/inputs/select.jsx +104 -0
- package/src/{key-value-store.mjs → key-value-store.js} +1 -1
- package/src/link.jsx +54 -9
- package/src/logger.js +38 -0
- package/src/modal.jsx +37 -0
- package/src/model-class-require.js +17 -0
- package/src/{model-events.mjs → model-events.js} +1 -1
- package/src/{model-name.mjs → model-name.js} +8 -8
- package/src/{model-recipes-loader.mjs → model-recipes-loader.js} +1 -1
- package/src/{model-recipes-model-loader.mjs → model-recipes-model-loader.js} +5 -5
- package/src/{models-response-reader.mjs → models-response-reader.js} +3 -4
- package/src/models.js +7 -0
- package/src/{models.mjs.erb → models.js.erb} +6 -3
- package/src/{money-formatter.mjs → money-formatter.js} +5 -4
- package/src/{params.mjs → params.js} +17 -7
- package/src/{preloaded.mjs → preloaded.js} +2 -2
- package/src/resize-observer.jsx +10 -0
- package/src/result.js +13 -0
- package/src/router/route.jsx +246 -0
- package/src/router/switch.jsx +76 -0
- package/src/router.jsx +23 -21
- package/src/{routes-native.mjs → routes-native.js} +12 -6
- package/src/{routes.mjs → routes.js} +1 -1
- package/src/run-last.js +39 -0
- package/src/{serializer.mjs → serializer.js} +2 -2
- package/src/{services.mjs → services.js} +1 -1
- package/src/session-status-updater.js +172 -0
- package/src/{source-maps-loader.mjs → source-maps-loader.js} +54 -28
- package/src/super-admin/config-reader.jsx +93 -0
- package/src/super-admin/edit-page/edit-attribute-checkbox.jsx +81 -0
- package/src/super-admin/edit-page/edit-attribute-content.jsx +57 -0
- package/src/super-admin/edit-page/edit-attribute-input.jsx +71 -0
- package/src/super-admin/edit-page/edit-attribute.jsx +81 -0
- package/src/super-admin/edit-page.jsx +117 -0
- package/src/super-admin/has-edit-config.js +15 -0
- package/src/super-admin/index-page.jsx +23 -0
- package/src/super-admin/index.jsx +197 -0
- package/src/super-admin/layout/header/index.jsx +144 -0
- package/src/super-admin/layout/header/style.scss +45 -0
- package/src/super-admin/layout/index.jsx +154 -0
- package/src/super-admin/layout/menu/index.jsx +171 -0
- package/src/super-admin/layout/menu/menu-content.jsx +43 -0
- package/src/super-admin/layout/menu/menu-item.jsx +70 -0
- package/src/super-admin/layout/menu/style.scss +11 -0
- package/src/super-admin/layout/no-access.jsx +26 -0
- package/src/super-admin/model-class-table.jsx +66 -0
- package/src/super-admin/models.js +11 -0
- package/src/super-admin/show-nav.jsx +44 -0
- package/src/super-admin/show-page/belongs-to-attribute-row.jsx +30 -0
- package/src/super-admin/show-page/index.jsx +141 -0
- package/src/super-admin/show-reflection-actions.jsx +49 -0
- package/src/super-admin/show-reflection-link.jsx +40 -0
- package/src/super-admin/show-reflection-page.jsx +47 -0
- package/src/super-admin/stylesheets/variables.scss +11 -0
- package/src/table/column-content.jsx +122 -0
- package/src/table/column-identifier.js +23 -0
- package/src/table/column-visible.js +7 -0
- package/src/table/components/column.jsx +19 -0
- package/src/table/components/flat-list.jsx +19 -0
- package/src/table/components/header.jsx +21 -0
- package/src/table/components/row.jsx +23 -0
- package/src/table/filters/attribute-element.jsx +47 -0
- package/src/table/filters/filter-form.jsx +407 -0
- package/src/table/filters/filter.jsx +70 -0
- package/src/table/filters/index.jsx +170 -0
- package/src/table/filters/load-search-modal.jsx +146 -0
- package/src/table/filters/reflection-element.jsx +38 -0
- package/src/table/filters/save-search-modal.jsx +74 -0
- package/src/table/filters/scope-element.jsx +44 -0
- package/src/table/header-column-content.jsx +55 -0
- package/src/table/header-column.jsx +129 -0
- package/src/table/header-select.jsx +73 -0
- package/src/table/model-callback-args.js +10 -0
- package/src/table/model-column.jsx +82 -0
- package/src/table/model-row.jsx +136 -0
- package/src/table/select-calculator.js +65 -0
- package/src/table/settings/column-row.jsx +93 -0
- package/src/table/settings/download-action.jsx +68 -0
- package/src/table/settings/index.jsx +65 -0
- package/src/table/table-settings.js +263 -0
- package/src/table/table.jsx +950 -0
- package/src/table/use-sorting.js +35 -0
- package/src/table/variables.scss +11 -0
- package/src/table/widths.jsx +87 -0
- package/src/table/worker-plugins-check-all-checkbox.jsx +112 -0
- package/src/table/worker-plugins-checkbox.jsx +104 -0
- package/src/translated-attributes.js +11 -0
- package/src/{translated-collections.mjs → translated-collections.js} +3 -2
- package/src/updated-attribute.jsx +1 -1
- package/src/url-encode.js +18 -0
- package/src/use-breakpoint.js +76 -0
- package/src/use-can-can.js +55 -0
- package/src/use-collection.js +280 -0
- package/src/use-created-event.js +55 -0
- package/src/use-current-user.js +88 -0
- package/src/use-destroyed-event.js +60 -0
- package/src/use-event-emitter.js +15 -0
- package/src/use-event-listener.js +19 -0
- package/src/use-input.js +157 -0
- package/src/use-model-event.js +60 -0
- package/src/use-model.js +189 -0
- package/src/use-resize-observer.js +24 -0
- package/src/use-router.jsx +128 -0
- package/src/use-screen-layout.js +49 -0
- package/src/use-updated-event.js +60 -0
- package/src/use-validation-errors.js +33 -0
- package/src/utils/card.jsx +49 -0
- package/src/utils/checkbox.jsx +80 -0
- package/src/utils/checkboxes.jsx +158 -0
- package/src/utils/default-style.jsx +25 -0
- package/src/utils/icon.jsx +21 -0
- package/src/utils/invalid-feedback.jsx +20 -0
- package/src/utils/modal.jsx +60 -0
- package/src/utils/text.jsx +16 -0
- package/src/{validation-error.mjs → validation-error.js} +9 -5
- package/src/{validation-errors.mjs → validation-errors.js} +15 -27
- package/src/with-api-maker.jsx +31 -0
- package/src/with-collection.jsx +17 -0
- package/src/with-current-user.jsx +7 -25
- package/src/with-model.jsx +16 -0
- package/src/with-router.jsx +7 -129
- package/__tests__/base-model.test.js +0 -71
- package/__tests__/cable-connection-pool.test.js +0 -227
- package/__tests__/cable-subscription-pool.test.js +0 -26
- package/__tests__/can-can.test.js +0 -34
- package/__tests__/collection.test.js +0 -51
- package/__tests__/custom-error.test.js +0 -13
- package/__tests__/model-name.test.js +0 -34
- package/__tests__/model-prop-type.test.js +0 -113
- package/__tests__/params.test.js +0 -40
- package/__tests__/routes-native.test.js +0 -103
- package/__tests__/routes.test.js +0 -46
- package/__tests__/serializer.test.js +0 -30
- package/__tests__/support/task.js +0 -27
- package/__tests__/support/user.js +0 -32
- package/index.js +0 -1
- package/jest.config.js +0 -4
- package/src/can-can-loader.jsx +0 -54
- package/src/channels-consumer.mjs +0 -3
- package/src/destroy-error.mjs +0 -7
- package/src/devise.mjs +0 -122
- package/src/event-created.jsx +0 -65
- package/src/event-destroyed.jsx +0 -29
- package/src/event-listener.jsx +0 -38
- package/src/event-updated.jsx +0 -74
- package/src/logger.mjs +0 -25
- package/src/model-class-require.mjs +0 -10
- package/src/model-load-wrapper.jsx +0 -116
- package/src/result.mjs +0 -29
- package/src/session-status-updater.mjs +0 -116
- package/webpack.config.js +0 -15
- /package/src/{attribute-not-loaded-error.mjs → attribute-not-loaded-error.js} +0 -0
- /package/src/{instance-of-class-name.mjs → instance-of-class-name.js} +0 -0
- /package/src/{model-prop-type.mjs → model-prop-type.js} +0 -0
- /package/src/{not-loaded-error.mjs → not-loaded-error.js} +0 -0
- /package/src/{translated-collections-data.mjs.erb → translated-collections-data.js.erb} +0 -0
|
@@ -0,0 +1,950 @@
|
|
|
1
|
+
import {digg, digs} from "diggerize"
|
|
2
|
+
import React, {createContext, useContext, useMemo, useRef} from "react"
|
|
3
|
+
import {Animated, Pressable, View} from "react-native"
|
|
4
|
+
import BaseComponent from "../base-component"
|
|
5
|
+
import Card from "../bootstrap/card"
|
|
6
|
+
import classNames from "classnames"
|
|
7
|
+
import Collection from "../collection"
|
|
8
|
+
import columnVisible from "./column-visible"
|
|
9
|
+
import debounce from "debounce"
|
|
10
|
+
import DraggableSort from "../draggable-sort/index"
|
|
11
|
+
import EventEmitter from "events"
|
|
12
|
+
import Filters from "./filters"
|
|
13
|
+
import FlatList from "./components/flat-list"
|
|
14
|
+
import {Form} from "../form"
|
|
15
|
+
import Header from "./components/header"
|
|
16
|
+
import HeaderColumn from "./header-column"
|
|
17
|
+
import HeaderSelect from "./header-select"
|
|
18
|
+
import Icon from "../utils/icon"
|
|
19
|
+
import * as inflection from "inflection"
|
|
20
|
+
import memo from "set-state-compare/src/memo"
|
|
21
|
+
import modelClassRequire from "../model-class-require"
|
|
22
|
+
import ModelRow from "./model-row"
|
|
23
|
+
import Paginate from "../bootstrap/paginate"
|
|
24
|
+
import Params from "../params"
|
|
25
|
+
import PropTypes from "prop-types"
|
|
26
|
+
import Row from "./components/row"
|
|
27
|
+
import selectCalculator from "./select-calculator"
|
|
28
|
+
import Select from "../inputs/select"
|
|
29
|
+
import Settings from "./settings/index"
|
|
30
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
31
|
+
import TableSettings from "./table-settings"
|
|
32
|
+
import Text from "../utils/text"
|
|
33
|
+
import uniqunize from "uniqunize"
|
|
34
|
+
import useBreakpoint from "../use-breakpoint"
|
|
35
|
+
import useCollection from "../use-collection"
|
|
36
|
+
import useI18n from "i18n-on-steroids/src/use-i18n"
|
|
37
|
+
import useEventEmitter from "../use-event-emitter"
|
|
38
|
+
import useModelEvent from "../use-model-event"
|
|
39
|
+
import useQueryParams from "on-location-changed/build/use-query-params"
|
|
40
|
+
import Widths from "./widths"
|
|
41
|
+
|
|
42
|
+
const paginationOptions = [30, 60, 90, ["All", "all"]]
|
|
43
|
+
const WorkerPluginsCheckAllCheckbox = React.lazy(() => import("./worker-plugins-check-all-checkbox"))
|
|
44
|
+
const TableContext = createContext()
|
|
45
|
+
|
|
46
|
+
const ListHeaderComponent = memo(shapeComponent(class ListHeaderComponent extends BaseComponent {
|
|
47
|
+
setup() {
|
|
48
|
+
this.useStates({
|
|
49
|
+
lastUpdate: new Date()
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
render() {
|
|
54
|
+
const {mdUp} = useBreakpoint()
|
|
55
|
+
const tableContextValue = useContext(TableContext)
|
|
56
|
+
const table = tableContextValue.table
|
|
57
|
+
const {collection, events, queryWithoutPagination, t} = table.tt
|
|
58
|
+
const {query} = digs(collection, "query")
|
|
59
|
+
|
|
60
|
+
useEventEmitter(events, "columnVisibilityUpdated", this.tt.onColumnVisibilityUpdated)
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<Row dataSet={{class: "api-maker/table/header-row"}} style={table.styleForRowHeader()}>
|
|
64
|
+
{table.p.workplace && table.s.currentWorkplace &&
|
|
65
|
+
<Header style={table.styleForHeader({style: {width: mdUp ? 41 : undefined}})}>
|
|
66
|
+
<WorkerPluginsCheckAllCheckbox
|
|
67
|
+
currentWorkplace={table.s.currentWorkplace}
|
|
68
|
+
query={queryWithoutPagination}
|
|
69
|
+
style={{marginHorizontal: "auto"}}
|
|
70
|
+
/>
|
|
71
|
+
{!mdUp &&
|
|
72
|
+
<Text style={{marginLeft: 3}}>
|
|
73
|
+
{t(".select_all_found", {defaultValue: "Select all found"})}
|
|
74
|
+
</Text>
|
|
75
|
+
}
|
|
76
|
+
</Header>
|
|
77
|
+
}
|
|
78
|
+
{!mdUp &&
|
|
79
|
+
<Header style={table.styleForHeader({style: {}})}>
|
|
80
|
+
<HeaderSelect preparedColumns={table.s.preparedColumns} query={query} table={table} />
|
|
81
|
+
</Header>
|
|
82
|
+
}
|
|
83
|
+
{mdUp &&
|
|
84
|
+
<>
|
|
85
|
+
{table.headersContentFromColumns()}
|
|
86
|
+
<Header style={table.styleForHeader({style: {}, type: "actions"})} />
|
|
87
|
+
</>
|
|
88
|
+
}
|
|
89
|
+
</Row>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
onColumnVisibilityUpdated = () => this.setState({lastUpdate: new Date()})
|
|
94
|
+
}))
|
|
95
|
+
|
|
96
|
+
export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
97
|
+
static defaultProps = {
|
|
98
|
+
card: true,
|
|
99
|
+
currentUser: null,
|
|
100
|
+
destroyEnabled: true,
|
|
101
|
+
filterCard: true,
|
|
102
|
+
filterSubmitButton: true,
|
|
103
|
+
noRecordsAvailableContent: undefined,
|
|
104
|
+
noRecordsFoundContent: undefined,
|
|
105
|
+
preloads: [],
|
|
106
|
+
select: {},
|
|
107
|
+
styleUI: true,
|
|
108
|
+
workplace: false
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
static propTypes = {
|
|
112
|
+
abilities: PropTypes.object,
|
|
113
|
+
actionsContent: PropTypes.func,
|
|
114
|
+
appHistory: PropTypes.object,
|
|
115
|
+
card: PropTypes.bool.isRequired,
|
|
116
|
+
className: PropTypes.string,
|
|
117
|
+
collection: PropTypes.instanceOf(Collection),
|
|
118
|
+
columns: PropTypes.oneOfType([PropTypes.array, PropTypes.func]),
|
|
119
|
+
controls: PropTypes.func,
|
|
120
|
+
currentUser: PropTypes.object,
|
|
121
|
+
defaultDateFormatName: PropTypes.string,
|
|
122
|
+
defaultDateTimeFormatName: PropTypes.string,
|
|
123
|
+
defaultParams: PropTypes.object,
|
|
124
|
+
destroyEnabled: PropTypes.bool.isRequired,
|
|
125
|
+
destroyMessage: PropTypes.string,
|
|
126
|
+
editModelPath: PropTypes.func,
|
|
127
|
+
filterCard: PropTypes.bool.isRequired,
|
|
128
|
+
filterContent: PropTypes.func,
|
|
129
|
+
filterSubmitLabel: PropTypes.node,
|
|
130
|
+
groupBy: PropTypes.array,
|
|
131
|
+
header: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
|
|
132
|
+
identifier: PropTypes.string,
|
|
133
|
+
modelClass: PropTypes.func.isRequired,
|
|
134
|
+
noRecordsAvailableContent: PropTypes.func,
|
|
135
|
+
noRecordsFoundContent: PropTypes.func,
|
|
136
|
+
onModelsLoaded: PropTypes.func,
|
|
137
|
+
paginateContent: PropTypes.func,
|
|
138
|
+
paginationComponent: PropTypes.func,
|
|
139
|
+
preloads: PropTypes.array.isRequired,
|
|
140
|
+
queryMethod: PropTypes.func,
|
|
141
|
+
queryName: PropTypes.string,
|
|
142
|
+
select: PropTypes.object,
|
|
143
|
+
selectColumns: PropTypes.object,
|
|
144
|
+
styles: PropTypes.object,
|
|
145
|
+
styleUI: PropTypes.bool.isRequired,
|
|
146
|
+
viewModelPath: PropTypes.func,
|
|
147
|
+
workplace: PropTypes.bool.isRequired
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
draggableSortEvents = new EventEmitter()
|
|
151
|
+
events = new EventEmitter()
|
|
152
|
+
tableSettings = null
|
|
153
|
+
|
|
154
|
+
setup() {
|
|
155
|
+
const {t} = useI18n({namespace: "js.api_maker.table"})
|
|
156
|
+
const {name: breakpoint, mdUp} = useBreakpoint()
|
|
157
|
+
const queryParams = useQueryParams()
|
|
158
|
+
|
|
159
|
+
this.setInstance({
|
|
160
|
+
breakpoint,
|
|
161
|
+
filterFormRef: useRef(),
|
|
162
|
+
mdUp,
|
|
163
|
+
t
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
const collectionKey = digg(this.p.modelClass.modelClassData(), "collectionKey")
|
|
167
|
+
let queryName = this.props.queryName
|
|
168
|
+
|
|
169
|
+
if (!queryName) queryName = collectionKey
|
|
170
|
+
|
|
171
|
+
const querySName = `${queryName}_s`
|
|
172
|
+
|
|
173
|
+
this.useStates({
|
|
174
|
+
columns: () => this.columnsAsArray(),
|
|
175
|
+
currentWorkplace: undefined,
|
|
176
|
+
currentWorkplaceCount: null,
|
|
177
|
+
filterForm: null,
|
|
178
|
+
columnsToShow: null,
|
|
179
|
+
draggedColumn: null,
|
|
180
|
+
identifier: () => this.props.identifier || `${collectionKey}-default`,
|
|
181
|
+
lastUpdate: () => new Date(),
|
|
182
|
+
preload: undefined,
|
|
183
|
+
preparedColumns: undefined,
|
|
184
|
+
queryName,
|
|
185
|
+
queryQName: () => `${queryName}_q`,
|
|
186
|
+
queryPageName: () => `${queryName}_page`,
|
|
187
|
+
querySName,
|
|
188
|
+
resizing: false,
|
|
189
|
+
showFilters: () => Boolean(queryParams[querySName]),
|
|
190
|
+
showSettings: false,
|
|
191
|
+
tableSetting: undefined,
|
|
192
|
+
tableSettingLoaded: false,
|
|
193
|
+
tableSettingFullCacheKey: undefined,
|
|
194
|
+
width: undefined,
|
|
195
|
+
widths: null
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
this.tableContextValue = useMemo(
|
|
199
|
+
() => ({
|
|
200
|
+
cacheKey: this.s.tableSettingFullCacheKey,
|
|
201
|
+
lastUpdate: this.s.lastUpdate,
|
|
202
|
+
resizing: this.s.resizing,
|
|
203
|
+
table: this
|
|
204
|
+
}),
|
|
205
|
+
[this.s.lastUpdate, this.s.resizing, this.s.tableSettingFullCacheKey]
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
useMemo(() => {
|
|
209
|
+
if (this.props.workplace) {
|
|
210
|
+
this.loadCurrentWorkplace().then(() => {
|
|
211
|
+
this.loadCurrentWorkplaceCount()
|
|
212
|
+
})
|
|
213
|
+
}
|
|
214
|
+
}, [this.p.currentUser?.id()])
|
|
215
|
+
|
|
216
|
+
useMemo(() => {
|
|
217
|
+
if (!this.tt.tableSettings && this.s.width) {
|
|
218
|
+
this.loadTableSetting()
|
|
219
|
+
}
|
|
220
|
+
}, [this.p.currentUser?.id(), this.s.width])
|
|
221
|
+
|
|
222
|
+
useModelEvent(this.s.currentWorkplace, "workplace_links_created", this.tt.onLinksCreated)
|
|
223
|
+
useModelEvent(this.s.currentWorkplace, "workplace_links_destroyed", this.tt.onLinksDestroyed)
|
|
224
|
+
|
|
225
|
+
let collectionReady = true
|
|
226
|
+
let select
|
|
227
|
+
|
|
228
|
+
if (!this.s.preparedColumns) {
|
|
229
|
+
collectionReady = false
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (collectionReady) {
|
|
233
|
+
select = selectCalculator({table: this})
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
this.collection = useCollection({
|
|
237
|
+
abilities: this.abilitiesToLoad(),
|
|
238
|
+
defaultParams: this.props.defaultParams,
|
|
239
|
+
collection: this.props.collection,
|
|
240
|
+
groupBy: this.props.groupBy,
|
|
241
|
+
ifCondition: collectionReady,
|
|
242
|
+
modelClass: this.props.modelClass,
|
|
243
|
+
onModelsLoaded: this.props.onModelsLoaded,
|
|
244
|
+
noRecordsAvailableContent: this.props.noRecordsAvailableContent,
|
|
245
|
+
noRecordsFoundContent: this.props.noRecordsFoundContent,
|
|
246
|
+
pagination: true,
|
|
247
|
+
preloads: this.state.preload,
|
|
248
|
+
queryMethod: this.props.queryMethod,
|
|
249
|
+
queryName,
|
|
250
|
+
select,
|
|
251
|
+
selectColumns: this.props.selectColumns
|
|
252
|
+
})
|
|
253
|
+
this.queryWithoutPagination = useMemo(
|
|
254
|
+
() => this.collection?.query?.clone()?.except("page"),
|
|
255
|
+
[this.collection.query]
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
useEventEmitter(this.tt.draggableSortEvents, "onDragStart", this.tt.onDragStart)
|
|
259
|
+
useEventEmitter(this.tt.draggableSortEvents, "onDragEndAnimation", this.tt.onDragEndAnimation)
|
|
260
|
+
useEventEmitter(this.tt.events, "columnVisibilityUpdated", this.tt.onColumnVisibilityUpdated)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
onColumnVisibilityUpdated = () => this.setState({columnsToShow: this.getColumnsToShow(this.s.columns), lastUpdate: new Date()})
|
|
264
|
+
onDragStart = ({item}) => item.animatedZIndex.setValue(9999)
|
|
265
|
+
onDragEndAnimation = ({item}) => item.animatedZIndex.setValue(0)
|
|
266
|
+
|
|
267
|
+
async loadCurrentWorkplace() {
|
|
268
|
+
const Workplace = modelClassRequire("Workplace")
|
|
269
|
+
const result = await Workplace.current()
|
|
270
|
+
const currentWorkplace = digg(result, "current", 0)
|
|
271
|
+
|
|
272
|
+
this.setState({currentWorkplace})
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async loadCurrentWorkplaceCount() {
|
|
276
|
+
const WorkplaceLink = modelClassRequire("WorkplaceLink")
|
|
277
|
+
const currentWorkplaceCount = await WorkplaceLink
|
|
278
|
+
.ransack({
|
|
279
|
+
resource_type_eq: this.p.modelClass.modelClassData().name,
|
|
280
|
+
workplace_id_eq: this.s.currentWorkplace.id()
|
|
281
|
+
})
|
|
282
|
+
.count()
|
|
283
|
+
|
|
284
|
+
this.setState({currentWorkplaceCount})
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
getColumnsToShow(columns) {
|
|
288
|
+
return columns
|
|
289
|
+
.filter(({column, tableSettingColumn}) => columnVisible(column, tableSettingColumn))
|
|
290
|
+
.sort((a, b) => a.tableSettingColumn.position() - b.tableSettingColumn.position())
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async loadTableSetting() {
|
|
294
|
+
this.tableSettings = new TableSettings({table: this})
|
|
295
|
+
|
|
296
|
+
const tableSetting = await this.tableSettings.loadExistingOrCreateTableSettings()
|
|
297
|
+
const {columns, preload} = this.tableSettings.preparedColumns(tableSetting)
|
|
298
|
+
const {width} = this.s
|
|
299
|
+
const widths = new Widths({columns, table: this, width})
|
|
300
|
+
const columnsToShow = this.getColumnsToShow(columns)
|
|
301
|
+
|
|
302
|
+
this.setState({
|
|
303
|
+
columns,
|
|
304
|
+
columnsToShow,
|
|
305
|
+
preparedColumns: columns,
|
|
306
|
+
preload: this.mergedPreloads(preload),
|
|
307
|
+
tableSetting,
|
|
308
|
+
tableSettingLoaded: true,
|
|
309
|
+
tableSettingFullCacheKey: tableSetting.fullCacheKey(),
|
|
310
|
+
widths
|
|
311
|
+
})
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
updateSettingsFullCacheKey = () => this.setState({tableSettingFullCacheKey: this.state.tableSetting.fullCacheKey()})
|
|
315
|
+
|
|
316
|
+
columnsAsArray = () => {
|
|
317
|
+
if (typeof this.props.columns == "function") {
|
|
318
|
+
return this.props.columns()
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return this.props.columns
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
mergedPreloads(preload) {
|
|
325
|
+
const {preloads} = this.props
|
|
326
|
+
let mergedPreloads = []
|
|
327
|
+
|
|
328
|
+
if (preloads) mergedPreloads = mergedPreloads.concat(preloads)
|
|
329
|
+
if (preload) mergedPreloads = mergedPreloads.concat(preload)
|
|
330
|
+
|
|
331
|
+
return uniqunize(mergedPreloads)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
render () {
|
|
335
|
+
const {modelClass, noRecordsAvailableContent, noRecordsFoundContent} = this.p
|
|
336
|
+
const {collection, currentUser} = this.props
|
|
337
|
+
const {queryName, querySName, showFilters} = this.s
|
|
338
|
+
const {
|
|
339
|
+
models,
|
|
340
|
+
overallCount,
|
|
341
|
+
qParams,
|
|
342
|
+
query,
|
|
343
|
+
result,
|
|
344
|
+
showNoRecordsAvailableContent,
|
|
345
|
+
showNoRecordsFoundContent
|
|
346
|
+
} = digs(
|
|
347
|
+
this.collection,
|
|
348
|
+
"models",
|
|
349
|
+
"overallCount",
|
|
350
|
+
"qParams",
|
|
351
|
+
"query",
|
|
352
|
+
"result",
|
|
353
|
+
"showNoRecordsAvailableContent",
|
|
354
|
+
"showNoRecordsFoundContent"
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
if (collection && collection.args.modelClass.modelClassData().name != modelClass.modelClassData().name) {
|
|
358
|
+
throw new Error(
|
|
359
|
+
`Model class from collection '${collection.args.modelClass.modelClassData().name}' ` +
|
|
360
|
+
`didn't match model class on table: '${modelClass.modelClassData().name}'`
|
|
361
|
+
)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return (
|
|
365
|
+
<View dataSet={{class: this.className()}} onLayout={this.tt.onContainerLayout} style={this.props.styles?.container}>
|
|
366
|
+
{showNoRecordsAvailableContent &&
|
|
367
|
+
<div className="live-table--no-records-available-content">
|
|
368
|
+
{noRecordsAvailableContent({models, qParams, overallCount})}
|
|
369
|
+
</div>
|
|
370
|
+
}
|
|
371
|
+
{showNoRecordsFoundContent &&
|
|
372
|
+
<div className="live-table--no-records-found-content">
|
|
373
|
+
{noRecordsFoundContent({models, qParams, overallCount})}
|
|
374
|
+
</div>
|
|
375
|
+
}
|
|
376
|
+
{showFilters &&
|
|
377
|
+
<Filters currentUser={currentUser} modelClass={modelClass} queryName={queryName} querySName={querySName} />
|
|
378
|
+
}
|
|
379
|
+
{qParams && query && result && models && !showNoRecordsAvailableContent && !showNoRecordsFoundContent &&
|
|
380
|
+
this.cardOrTable()
|
|
381
|
+
}
|
|
382
|
+
</View>
|
|
383
|
+
)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
abilitiesToLoad () {
|
|
387
|
+
const abilitiesToLoad = {}
|
|
388
|
+
const {abilities, modelClass} = this.props
|
|
389
|
+
const ownAbilities = []
|
|
390
|
+
|
|
391
|
+
if (this.props.destroyEnabled) ownAbilities.push("destroy")
|
|
392
|
+
if (this.props.editModelPath) ownAbilities.push("edit")
|
|
393
|
+
if (this.props.viewModelPath) ownAbilities.push("show")
|
|
394
|
+
|
|
395
|
+
if (ownAbilities.length > 0) {
|
|
396
|
+
const modelClassName = digg(modelClass.modelClassData(), "name")
|
|
397
|
+
|
|
398
|
+
abilitiesToLoad[modelClassName] = ownAbilities
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
if (abilities) {
|
|
402
|
+
for (const modelName in abilities) {
|
|
403
|
+
if (!(modelName in abilitiesToLoad)) {
|
|
404
|
+
abilitiesToLoad[modelName] = []
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
for (const ability of abilities[modelName]) {
|
|
408
|
+
abilitiesToLoad[modelName].push(ability)
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return abilitiesToLoad
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
cardOrTable () {
|
|
417
|
+
const {
|
|
418
|
+
abilities,
|
|
419
|
+
actionsContent,
|
|
420
|
+
appHistory,
|
|
421
|
+
card,
|
|
422
|
+
className,
|
|
423
|
+
collection,
|
|
424
|
+
columns,
|
|
425
|
+
controls,
|
|
426
|
+
currentUser,
|
|
427
|
+
defaultDateFormatName,
|
|
428
|
+
defaultDateTimeFormatName,
|
|
429
|
+
defaultParams,
|
|
430
|
+
destroyEnabled,
|
|
431
|
+
destroyMessage,
|
|
432
|
+
editModelPath,
|
|
433
|
+
filterCard,
|
|
434
|
+
filterContent,
|
|
435
|
+
filterSubmitButton,
|
|
436
|
+
filterSubmitLabel,
|
|
437
|
+
groupBy,
|
|
438
|
+
header,
|
|
439
|
+
identifier,
|
|
440
|
+
modelClass,
|
|
441
|
+
noRecordsAvailableContent,
|
|
442
|
+
noRecordsFoundContent,
|
|
443
|
+
onModelsLoaded,
|
|
444
|
+
paginateContent,
|
|
445
|
+
paginationComponent,
|
|
446
|
+
preloads,
|
|
447
|
+
queryMethod,
|
|
448
|
+
queryName,
|
|
449
|
+
select,
|
|
450
|
+
selectColumns,
|
|
451
|
+
styleUI,
|
|
452
|
+
viewModelPath,
|
|
453
|
+
workplace,
|
|
454
|
+
...restProps
|
|
455
|
+
} = this.props
|
|
456
|
+
const {models, qParams, query, result} = digs(this.collection, "models", "qParams", "query", "result")
|
|
457
|
+
|
|
458
|
+
let headerContent, PaginationComponent
|
|
459
|
+
|
|
460
|
+
if (typeof header == "function") {
|
|
461
|
+
headerContent = header({models, qParams, query, result})
|
|
462
|
+
} else if (header) {
|
|
463
|
+
headerContent = header
|
|
464
|
+
} else {
|
|
465
|
+
headerContent = modelClass.modelName().human({count: 2})
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (!paginateContent) {
|
|
469
|
+
if (paginationComponent) {
|
|
470
|
+
PaginationComponent = paginationComponent
|
|
471
|
+
} else {
|
|
472
|
+
PaginationComponent = Paginate
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const flatListStyle = {
|
|
477
|
+
overflowX: "auto"
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (styleUI) {
|
|
481
|
+
flatListStyle.border = "1px solid #dbdbdb"
|
|
482
|
+
flatListStyle.borderRadius = 5
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const flatList = (
|
|
486
|
+
<TableContext.Provider value={this.tt.tableContextValue}>
|
|
487
|
+
<FlatList
|
|
488
|
+
data={models}
|
|
489
|
+
dataSet={{
|
|
490
|
+
class: classNames("api-maker--table", className),
|
|
491
|
+
cacheKey: this.s.tableSettingFullCacheKey,
|
|
492
|
+
lastUpdate: this.s.lastUpdate
|
|
493
|
+
}}
|
|
494
|
+
extraData={this.s.lastUpdate}
|
|
495
|
+
keyExtractor={this.tt.keyExtrator}
|
|
496
|
+
ListHeaderComponent={ListHeaderComponent}
|
|
497
|
+
renderItem={this.tt.renderItem}
|
|
498
|
+
showsHorizontalScrollIndicator
|
|
499
|
+
style={flatListStyle}
|
|
500
|
+
{...restProps}
|
|
501
|
+
/>
|
|
502
|
+
</TableContext.Provider>
|
|
503
|
+
)
|
|
504
|
+
|
|
505
|
+
return (
|
|
506
|
+
<>
|
|
507
|
+
{filterContent && filterCard &&
|
|
508
|
+
<Card className="live-table--filter-card mb-4">
|
|
509
|
+
{this.filterForm()}
|
|
510
|
+
</Card>
|
|
511
|
+
}
|
|
512
|
+
{filterContent && !filterCard &&
|
|
513
|
+
this.filterForm()
|
|
514
|
+
}
|
|
515
|
+
{card &&
|
|
516
|
+
<Card
|
|
517
|
+
className={classNames("live-table--table-card", "mb-4", className)}
|
|
518
|
+
controls={this.tableControls()}
|
|
519
|
+
header={headerContent}
|
|
520
|
+
footer={this.tableFooter()}
|
|
521
|
+
{...restProps}
|
|
522
|
+
>
|
|
523
|
+
{flatList}
|
|
524
|
+
</Card>
|
|
525
|
+
}
|
|
526
|
+
{!card && flatList}
|
|
527
|
+
{result && PaginationComponent &&
|
|
528
|
+
<PaginationComponent result={result} />
|
|
529
|
+
}
|
|
530
|
+
{result && paginateContent &&
|
|
531
|
+
paginateContent({result})
|
|
532
|
+
}
|
|
533
|
+
</>
|
|
534
|
+
)
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
onContainerLayout = (e) => {
|
|
538
|
+
const {width} = e.nativeEvent.layout
|
|
539
|
+
const {widths} = this.s
|
|
540
|
+
|
|
541
|
+
this.setState({width})
|
|
542
|
+
if (widths) widths.tableWidth = width
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
onLinksCreated = ({args}) => {
|
|
546
|
+
const modelClassName = this.p.modelClass.modelClassData().name
|
|
547
|
+
|
|
548
|
+
if (args.created[modelClassName]) {
|
|
549
|
+
const amountCreated = args.created[modelClassName].length
|
|
550
|
+
|
|
551
|
+
this.setState((prevState) => ({
|
|
552
|
+
currentWorkplaceCount: prevState.currentWorkplaceCount + amountCreated
|
|
553
|
+
}))
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
onLinksDestroyed = ({args}) => {
|
|
558
|
+
const modelClassName = this.p.modelClass.modelClassData().name
|
|
559
|
+
|
|
560
|
+
if (args.destroyed[modelClassName]) {
|
|
561
|
+
const amountDestroyed = args.destroyed[modelClassName].length
|
|
562
|
+
|
|
563
|
+
this.setState((prevState) => ({
|
|
564
|
+
currentWorkplaceCount: prevState.currentWorkplaceCount - amountDestroyed
|
|
565
|
+
}))
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
keyExtrator = (model) => `${this.s.tableSettingFullCacheKey}-${model.id()}`
|
|
570
|
+
|
|
571
|
+
filterForm = () => {
|
|
572
|
+
const {filterFormRef, submitFilter, submitFilterDebounce} = this.tt
|
|
573
|
+
const {filterContent, filterSubmitButton} = this.p
|
|
574
|
+
const {queryQName} = this.s
|
|
575
|
+
const {filterSubmitLabel} = this.props
|
|
576
|
+
const {qParams} = digs(this.collection, "qParams")
|
|
577
|
+
|
|
578
|
+
return (
|
|
579
|
+
<Form className="live-table--filter-form" formRef={filterFormRef} onSubmit={this.tt.onFilterFormSubmit} setForm={this.setStates.filterForm}>
|
|
580
|
+
{"s" in qParams &&
|
|
581
|
+
<input name="s" type="hidden" value={qParams.s} />
|
|
582
|
+
}
|
|
583
|
+
{filterContent({
|
|
584
|
+
onFilterChanged: submitFilter,
|
|
585
|
+
onFilterChangedWithDelay: submitFilterDebounce,
|
|
586
|
+
qParams,
|
|
587
|
+
queryQName
|
|
588
|
+
})}
|
|
589
|
+
{filterSubmitButton &&
|
|
590
|
+
<input
|
|
591
|
+
className="btn btn-primary live-table--submit-filter-button"
|
|
592
|
+
type="submit"
|
|
593
|
+
style={{marginTop: "8px"}}
|
|
594
|
+
value={filterSubmitLabel || this.t(".filter", {defaultValue: "Filter"})}
|
|
595
|
+
/>
|
|
596
|
+
}
|
|
597
|
+
</Form>
|
|
598
|
+
)
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
onFilterClicked = (e) => {
|
|
602
|
+
e.preventDefault()
|
|
603
|
+
this.setState({showFilters: !this.state.showFilters})
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
onPerPageChanged = (e) => {
|
|
607
|
+
const {queryName} = this.s
|
|
608
|
+
const newPerPageValue = digg(e, "target", "value")
|
|
609
|
+
const perKey = `${queryName}_per`
|
|
610
|
+
const paramsChange = {}
|
|
611
|
+
|
|
612
|
+
paramsChange[perKey] = newPerPageValue
|
|
613
|
+
|
|
614
|
+
Params.changeParams(paramsChange)
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
renderItem = ({index, item: model}) => {
|
|
618
|
+
if (!this.s.tableSettingLoaded) {
|
|
619
|
+
return (
|
|
620
|
+
<View>
|
|
621
|
+
<Text>
|
|
622
|
+
{this.t(".loading_dot_dot_dot", {defaultValue: "Loading..."})}
|
|
623
|
+
</Text>
|
|
624
|
+
</View>
|
|
625
|
+
)
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
return (
|
|
629
|
+
<ModelRow
|
|
630
|
+
cacheKey={model.cacheKey()}
|
|
631
|
+
columns={this.s.columnsToShow}
|
|
632
|
+
columnWidths={this.columnWidths()}
|
|
633
|
+
events={this.tt.events}
|
|
634
|
+
index={index}
|
|
635
|
+
key={model.id()}
|
|
636
|
+
model={model}
|
|
637
|
+
table={this}
|
|
638
|
+
tableSettingFullCacheKey={this.s.tableSettingFullCacheKey}
|
|
639
|
+
/>
|
|
640
|
+
)
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
styleForColumn = ({column, columnIndex, even, style, type}) => {
|
|
644
|
+
const {styleUI} = this.p
|
|
645
|
+
const defaultStyle = {
|
|
646
|
+
justifyContent: "center",
|
|
647
|
+
padding: 8,
|
|
648
|
+
overflow: "hidden"
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
if (styleUI) {
|
|
652
|
+
Object.assign(defaultStyle, {
|
|
653
|
+
backgroundColor: even ? "#f5f5f5" : "#fff"
|
|
654
|
+
})
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (type == "actions") {
|
|
658
|
+
defaultStyle.flexDirection = "row"
|
|
659
|
+
defaultStyle.alignItems = "center"
|
|
660
|
+
|
|
661
|
+
if (this.tt.mdUp) {
|
|
662
|
+
defaultStyle.marginLeft = "auto"
|
|
663
|
+
} else {
|
|
664
|
+
defaultStyle.marginRight = "auto"
|
|
665
|
+
}
|
|
666
|
+
} else if (this.tt.mdUp && styleUI) {
|
|
667
|
+
defaultStyle.borderRight = "1px solid #dbdbdb"
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
const actualStyle = Object.assign(
|
|
671
|
+
defaultStyle,
|
|
672
|
+
style
|
|
673
|
+
)
|
|
674
|
+
|
|
675
|
+
return actualStyle
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
styleForHeader = ({column, columnIndex, style, type}) => {
|
|
679
|
+
const {mdUp} = this.tt
|
|
680
|
+
const defaultStyle = {
|
|
681
|
+
flexDirection: "row",
|
|
682
|
+
alignItems: "center",
|
|
683
|
+
padding: 8
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
if (type != "actions" && mdUp && this.p.styleUI) {
|
|
687
|
+
defaultStyle.borderRight = "1px solid #dbdbdb"
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
const actualStyle = Object.assign(
|
|
691
|
+
defaultStyle,
|
|
692
|
+
style
|
|
693
|
+
)
|
|
694
|
+
|
|
695
|
+
return actualStyle
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
styleForHeaderText() {
|
|
699
|
+
const actualStyle = {fontWeight: "bold"}
|
|
700
|
+
|
|
701
|
+
return actualStyle
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
styleForRow = ({even} = {}) => {
|
|
705
|
+
const actualStyle = {
|
|
706
|
+
flex: 1,
|
|
707
|
+
alignItems: "stretch"
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
if (even && this.p.styleUI) {
|
|
711
|
+
actualStyle.backgroundColor = "#f5f5f5"
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
return actualStyle
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
styleForRowHeader = () => {
|
|
718
|
+
const actualStyle = {
|
|
719
|
+
flex: 1,
|
|
720
|
+
alignItems: "stretch"
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
return actualStyle
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
tableControls() {
|
|
727
|
+
const {controls} = this.props
|
|
728
|
+
const {showSettings} = this.s
|
|
729
|
+
const {models, qParams, query, result} = digs(this.collection, "models", "qParams", "query", "result")
|
|
730
|
+
|
|
731
|
+
return (
|
|
732
|
+
<View style={{flexDirection: "row"}}>
|
|
733
|
+
{controls && controls({models, qParams, query, result})}
|
|
734
|
+
<Pressable dataSet={{class: "filter-button"}} onPress={this.tt.onFilterClicked}>
|
|
735
|
+
<Icon name="search" size={20} />
|
|
736
|
+
</Pressable>
|
|
737
|
+
<View style={{position: "relative"}}>
|
|
738
|
+
{showSettings &&
|
|
739
|
+
<Settings onRequestClose={this.tt.onRequestCloseSettings} table={this} />
|
|
740
|
+
}
|
|
741
|
+
<Pressable dataSet={{class: "settings-button"}} onPress={this.tt.onSettingsClicked}>
|
|
742
|
+
<Icon name="gear" size={20} />
|
|
743
|
+
</Pressable>
|
|
744
|
+
</View>
|
|
745
|
+
</View>
|
|
746
|
+
)
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
tableFooter() {
|
|
750
|
+
const {result} = digs(this.collection, "result")
|
|
751
|
+
const currentPage = result.currentPage()
|
|
752
|
+
const totalCount = result.totalCount()
|
|
753
|
+
const perPage = result.perPage()
|
|
754
|
+
const to = Math.min(currentPage * perPage, totalCount)
|
|
755
|
+
const defaultValue = "Showing %{from} to %{to} out of %{total_count} total."
|
|
756
|
+
let from = ((currentPage - 1) * perPage) + 1
|
|
757
|
+
|
|
758
|
+
if (to === 0) from = 0
|
|
759
|
+
|
|
760
|
+
return (
|
|
761
|
+
<View style={{flexDirection: "row", justifyContent: "space-between", marginTop: 10}}>
|
|
762
|
+
<View dataSet={{class: "showing-counts"}} style={{flexDirection: "row"}}>
|
|
763
|
+
<Text>
|
|
764
|
+
{this.t(".showing_from_to_out_of_total", {defaultValue, from, to, total_count: totalCount})}
|
|
765
|
+
</Text>
|
|
766
|
+
{this.p.workplace && this.s.currentWorkplaceCount !== null &&
|
|
767
|
+
<Text style={{marginLeft: 3}}>
|
|
768
|
+
{this.t(".x_selected", {defaultValue: "%{selected} selected.", selected: this.s.currentWorkplaceCount})}
|
|
769
|
+
</Text>
|
|
770
|
+
}
|
|
771
|
+
</View>
|
|
772
|
+
<View>
|
|
773
|
+
<Select
|
|
774
|
+
className="per-page-select"
|
|
775
|
+
defaultValue={perPage}
|
|
776
|
+
onChange={this.tt.onPerPageChanged}
|
|
777
|
+
options={paginationOptions}
|
|
778
|
+
/>
|
|
779
|
+
</View>
|
|
780
|
+
</View>
|
|
781
|
+
)
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
className() {
|
|
785
|
+
const classNames = ["api-maker--table"]
|
|
786
|
+
|
|
787
|
+
if (this.props.className) {
|
|
788
|
+
classNames.push(this.props.className)
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
return classNames.join(" ")
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
columnProps(column) {
|
|
795
|
+
const props = {}
|
|
796
|
+
|
|
797
|
+
if (column.textCenter) {
|
|
798
|
+
props.style ||= {}
|
|
799
|
+
props.style.textAlign = "center"
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
if (column.textRight) {
|
|
803
|
+
props.style ||= {}
|
|
804
|
+
props.style.textAlign = "right"
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
return props
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
headerProps(column) {
|
|
811
|
+
const props = {}
|
|
812
|
+
|
|
813
|
+
if (column.textCenter) {
|
|
814
|
+
props.style ||= {}
|
|
815
|
+
props.style.justifyContent = "center"
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
if (column.textRight) {
|
|
819
|
+
props.style ||= {}
|
|
820
|
+
props.style.justifyContent = "end"
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
return props
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
columnWidths() {
|
|
827
|
+
const columnWidths = {}
|
|
828
|
+
|
|
829
|
+
for (const column of this.s.preparedColumns) {
|
|
830
|
+
columnWidths[column.tableSettingColumn.identifier()] = column.width
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
return columnWidths
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
headersContentFromColumns = () => {
|
|
837
|
+
return (
|
|
838
|
+
<DraggableSort
|
|
839
|
+
data={this.s.columnsToShow}
|
|
840
|
+
events={this.tt.draggableSortEvents}
|
|
841
|
+
horizontal
|
|
842
|
+
keyExtractor={this.tt.dragListkeyExtractor}
|
|
843
|
+
onItemMoved={this.tt.onItemMoved}
|
|
844
|
+
onReordered={this.tt.onReordered}
|
|
845
|
+
renderItem={this.tt.dragListRenderItemContent}
|
|
846
|
+
/>
|
|
847
|
+
)
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
dragListCacheKeyExtractor = (item) => `${item.tableSettingColumn.identifier()}-${this.s.resizing}`
|
|
851
|
+
dragListkeyExtractor = (item) => item.tableSettingColumn.identifier()
|
|
852
|
+
|
|
853
|
+
onItemMoved = ({animationArgs, itemIndex, x, y}) => {
|
|
854
|
+
const animatedPosition = digg(this, "s", "columnsToShow", itemIndex, "animatedPosition")
|
|
855
|
+
|
|
856
|
+
if (animationArgs) {
|
|
857
|
+
Animated.timing(animatedPosition, animationArgs).start()
|
|
858
|
+
} else {
|
|
859
|
+
animatedPosition.setValue({x, y})
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
onReordered = async ({fromItem, fromPosition, toItem, toPosition}) => {
|
|
864
|
+
if (fromPosition == toPosition) return // Only do requests and queries if changed
|
|
865
|
+
|
|
866
|
+
const TableSettingColumn = fromItem.tableSettingColumn.constructor
|
|
867
|
+
const toColumn = await TableSettingColumn.find(toItem.tableSettingColumn.id()) // Need to load latest position because ActsAsList might have changed it
|
|
868
|
+
|
|
869
|
+
await fromItem.tableSettingColumn.update({position: toColumn.position()})
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
dragListRenderItemContent = ({isActive, item, touchProps}) => {
|
|
873
|
+
const {animatedWidth, animatedZIndex, column, tableSettingColumn} = item
|
|
874
|
+
|
|
875
|
+
return (
|
|
876
|
+
<HeaderColumn
|
|
877
|
+
active={isActive}
|
|
878
|
+
animatedWidth={animatedWidth}
|
|
879
|
+
animatedZIndex={animatedZIndex}
|
|
880
|
+
column={column}
|
|
881
|
+
key={tableSettingColumn.identifier()}
|
|
882
|
+
resizing={this.s.resizing}
|
|
883
|
+
table={this}
|
|
884
|
+
tableSettingColumn={tableSettingColumn}
|
|
885
|
+
touchProps={touchProps}
|
|
886
|
+
widths={this.s.widths}
|
|
887
|
+
/>
|
|
888
|
+
)
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
headerClassNameForColumn(column) {
|
|
892
|
+
const classNames = []
|
|
893
|
+
|
|
894
|
+
if (column.commonProps && column.commonProps.className) classNames.push(column.commonProps.className)
|
|
895
|
+
if (column.headerProps && column.headerProps.className) classNames.push(column.headerProps.className)
|
|
896
|
+
|
|
897
|
+
return classNames
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
headerLabelForColumn(column) {
|
|
901
|
+
const {modelClass} = this.p
|
|
902
|
+
|
|
903
|
+
if ("label" in column) {
|
|
904
|
+
if (typeof column.label == "function") {
|
|
905
|
+
return column.label()
|
|
906
|
+
} else {
|
|
907
|
+
return column.label
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
let currentModelClass = modelClass
|
|
912
|
+
|
|
913
|
+
// Calculate current model class through path
|
|
914
|
+
if (column.path) {
|
|
915
|
+
for (const pathPart of column.path) {
|
|
916
|
+
const relationships = digg(currentModelClass.modelClassData(), "relationships")
|
|
917
|
+
const relationship = relationships.find((relationshipInArray) => relationshipInArray.name == inflection.underscore(pathPart))
|
|
918
|
+
|
|
919
|
+
currentModelClass = modelClassRequire(digg(relationship, "resource_name"))
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
if (column.attribute) return currentModelClass.humanAttributeName(column.attribute)
|
|
924
|
+
|
|
925
|
+
throw new Error("No 'label' or 'attribute' was given")
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
onFilterFormSubmit = () => this.submitFilter()
|
|
929
|
+
onRequestCloseSettings = () => this.setState({showSettings: false})
|
|
930
|
+
|
|
931
|
+
onSettingsClicked = (e) => {
|
|
932
|
+
e.preventDefault()
|
|
933
|
+
|
|
934
|
+
this.setState({showSettings: !this.s.showSettings})
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
submitFilter = () => {
|
|
938
|
+
const filterForm = digg(this.tt.filterFormRef, "current")
|
|
939
|
+
const {appHistory} = this.props
|
|
940
|
+
const qParams = Params.serializeForm(filterForm)
|
|
941
|
+
const {queryQName} = this.s
|
|
942
|
+
const changeParamsParams = {}
|
|
943
|
+
|
|
944
|
+
changeParamsParams[queryQName] = JSON.stringify(qParams)
|
|
945
|
+
|
|
946
|
+
Params.changeParams(changeParamsParams, {appHistory})
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
submitFilterDebounce = debounce(this.tt.submitFilter)
|
|
950
|
+
}))
|