Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
Keep every country selectable and gray out engines that can't collect there (#1050)
Carter Smith6f8402fe1226
diff --git a/src/client/features/ai-visibility/TrackerEditor.tsx b/src/client/features/ai-visibility/TrackerEditor.tsxindex 60d286a4..6e3b7b32 100644--- a/src/client/features/ai-visibility/TrackerEditor.tsx+++ b/src/client/features/ai-visibility/TrackerEditor.tsx@@ -17,10 +17,14 @@ import {aiTrackerPatchSchema,type AiTrackerPatch,} from "@/types/schemas/ai-visibility";-import type { AiTrackerState, AiRun } from "@/shared/ai-visibility";+import {+ aiEnginesWithoutLocation,+ type AiTrackerState,+ type AiRun,+} from "@/shared/ai-visibility";+import { DEFAULT_LOCATION_CODE } from "@/shared/keyword-locations";import {TrackerTrackingFields,- collectableMarket,type TrackerDraft,} from "./TrackerTrackingFields";import { TrackerPromptFields } from "./TrackerPromptFields";@@ -73,6 +77,13 @@ export function TrackerEditor({const engines = state.engines.length? state.engines: state.capabilities.slice(0, 1).map((capability) => capability.engine);+ // A new tracker starts in the project's market when its engines support it.+ const newMarket = aiEnginesWithoutLocation(+ engines,+ defaultMarket.locationCode,+ ).length+ ? { locationCode: DEFAULT_LOCATION_CODE, languageCode: "en" }+ : defaultMarket;const defaultDraft: TrackerDraft = {engines,...(state.tracker@@ -80,7 +91,7 @@ export function TrackerEditor({locationCode: state.tracker.locationCode,languageCode: state.tracker.languageCode,}- : collectableMarket(engines, defaultMarket)),+ : newMarket),topic: { name: topic, prompts: ["", "", ""] },};const prepare = useMutation({@@ -241,7 +252,6 @@ export function TrackerEditor({{!adding && (<TrackerTrackingFieldsstate={state}- defaultMarket={defaultMarket}value={field.state.value}onChange={field.handleChange}disabled={prepare.isPending}diff --git a/src/client/features/ai-visibility/TrackerTrackingFields.tsx b/src/client/features/ai-visibility/TrackerTrackingFields.tsxindex b8ec90cd..c5345ed5 100644--- a/src/client/features/ai-visibility/TrackerTrackingFields.tsx+++ b/src/client/features/ai-visibility/TrackerTrackingFields.tsx@@ -1,4 +1,5 @@-import { Info } from "lucide-react";+import { cn } from "cn";+import { Info, TriangleAlert } from "lucide-react";import { EngineLabel } from "./EngineLabel";import { Checkbox } from "@/client/components/ui/checkbox";import {@@ -7,17 +8,13 @@ import {TooltipTrigger,} from "@/client/components/ui/tooltip";import { ProjectMarketFields } from "@/client/features/projects/ProjectMarketFields";-import type { ProjectMarket } from "@/client/features/projects/types";import {- aiEnginesWithoutLocation,+ AI_UNSUPPORTED_LOCATIONS,+ aiCountryLabel,type AiCapability,type AiEngine,type AiTrackerState,} from "@/shared/ai-visibility";-import {- DEFAULT_LOCATION_CODE,- LOCATION_OPTIONS,-} from "@/shared/keyword-locations";export type TrackerDraft = {locationCode: number;@@ -28,40 +25,19 @@ export type TrackerDraft = {export const MAX_PROMPTS_PER_ADDITION = 5;-/**- * The first market every engine can collect in, else US English. Keeps the- * country valid when the engine selection changes.- */-export function collectableMarket(- engines: AiEngine[],- ...markets: ProjectMarket[]-): ProjectMarket {- return (- markets.find(- (market) =>- !aiEnginesWithoutLocation(engines, market.locationCode).length,- ) ?? { locationCode: DEFAULT_LOCATION_CODE, languageCode: "en" }- );-}-export function TrackerTrackingFields({state,- defaultMarket,value,onChange,disabled,}: {state: AiTrackerState;- /** The project's market, or US English. */- defaultMarket: ProjectMarket;value: TrackerDraft;onChange: (value: TrackerDraft) => void;// Base UI checkboxes aren't native inputs, so a disabled <fieldset> misses them.disabled: boolean;}) {- const countryOptions = LOCATION_OPTIONS.filter(- (option) => !aiEnginesWithoutLocation(value.engines, option.code).length,- );+ const country = aiCountryLabel(value.locationCode);const engineGroup = (title: string,help: string,@@ -86,42 +62,54 @@ export function TrackerTrackingFields({</Tooltip></div><div className="grid gap-2 sm:grid-cols-2">- {capabilities.map((capability) => (- <label- key={capability.engine}- className="flex cursor-pointer items-center gap-3 rounded-lg border p-3 border-border"- >- <Checkbox- checked={value.engines.includes(capability.engine)}- disabled={disabled}- onCheckedChange={(checked) => {- const engines = checked- ? [...value.engines, capability.engine]- : value.engines.filter(- (engine) => engine !== capability.engine,- );- onChange({- ...value,- engines,- ...collectableMarket(- engines,- {- locationCode: value.locationCode,- languageCode: value.languageCode,- },- defaultMarket,- ),- });- }}- />- <span className="text-sm font-medium">- <EngineLabel- engine={capability.engine}- label={capability.label}- />- </span>- </label>- ))}+ {capabilities.map((capability) => {+ const unavailable = AI_UNSUPPORTED_LOCATIONS[+ capability.engine+ ].includes(value.locationCode);+ return (+ <Tooltip key={capability.engine} disabled={!unavailable}>+ <TooltipTrigger+ render={+ <label+ className={cn(+ "flex items-center gap-3 rounded-lg border p-3 border-border",+ unavailable+ ? "cursor-not-allowed opacity-50"+ : "cursor-pointer",+ )}+ />+ }+ >+ <Checkbox+ checked={value.engines.includes(capability.engine)}+ disabled={disabled || unavailable}+ onCheckedChange={(checked) =>+ onChange({+ ...value,+ engines: checked+ ? [...value.engines, capability.engine]+ : value.engines.filter(+ (engine) => engine !== capability.engine,+ ),+ })+ }+ />+ <span className="text-sm font-medium">+ <EngineLabel+ engine={capability.engine}+ label={capability.label}+ />+ </span>+ {unavailable && (+ <TriangleAlert className="ml-auto size-4 text-muted-foreground" />+ )}+ </TooltipTrigger>+ <TooltipContent>+ {capability.label} can't collect answers in {country}.+ </TooltipContent>+ </Tooltip>+ );+ })}</div></div>);@@ -139,8 +127,17 @@ export function TrackerTrackingFields({)}<ProjectMarketFieldsvalue={value}- countryOptions={countryOptions}- onChange={(market) => onChange({ ...value, ...market })}+ onChange={(market) =>+ onChange({+ ...value,+ ...market,+ // Drop engines that cannot collect in the new country.+ engines: value.engines.filter(+ (engine) =>+ !AI_UNSUPPORTED_LOCATIONS[engine].includes(market.locationCode),+ ),+ })+ }/></section>);