Switch domain sorting defaults and rank-tracking suggestions to traffic (#223)
* Default domain keyword sorting to traffic * Align keyword suggestion preselection with traffic sort
This commit is contained in:
parent
d23b4eebfb
commit
f95c66b7f2
@ -78,7 +78,7 @@ export function DomainSearchCard({
|
|||||||
className="select select-bordered shrink-0"
|
className="select select-bordered shrink-0"
|
||||||
value={field.state.value}
|
value={field.state.value}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
const next = toSortMode(event.target.value) ?? "rank";
|
const next = toSortMode(event.target.value) ?? "traffic";
|
||||||
field.handleChange(next);
|
field.handleChange(next);
|
||||||
onSortChange(next);
|
onSortChange(next);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@ -45,7 +45,7 @@ function numberToFilterString(value: number | undefined): string {
|
|||||||
export function getDomainRouteState(
|
export function getDomainRouteState(
|
||||||
search: DomainSearchParams,
|
search: DomainSearchParams,
|
||||||
): DomainOverviewRouteState {
|
): DomainOverviewRouteState {
|
||||||
const normalizedSort = toSortMode(search.sort ?? null) ?? "rank";
|
const normalizedSort = toSortMode(search.sort ?? null) ?? "traffic";
|
||||||
const normalizedLocationCode =
|
const normalizedLocationCode =
|
||||||
search.loc != null && isSupportedLocationCode(search.loc)
|
search.loc != null && isSupportedLocationCode(search.loc)
|
||||||
? search.loc
|
? search.loc
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export function resolveSortOrder(
|
|||||||
export function toSortSearchParam(
|
export function toSortSearchParam(
|
||||||
sortMode: DomainSortMode,
|
sortMode: DomainSortMode,
|
||||||
): DomainSortMode | undefined {
|
): DomainSortMode | undefined {
|
||||||
return sortMode === "rank" ? undefined : sortMode;
|
return sortMode === "traffic" ? undefined : sortMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toSortOrderSearchParam(
|
export function toSortOrderSearchParam(
|
||||||
|
|||||||
@ -160,7 +160,7 @@ export function KeywordSuggestionStep({
|
|||||||
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
||||||
const [hasInitialized, setHasInitialized] = useState(false);
|
const [hasInitialized, setHasInitialized] = useState(false);
|
||||||
const [sorting, setSorting] = useState<SortingState>([
|
const [sorting, setSorting] = useState<SortingState>([
|
||||||
{ id: "position", desc: false },
|
{ id: "traffic", desc: true },
|
||||||
]);
|
]);
|
||||||
const selectAnchorRef = useRef<SelectionAnchor | null>(null);
|
const selectAnchorRef = useRef<SelectionAnchor | null>(null);
|
||||||
|
|
||||||
@ -188,17 +188,15 @@ export function KeywordSuggestionStep({
|
|||||||
|
|
||||||
const data = suggestionsQuery.data ?? [];
|
const data = suggestionsQuery.data ?? [];
|
||||||
|
|
||||||
// Pre-select top 20 by position once data loads
|
// Pre-select top 20 by traffic once data loads.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const items = suggestionsQuery.data;
|
const items = suggestionsQuery.data;
|
||||||
if (items && items.length > 0 && !hasInitialized) {
|
if (items && items.length > 0 && !hasInitialized) {
|
||||||
// Data comes sorted by search volume from the API, but we display sorted
|
|
||||||
// by position. Pre-select the 20 with the best (lowest) positions.
|
|
||||||
const indexed = items.map((item, i) => ({
|
const indexed = items.map((item, i) => ({
|
||||||
index: i,
|
index: i,
|
||||||
position: item.position ?? 999,
|
traffic: item.traffic ?? 0,
|
||||||
}));
|
}));
|
||||||
indexed.sort((a, b) => a.position - b.position);
|
indexed.sort((a, b) => b.traffic - a.traffic);
|
||||||
const initial: RowSelectionState = {};
|
const initial: RowSelectionState = {};
|
||||||
for (let i = 0; i < Math.min(PRE_SELECT_COUNT, indexed.length); i++) {
|
for (let i = 0; i < Math.min(PRE_SELECT_COUNT, indexed.length); i++) {
|
||||||
initial[indexed[i].index] = true;
|
initial[indexed[i].index] = true;
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import { getDomainRouteState } from "@/client/features/domain/domainRouteState";
|
|||||||
const DEFAULT_DOMAIN_SEARCH = {
|
const DEFAULT_DOMAIN_SEARCH = {
|
||||||
domain: "",
|
domain: "",
|
||||||
subdomains: true,
|
subdomains: true,
|
||||||
sort: "rank",
|
sort: "traffic",
|
||||||
order: undefined,
|
order: undefined,
|
||||||
tab: "keywords",
|
tab: "keywords",
|
||||||
loc: DEFAULT_LOCATION_CODE,
|
loc: DEFAULT_LOCATION_CODE,
|
||||||
|
|||||||
@ -143,7 +143,7 @@ async function getSuggestedKeywords(
|
|||||||
locationCode: input.locationCode,
|
locationCode: input.locationCode,
|
||||||
languageCode: input.languageCode,
|
languageCode: input.languageCode,
|
||||||
limit: 100,
|
limit: 100,
|
||||||
orderBy: ["keyword_data.keyword_info.search_volume,desc"],
|
orderBy: ["ranked_serp_element.serp_item.etv,desc"],
|
||||||
});
|
});
|
||||||
|
|
||||||
const keywords = rankedKeywordsResponse.items
|
const keywords = rankedKeywordsResponse.items
|
||||||
|
|||||||
@ -109,8 +109,8 @@ export const domainKeywordsPageRequestSchema = z.object({
|
|||||||
(DOMAIN_KEYWORDS_PAGE_SIZES as readonly number[]).includes(value),
|
(DOMAIN_KEYWORDS_PAGE_SIZES as readonly number[]).includes(value),
|
||||||
)
|
)
|
||||||
.default(DEFAULT_DOMAIN_KEYWORDS_PAGE_SIZE),
|
.default(DEFAULT_DOMAIN_KEYWORDS_PAGE_SIZE),
|
||||||
sortMode: z.enum(domainSortModes).default("rank"),
|
sortMode: z.enum(domainSortModes).default("traffic"),
|
||||||
sortOrder: z.enum(domainSortOrders).default("asc"),
|
sortOrder: z.enum(domainSortOrders).default("desc"),
|
||||||
filters: domainKeywordsFiltersSchema.default({}),
|
filters: domainKeywordsFiltersSchema.default({}),
|
||||||
search: z.string().optional(),
|
search: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user