3 lines
8.4 KiB
JavaScript
3 lines
8.4 KiB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/js/main-af3pcbZa.js","assets/js/chunk-UIGDSWPH-BhuNDbxn.js","assets/css/main-3ECtE3fa.css"])))=>i.map(i=>d[i]);
|
|
import{r as l,_ as j,j as m}from"./chunk-UIGDSWPH-BhuNDbxn.js";import{u as le,T as ne}from"./TablePageTemplate-BEWe6AkV.js";import{u as de,b as ce,d as ue,s as U,M as fe,g as ye}from"./main-af3pcbZa.js";import{a as we,b as me,g as he}from"./difficulty-j1OGc4r8.js";import{B as z}from"./Badge-DM3morB7.js";import{S as ge}from"./plus-2WF6_FMG.js";import{P as pe}from"./PageHeader-iXTYKDGo.js";import"./SelectDropdown-C8sZwHi_.js";import"./AlertModal-BhtTtzZV.js";import"./index-ju2wdkG8.js";import"./check-circle--AtVWUy0.js";import"./arrow-right-DC7G5FiV.js";import"./pencil-CuC2vg9I.js";import"./angle-left-CYBnq6Pg.js";function Le(){const d=de(),{activeSite:a}=ce(),{activeSector:f,loadSectorsForSite:q}=ue(),{pageSize:T}=le(),[D,x]=l.useState([]),[G,N]=l.useState(!0),[J,B]=l.useState(!1),[Q,$]=l.useState([]),M=l.useRef(new Set),[L,S]=l.useState(1),[X,V]=l.useState(1),[Y,R]=l.useState(0),[g,Z]=l.useState("keyword"),[A,ee]=l.useState("asc"),[k,te]=l.useState(""),[F,re]=l.useState(""),[P,oe]=l.useState(""),[_,Se]=l.useState(""),[v,be]=l.useState("");l.useEffect(()=>{a!=null&&a.id&&q(a.id)},[a==null?void 0:a.id]);const O=l.useCallback(async()=>{if(!a||!a.industry){x([]),R(0),V(1),N(!1);return}N(!0),B(!1);try{let r=new Set;try{const{fetchKeywords:o,fetchSiteSectors:n}=await j(async()=>{const{fetchKeywords:u,fetchSiteSectors:K}=await import("./main-af3pcbZa.js").then(I=>I.ay);return{fetchKeywords:u,fetchSiteSectors:K}},__vite__mapDeps([0,1,2])),y=await n(a.id);for(const u of y)try{((await o({site_id:a.id,sector_id:u.id,page_size:1e3})).results||[]).forEach(I=>{const W=I.seed_keyword_id||I.seed_keyword&&I.seed_keyword.id;W&&r.add(Number(W))})}catch(K){console.warn(`Could not fetch attached keywords for sector ${u.id}:`,K)}}catch(o){console.warn("Could not fetch sectors or attached keywords:",o)}const t={industry:a.industry,page_size:1e3};f&&f.industry_sector&&(t.sector=f.industry_sector),k&&(t.search=k),F&&(t.intent=F);let e=[],s=1,i=!0;for(;i;){const o={...t,page:s},n=await U(o);if(n.results&&n.results.length>0&&(e=[...e,...n.results]),i=n.next!==null&&n.next!==void 0,s++,s>100){console.warn("Reached maximum page limit (100) while fetching seed keywords");break}}let c=e.map(o=>{const n=r.has(Number(o.id))||M.current.has(Number(o.id));return{...o,isAdded:!!n}});if(P){const o=parseInt(P),n=we(o);if(n!==null){const y=me(n);y&&(c=c.filter(u=>u.difficulty>=y.min&&u.difficulty<=y.max))}}_!==""&&_!==null&&_!==void 0&&(c=c.filter(o=>o.volume>=Number(_))),v!==""&&v!==null&&v!==void 0&&(c=c.filter(o=>o.volume<=Number(v))),g&&c.sort((o,n)=>{let y,u;if(g==="keyword")y=o.keyword.toLowerCase(),u=n.keyword.toLowerCase();else if(g==="volume")y=o.volume,u=n.volume;else if(g==="difficulty")y=o.difficulty,u=n.difficulty;else if(g==="intent")y=o.intent.toLowerCase(),u=n.intent.toLowerCase();else return 0;return y<u?A==="asc"?-1:1:y>u?A==="asc"?1:-1:0});const p=c.length,h=T||10,E=(L-1)*h,w=E+h,b=c.slice(E,w);x(b),R(p),V(Math.ceil(p/h)),B(!0)}catch(r){console.error("Error loading seed keywords:",r),d.error(`Failed to load keyword opportunities: ${r.message}`),x([]),R(0),V(1)}finally{N(!1)}},[a,f,L,T,k,F,P,_,v,g,A]);l.useEffect(()=>{O()},[O]),l.useEffect(()=>{const r=setTimeout(()=>{S(1)},500);return()=>clearTimeout(r)},[k]),l.useEffect(()=>{S(1)},[T]);const se=(r,t)=>{Z(r||"keyword"),ee(t),S(1)},C=l.useCallback(async r=>{var e;if(!a){d.error("Please select an active site first");return}let t=f;if(!t)try{const{fetchSiteSectors:s}=await j(async()=>{const{fetchSiteSectors:c}=await import("./main-af3pcbZa.js").then(p=>p.ay);return{fetchSiteSectors:c}},__vite__mapDeps([0,1,2])),i=await s(a.id);if(i.length===0){d.error("No sectors available for this site. Please create a sector first.");return}t={id:i[0].id,name:i[0].name,slug:i[0].slug,site_id:a.id,is_active:i[0].is_active!==!1,industry_sector:i[0].industry_sector||null}}catch(s){d.error(`Failed to get sectors: ${s.message}`);return}try{const s=await fe(r,a.id,t.id);s.success?(d.success(`Successfully added ${s.created} keyword(s) to workflow`),r.forEach(i=>{M.current.add(i)}),$([]),x(i=>i.map(c=>r.includes(c.id)?{...c,isAdded:!0}:c))):d.error(`Failed to add keywords: ${((e=s.errors)==null?void 0:e.join(", "))||"Unknown error"}`)}catch(s){d.error(`Failed to add keywords: ${s.message}`)}},[a,f,d]),ae=l.useCallback(async r=>{if(r.length===0){d.error("Please select at least one keyword");return}const t=r.filter(s=>{const i=D.find(c=>String(c.id)===s);return i&&!i.isAdded});if(t.length===0){d.error("All selected keywords are already added to workflow");return}t.length<r.length&&d.info(`${r.length-t.length} keyword(s) were already added and were skipped`);const e=t.map(s=>parseInt(s));await C(e)},[C,d,D]),ie=l.useCallback(async()=>{if(!a||!a.industry){d.error("Please select an active site first");return}try{const r={industry:a.industry,page_size:1e3};f!=null&&f.industry_sector&&(r.sector=f.industry_sector);const e=(await U(r)).results||[];if(e.length===0){d.error("No keywords available to add");return}const{fetchKeywords:s,fetchSiteSectors:i}=await j(async()=>{const{fetchKeywords:w,fetchSiteSectors:b}=await import("./main-af3pcbZa.js").then(o=>o.ay);return{fetchKeywords:w,fetchSiteSectors:b}},__vite__mapDeps([0,1,2])),c=await i(a.id);let p=new Set;for(const w of c)try{((await s({site_id:a.id,sector_id:w.id,page_size:1e3})).results||[]).forEach(o=>{const n=o.seed_keyword_id||o.seed_keyword&&o.seed_keyword.id;n&&p.add(Number(n))})}catch(b){console.warn(`Could not fetch attached keywords for sector ${w.id}:`,b)}const h=e.filter(w=>!p.has(w.id));if(h.length===0){d.error("All keywords are already added to workflow");return}h.length<e.length&&d.info(`${e.length-h.length} keyword(s) were already added and were skipped`);const E=h.map(w=>w.id);await C(E)}catch(r){d.error(`Failed to load all keywords: ${r.message}`)}},[a,f,C,d]),H=l.useMemo(()=>({columns:[{key:"keyword",label:"Keyword",sortable:!0,sortField:"keyword"},...!f?[{key:"sector_name",label:"Sector",sortable:!1,render:(t,e)=>m.jsx(z,{color:"info",size:"sm",variant:"light",children:e.sector_name||"-"})}]:[],{key:"volume",label:"Volume",sortable:!0,sortField:"volume",render:t=>t.toLocaleString()},{key:"difficulty",label:"Difficulty",sortable:!0,sortField:"difficulty",align:"center",render:t=>{const e=he(t),s=typeof e=="number"&&e===5?"solid":typeof e=="number"&&(e===2||e===3||e===4)?"light":typeof e=="number"&&e===1?"solid":"light",i=typeof e=="number"&&e===1||typeof e=="number"&&e===2?"success":typeof e=="number"&&e===3?"warning":typeof e=="number"&&e===4||typeof e=="number"&&e===5?"error":"light";return typeof e=="number"?m.jsx(z,{color:i,variant:s,size:"sm",children:e}):e}},{key:"intent",label:"Intent",sortable:!0,sortField:"intent",render:t=>{const e=s=>{const i=(s==null?void 0:s.toLowerCase())||"";return i==="transactional"||i==="commercial"?"success":i==="navigational"?"warning":"info"};return m.jsx(z,{color:e(t),size:"sm",variant:(t==null?void 0:t.toLowerCase())==="informational"?"light":void 0,children:t})}}],filters:[{key:"search",label:"Search",type:"text",placeholder:"Search keywords..."},{key:"intent",label:"Intent",type:"select",options:[{value:"",label:"All Intent"},{value:"informational",label:"Informational"},{value:"navigational",label:"Navigational"},{value:"transactional",label:"Transactional"},{value:"commercial",label:"Commercial"}]},{key:"difficulty",label:"Difficulty",type:"select",options:[{value:"",label:"All Difficulty"},{value:"1",label:"1 - Very Easy"},{value:"2",label:"2 - Easy"},{value:"3",label:"3 - Medium"},{value:"4",label:"4 - Hard"},{value:"5",label:"5 - Very Hard"}]}]}),[f]);return m.jsxs(m.Fragment,{children:[m.jsx(pe,{title:"Keyword Opportunities",badge:{icon:m.jsx(ye,{}),color:"orange"}}),m.jsx(ne,{columns:H.columns,data:D,loading:G,showContent:J,filters:H.filters,filterValues:{search:k,intent:F,difficulty:P},onFilterChange:(r,t)=>{const e=t==null?"":String(t);r==="search"?te(e):r==="intent"?(re(e),S(1)):r==="difficulty"&&(oe(e),S(1))},onRowAction:async(r,t)=>{if(r==="add_to_workflow"){if(t.isAdded){d.info("This keyword is already added to workflow");return}await C([t.id])}},onBulkAction:async(r,t)=>{r==="add_selected_to_workflow"&&await ae(t)},onCreate:ie,createLabel:"Add All to Workflow",onCreateIcon:m.jsx(ge,{}),pagination:{currentPage:L,totalPages:X,totalCount:Y,onPageChange:S},sorting:{sortBy:g,sortDirection:A,onSort:se},selection:{selectedIds:Q,onSelectionChange:$}})]})}export{Le as default};
|