-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
c7e7809
commit 4b59a24
Showing
13 changed files
with
142 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/components/details-page/components/details-page/accessRequestButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters