Repository URL to install this package:
|
Version:
3.12.20 ▾
|
@filerobot/explorer
/
lib
/
components
/
CollectionsView
/
Collection
/
PreviewCollectionDialog
/
index.js
|
|---|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { useRef, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useTheme } from '@scaleflex/ui/theme/hooks';
import { Button, Accordion } from '@scaleflex/ui/core';
import { OverlayCard, BackButton, CloseButton, Spinner, PC } from '@filerobot/common';
import { COLLECTION_TYPE_IDS } from '@filerobot/utils/lib/constants';
// LEGACY COMPONENT
// Replaced by GridView component
// TODO: remove this component when it isn't used anymore
// import GridLi from '@filerobot/provider-views/lib/components/AssetsList/GridView/GridLi'
// import getItemIcon from '@filerobot/utils/lib/getItemIcon'
import handlePromise from '@filerobot/utils/lib/handlePromise';
import { useExplorer } from '../../../../hooks';
import { fetchCollectionPreviewFiles } from './PreviewCollectionDialog.thunks';
import { previewCollectionPanelOpened, selectCreatePreviewCollection, selectPreviewCollection } from '../../../../slices/panels.slice';
import { createCollection } from '../../../../slices/collections.slice';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var PreviewCollectionDialog = function PreviewCollectionDialog() {
var dispatch = useDispatch();
var _useExplorer = useExplorer(),
i18n = _useExplorer.i18n,
info = _useExplorer.info,
floaty = _useExplorer.opts.floaty;
var theme = useTheme();
var iconPrimaryColor = theme.palette[PC.IconsPrimary];
var createPreviewCollection = useSelector(selectCreatePreviewCollection);
var previewCollection = useSelector(selectPreviewCollection);
// const isDevEnv = useExplorerContext(({ isDevEnv }) => isDevEnv)
// const container = useExplorerContext(({ container }) => container)
var _useState = useState(false),
_useState2 = _slicedToArray(_useState, 2),
isLoading = _useState2[0],
setIsLoading = _useState2[1];
var _useState3 = useState(false),
_useState4 = _slicedToArray(_useState3, 2),
isCreation = _useState4[0],
setIsCreation = _useState4[1];
var _useState5 = useState([]),
_useState6 = _slicedToArray(_useState5, 2),
collectionPreviewFiles = _useState6[0],
setCollectionPreviewFiles = _useState6[1];
var _useState7 = useState(true),
_useState8 = _slicedToArray(_useState7, 2),
isExpanded = _useState8[0],
setIsExpanded = _useState8[1];
var wrapperRef = useRef();
var handleCancel = function handleCancel() {
dispatch(previewCollectionPanelOpened({
showPreviewCollectionPanel: false
}));
};
var toggleExpanded = function toggleExpanded() {
return setIsExpanded(function (_value) {
return !_value;
});
};
var handleCreateCollection = function handleCreateCollection() {
setIsCreation(true);
dispatch(createCollection({
collection: previewCollection
}));
};
useEffect(function () {
if (previewCollection) {
var filters = {};
if ((previewCollection === null || previewCollection === void 0 ? void 0 : previewCollection.type) === COLLECTION_TYPE_IDS.FILTERS) {
var _previewCollection$da;
filters = previewCollection === null || previewCollection === void 0 ? void 0 : (_previewCollection$da = previewCollection.data) === null || _previewCollection$da === void 0 ? void 0 : _previewCollection$da.filters;
}
setIsLoading(true);
handlePromise(dispatch(fetchCollectionPreviewFiles({
filters: filters
})), setCollectionPreviewFiles, info, function () {
return setIsLoading(false);
});
}
}, [previewCollection]);
// const itemProps = (file) => ({
// id: file.uuid || file.id,
// title: file.name,
// size: file.size,
// showTitles: true,
// showMeta: true,
// i18n,
// containerWidth,
// lastModify: file.modified_at || file.updated_at,
// type: 'file',
// url: file.url
// })
var renderFilesList = function renderFilesList() {
return (collectionPreviewFiles || []).length > 0 ? /*#__PURE__*/_jsx("div", {
className: "filerobot-ProviderBrowser filerobot-ProviderBrowser-layoutType--grid",
children: /*#__PURE__*/_jsx("ul", {
className: "filerobot-Provider-ItemCategory-wrapper-list",
style: {
margin: 0
}
})
}) : isLoading ? /*#__PURE__*/_jsx(Spinner, {
fillContainer: true
}) : /*#__PURE__*/_jsx("div", {
className: "filerobot-c-empty left",
children: i18n('collectionDialogNoAssetsFoundText')
});
};
return /*#__PURE__*/_jsxs(OverlayCard, {
ref: wrapperRef,
children: [/*#__PURE__*/_jsxs("div", {
className: "filerobot-Explorer-PreviewCollectionDialog-header",
children: [/*#__PURE__*/_jsxs("div", {
className: "filerobot-Explorer-PreviewCollectionDialog-header-leftSide",
children: [!floaty && /*#__PURE__*/_jsx(BackButton, {
onClick: handleCancel,
iconPrimaryColor: iconPrimaryColor,
noMargin: true,
style: {
marginRight: 12
}
}), /*#__PURE__*/_jsx("label", {
children: i18n('collectionDialogPreviewCollectionLabel')
}), /*#__PURE__*/_jsx("div", {
children: previewCollection && createPreviewCollection && /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({
color: "primary",
onClick: handleCreateCollection,
loading: isCreation
}, floaty ? {
style: {
marginLeft: 16
}
} : {}), {}, {
children: i18n('collectionDialogCreateCollectionButton')
}))
})]
}), floaty && /*#__PURE__*/_jsx(CloseButton, {
hideDivider: true,
iconPrimaryColor: iconPrimaryColor,
onClick: handleCancel
})]
}), /*#__PURE__*/_jsx("div", {
className: "filerobot-Explorer-PreviewCollectionDialog-body",
children: /*#__PURE__*/_jsx(Accordion, {
expanded: isExpanded,
onChange: toggleExpanded,
label: i18n('mutualizedFilesWithCountLabel', {
files_count: collectionPreviewFiles.length
}),
children: renderFilesList()
})
})]
});
};
export default PreviewCollectionDialog;