Files
klz-cables.com/.pnpm-store/v10/files/3b/c8e71e35e5e1891e702e3815dc3636246fa8345c769d2d86433324dcf54e400e1c9a115c4019c2173e62094002ddf8432865c3906fe55b524fb2daeb25c00a
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

136 lines
4.5 KiB
Plaintext

'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import { useModal } from '@faceless-ui/modal';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { toast } from 'sonner';
import { LoadingOverlay } from '../../elements/Loading/index.js';
import { useConfig } from '../../providers/Config/index.js';
import { useServerFunctions } from '../../providers/ServerFunctions/index.js';
import { useTranslation } from '../../providers/Translation/index.js';
import { abortAndIgnore, handleAbortRef } from '../../utilities/abortAndIgnore.js';
import { DocumentDrawerContextProvider } from './Provider.js';
export const DocumentDrawerContent = ({
id: docID,
collectionSlug,
disableActions,
drawerSlug,
initialData,
onDelete: onDeleteFromProps,
onDuplicate: onDuplicateFromProps,
onSave: onSaveFromProps,
overrideEntityVisibility = true,
redirectAfterCreate,
redirectAfterDelete,
redirectAfterDuplicate,
redirectAfterRestore
}) => {
const {
getEntityConfig
} = useConfig();
const [collectionConfig] = useState(() => getEntityConfig({
collectionSlug
}));
const abortGetDocumentViewRef = React.useRef(null);
const {
closeModal
} = useModal();
const {
t
} = useTranslation();
const {
renderDocument
} = useServerFunctions();
const [DocumentView, setDocumentView] = useState(undefined);
const [isLoading, setIsLoading] = useState(true);
const hasInitialized = useRef(false);
const getDocumentView = useCallback((docID_0, showLoadingIndicator = false) => {
const controller = handleAbortRef(abortGetDocumentViewRef);
const fetchDocumentView = async () => {
if (showLoadingIndicator) {
setIsLoading(true);
}
try {
const result = await renderDocument({
collectionSlug,
disableActions,
docID: docID_0,
drawerSlug,
initialData,
overrideEntityVisibility,
redirectAfterCreate,
redirectAfterDelete: redirectAfterDelete !== undefined ? redirectAfterDelete : false,
redirectAfterDuplicate: redirectAfterDuplicate !== undefined ? redirectAfterDuplicate : false,
redirectAfterRestore: redirectAfterRestore !== undefined ? redirectAfterRestore : false,
signal: controller.signal
});
if (result?.Document) {
setDocumentView(result.Document);
setIsLoading(false);
}
} catch (error) {
toast.error(error?.message || t('error:unspecific'));
closeModal(drawerSlug);
}
abortGetDocumentViewRef.current = null;
};
void fetchDocumentView();
}, [collectionSlug, disableActions, drawerSlug, initialData, redirectAfterDelete, redirectAfterDuplicate, redirectAfterRestore, renderDocument, redirectAfterCreate, closeModal, overrideEntityVisibility, t]);
const onSave = useCallback(args => {
if (args.operation === 'create') {
getDocumentView(args.doc.id);
}
if (typeof onSaveFromProps === 'function') {
void onSaveFromProps({
...args,
collectionConfig
});
}
}, [onSaveFromProps, collectionConfig, getDocumentView]);
const onDuplicate = useCallback(args_0 => {
getDocumentView(args_0.doc.id);
if (typeof onDuplicateFromProps === 'function') {
void onDuplicateFromProps({
...args_0,
collectionConfig
});
}
}, [onDuplicateFromProps, collectionConfig, getDocumentView]);
const onDelete = useCallback(args_1 => {
if (typeof onDeleteFromProps === 'function') {
void onDeleteFromProps({
...args_1,
collectionConfig
});
}
closeModal(drawerSlug);
}, [onDeleteFromProps, closeModal, drawerSlug, collectionConfig]);
const clearDoc = useCallback(() => {
getDocumentView(undefined, true);
}, [getDocumentView]);
useEffect(() => {
if (!DocumentView && !hasInitialized.current) {
getDocumentView(docID, true);
hasInitialized.current = true;
}
}, [DocumentView, getDocumentView, docID]);
// Cleanup any pending requests when the component unmounts
useEffect(() => {
const abortGetDocumentView = abortGetDocumentViewRef.current;
return () => {
abortAndIgnore(abortGetDocumentView);
};
}, []);
if (isLoading) {
return /*#__PURE__*/_jsx(LoadingOverlay, {});
}
return /*#__PURE__*/_jsx(DocumentDrawerContextProvider, {
clearDoc: clearDoc,
drawerSlug: drawerSlug,
onDelete: onDelete,
onDuplicate: onDuplicate,
onSave: onSave,
children: DocumentView
});
};
//# sourceMappingURL=DrawerContent.js.map