import { isArray, castArray } from 'lodash'; import React, { useMemo } from 'react'; import QueryString from 'querystring'; import { RouteComponentProps, Redirect } from 'react-router'; import { RouteEntry, parseQueryString } from 'wdk-client/Core/RouteEntry'; import IndexController from 'wdk-client/Controllers/IndexController'; import RecordController from 'wdk-client/Controllers/RecordController'; import NotFoundController from 'wdk-client/Controllers/NotFoundController'; import AnswerController from 'wdk-client/Controllers/AnswerController'; import QuestionListController from 'wdk-client/Controllers/QuestionListController'; import DownloadFormController from 'wdk-client/Controllers/DownloadFormController'; import WebServicesHelpController from 'wdk-client/Controllers/WebServicesHelpController'; import UserRegistrationController from 'wdk-client/Controllers/UserRegistrationController'; import UserProfileController from 'wdk-client/Controllers/UserProfileController'; import UserPasswordChangeController from 'wdk-client/Controllers/UserPasswordChangeController'; import UserPasswordResetController from 'wdk-client/Controllers/UserPasswordResetController'; import UserMessageController from 'wdk-client/Controllers/UserMessageController'; import SiteMapController from 'wdk-client/Controllers/SiteMapController'; import FavoritesController from 'wdk-client/Controllers/FavoritesController'; import UserLoginController from 'wdk-client/Controllers/UserLoginController'; import QuestionController from 'wdk-client/Controllers/QuestionController'; import { SubmissionMetadata } from 'wdk-client/Actions/QuestionActions'; import { Plugin } from 'wdk-client/Utils/ClientPlugin'; import StrategyWorkspaceController from 'wdk-client/Controllers/StrategyWorkspaceController'; import BasketController from 'wdk-client/Controllers/BasketController'; import { Loading, PermissionDenied } from 'wdk-client/Components'; import NotFound from 'wdk-client/Views/NotFound/NotFound'; import Error from 'wdk-client/Components/PageStatus/Error'; const routes: RouteEntry[] = [ { path: '/', component: () => }, { path: '/search/:recordClass/:question/result', component: (props: RouteComponentProps<{recordClass: string; question: string;}>) => { const { filterTerm, filterAttributes = [], filterTables = [] } = QueryString.parse(props.location.search.slice(1)); const parameters = parseSearchParamsFromQueryParams(parseQueryString(props)); return ( ) } }, { path: '/search/:recordClass/:question', component: (props: RouteComponentProps<{recordClass: string; question: string;}>) => { // Parse querystring. Three types of query params are supported: autoRun, strategyName, // and param data: // - autoRun: boolean (interpretted as true if present without a value, or with 'true' or '1') // - strategyName: string // - param data: Prefix with "param.". E.g., "param.organism=Plasmodium+falciparum+3D7", or "param.ds_gene_ids.idList=PF3D7_1133400,PF3D7_1133401" const { autoRun, strategyName, ...restQueryParams } = parseQueryString(props); const initialParamData = parseSearchParamsFromQueryParams(restQueryParams); const submissionMetadata = useMemo( (): SubmissionMetadata => ({ type: 'create-strategy', strategyName, }), [strategyName] ); return ( } /> ); } }, { path: '/record/:recordClass/download/:primaryKey+', component: (props: RouteComponentProps<{recordClass: string; primaryKey: string;}>) => { const { format, summaryView } = parseQueryString(props); return } }, { path: '/workspace/basket/:basketName/download', component: (props: RouteComponentProps<{ basketName: string }>) => { const { format } = parseQueryString(props); return ( ); } }, { path: '/web-services-help', component: (props: RouteComponentProps<{}>) => , rootClassNameModifier: 'web-services-help' }, { path: '/record/:recordClass/:primaryKey+', component: (props: RouteComponentProps<{ recordClass: string; primaryKey: string; }>) => }, { path: '/step/:stepId(\\d+)/download', component: (props: RouteComponentProps<{ stepId: string }>) => { const { format, summaryView } = parseQueryString(props); const stepId = Number(props.match.params.stepId); return ( ); } }, { path: '/user/login', component: (props: RouteComponentProps) => { const { destination } = parseQueryString(props); return ( ); } }, { path: '/user/registration', component: (props: RouteComponentProps) => { const initialFormFields = props.location.search.length === 0 ? undefined : parseQueryString(props); return ; } }, { path: '/user/profile', component: () => }, { path: '/user/profile/password', component: () => }, { path: '/user/forgot-password', component: () => }, { path: '/user/message/:messageKey', component: (props: RouteComponentProps<{messageKey: string}>) => }, { path: '/workspace/basket', requiresLogin: true, component: BasketController }, { path: '/workspace/strategies/:subPath*', exact: false, component: (props: RouteComponentProps<{ subPath?: string }, {}, { allowEmptyOpened?: boolean } | undefined>) => { const queryParams = parseQueryString(props); const { subPath = '' } = props.match.params; const { allowEmptyOpened = false } = props.location.state || {}; return ( ); } }, { path: '/workspace/favorites', requiresLogin: true, component: () => }, { path: '/data-finder', component: () => }, { path: '/question-list', component: () => }, { path: '/import/:signature', component: (props: RouteComponentProps<{ signature: string }>) => }, { path: '/401', component: PermissionDenied }, { path: '/404', component: NotFound }, { path: '/500', component: Error }, { path: '*', component: () => } ]; export default routes; function parseSearchParamsFromQueryParams(restQueryParams: { [x: string]: string; }): Record | undefined { const initialParamValuesEntries = Object.entries(restQueryParams) .filter(([key]) => key.startsWith('param.')) .map(([key, value]) => [key.replace(/^param\./, ''), value]); return initialParamValuesEntries.length > 0 ? Object.fromEntries(initialParamValuesEntries) : undefined; }