UNPKG

synapse-react-client

Version:

[![Build Status](https://travis-ci.com/Sage-Bionetworks/Synapse-React-Client.svg?branch=main)](https://travis-ci.com/Sage-Bionetworks/Synapse-React-Client) [![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synaps

87 lines 3.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getQueryRequestFromLink = exports.updateUrlWithNewSearchParam = exports.getSearchParamValueFromUrl = void 0; var __1 = require(".."); var sqlFunctions_1 = require("./sqlFunctions"); //id consists of a component class/function name and it's index function getComponentSearchHashId(componentName, componentIndex) { return "" + componentName + componentIndex; } //returns updated search string with the component's info function patchSearchString(componentSearchHashId, stringifiedQuery) { var searchString = window.location.search; var searchFragment = componentSearchHashId + "=" + stringifiedQuery; if (!searchString) { return searchFragment; } if (!searchString.includes(componentSearchHashId + "=")) { //substr(1) because we don't want '?' character return searchString.substr(1) + "&" + searchFragment; } var searchHashes = window.location.search .slice(searchString.indexOf('?') + 1) .split('&'); var searchHashesUpdated = searchHashes .map(function (item) { var split = item.split('='); if (split[0] === componentSearchHashId) { return "" + searchFragment; } else return item; }) .join('&'); return searchHashesUpdated; } //gets a value for the search param for the component from the url function getSearchParamValueFromUrl(componentName, componentIndex) { if (!window.location.search) { return undefined; } var componentSearchHashId = getComponentSearchHashId(componentName, componentIndex); var hashes = window.location.search .slice(window.location.search.indexOf('?') + 1) .split('&'); var getSearchParamValue = hashes .filter(function (item) { var hash = item.split('='); return hash[0] === componentSearchHashId; }) .map(function (item) { return item.split('=')[1]; })[0]; return getSearchParamValue ? decodeURIComponent(getSearchParamValue) : undefined; } exports.getSearchParamValueFromUrl = getSearchParamValueFromUrl; //updates the url with the components new search params function updateUrlWithNewSearchParam(componentName, componentIndex, stringifiedQuery) { var componentSearchHashId = componentIndex !== undefined ? getComponentSearchHashId(componentName, componentIndex) : componentName; var searchString = patchSearchString(componentSearchHashId, stringifiedQuery); var location = window.location; var newURL = location.protocol + "//" + location.hostname + (location.port ? ':' + location.port : '') + location.pathname + "?" + searchString; window.history.pushState('object or string', 'Title', newURL); } exports.updateUrlWithNewSearchParam = updateUrlWithNewSearchParam; function getQueryRequestFromLink(componentName, componentIndex) { var searchParamValue = getSearchParamValueFromUrl(componentName, componentIndex); var initQueryRequest = undefined; if (searchParamValue) { var query = JSON.parse(searchParamValue); if (query.sql) { initQueryRequest = { concreteType: 'org.sagebionetworks.repo.model.table.QueryBundleRequest', partMask: __1.SynapseConstants.BUNDLE_MASK_QUERY_COLUMN_MODELS | __1.SynapseConstants.BUNDLE_MASK_QUERY_FACETS | __1.SynapseConstants.BUNDLE_MASK_QUERY_SELECT_COLUMNS | __1.SynapseConstants.BUNDLE_MASK_QUERY_RESULTS, entityId: (0, sqlFunctions_1.parseEntityIdFromSqlStatement)(query.sql), query: query, }; } } return initQueryRequest; } exports.getQueryRequestFromLink = getQueryRequestFromLink; //# sourceMappingURL=deepLinkingUtils.js.map