134 lines
3.1 KiB
JavaScript
134 lines
3.1 KiB
JavaScript
export const normalizeRouteStateQuery = (query = {}) => {
|
|
const viewAll = query?.va === "true";
|
|
const advanced = query?.adv === "true";
|
|
const address = query?.ads === "true";
|
|
|
|
return {
|
|
viewAll,
|
|
advanced,
|
|
address,
|
|
key: query?.key
|
|
};
|
|
};
|
|
|
|
export const resolveSearchResultsHref = ({
|
|
query = {},
|
|
hasSession = false,
|
|
includeViewAll = true,
|
|
fallbackToMyPortalWhenNoFlags = false,
|
|
isDnsRoute = false
|
|
} = {}) => {
|
|
const routeState = normalizeRouteStateQuery(query);
|
|
const { viewAll, advanced, address, key } = routeState;
|
|
const base = hasSession ? "/myportal" : "";
|
|
const hasSearchQuery =
|
|
typeof query?.q === "string" && query.q.trim().length > 0;
|
|
|
|
if (fallbackToMyPortalWhenNoFlags && !viewAll && !advanced && !address) {
|
|
if (hasSearchQuery) {
|
|
return {
|
|
pathname: `${base}/searchresults`,
|
|
query
|
|
};
|
|
}
|
|
return {
|
|
pathname: "/myportal"
|
|
};
|
|
}
|
|
|
|
if (isDnsRoute) {
|
|
return {
|
|
pathname: `${base}/dnsapplications`
|
|
};
|
|
}
|
|
|
|
if (includeViewAll && viewAll) {
|
|
return {
|
|
pathname: "/myportal/viewall",
|
|
query: { key }
|
|
};
|
|
}
|
|
|
|
if (advanced) {
|
|
return {
|
|
pathname: `${base}/advancedsearchresults`,
|
|
query
|
|
};
|
|
}
|
|
|
|
if (address) {
|
|
return {
|
|
pathname: `${base}/addresssearchresults`,
|
|
query
|
|
};
|
|
}
|
|
|
|
return {
|
|
pathname: `${base}/searchresults`,
|
|
query
|
|
};
|
|
};
|
|
|
|
export const resolveSearchBreadcrumbLabel = ({
|
|
query = {},
|
|
getViewAllLabel = () => null,
|
|
advancedLabel = "",
|
|
addressLabel = "",
|
|
defaultLabel = ""
|
|
} = {}) => {
|
|
const routeState = normalizeRouteStateQuery(query);
|
|
const { viewAll, advanced, address, key } = routeState;
|
|
|
|
if (viewAll) {
|
|
return getViewAllLabel(key);
|
|
}
|
|
|
|
const keyedLabel = getViewAllLabel(key);
|
|
if (keyedLabel) return keyedLabel;
|
|
|
|
if (advanced) return advancedLabel;
|
|
if (address) return addressLabel;
|
|
|
|
return defaultLabel;
|
|
};
|
|
|
|
export const isDnsRoutePath = (pathname = "") => {
|
|
return (
|
|
pathname === "/dns" ||
|
|
pathname.startsWith("/dns/") ||
|
|
pathname === "/myportal/dns" ||
|
|
pathname.startsWith("/myportal/dns/")
|
|
);
|
|
};
|
|
|
|
export const resolveCaseBreadcrumbState = ({
|
|
query = {},
|
|
hasSession = false,
|
|
getViewAllLabel = () => null,
|
|
advancedLabel = "",
|
|
addressLabel = "",
|
|
defaultLabel = ""
|
|
} = {}) => {
|
|
return {
|
|
breadcrumbHref: resolveSearchResultsHref({
|
|
query,
|
|
hasSession,
|
|
includeViewAll: true,
|
|
fallbackToMyPortalWhenNoFlags: true
|
|
}),
|
|
caseResultsHref: resolveSearchResultsHref({
|
|
query,
|
|
hasSession,
|
|
includeViewAll: false,
|
|
fallbackToMyPortalWhenNoFlags: false
|
|
}),
|
|
breadcrumbLabel: resolveSearchBreadcrumbLabel({
|
|
query,
|
|
getViewAllLabel,
|
|
advancedLabel,
|
|
addressLabel,
|
|
defaultLabel
|
|
})
|
|
};
|
|
};
|