Skip to content

Commit

Permalink
Integrate with kudaf (#2155)
Browse files Browse the repository at this point in the history
* Add integration with kudaf application

* Add dataset to white list in staging using kudaf application request url

* Update src/components/details-page/components/details-page/accessRequestButton.tsx

Co-authored-by: Jeff Reiffers <[email protected]>

* Add a todo

* Add ACCESS_REQUEST_API_HOST to deploy env

* Add ACCESS_REQUEST_API_HOST to docker compose

* Update readme

---------

Co-authored-by: Jeff Reiffers <[email protected]>
  • Loading branch information
halvorbmundal and jeffreiffers authored Oct 24, 2024
1 parent c7e7809 commit 4b59a24
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion config.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
5 changes: 5 additions & 0 deletions deploy/demo/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions deploy/prod/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions deploy/staging/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 1 addition & 3 deletions src/components/analytics-siteimprove/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string> => {
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 (
<SC.AccessRequest>
<Button
onClick={() => {
trackAccessRequest();
createAccessRequestUrl(entity, entityId).then(url => {
window.location.href = url;
});
}}
>
{translations.detailsPage.requestDataButton}
</Button>
</SC.AccessRequest>
);
}

if (accessRequest === undefined) {
return null;
}

return (
<SC.AccessRequest>
<a href={accessRequest.requestAddress} target='_blank' rel='noreferrer'>
<Button onClick={trackAccessRequest}>
{translations.detailsPage.requestDataButton}
</Button>
</a>
</SC.AccessRequest>
);
}
34 changes: 6 additions & 28 deletions src/components/details-page/components/details-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -320,27 +314,11 @@ const DetailsPage: FC<PropsWithChildren<Props>> = ({
{renderThemeItems().length > 0 && (
<SC.Themes>{renderThemeItems()}</SC.Themes>
)}
{accessRequest && (
<SC.AccessRequest>
<a
href={accessRequest.requestAddress}
target='_blank'
rel='noreferrer'
>
<Button
onClick={() =>
trackSiteImproveEvent({
category: EventCategory.DETAILS_PAGE,
action: EventAction.REQUEST_ACCESS,
label: entityId
})
}
>
{translations.detailsPage.requestDataButton}
</Button>
</a>
</SC.AccessRequest>
)}
<AccessRequestButton
accessRequest={accessRequest}
entityId={entityId}
entity={entity}
/>
</SC.HeadingLeft>
</SC.Heading>
<SC.Page>
Expand Down
5 changes: 4 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ''
Expand Down Expand Up @@ -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;
4 changes: 3 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
);
1 change: 1 addition & 0 deletions src/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 4 additions & 0 deletions src/white-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 4b59a24

Please sign in to comment.