Refactor keyword handling: Replace 'intent' with 'country' across backend and frontend
- Updated AutomationService to include estimated_word_count. - Increased stage_1_batch_size from 20 to 50 in AutomationViewSet. - Changed Keywords model to replace 'intent' property with 'country'. - Adjusted ClusteringService to allow a maximum of 50 keywords for clustering. - Modified admin and management commands to remove 'intent' and use 'country' instead. - Updated serializers to reflect the change from 'intent' to 'country'. - Adjusted views and filters to use 'country' instead of 'intent'. - Updated frontend forms, filters, and pages to replace 'intent' with 'country'. - Added migration to remove 'intent' field and add 'country' field to SeedKeyword model.
This commit is contained in:
@@ -39,7 +39,7 @@ interface DashboardStats {
|
||||
mapped: number;
|
||||
unmapped: number;
|
||||
byStatus: Record<string, number>;
|
||||
byIntent: Record<string, number>;
|
||||
byCountry: Record<string, number>;
|
||||
};
|
||||
clusters: {
|
||||
total: number;
|
||||
@@ -90,11 +90,11 @@ export default function PlannerDashboard() {
|
||||
const unmappedKeywords = keywords.filter(k => !k.cluster || k.cluster.length === 0);
|
||||
|
||||
const keywordsByStatus: Record<string, number> = {};
|
||||
const keywordsByIntent: Record<string, number> = {};
|
||||
const keywordsByCountry: Record<string, number> = {};
|
||||
keywords.forEach(k => {
|
||||
keywordsByStatus[k.status || 'unknown'] = (keywordsByStatus[k.status || 'unknown'] || 0) + 1;
|
||||
if (k.intent) {
|
||||
keywordsByIntent[k.intent] = (keywordsByIntent[k.intent] || 0) + 1;
|
||||
if (k.country) {
|
||||
keywordsByCountry[k.country] = (keywordsByCountry[k.country] || 0) + 1;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -135,7 +135,7 @@ export default function PlannerDashboard() {
|
||||
mapped: mappedKeywords.length,
|
||||
unmapped: unmappedKeywords.length,
|
||||
byStatus: keywordsByStatus,
|
||||
byIntent: keywordsByIntent
|
||||
byCountry: keywordsByCountry
|
||||
},
|
||||
clusters: {
|
||||
total: clusters.length,
|
||||
|
||||
@@ -47,7 +47,7 @@ export default function KeywordOpportunities() {
|
||||
|
||||
// Filter state
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [intentFilter, setIntentFilter] = useState('');
|
||||
const [countryFilter, setCountryFilter] = useState('');
|
||||
const [difficultyFilter, setDifficultyFilter] = useState('');
|
||||
const [volumeMin, setVolumeMin] = useState<number | ''>('');
|
||||
const [volumeMax, setVolumeMax] = useState<number | ''>('');
|
||||
@@ -119,7 +119,7 @@ export default function KeywordOpportunities() {
|
||||
}
|
||||
|
||||
if (searchTerm) baseFilters.search = searchTerm;
|
||||
if (intentFilter) baseFilters.intent = intentFilter;
|
||||
if (countryFilter) baseFilters.country = countryFilter;
|
||||
|
||||
// Fetch ALL pages to get complete dataset
|
||||
let allResults: SeedKeyword[] = [];
|
||||
@@ -227,7 +227,7 @@ export default function KeywordOpportunities() {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [activeSite, activeSector, currentPage, pageSize, searchTerm, intentFilter, difficultyFilter, volumeMin, volumeMax, sortBy, sortDirection]);
|
||||
}, [activeSite, activeSector, currentPage, pageSize, searchTerm, countryFilter, difficultyFilter, volumeMin, volumeMax, sortBy, sortDirection]);
|
||||
|
||||
// Load data on mount and when filters change (excluding search - handled separately)
|
||||
useEffect(() => {
|
||||
@@ -504,28 +504,27 @@ export default function KeywordOpportunities() {
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'intent',
|
||||
label: 'Intent',
|
||||
key: 'country',
|
||||
label: 'Country',
|
||||
sortable: true,
|
||||
sortField: 'intent',
|
||||
sortField: 'country',
|
||||
render: (value: string) => {
|
||||
const getIntentColor = (intent: string) => {
|
||||
const lowerIntent = intent?.toLowerCase() || '';
|
||||
if (lowerIntent === 'transactional' || lowerIntent === 'commercial') {
|
||||
return 'success';
|
||||
} else if (lowerIntent === 'navigational') {
|
||||
return 'warning';
|
||||
}
|
||||
return 'info';
|
||||
const countryNames: Record<string, string> = {
|
||||
'US': 'United States',
|
||||
'CA': 'Canada',
|
||||
'GB': 'United Kingdom',
|
||||
'AE': 'United Arab Emirates',
|
||||
'AU': 'Australia',
|
||||
'IN': 'India',
|
||||
'PK': 'Pakistan',
|
||||
};
|
||||
|
||||
return (
|
||||
<Badge
|
||||
color={getIntentColor(value)}
|
||||
color="info"
|
||||
size="sm"
|
||||
variant={value?.toLowerCase() === 'informational' ? 'light' : undefined}
|
||||
variant="light"
|
||||
>
|
||||
{value}
|
||||
{value || '-'}
|
||||
</Badge>
|
||||
);
|
||||
},
|
||||
@@ -539,15 +538,18 @@ export default function KeywordOpportunities() {
|
||||
placeholder: 'Search keywords...',
|
||||
},
|
||||
{
|
||||
key: 'intent',
|
||||
label: 'Intent',
|
||||
key: 'country',
|
||||
label: 'Country',
|
||||
type: 'select',
|
||||
options: [
|
||||
{ value: '', label: 'All Intent' },
|
||||
{ value: 'informational', label: 'Informational' },
|
||||
{ value: 'navigational', label: 'Navigational' },
|
||||
{ value: 'transactional', label: 'Transactional' },
|
||||
{ value: 'commercial', label: 'Commercial' },
|
||||
{ value: '', label: 'All Countries' },
|
||||
{ value: 'US', label: 'United States' },
|
||||
{ value: 'CA', label: 'Canada' },
|
||||
{ value: 'GB', label: 'United Kingdom' },
|
||||
{ value: 'AE', label: 'United Arab Emirates' },
|
||||
{ value: 'AU', label: 'Australia' },
|
||||
{ value: 'IN', label: 'India' },
|
||||
{ value: 'PK', label: 'Pakistan' },
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -612,7 +614,7 @@ export default function KeywordOpportunities() {
|
||||
filters={pageConfig.filters}
|
||||
filterValues={{
|
||||
search: searchTerm,
|
||||
intent: intentFilter,
|
||||
country: countryFilter,
|
||||
difficulty: difficultyFilter,
|
||||
}}
|
||||
onFilterChange={(key, value) => {
|
||||
@@ -620,8 +622,8 @@ export default function KeywordOpportunities() {
|
||||
|
||||
if (key === 'search') {
|
||||
setSearchTerm(stringValue);
|
||||
} else if (key === 'intent') {
|
||||
setIntentFilter(stringValue);
|
||||
} else if (key === 'country') {
|
||||
setCountryFilter(stringValue);
|
||||
setCurrentPage(1);
|
||||
} else if (key === 'difficulty') {
|
||||
setDifficultyFilter(stringValue);
|
||||
|
||||
@@ -52,7 +52,7 @@ export default function Keywords() {
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [statusFilter, setStatusFilter] = useState('');
|
||||
const [clusterFilter, setClusterFilter] = useState('');
|
||||
const [intentFilter, setIntentFilter] = useState('');
|
||||
const [countryFilter, setCountryFilter] = useState('');
|
||||
const [difficultyFilter, setDifficultyFilter] = useState('');
|
||||
const [volumeMin, setVolumeMin] = useState<number | ''>('');
|
||||
const [volumeMax, setVolumeMax] = useState<number | ''>('');
|
||||
@@ -81,7 +81,7 @@ export default function Keywords() {
|
||||
keyword: '',
|
||||
volume: null,
|
||||
difficulty: null,
|
||||
intent: 'informational',
|
||||
country: 'US',
|
||||
cluster_id: null,
|
||||
status: 'new',
|
||||
});
|
||||
@@ -156,7 +156,7 @@ export default function Keywords() {
|
||||
...(searchTerm && { search: searchTerm }),
|
||||
...(statusFilter && { status: statusFilter }),
|
||||
...(clusterFilter && { cluster_id: clusterFilter }),
|
||||
...(intentFilter && { intent: intentFilter }),
|
||||
...(countryFilter && { country: countryFilter }),
|
||||
...(activeSector?.id && { sector_id: activeSector.id }),
|
||||
page: currentPage,
|
||||
page_size: pageSize || 10, // Ensure we always send a page_size
|
||||
@@ -200,7 +200,7 @@ export default function Keywords() {
|
||||
setShowContent(true);
|
||||
setLoading(false);
|
||||
}
|
||||
}, [currentPage, statusFilter, clusterFilter, intentFilter, difficultyFilter, volumeMin, volumeMax, sortBy, sortDirection, searchTerm, activeSite, activeSector, pageSize]);
|
||||
}, [currentPage, statusFilter, clusterFilter, countryFilter, difficultyFilter, volumeMin, volumeMax, sortBy, sortDirection, searchTerm, activeSite, activeSector, pageSize]);
|
||||
|
||||
// Listen for site and sector changes and refresh data
|
||||
useEffect(() => {
|
||||
@@ -324,8 +324,8 @@ export default function Keywords() {
|
||||
toast.error('Please select at least one keyword to cluster');
|
||||
return;
|
||||
}
|
||||
if (ids.length > 20) {
|
||||
toast.error('Maximum 20 keywords allowed for clustering');
|
||||
if (ids.length > 50) {
|
||||
toast.error('Maximum 50 keywords allowed for clustering');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -536,7 +536,7 @@ export default function Keywords() {
|
||||
keyword: '',
|
||||
volume: null,
|
||||
difficulty: null,
|
||||
intent: 'informational',
|
||||
country: 'US',
|
||||
cluster_id: null,
|
||||
status: 'new',
|
||||
});
|
||||
@@ -605,8 +605,8 @@ export default function Keywords() {
|
||||
setSearchTerm,
|
||||
statusFilter,
|
||||
setStatusFilter,
|
||||
intentFilter,
|
||||
setIntentFilter,
|
||||
countryFilter,
|
||||
setCountryFilter,
|
||||
difficultyFilter,
|
||||
setDifficultyFilter,
|
||||
clusterFilter,
|
||||
@@ -632,7 +632,7 @@ export default function Keywords() {
|
||||
formData,
|
||||
searchTerm,
|
||||
statusFilter,
|
||||
intentFilter,
|
||||
countryFilter,
|
||||
difficultyFilter,
|
||||
clusterFilter,
|
||||
volumeMin,
|
||||
@@ -776,7 +776,7 @@ export default function Keywords() {
|
||||
keyword: keyword.keyword,
|
||||
volume: keyword.volume,
|
||||
difficulty: keyword.difficulty,
|
||||
intent: keyword.intent,
|
||||
country: keyword.country,
|
||||
cluster_id: keyword.cluster_id,
|
||||
status: keyword.status,
|
||||
});
|
||||
@@ -807,7 +807,7 @@ export default function Keywords() {
|
||||
filterValues={{
|
||||
search: searchTerm,
|
||||
status: statusFilter,
|
||||
intent: intentFilter,
|
||||
country: countryFilter,
|
||||
difficulty: difficultyFilter,
|
||||
cluster_id: clusterFilter,
|
||||
volumeMin: volumeMin,
|
||||
@@ -823,8 +823,8 @@ export default function Keywords() {
|
||||
} else if (key === 'status') {
|
||||
setStatusFilter(stringValue);
|
||||
setCurrentPage(1);
|
||||
} else if (key === 'intent') {
|
||||
setIntentFilter(stringValue);
|
||||
} else if (key === 'country') {
|
||||
setCountryFilter(stringValue);
|
||||
setCurrentPage(1);
|
||||
} else if (key === 'difficulty') {
|
||||
setDifficultyFilter(stringValue);
|
||||
@@ -868,7 +868,7 @@ export default function Keywords() {
|
||||
search: searchTerm,
|
||||
status: statusFilter,
|
||||
cluster_id: clusterFilter,
|
||||
intent: intentFilter,
|
||||
country: countryFilter,
|
||||
difficulty: difficultyFilter,
|
||||
};
|
||||
await handleExport('csv', filterValues);
|
||||
@@ -903,7 +903,7 @@ export default function Keywords() {
|
||||
setSearchTerm('');
|
||||
setStatusFilter('');
|
||||
setClusterFilter('');
|
||||
setIntentFilter('');
|
||||
setCountryFilter('');
|
||||
setDifficultyFilter('');
|
||||
setVolumeMin('');
|
||||
setVolumeMax('');
|
||||
|
||||
Reference in New Issue
Block a user