12 lines
713 B
TypeScript
12 lines
713 B
TypeScript
const territoryKeys=['province_id','district_id','admin_post_id','locality_id'];
|
|
/** No fallback scope: an explicit empty path means all; a selected path replaces its old descendants. */
|
|
export function territorialSearchParams(entries: Iterable<[string,FormDataEntryValue]>, path?: {id:string;location_type:string}[]): URLSearchParams {
|
|
const params=new URLSearchParams();
|
|
for(const [key,value] of entries)if(typeof value==='string'&&value!==''&&key!=='page')params.set(key,value);
|
|
if(path){
|
|
territoryKeys.forEach(key=>params.delete(key));
|
|
for(const node of path){const key=`${node.location_type}_id`;if(territoryKeys.includes(key))params.set(key,node.id);}
|
|
}
|
|
return params;
|
|
}
|