@medusajs/loyalty-plugin 0.0.1 → 0.0.3
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/.medusa/server/src/admin/index.js +30277 -0
- package/.medusa/server/src/admin/index.mjs +30256 -0
- package/.medusa/server/src/api/store/carts/[id]/store-credits/route.js +24 -0
- package/.medusa/server/src/api/store/carts/middlewares.js +9 -1
- package/.medusa/server/src/api/store/carts/validators.js +5 -2
- package/.medusa/server/src/links/customer-gift-card-link.js +2 -2
- package/.medusa/server/src/links/customer-store-credit-account-link.js +2 -2
- package/.medusa/server/src/links/order-line-item-gift-card-link.js +2 -2
- package/.medusa/server/src/workflows/carts/workflows/add-store-credits-to-cart.js +104 -0
- package/.medusa/server/src/workflows/hooks/after-order-created.js +2 -2
- package/.medusa/server/src/workflows/hooks/after-order-credit-lines-created.js +3 -3
- package/.medusa/server/src/workflows/hooks/before-payment-collection-refresh.js +1 -1
- package/.medusa/server/src/workflows/hooks/complete-cart-before-payment-authorization.js +1 -1
- package/.medusa/server/src/workflows/orders/workflows/refund-credit-lines.js +115 -0
- package/package.json +14 -9
- package/.medusa/server/src/admin/components/action-menu.js +0 -63
- package/.medusa/server/src/admin/components/chip-group.js +0 -82
- package/.medusa/server/src/admin/components/chip-input.js +0 -157
- package/.medusa/server/src/admin/components/combobox.js +0 -324
- package/.medusa/server/src/admin/components/conditional-tooltip.js +0 -15
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-boolean-cell.js +0 -66
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-cell-container.js +0 -77
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-currency-cell.js +0 -110
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-duplicate-cell.js +0 -16
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-keyboard-shortcut-modal.js +0 -214
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-number-cell.js +0 -77
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-readonly-cell.js +0 -32
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-root.js +0 -743
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-row-error-indicator.js +0 -37
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-skeleton.js +0 -54
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-text-cell.js +0 -66
- package/.medusa/server/src/admin/components/data-grid/components/data-grid-toggleable-number-cell.js +0 -166
- package/.medusa/server/src/admin/components/data-grid/components/index.js +0 -16
- package/.medusa/server/src/admin/components/data-grid/context/data-grid-context.js +0 -7
- package/.medusa/server/src/admin/components/data-grid/context/index.js +0 -6
- package/.medusa/server/src/admin/components/data-grid/context/use-data-grid-context.js +0 -14
- package/.medusa/server/src/admin/components/data-grid/data-grid.js +0 -31
- package/.medusa/server/src/admin/components/data-grid/helpers/create-data-grid-column-helper.js +0 -28
- package/.medusa/server/src/admin/components/data-grid/helpers/create-data-grid-price-columns.js +0 -85
- package/.medusa/server/src/admin/components/data-grid/helpers/index.js +0 -6
- package/.medusa/server/src/admin/components/data-grid/hooks/index.js +0 -31
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-error.js +0 -50
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-handlers.js +0 -123
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-metadata.js +0 -52
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell-snapshot.js +0 -43
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-cell.js +0 -191
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-clipboard-events.js +0 -70
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-column-visibility.js +0 -51
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-duplicate-cell.js +0 -15
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-error-highlighting.js +0 -86
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-form-handlers.js +0 -149
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-keydown-event.js +0 -482
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-mouse-up-event.js +0 -64
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-navigation.js +0 -81
- package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-query-tool.js +0 -14
- package/.medusa/server/src/admin/components/data-grid/index.js +0 -8
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-bulk-update-command.js +0 -27
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-matrix.js +0 -296
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-query-tool.js +0 -62
- package/.medusa/server/src/admin/components/data-grid/models/data-grid-update-command.js +0 -25
- package/.medusa/server/src/admin/components/data-grid/models/index.js +0 -10
- package/.medusa/server/src/admin/components/data-grid/types.js +0 -1
- package/.medusa/server/src/admin/components/data-grid/utils.js +0 -18
- package/.medusa/server/src/admin/components/data-table/components/data-table-status-cell/data-table-status-cell.js +0 -36
- package/.medusa/server/src/admin/components/data-table/data-table.js +0 -271
- package/.medusa/server/src/admin/components/data-table/helpers/general/use-data-table-date-columns.js +0 -51
- package/.medusa/server/src/admin/components/data-table/helpers/general/use-data-table-date-filters.js +0 -90
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/index.js +0 -10
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-columns.js +0 -48
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-empty-state.js +0 -19
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-filters.js +0 -30
- package/.medusa/server/src/admin/components/data-table/helpers/sales-channels/use-sales-channel-table-query.js +0 -23
- package/.medusa/server/src/admin/components/data-table/index.js +0 -4
- package/.medusa/server/src/admin/components/data-table.js +0 -249
- package/.medusa/server/src/admin/components/display-id.js +0 -18
- package/.medusa/server/src/admin/components/file-upload.js +0 -116
- package/.medusa/server/src/admin/components/form.js +0 -151
- package/.medusa/server/src/admin/components/handle-input.js +0 -22
- package/.medusa/server/src/admin/components/header.js +0 -41
- package/.medusa/server/src/admin/components/icon-avatar.js +0 -27
- package/.medusa/server/src/admin/components/json-view-section.js +0 -139
- package/.medusa/server/src/admin/components/keybound-form.js +0 -32
- package/.medusa/server/src/admin/components/layouts/single-column.js +0 -7
- package/.medusa/server/src/admin/components/layouts/two-column.js +0 -13
- package/.medusa/server/src/admin/components/listicle.js +0 -20
- package/.medusa/server/src/admin/components/modals/index.js +0 -19
- package/.medusa/server/src/admin/components/modals/route-drawer/index.js +0 -4
- package/.medusa/server/src/admin/components/modals/route-drawer/route-drawer.js +0 -57
- package/.medusa/server/src/admin/components/modals/route-focus-modal/index.js +0 -4
- package/.medusa/server/src/admin/components/modals/route-focus-modal/route-focus-modal.js +0 -71
- package/.medusa/server/src/admin/components/modals/route-modal-form/index.js +0 -4
- package/.medusa/server/src/admin/components/modals/route-modal-form/route-modal-form.js +0 -60
- package/.medusa/server/src/admin/components/modals/route-modal-provider/index.js +0 -6
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-modal-context.js +0 -5
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-provider.js +0 -30
- package/.medusa/server/src/admin/components/modals/route-modal-provider/use-route-modal.js +0 -12
- package/.medusa/server/src/admin/components/modals/stacked-drawer/index.js +0 -5
- package/.medusa/server/src/admin/components/modals/stacked-drawer/stacked-drawer.js +0 -55
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/index.js +0 -5
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/stacked-focus-modal.js +0 -63
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/index.js +0 -6
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-context.js +0 -5
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-provider.js +0 -47
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/use-stacked-modal.js +0 -14
- package/.medusa/server/src/admin/components/placeholder-cell.js +0 -7
- package/.medusa/server/src/admin/components/product/product-cell/index.js +0 -5
- package/.medusa/server/src/admin/components/product/product-cell/product-cell.js +0 -15
- package/.medusa/server/src/admin/components/product/product-status-cell/index.js +0 -5
- package/.medusa/server/src/admin/components/product/product-status-cell/product-status-cell.js +0 -18
- package/.medusa/server/src/admin/components/product/sales-channels-cell/index.js +0 -5
- package/.medusa/server/src/admin/components/product/sales-channels-cell/sales-channels-cell.js +0 -31
- package/.medusa/server/src/admin/components/product/variant-cell/index.js +0 -5
- package/.medusa/server/src/admin/components/product/variant-cell/variant-cell.js +0 -15
- package/.medusa/server/src/admin/components/section-row.js +0 -32
- package/.medusa/server/src/admin/components/sidebar-link.js +0 -31
- package/.medusa/server/src/admin/components/sortable-list.js +0 -152
- package/.medusa/server/src/admin/components/switch-box.js +0 -43
- package/.medusa/server/src/admin/components/tax-badge.js +0 -18
- package/.medusa/server/src/admin/components/thumbnail.js +0 -28
- package/.medusa/server/src/admin/components/upload-media-form-item.js +0 -83
- package/.medusa/server/src/admin/hooks/api/customers.js +0 -26
- package/.medusa/server/src/admin/hooks/api/gift-cards.js +0 -107
- package/.medusa/server/src/admin/hooks/api/order.js +0 -16
- package/.medusa/server/src/admin/hooks/api/price-preferences.js +0 -19
- package/.medusa/server/src/admin/hooks/api/products.js +0 -127
- package/.medusa/server/src/admin/hooks/api/regions.js +0 -17
- package/.medusa/server/src/admin/hooks/api/sales-channels.js +0 -28
- package/.medusa/server/src/admin/hooks/api/store-credit-accounts.js +0 -41
- package/.medusa/server/src/admin/hooks/api/store.js +0 -31
- package/.medusa/server/src/admin/hooks/api/transaction-groups.js +0 -23
- package/.medusa/server/src/admin/hooks/api/transactions.js +0 -23
- package/.medusa/server/src/admin/hooks/commands/use-command-history.js +0 -45
- package/.medusa/server/src/admin/hooks/common/use-combobox-data.js +0 -59
- package/.medusa/server/src/admin/hooks/common/use-data-table-date-filters.js +0 -89
- package/.medusa/server/src/admin/hooks/common/use-date.js +0 -32
- package/.medusa/server/src/admin/hooks/common/use-debounced-search.js +0 -22
- package/.medusa/server/src/admin/hooks/common/use-query-params.js +0 -14
- package/.medusa/server/src/admin/hooks/query/use-customers-filters.js +0 -30
- package/.medusa/server/src/admin/hooks/query/use-transaction-groups-filters.js +0 -30
- package/.medusa/server/src/admin/hooks/sales-channels/index.js +0 -10
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-columns.js +0 -48
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-empty-state.js +0 -19
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-filters.js +0 -30
- package/.medusa/server/src/admin/hooks/sales-channels/use-sales-channel-table-query.js +0 -23
- package/.medusa/server/src/admin/lib/currencies.js +0 -729
- package/.medusa/server/src/admin/lib/query-key.js +0 -17
- package/.medusa/server/src/admin/lib/sdk.js +0 -10
- package/.medusa/server/src/admin/routes/gift-card-products/@create/page.js +0 -75
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@denominations/components/gift-card-product-edit-denominations-form.js +0 -172
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@denominations/page.js +0 -30
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@edit/components/gift-card-product-edit-form.js +0 -180
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/@edit/page.js +0 -30
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-general-section.js +0 -97
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-media-section.js +0 -162
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-sales-channel-section.js +0 -89
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/components/product-variant-section.js +0 -199
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/edit-product-media-form/edit-product-media-form.js +0 -353
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/edit-product-media-form/index.js +0 -5
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-gallery/index.js +0 -4
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-gallery/product-media-gallery.js +0 -247
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/index.js +0 -4
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/product-media-view-context.js +0 -5
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/product-media-view.js +0 -48
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/components/product-media-view/use-product-media-view.js +0 -14
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/media/page.js +0 -28
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/page.js +0 -40
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/prices/components/prices-edit.js +0 -121
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/prices/components/variant-pricing-form.js +0 -72
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/prices/page.js +0 -23
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/sales-channels/components/edit-sales-channel-form.js +0 -123
- package/.medusa/server/src/admin/routes/gift-card-products/_id_/sales-channels/page.js +0 -23
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/general-form-section.js +0 -1
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-denominations-form.js +0 -98
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-details-form.js +0 -28
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-denominations.js +0 -96
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-general.js +0 -90
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-media.js +0 -288
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-organize-section.js +0 -111
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form-organize.js +0 -23
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-create-form.js +0 -285
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/gift-card-product-sales-channel-stacked-modal.js +0 -124
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/index.js +0 -4
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/schema.js +0 -112
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-product-create-form/types.js +0 -1
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/columns.js +0 -35
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/filters.js +0 -11
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/gift-card-products-table.js +0 -61
- package/.medusa/server/src/admin/routes/gift-card-products/components/gift-card-products-table/query.js +0 -23
- package/.medusa/server/src/admin/routes/gift-card-products/page.js +0 -18
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@expiration/page.js +0 -137
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@note/page.js +0 -87
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@owner/components/transfer-icon.js +0 -352
- package/.medusa/server/src/admin/routes/gift-cards/_id_/@owner/page.js +0 -116
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-balance-section.js +0 -49
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-general-section.js +0 -177
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-note-section.js +0 -27
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-order-section.js +0 -33
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-owner-section.js +0 -33
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/gift-card-transactions-section.js +0 -18
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/transactions-table/columns.js +0 -50
- package/.medusa/server/src/admin/routes/gift-cards/_id_/components/transactions-table/query.js +0 -23
- package/.medusa/server/src/admin/routes/gift-cards/_id_/page.js +0 -78
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-card-products-section.js +0 -40
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/columns.js +0 -57
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/filters.js +0 -13
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/gift-cards-table.js +0 -61
- package/.medusa/server/src/admin/routes/gift-cards/components/gift-cards-table/query.js +0 -23
- package/.medusa/server/src/admin/routes/gift-cards/page.js +0 -27
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/credit-card-icon.js +0 -126
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/store-credit-account-balance-section.js +0 -31
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/store-credit-account-details-section.js +0 -43
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/columns.js +0 -44
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/filters.js +0 -18
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/query.js +0 -37
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/components/transactions-table/table.js +0 -58
- package/.medusa/server/src/admin/routes/store-credit-accounts/_id_/page.js +0 -39
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/columns.js +0 -58
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/filters.js +0 -13
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/query.js +0 -31
- package/.medusa/server/src/admin/routes/store-credit-accounts/components/store-credit-accounts-table/table.js +0 -56
- package/.medusa/server/src/admin/routes/store-credit-accounts/page.js +0 -19
- package/.medusa/server/src/admin/utils/date-utils.js +0 -27
- package/.medusa/server/src/admin/utils/format-amount.js +0 -9
- package/.medusa/server/src/admin/utils/format-date.js +0 -21
- package/.medusa/server/src/admin/utils/refs.js +0 -20
- package/.medusa/server/src/admin/utils/statuses.js +0 -23
- package/.medusa/server/src/admin/utils/validations.js +0 -71
- package/.medusa/server/src/admin/utils/variants.js +0 -92
- package/.medusa/server/src/admin/widgets/customer-gift-cards-widget.js +0 -67
- package/.medusa/server/src/admin/widgets/customer-store-credit-widget.js +0 -42
- package/.medusa/server/src/admin/widgets/order-gift-cards-widget.js +0 -58
- package/.medusa/server/src/workflows/orders/workflows/refund-gift-card-credit-lines.js +0 -96
- package/.medusa/server/types/loyalty/module.js +0 -8
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import { DataGridUpdateCommand } from "../models/data-grid-update-command.js";
|
|
3
|
-
const useDataGridCellHandlers = ({
|
|
4
|
-
matrix,
|
|
5
|
-
anchor,
|
|
6
|
-
rangeEnd,
|
|
7
|
-
setRangeEnd,
|
|
8
|
-
isDragging,
|
|
9
|
-
setIsDragging,
|
|
10
|
-
isSelecting,
|
|
11
|
-
setIsSelecting,
|
|
12
|
-
setSingleRange,
|
|
13
|
-
dragEnd,
|
|
14
|
-
setDragEnd,
|
|
15
|
-
setValue,
|
|
16
|
-
execute,
|
|
17
|
-
multiColumnSelection
|
|
18
|
-
}) => {
|
|
19
|
-
const getWrapperFocusHandler = useCallback(
|
|
20
|
-
(coords) => {
|
|
21
|
-
return (_e) => {
|
|
22
|
-
setSingleRange(coords);
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
[setSingleRange]
|
|
26
|
-
);
|
|
27
|
-
const getOverlayMouseDownHandler = useCallback(
|
|
28
|
-
(coords) => {
|
|
29
|
-
return (e) => {
|
|
30
|
-
e.stopPropagation();
|
|
31
|
-
e.preventDefault();
|
|
32
|
-
if (e.shiftKey) {
|
|
33
|
-
setRangeEnd(coords);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
setIsSelecting(true);
|
|
37
|
-
setSingleRange(coords);
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
[setIsSelecting, setRangeEnd, setSingleRange]
|
|
41
|
-
);
|
|
42
|
-
const getWrapperMouseOverHandler = useCallback(
|
|
43
|
-
(coords) => {
|
|
44
|
-
if (!isDragging && !isSelecting) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
return (_e) => {
|
|
48
|
-
if ((anchor == null ? void 0 : anchor.col) !== coords.col && !multiColumnSelection) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (isSelecting) {
|
|
52
|
-
setRangeEnd(coords);
|
|
53
|
-
} else {
|
|
54
|
-
setDragEnd(coords);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
[
|
|
59
|
-
anchor == null ? void 0 : anchor.col,
|
|
60
|
-
isDragging,
|
|
61
|
-
isSelecting,
|
|
62
|
-
setDragEnd,
|
|
63
|
-
setRangeEnd,
|
|
64
|
-
multiColumnSelection
|
|
65
|
-
]
|
|
66
|
-
);
|
|
67
|
-
const getInputChangeHandler = useCallback(
|
|
68
|
-
// Using `any` here as the generic type of Path<TFieldValues> will
|
|
69
|
-
// not be inferred correctly.
|
|
70
|
-
(field) => {
|
|
71
|
-
return (next, prev) => {
|
|
72
|
-
const command = new DataGridUpdateCommand({
|
|
73
|
-
next,
|
|
74
|
-
prev,
|
|
75
|
-
setter: (value) => {
|
|
76
|
-
setValue(field, value, {
|
|
77
|
-
shouldDirty: true,
|
|
78
|
-
shouldTouch: true
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
execute(command);
|
|
83
|
-
};
|
|
84
|
-
},
|
|
85
|
-
[setValue, execute]
|
|
86
|
-
);
|
|
87
|
-
const onDragToFillStart = useCallback(
|
|
88
|
-
(_e) => {
|
|
89
|
-
setIsDragging(true);
|
|
90
|
-
},
|
|
91
|
-
[setIsDragging]
|
|
92
|
-
);
|
|
93
|
-
const getIsCellSelected = useCallback(
|
|
94
|
-
(cell) => {
|
|
95
|
-
if (!cell || !anchor || !rangeEnd) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
return matrix.getIsCellSelected(cell, anchor, rangeEnd);
|
|
99
|
-
},
|
|
100
|
-
[anchor, rangeEnd, matrix]
|
|
101
|
-
);
|
|
102
|
-
const getIsCellDragSelected = useCallback(
|
|
103
|
-
(cell) => {
|
|
104
|
-
if (!cell || !anchor || !dragEnd) {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
return matrix.getIsCellSelected(cell, anchor, dragEnd);
|
|
108
|
-
},
|
|
109
|
-
[anchor, dragEnd, matrix]
|
|
110
|
-
);
|
|
111
|
-
return {
|
|
112
|
-
getWrapperFocusHandler,
|
|
113
|
-
getOverlayMouseDownHandler,
|
|
114
|
-
getWrapperMouseOverHandler,
|
|
115
|
-
getInputChangeHandler,
|
|
116
|
-
getIsCellSelected,
|
|
117
|
-
getIsCellDragSelected,
|
|
118
|
-
onDragToFillStart
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
export {
|
|
122
|
-
useDataGridCellHandlers
|
|
123
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import { generateCellId } from "../utils.js";
|
|
3
|
-
const useDataGridCellMetadata = ({
|
|
4
|
-
matrix
|
|
5
|
-
}) => {
|
|
6
|
-
const getCellMetadata = useCallback(
|
|
7
|
-
(coords) => {
|
|
8
|
-
const { row, col } = coords;
|
|
9
|
-
const id = generateCellId(coords);
|
|
10
|
-
const field = matrix.getCellField(coords);
|
|
11
|
-
const type = matrix.getCellType(coords);
|
|
12
|
-
if (!field || !type) {
|
|
13
|
-
throw new Error(`'field' or 'type' is null for cell ${id}`);
|
|
14
|
-
}
|
|
15
|
-
const inputAttributes = {
|
|
16
|
-
"data-row": row,
|
|
17
|
-
"data-col": col,
|
|
18
|
-
"data-cell-id": id,
|
|
19
|
-
"data-field": field
|
|
20
|
-
};
|
|
21
|
-
const innerAttributes = {
|
|
22
|
-
"data-container-id": id
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
id,
|
|
26
|
-
field,
|
|
27
|
-
type,
|
|
28
|
-
inputAttributes,
|
|
29
|
-
innerAttributes
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
[matrix]
|
|
33
|
-
);
|
|
34
|
-
const getCellErrorMetadata = useCallback(
|
|
35
|
-
(coords) => {
|
|
36
|
-
const accessor = matrix.getRowAccessor(coords.row);
|
|
37
|
-
const field = matrix.getCellField(coords);
|
|
38
|
-
return {
|
|
39
|
-
accessor,
|
|
40
|
-
field
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
[matrix]
|
|
44
|
-
);
|
|
45
|
-
return {
|
|
46
|
-
getCellMetadata,
|
|
47
|
-
getCellErrorMetadata
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
export {
|
|
51
|
-
useDataGridCellMetadata
|
|
52
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { useState, useCallback } from "react";
|
|
2
|
-
const useDataGridCellSnapshot = ({
|
|
3
|
-
matrix,
|
|
4
|
-
form
|
|
5
|
-
}) => {
|
|
6
|
-
const [snapshot, setSnapshot] = useState(null);
|
|
7
|
-
const { getValues, setValue } = form;
|
|
8
|
-
const createSnapshot = useCallback(
|
|
9
|
-
(cell) => {
|
|
10
|
-
if (!cell) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
const field = matrix.getCellField(cell);
|
|
14
|
-
if (!field) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
const value = getValues(field);
|
|
18
|
-
setSnapshot((curr) => {
|
|
19
|
-
if ((curr == null ? void 0 : curr.field) === field) {
|
|
20
|
-
return curr;
|
|
21
|
-
}
|
|
22
|
-
return { field, value };
|
|
23
|
-
});
|
|
24
|
-
},
|
|
25
|
-
[getValues, matrix]
|
|
26
|
-
);
|
|
27
|
-
const restoreSnapshot = useCallback(() => {
|
|
28
|
-
if (!snapshot) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const { field, value } = snapshot;
|
|
32
|
-
requestAnimationFrame(() => {
|
|
33
|
-
setValue(field, value);
|
|
34
|
-
});
|
|
35
|
-
}, [setValue, snapshot]);
|
|
36
|
-
return {
|
|
37
|
-
createSnapshot,
|
|
38
|
-
restoreSnapshot
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
export {
|
|
42
|
-
useDataGridCellSnapshot
|
|
43
|
-
};
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { useMemo, useState, useRef, useCallback, useEffect } from "react";
|
|
2
|
-
import "../context/data-grid-context.js";
|
|
3
|
-
import { useDataGridContext } from "../context/use-data-grid-context.js";
|
|
4
|
-
import { isSpecialFocusKey, isCellMatch } from "../utils.js";
|
|
5
|
-
const textCharacterRegex = /^.$/u;
|
|
6
|
-
const numberCharacterRegex = /^[0-9]$/u;
|
|
7
|
-
const useDataGridCell = ({
|
|
8
|
-
context
|
|
9
|
-
}) => {
|
|
10
|
-
const {
|
|
11
|
-
register,
|
|
12
|
-
control,
|
|
13
|
-
anchor,
|
|
14
|
-
setIsEditing,
|
|
15
|
-
setSingleRange,
|
|
16
|
-
setIsSelecting,
|
|
17
|
-
setRangeEnd,
|
|
18
|
-
getWrapperFocusHandler,
|
|
19
|
-
getWrapperMouseOverHandler,
|
|
20
|
-
getInputChangeHandler,
|
|
21
|
-
getIsCellSelected,
|
|
22
|
-
getIsCellDragSelected,
|
|
23
|
-
getCellMetadata
|
|
24
|
-
} = useDataGridContext();
|
|
25
|
-
const { rowIndex, columnIndex } = context;
|
|
26
|
-
const coords = useMemo(
|
|
27
|
-
() => ({ row: rowIndex, col: columnIndex }),
|
|
28
|
-
[rowIndex, columnIndex]
|
|
29
|
-
);
|
|
30
|
-
const { id, field, type, innerAttributes, inputAttributes } = useMemo(() => {
|
|
31
|
-
return getCellMetadata(coords);
|
|
32
|
-
}, [coords, getCellMetadata]);
|
|
33
|
-
const [showOverlay, setShowOverlay] = useState(true);
|
|
34
|
-
const containerRef = useRef(null);
|
|
35
|
-
const inputRef = useRef(null);
|
|
36
|
-
const handleOverlayMouseDown = useCallback(
|
|
37
|
-
(e) => {
|
|
38
|
-
e.preventDefault();
|
|
39
|
-
e.stopPropagation();
|
|
40
|
-
if (e.detail === 2) {
|
|
41
|
-
if (inputRef.current) {
|
|
42
|
-
setShowOverlay(false);
|
|
43
|
-
inputRef.current.focus();
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (e.shiftKey) {
|
|
48
|
-
if (coords.col === (anchor == null ? void 0 : anchor.col)) {
|
|
49
|
-
setRangeEnd(coords);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (containerRef.current) {
|
|
54
|
-
setSingleRange(coords);
|
|
55
|
-
setIsSelecting(true);
|
|
56
|
-
containerRef.current.focus();
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
[coords, anchor, setRangeEnd, setSingleRange, setIsSelecting]
|
|
60
|
-
);
|
|
61
|
-
const handleBooleanInnerMouseDown = useCallback(
|
|
62
|
-
(e) => {
|
|
63
|
-
var _a;
|
|
64
|
-
e.preventDefault();
|
|
65
|
-
e.stopPropagation();
|
|
66
|
-
if (e.detail === 2) {
|
|
67
|
-
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (e.shiftKey) {
|
|
71
|
-
setRangeEnd(coords);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (containerRef.current) {
|
|
75
|
-
setSingleRange(coords);
|
|
76
|
-
setIsSelecting(true);
|
|
77
|
-
containerRef.current.focus();
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
[setIsSelecting, setSingleRange, setRangeEnd, coords]
|
|
81
|
-
);
|
|
82
|
-
const handleInputBlur = useCallback(() => {
|
|
83
|
-
setShowOverlay(true);
|
|
84
|
-
setIsEditing(false);
|
|
85
|
-
}, [setIsEditing]);
|
|
86
|
-
const handleInputFocus = useCallback(() => {
|
|
87
|
-
setShowOverlay(false);
|
|
88
|
-
setIsEditing(true);
|
|
89
|
-
}, [setIsEditing]);
|
|
90
|
-
const validateKeyStroke = useCallback(
|
|
91
|
-
(key) => {
|
|
92
|
-
switch (type) {
|
|
93
|
-
case "togglable-number":
|
|
94
|
-
case "number":
|
|
95
|
-
return numberCharacterRegex.test(key);
|
|
96
|
-
case "text":
|
|
97
|
-
return textCharacterRegex.test(key);
|
|
98
|
-
default:
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
[type]
|
|
103
|
-
);
|
|
104
|
-
const handleContainerKeyDown = useCallback(
|
|
105
|
-
(e) => {
|
|
106
|
-
var _a;
|
|
107
|
-
if (!inputRef.current || !validateKeyStroke(e.key) || !showOverlay) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (e.key.toLowerCase() === "z" && (e.ctrlKey || e.metaKey)) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
if (e.key.toLowerCase() === "c" && (e.ctrlKey || e.metaKey)) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if (e.key.toLowerCase() === "v" && (e.ctrlKey || e.metaKey)) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (e.key === "Enter") {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (isSpecialFocusKey(e.nativeEvent)) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
inputRef.current.focus();
|
|
126
|
-
setShowOverlay(false);
|
|
127
|
-
if (inputRef.current instanceof HTMLInputElement) {
|
|
128
|
-
inputRef.current.value = "";
|
|
129
|
-
const nativeInputValueSetter = (_a = Object.getOwnPropertyDescriptor(
|
|
130
|
-
window.HTMLInputElement.prototype,
|
|
131
|
-
"value"
|
|
132
|
-
)) == null ? void 0 : _a.set;
|
|
133
|
-
nativeInputValueSetter == null ? void 0 : nativeInputValueSetter.call(inputRef.current, e.key);
|
|
134
|
-
const event = new Event("input", { bubbles: true });
|
|
135
|
-
inputRef.current.dispatchEvent(event);
|
|
136
|
-
}
|
|
137
|
-
e.stopPropagation();
|
|
138
|
-
e.preventDefault();
|
|
139
|
-
},
|
|
140
|
-
[showOverlay, validateKeyStroke]
|
|
141
|
-
);
|
|
142
|
-
const isAnchor = useMemo(() => {
|
|
143
|
-
return anchor ? isCellMatch(coords, anchor) : false;
|
|
144
|
-
}, [anchor, coords]);
|
|
145
|
-
const fieldWithoutOverlay = useMemo(() => {
|
|
146
|
-
return type === "boolean";
|
|
147
|
-
}, [type]);
|
|
148
|
-
useEffect(() => {
|
|
149
|
-
var _a, _b;
|
|
150
|
-
if (isAnchor && !((_a = containerRef.current) == null ? void 0 : _a.contains(document.activeElement))) {
|
|
151
|
-
(_b = containerRef.current) == null ? void 0 : _b.focus();
|
|
152
|
-
}
|
|
153
|
-
}, [isAnchor]);
|
|
154
|
-
const renderProps = {
|
|
155
|
-
container: {
|
|
156
|
-
field,
|
|
157
|
-
isAnchor,
|
|
158
|
-
isSelected: getIsCellSelected(coords),
|
|
159
|
-
isDragSelected: getIsCellDragSelected(coords),
|
|
160
|
-
showOverlay: fieldWithoutOverlay ? false : showOverlay,
|
|
161
|
-
innerProps: {
|
|
162
|
-
ref: containerRef,
|
|
163
|
-
onMouseOver: getWrapperMouseOverHandler(coords),
|
|
164
|
-
onMouseDown: type === "boolean" ? handleBooleanInnerMouseDown : void 0,
|
|
165
|
-
onKeyDown: handleContainerKeyDown,
|
|
166
|
-
onFocus: getWrapperFocusHandler(coords),
|
|
167
|
-
...innerAttributes
|
|
168
|
-
},
|
|
169
|
-
overlayProps: {
|
|
170
|
-
onMouseDown: handleOverlayMouseDown
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
input: {
|
|
174
|
-
ref: inputRef,
|
|
175
|
-
onBlur: handleInputBlur,
|
|
176
|
-
onFocus: handleInputFocus,
|
|
177
|
-
onChange: getInputChangeHandler(field),
|
|
178
|
-
...inputAttributes
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
return {
|
|
182
|
-
id,
|
|
183
|
-
field,
|
|
184
|
-
register,
|
|
185
|
-
control,
|
|
186
|
-
renderProps
|
|
187
|
-
};
|
|
188
|
-
};
|
|
189
|
-
export {
|
|
190
|
-
useDataGridCell
|
|
191
|
-
};
|
package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-clipboard-events.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
import { DataGridBulkUpdateCommand } from "../models/data-grid-bulk-update-command.js";
|
|
3
|
-
const useDataGridClipboardEvents = ({
|
|
4
|
-
matrix,
|
|
5
|
-
anchor,
|
|
6
|
-
rangeEnd,
|
|
7
|
-
isEditing,
|
|
8
|
-
getSelectionValues,
|
|
9
|
-
setSelectionValues,
|
|
10
|
-
execute
|
|
11
|
-
}) => {
|
|
12
|
-
const handleCopyEvent = useCallback(
|
|
13
|
-
(e) => {
|
|
14
|
-
var _a;
|
|
15
|
-
if (isEditing || !anchor || !rangeEnd) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
e.preventDefault();
|
|
19
|
-
const fields = matrix.getFieldsInSelection(anchor, rangeEnd);
|
|
20
|
-
const values = getSelectionValues(fields);
|
|
21
|
-
const text = values.map((value) => {
|
|
22
|
-
if (typeof value === "object" && value !== null) {
|
|
23
|
-
return JSON.stringify(value);
|
|
24
|
-
}
|
|
25
|
-
return `${value}` ?? "";
|
|
26
|
-
}).join(" ");
|
|
27
|
-
(_a = e.clipboardData) == null ? void 0 : _a.setData("text/plain", text);
|
|
28
|
-
},
|
|
29
|
-
[isEditing, anchor, rangeEnd, matrix, getSelectionValues]
|
|
30
|
-
);
|
|
31
|
-
const handlePasteEvent = useCallback(
|
|
32
|
-
(e) => {
|
|
33
|
-
var _a;
|
|
34
|
-
if (isEditing || !anchor || !rangeEnd) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
e.preventDefault();
|
|
38
|
-
const text = (_a = e.clipboardData) == null ? void 0 : _a.getData("text/plain");
|
|
39
|
-
if (!text) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const next = text.split(" ");
|
|
43
|
-
const fields = matrix.getFieldsInSelection(anchor, rangeEnd);
|
|
44
|
-
const prev = getSelectionValues(fields);
|
|
45
|
-
const command = new DataGridBulkUpdateCommand({
|
|
46
|
-
fields,
|
|
47
|
-
next,
|
|
48
|
-
prev,
|
|
49
|
-
setter: setSelectionValues
|
|
50
|
-
});
|
|
51
|
-
execute(command);
|
|
52
|
-
},
|
|
53
|
-
[
|
|
54
|
-
isEditing,
|
|
55
|
-
anchor,
|
|
56
|
-
rangeEnd,
|
|
57
|
-
matrix,
|
|
58
|
-
getSelectionValues,
|
|
59
|
-
setSelectionValues,
|
|
60
|
-
execute
|
|
61
|
-
]
|
|
62
|
-
);
|
|
63
|
-
return {
|
|
64
|
-
handleCopyEvent,
|
|
65
|
-
handlePasteEvent
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
export {
|
|
69
|
-
useDataGridClipboardEvents
|
|
70
|
-
};
|
package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-column-visibility.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { useCallback } from "react";
|
|
2
|
-
function useDataGridColumnVisibility(grid, matrix) {
|
|
3
|
-
const columns = grid.getAllLeafColumns();
|
|
4
|
-
const columnOptions = columns.map((column) => ({
|
|
5
|
-
id: column.id,
|
|
6
|
-
name: getColumnName(column),
|
|
7
|
-
checked: column.getIsVisible(),
|
|
8
|
-
disabled: !column.getCanHide()
|
|
9
|
-
}));
|
|
10
|
-
const handleToggleColumn = useCallback(
|
|
11
|
-
(index) => (value) => {
|
|
12
|
-
const column = columns[index];
|
|
13
|
-
if (!column.getCanHide()) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
matrix.toggleColumn(index, value);
|
|
17
|
-
column.toggleVisibility(value);
|
|
18
|
-
},
|
|
19
|
-
[columns, matrix]
|
|
20
|
-
);
|
|
21
|
-
const handleResetColumns = useCallback(() => {
|
|
22
|
-
grid.setColumnVisibility({});
|
|
23
|
-
}, [grid]);
|
|
24
|
-
const optionCount = columnOptions.filter((c) => !c.disabled).length;
|
|
25
|
-
const isDisabled = optionCount === 0;
|
|
26
|
-
return {
|
|
27
|
-
columnOptions,
|
|
28
|
-
handleToggleColumn,
|
|
29
|
-
handleResetColumns,
|
|
30
|
-
isDisabled
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function getColumnName(column) {
|
|
34
|
-
const id = column.columnDef.id;
|
|
35
|
-
const enableHiding = column.columnDef.enableHiding;
|
|
36
|
-
const meta = column == null ? void 0 : column.columnDef.meta;
|
|
37
|
-
if (!id) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
"Column is missing an id, which is a required field. Please provide an id for the column."
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
if (process.env.NODE_ENV === "development" && !(meta == null ? void 0 : meta.name) && enableHiding) {
|
|
43
|
-
console.warn(
|
|
44
|
-
`Column "${id}" does not have a name. You should add a name to the column definition. Falling back to the column id.`
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
return (meta == null ? void 0 : meta.name) || id;
|
|
48
|
-
}
|
|
49
|
-
export {
|
|
50
|
-
useDataGridColumnVisibility
|
|
51
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { useWatch } from "/Users/oliverjuhl/Desktop/medusa/loyalty-plugin/node_modules/react-hook-form/dist/index.esm.mjs";
|
|
2
|
-
import "../context/data-grid-context.js";
|
|
3
|
-
import { useDataGridContext } from "../context/use-data-grid-context.js";
|
|
4
|
-
const useDataGridDuplicateCell = ({
|
|
5
|
-
duplicateOf
|
|
6
|
-
}) => {
|
|
7
|
-
const { control } = useDataGridContext();
|
|
8
|
-
const watchedValue = useWatch({ control, name: duplicateOf });
|
|
9
|
-
return {
|
|
10
|
-
watchedValue
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
export {
|
|
14
|
-
useDataGridDuplicateCell
|
|
15
|
-
};
|
package/.medusa/server/src/admin/components/data-grid/hooks/use-data-grid-error-highlighting.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { useState, useMemo, useCallback } from "react";
|
|
2
|
-
const useDataGridErrorHighlighting = (matrix, grid, errors) => {
|
|
3
|
-
const [isHighlighted, setIsHighlighted] = useState(false);
|
|
4
|
-
const [visibilitySnapshot, setVisibilitySnapshot] = useState(null);
|
|
5
|
-
const { flatRows } = grid.getRowModel();
|
|
6
|
-
const flatColumns = grid.getAllFlatColumns();
|
|
7
|
-
const errorPaths = findErrorPaths(errors);
|
|
8
|
-
const errorCount = errorPaths.length;
|
|
9
|
-
const { rowsWithErrors, columnsWithErrors } = useMemo(() => {
|
|
10
|
-
const rowsWithErrors2 = /* @__PURE__ */ new Set();
|
|
11
|
-
const columnsWithErrors2 = /* @__PURE__ */ new Set();
|
|
12
|
-
errorPaths.forEach((errorPath) => {
|
|
13
|
-
const rowIndex = matrix.rowAccessors.findIndex(
|
|
14
|
-
(accessor) => accessor && (errorPath === accessor || errorPath.startsWith(`${accessor}.`))
|
|
15
|
-
);
|
|
16
|
-
if (rowIndex !== -1) {
|
|
17
|
-
rowsWithErrors2.add(rowIndex);
|
|
18
|
-
}
|
|
19
|
-
const columnIndex = matrix.columnAccessors.findIndex(
|
|
20
|
-
(accessor) => accessor && (errorPath === accessor || errorPath.endsWith(`.${accessor}`))
|
|
21
|
-
);
|
|
22
|
-
if (columnIndex !== -1) {
|
|
23
|
-
columnsWithErrors2.add(columnIndex);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
return { rowsWithErrors: rowsWithErrors2, columnsWithErrors: columnsWithErrors2 };
|
|
27
|
-
}, [errorPaths, matrix.rowAccessors, matrix.columnAccessors]);
|
|
28
|
-
const toggleErrorHighlighting = useCallback(
|
|
29
|
-
(currentRowVisibility, currentColumnVisibility, setRowVisibility, setColumnVisibility) => {
|
|
30
|
-
if (isHighlighted) {
|
|
31
|
-
if (visibilitySnapshot) {
|
|
32
|
-
setRowVisibility(visibilitySnapshot.rows);
|
|
33
|
-
setColumnVisibility(visibilitySnapshot.columns);
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
setVisibilitySnapshot({
|
|
37
|
-
rows: { ...currentRowVisibility },
|
|
38
|
-
columns: { ...currentColumnVisibility }
|
|
39
|
-
});
|
|
40
|
-
const rowsToHide = flatRows.map((_, index) => {
|
|
41
|
-
return !rowsWithErrors.has(index) ? index : void 0;
|
|
42
|
-
}).filter((index) => index !== void 0);
|
|
43
|
-
const columnsToHide = flatColumns.map((column, index) => {
|
|
44
|
-
return !columnsWithErrors.has(index) && index !== 0 ? column.id : void 0;
|
|
45
|
-
}).filter((id) => id !== void 0);
|
|
46
|
-
setRowVisibility(
|
|
47
|
-
rowsToHide.reduce((acc, row) => ({ ...acc, [row]: false }), {})
|
|
48
|
-
);
|
|
49
|
-
setColumnVisibility(
|
|
50
|
-
columnsToHide.reduce(
|
|
51
|
-
(acc, column) => ({ ...acc, [column]: false }),
|
|
52
|
-
{}
|
|
53
|
-
)
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
setIsHighlighted((prev) => !prev);
|
|
57
|
-
},
|
|
58
|
-
[
|
|
59
|
-
isHighlighted,
|
|
60
|
-
visibilitySnapshot,
|
|
61
|
-
flatRows,
|
|
62
|
-
flatColumns,
|
|
63
|
-
rowsWithErrors,
|
|
64
|
-
columnsWithErrors
|
|
65
|
-
]
|
|
66
|
-
);
|
|
67
|
-
return {
|
|
68
|
-
errorCount,
|
|
69
|
-
isHighlighted,
|
|
70
|
-
toggleErrorHighlighting
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
function findErrorPaths(obj, path = []) {
|
|
74
|
-
if (typeof obj !== "object" || obj === null) {
|
|
75
|
-
return [];
|
|
76
|
-
}
|
|
77
|
-
if ("message" in obj && "type" in obj) {
|
|
78
|
-
return [path.join(".")];
|
|
79
|
-
}
|
|
80
|
-
return Object.entries(obj).flatMap(
|
|
81
|
-
([key, value]) => findErrorPaths(value, [...path, key])
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
export {
|
|
85
|
-
useDataGridErrorHighlighting
|
|
86
|
-
};
|