import React, { useState, useRef, useEffect } from "react"; import { decodeEntities } from "@wordpress/html-entities"; import { IconSort, IconSmilingFace, IconNeutralFace, IconDisappointedFace } from "../../../icons/index"; import { __ } from "@wordpress/i18n"; import DocAuthor from "./DocAuthor.js"; import DocCategory from "./DocCategory.js"; import DocTags from "./DocTags.js"; import Pagination from "../../doc-categories/components/Pagination"; import NoDocsBody from "./NoDocsBody.js"; import ContextMenu from "./ContextMenu.js"; import { gutenbergEditScreenUrl } from "../helpers/Helpers"; import { useDashboardContext } from "../DashboardContext.js"; import ListLoader from "../loaders/ListLoader.js"; import KnowledgeBase from "./KnowledgeBase.js"; import NoDocsFound from "./NoDocsFound.js"; import { applyFilters } from "@wordpress/hooks"; const AllDocsListTable = ({ restoreIDS, setLoaderIDS, setLoading, status, onFilterSelect, docs, isLoading, totalItems, totalPages, setCurrentPage, currentPage, perPage = 20, bulkData, setBulkData, loaderIDS }) => { const { data: quickEdit, setData: setQuickEdit } = useDashboardContext(); return ( <> {betterdocs_admin?.multiple_kb == 1 && applyFilters('mkb_table_header', '')} {!isLoading && docs?.length > 0 && docs.map((doc, index) => { let authorInfo = doc?.author_info; let docCategoryInfo = doc?.doc_category_info; let doctagInfo = doc?.doc_tag_info; let wordCount = doc?.word_count; let status = doc?.status; let totalViews = doc?.total_views ?? 0; let dateString = new Date(doc.date).toLocaleDateString(); let reactions = doc?.reactions; let happy = reactions?.happy == null ? 0 : parseInt(reactions?.happy); let sad = reactions?.sad == null ? 0 : parseInt(reactions?.sad); let normal = reactions?.normal == null ? 0 : parseInt(reactions?.normal); let total_reaction = ( happy + sad + normal ); let max_reaction = ( happy > sad && happy > normal ) ? 'happy' : ( ( sad > happy && sad > normal ) ? 'sad' : ( ( normal > sad && normal > happy ) ? 'normal' : ( ( happy == sad || happy == normal ) ? 'happy' : ( ( normal == sad || normal == happy ) ? 'normal' : ( ( sad == normal || sad == happy ) ? 'sad' : 'all-equal' ) ) ) ) ); let knowledgebaseInfo = doc?.knowledge_base_info; return { // handleTRClick(doc, quickEdit); if( quickEdit?.isListMenuOpen ) { setQuickEdit((state) => ({...state, isListMenuOpen:false, docId: doc.id })); } }} > {betterdocs_admin?.multiple_kb == 1 && applyFilters('mkb_table_data', '', [KnowledgeBase, knowledgebaseInfo])} {loaderIDS.includes(doc?.id) &&
} {restoreIDS.includes(doc?.id) &&
} })} {isLoading && } {docs?.length === 0 && !isLoading && ( )}
0 && !isLoading ? true : false} onClick={(e) => { if( bulkData?.length == 0 ) { docs?.map((doc) => { if( ! bulkData?.includes(doc?.id) ) { bulkData?.push(doc?.id); } }) setBulkData([...bulkData]); } else { setBulkData([]); } }}> {__("Author", "betterdocs")} {__("Doc Category", "betterdocs")} {__("Doc Tag", "betterdocs")} {__("Views", "betterdocs")} {__("Reaction", "betterdocs")} {__("Action", "betterdocs")}
{ if( ! bulkData?.includes(doc?.id) ) { bulkData?.push(doc?.id); setBulkData([...bulkData]); } else { let filteredData = bulkData?.filter((docID) => { return docID != doc?.id; }); setBulkData([...filteredData]); } }} readOnly > {(doc.title?.rendered == null || doc?.title?.rendered == undefined || doc?.title?.rendered?.length == 0 ) ? '(no title) ' : decodeEntities(doc.title.rendered)} {status != 'publish' && {`- ${status?.charAt(0).toUpperCase()}${status?.slice(1)}`} } | {wordCount}  {__("Word Count", "betterdocs")} {totalViews} {max_reaction == 'happy' && } {max_reaction == 'normal' && } {max_reaction == 'sad' && } {max_reaction == 'all-equal' && <> } {total_reaction}
    {max_reaction == 'happy' && <>
  • {happy}
  • {normal}
  • {sad}
  • } {max_reaction == 'normal' && <>
  • {happy}
  • {normal}
  • {sad}
  • } {max_reaction == 'sad' && <>
  • {happy}
  • {normal}
  • {sad}
  • } {max_reaction == 'all-equal' && <>
  • {happy}
  • {normal}
  • {sad}
  • }
{dateString}
{/* Pagination — shared custom bd-dc-pagination component (no rc-pagination). */} { if (bulkData?.length > 0) { setBulkData([]); } setLoading(true); setCurrentPage((prevState) => { return { ...prevState, page: pageNumber }; }); }} onPerPageChange={(newPerPage) => { if (bulkData?.length > 0) { setBulkData([]); } setLoading(true); setCurrentPage((prevState) => { return { ...prevState, per_page: newPerPage }; }); }} /> ); }; export default AllDocsListTable;