11import React , { useState , FormEvent } from "react" ;
22import { Link , useNavigate } from "react-router-dom" ;
3+ import { useQuery } from "@tanstack/react-query" ;
34import { useUser } from "../queries" ;
45import * as API from "aws-amplify/api" ;
56import {
@@ -13,7 +14,7 @@ import { createLog } from "#src/utils/createLog.ts";
1314import { StyledLabeledInput } from "#src/components/StyledLabeledInput.tsx" ;
1415import { Card } from "#src/components/Card.tsx" ;
1516import { CgOptions } from "react-icons/cg" ;
16- import { TbList , TbMail } from "react-icons/tb" ;
17+ import { TbAlertTriangle , TbMail } from "react-icons/tb" ;
1718import { StyledButton } from "#src/components/StyledButton.tsx" ;
1819import { LuClipboardCheck , LuClipboardPaste , LuImport } from "react-icons/lu" ;
1920import styles from "./BuildAudit.module.scss" ;
@@ -27,6 +28,10 @@ interface Page {
2728 type : "html" | "pdf" ;
2829}
2930
31+ const apiClient = API . generateClient ( ) ;
32+ const URL_SOFT_LIMIT = 10_000 ;
33+ const AUDIT_SOFT_LIMIT = 10_000 ;
34+
3035export const BuildAudit = ( ) => {
3136 const navigate = useNavigate ( ) ;
3237 const { setAnnounceMessage } = useGlobalStore ( ) ;
@@ -38,9 +43,20 @@ export const BuildAudit = () => {
3843 const [ auditNameValid , setAuditNameValid ] = useState ( false ) ;
3944 const [ isSaving , setIsSaving ] = useState ( false ) ;
4045 const [ isSavingAndRunning , setIsSavingAndRunning ] = useState ( false ) ;
46+ const [ scanFrequency , setScanFrequency ] = useState ( "Manually" ) ;
4147
4248 const [ validRemoteCsv , setValidRemoteCsv ] = useState ( false ) ;
4349
50+ const { data : auditCount } = useQuery ( {
51+ queryKey : [ "auditCount" ] ,
52+ queryFn : async ( ) => {
53+ const result = ( await apiClient . graphql ( {
54+ query : `{ audits_aggregate(where: {interval: {_neq: "Quick Scan"}}) { aggregate { count } } }` ,
55+ } ) ) as any ;
56+ return result ?. data ?. audits_aggregate ?. aggregate ?. count ?? 0 ;
57+ } ,
58+ } ) ;
59+
4460 const defaultEmailList = {
4561 emails : [
4662 /* {
@@ -152,6 +168,14 @@ export const BuildAudit = () => {
152168 { /* <Link to="..">← Go Back</Link>
153169 */ }
154170 < h1 className = "initial-focus-element" > Audit Builder</ h1 >
171+ { auditCount >= AUDIT_SOFT_LIMIT && (
172+ < Card variant = "short-error" >
173+ < TbAlertTriangle className = "icon-small" />
174+ < div className = "font-small" >
175+ < b > Large number of audits:</ b > Your account has { auditCount . toLocaleString ( ) } audits. Having a large number of audits may affect system performance.
176+ </ div >
177+ </ Card >
178+ ) }
155179 < form onSubmit = { saveAndRunAudit } >
156180 < div className = "cards-38-62" >
157181 < Card variant = "light" >
@@ -178,15 +202,20 @@ export const BuildAudit = () => {
178202 id = "scanFrequency"
179203 name = "scanFrequency"
180204 className = { styles [ "input-element" ] }
205+ value = { scanFrequency }
206+ onChange = { ( e ) => setScanFrequency ( e . target . value ) }
181207 >
182208 < option > Manually</ option >
183209 < option > Daily</ option >
184210 < option > Weekly</ option >
185211 < option > Monthly</ option >
186- { /*
187- <option>On Monitor Update</option> */ }
188212 </ select >
189213 </ StyledLabeledInput >
214+ { scanFrequency === "Daily" && pages . length >= URL_SOFT_LIMIT && (
215+ < p className = "font-small" style = { { color : "#b45309" , display : "flex" , alignItems : "center" , gap : "4px" } } >
216+ < TbAlertTriangle /> Daily scans for audits with { pages . length . toLocaleString ( ) } URLs will use significant resources.
217+ </ p >
218+ ) }
190219 </ Card >
191220 < Card variant = "light" >
192221 < h2 >
0 commit comments