diff --git a/README.md b/README.md index 9a9f72229..56773445e 100644 --- a/README.md +++ b/README.md @@ -40,4 +40,4 @@ Adding new environment variables can be done by adding them to the `src/config.j - docker-compose.yml for use in local development ## Optional: Fetch sample data from the staging environment -Uncomment lines 10 to 21 in the `src/config.js` file +Uncomment lines 10 to 26 in the `src/config.js` file diff --git a/config.template.js b/config.template.js index 3623cd06a..2d4849254 100644 --- a/config.template.js +++ b/config.template.js @@ -24,5 +24,6 @@ window.env = { RESOURCE_API_HOST: '$RESOURCE_API_HOST', SEARCH_SERVICE_HOST: '$SEARCH_SERVICE_HOST', USE_DEMO_LOGO: '$USE_DEMO_LOGO', - CATALOG_PORTAL_BASE_URI: '$CATALOG_PORTAL_BASE_URI' + CATALOG_PORTAL_BASE_URI: '$CATALOG_PORTAL_BASE_URI', + ACCESS_REQUEST_API_HOST: '$ACCESS_REQUEST_API_HOST' }; diff --git a/deploy/demo/env.yaml b/deploy/demo/env.yaml index a3fabeb0f..d67282666 100644 --- a/deploy/demo/env.yaml +++ b/deploy/demo/env.yaml @@ -134,3 +134,8 @@ spec: secretKeyRef: name: commonurl-demo key: CATALOG_PORTAL_BASE_URI + - name: ACCESS_REQUEST_API_HOST + valueFrom: + secretKeyRef: + name: commonurl-demo + key: ACCESS_REQUEST_API_HOST diff --git a/deploy/prod/env.yaml b/deploy/prod/env.yaml index 096f25d35..a72007af3 100644 --- a/deploy/prod/env.yaml +++ b/deploy/prod/env.yaml @@ -134,3 +134,8 @@ spec: secretKeyRef: name: commonurl-prod key: CATALOG_PORTAL_BASE_URI + - name: ACCESS_REQUEST_API_HOST + valueFrom: + secretKeyRef: + name: commonurl-prod + key: ACCESS_REQUEST_API_HOST diff --git a/deploy/staging/env.yaml b/deploy/staging/env.yaml index 9847d530b..1258e65ca 100644 --- a/deploy/staging/env.yaml +++ b/deploy/staging/env.yaml @@ -134,3 +134,8 @@ spec: secretKeyRef: name: commonurl-staging key: CATALOG_PORTAL_BASE_URI + - name: ACCESS_REQUEST_API_HOST + valueFrom: + secretKeyRef: + name: commonurl-staging + key: ACCESS_REQUEST_API_HOST diff --git a/docker-compose.yml b/docker-compose.yml index 8c7e3713d..1d4790c42 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,4 +23,5 @@ services: - RESOURCE_API_HOST=https://resource.api.staging.fellesdatakatalog.digdir.no - SEARCH_SERVICE_HOST=https://search.api.staging.fellesdatakatalog.digdir.no - CATALOG_PORTAL_BASE_URI=https://catalog.portal.staging.fellesdatakatalog.digdir.no + - ACCESS_REQUEST_API_HOST=https://access-request.api.staging.fellesdatakatalog.digdir.no diff --git a/src/components/analytics-siteimprove/utils.ts b/src/components/analytics-siteimprove/utils.ts index 712b781aa..5855d06bb 100644 --- a/src/components/analytics-siteimprove/utils.ts +++ b/src/components/analytics-siteimprove/utils.ts @@ -20,9 +20,7 @@ export const trackSiteImproveEvent = ({ if (window._sz === undefined) { // eslint-disable-next-line no-console console.error('Unable to find Site Improve event library.'); - } - - if (label) { + } else if (label) { window._sz.push(['event', category, action, label]); } else { window._sz.push(['event', category, action]); diff --git a/src/components/details-page/components/details-page/accessRequestButton.tsx b/src/components/details-page/components/details-page/accessRequestButton.tsx new file mode 100644 index 000000000..c7824e335 --- /dev/null +++ b/src/components/details-page/components/details-page/accessRequestButton.tsx @@ -0,0 +1,104 @@ +import Button from '@fellesdatakatalog/button'; +import React from 'react'; +import translations from '../../../../lib/localization'; +import { AccessRequest } from '../../../../types'; +import SC from './styled'; +import { Entity } from '../../../../types/enums'; +import { + PATHNAME_CONCEPTS, + PATHNAME_DATA_SERVICES, + PATHNAME_DATASETS, + PATHNAME_EVENTS, + PATHNAME_INFORMATIONMODELS, + PATHNAME_PUBLIC_SERVICES +} from '../../../../constants/constants'; +import env from '../../../../env'; +import { + EventAction, + EventCategory, + trackSiteImproveEvent +} from '../../../analytics-siteimprove/utils'; + +const entityToPath = (entity: Entity): string => { + switch (entity) { + case Entity.DATASET: + return PATHNAME_DATASETS; + case Entity.DATA_SERVICE: + return PATHNAME_DATA_SERVICES; + case Entity.CONCEPT: + return PATHNAME_CONCEPTS; + case Entity.INFORMATION_MODEL: + return PATHNAME_INFORMATIONMODELS; + case Entity.PUBLIC_SERVICE: + return PATHNAME_PUBLIC_SERVICES; + case Entity.EVENT: + return PATHNAME_EVENTS; + default: + throw new Error('Unknown entity type'); + } +}; + +const createAccessRequestUrl = async ( + entity: Entity, + id: string +): Promise => { + const accessRequestApi = env.ACCESS_REQUEST_API_HOST; + const entityPath = entityToPath(entity); + + const input = `${accessRequestApi}/access-request/${translations.getLanguage()}${entityPath}/${id}`; + const response = await fetch(input, { + method: 'POST' + }); + + return response.text(); +}; + +export function AccessRequestButton({ + entityId, + entity, + accessRequest +}: { + entity: Entity; + entityId: string | undefined; + accessRequest: AccessRequest | undefined; +}) { + const trackAccessRequest = () => { + trackSiteImproveEvent({ + category: EventCategory.DETAILS_PAGE, + action: EventAction.REQUEST_ACCESS, + label: entityId + }); + }; + + // TODO - remove this when all access requests are routed through the access request api + if (entityId && accessRequest?.requestAddress === 'https://soknad.kudaf.no') { + return ( + + + + ); + } + + if (accessRequest === undefined) { + return null; + } + + return ( + + + + + + ); +} diff --git a/src/components/details-page/components/details-page/index.tsx b/src/components/details-page/components/details-page/index.tsx index 61ec1610b..f5623064f 100755 --- a/src/components/details-page/components/details-page/index.tsx +++ b/src/components/details-page/components/details-page/index.tsx @@ -10,8 +10,6 @@ import React, { import { compose } from 'redux'; import { Link } from 'react-router-dom'; import FdkLink from '@fellesdatakatalog/link'; - -import Button from '@fellesdatakatalog/button'; import translations from '../../../../lib/localization'; import { getTranslateText as translate } from '../../../../lib/translateText'; @@ -51,11 +49,7 @@ import withCommunity, { } from '../../../with-community'; import Aside from '../aside'; import { accessRequestWhiteList } from '../../../../white-list'; -import { - EventAction, - EventCategory, - trackSiteImproveEvent -} from '../../../analytics-siteimprove/utils'; +import { AccessRequestButton } from './accessRequestButton'; interface ExternalProps { entity: Entity; @@ -320,27 +314,11 @@ const DetailsPage: FC> = ({ {renderThemeItems().length > 0 && ( {renderThemeItems()} )} - {accessRequest && ( - - - - - - )} + diff --git a/src/config.js b/src/config.js index d976d5194..a52190c04 100644 --- a/src/config.js +++ b/src/config.js @@ -22,6 +22,8 @@ const env = window.env || { // env.FDK_MQA_API_BASE_URI = // 'https://mqa-scoring-api.staging.fellesdatakatalog.digdir.no'; // env.USE_DEMO_LOGO = true; +// env.ACCESS_REQUEST_API_HOST = +// 'https://access-request.api.staging.fellesdatakatalog.digdir.no'; const fdkPortalBaseUri = { host: env.FDK_PORTAL_BASE_URI || '' @@ -50,7 +52,8 @@ const config = { searchApi: { host: env.SEARCH_SERVICE_HOST }, store: { useLogger: env.REDUX_LOG === 'true' }, isNapProfile: isNapProfile(env.NAP_HOST), - useDemoLogo: env.USE_DEMO_LOGO + useDemoLogo: env.USE_DEMO_LOGO, + accessRequestApi: env.ACCESS_REQUEST_API_HOST }; export const getConfig = () => config; diff --git a/src/env.ts b/src/env.ts index fbd115cf1..b2f9199e0 100755 --- a/src/env.ts +++ b/src/env.ts @@ -30,6 +30,8 @@ export default validateEnv( INFORMATIONMODEL_HARVESTER_HOST: 'https://informationmodels.staging.fellesdatakatalog.digdir.no', CATALOG_PORTAL_BASE_URI: - 'https://catalog-portal.staging.fellesdatakatalog.digdir.no' + 'https://catalog-portal.staging.fellesdatakatalog.digdir.no', + ACCESS_REQUEST_API_HOST: + 'https://access-request.api.staging.fellesdatakatalog.digdir.no' } ); diff --git a/src/types/env.d.ts b/src/types/env.d.ts index e52cbcc5e..848222510 100755 --- a/src/types/env.d.ts +++ b/src/types/env.d.ts @@ -18,4 +18,5 @@ export interface EnvironmentVariables { RESOURCE_API_HOST: string; INFORMATIONMODEL_HARVESTER_HOST: string; CATALOG_PORTAL_BASE_URI: string; + ACCESS_REQUEST_API_HOST: string; } diff --git a/src/white-list.ts b/src/white-list.ts index 69b0292b6..9d087dc37 100644 --- a/src/white-list.ts +++ b/src/white-list.ts @@ -21,6 +21,10 @@ export const accessRequestWhiteList: AccessRequest[] = [ id: '8f305377-a3a3-3dde-be33-d5b5d0b8f818', requestAddress: 'https://forms.gle/VnBnZwvsWSu51a3V6' }, + { + id: '8b285b05-dd33-31db-a1b6-0cf605bf05dd', + requestAddress: 'https://soknad.kudaf.no' + }, // Production { id: 'a49ddd4a-8ccf-3054-8164-0bb9bfc9783c',