Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Expose licence object in handleAccept
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinogagliardi authored Jun 14, 2023
1 parent 6b5117b commit b1c6657
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [6.1.16] 2023-06-14

### Changed

- `LicenceWidget` now expose the whole licence for `handleAccept`

## [6.1.15] 2023-06-14

### Fixed
Expand Down
19 changes: 13 additions & 6 deletions cypress/component/LicenceWidget.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ describe('<LicenceWidget />', () => {
licences: [
{
id: 'licence-xyz',
revision: '3',
revision: 2,
label: 'Licence to use Copernicus products',
contents_url: '',
attachment_url: '',
accepted: true
},
{
id: 'licence-abc',
revision: '3',
revision: 3,
label: 'Additional licence to use non European contributions',
contents_url: '',
attachment_url: '',
Expand All @@ -43,7 +43,14 @@ describe('<LicenceWidget />', () => {
cy.get('@onLicenceAccept')
.should('have.been.calledOnce')
.its('firstCall.args.0')
.should('eq', 'licence-abc')
.should('deep.equal', {
id: 'licence-abc',
label: 'Additional licence to use non European contributions',
accepted: false,
revision: 3,
contents_url: '',
attachment_url: ''
})
})

it('handles licence click', () => {
Expand All @@ -56,15 +63,15 @@ describe('<LicenceWidget />', () => {
licences: [
{
id: 'licence-xyz',
revision: '3',
revision: 3,
label: 'Licence to use Copernicus products',
contents_url: '',
attachment_url: '',
accepted: true
},
{
id: 'licence-abc',
revision: '3',
revision: 3,
label: 'Additional licence to use non European contributions',
contents_url: '',
attachment_url: '',
Expand All @@ -89,7 +96,7 @@ describe('<LicenceWidget />', () => {
.its('firstCall.args.0')
.should('deep.equal', {
id: 'licence-xyz',
revision: '3',
revision: 3,
label: 'Licence to use Copernicus products',
contents_url: '',
attachment_url: '',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ecmwf-projects/cads-ui-library",
"version": "6.1.15",
"version": "6.1.16",
"description": "Common UI kit library",
"repository": {
"type": "git",
Expand Down
7 changes: 2 additions & 5 deletions src/widgets/LicenceWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { CheckIcon } from '@radix-ui/react-icons'

import { BaseButton } from '../index'

import { TMarkdownToJSX } from '../internal'
import { Widget, WidgetHeader, WidgetTitle } from './Widget'
import { WidgetTooltip } from '../index'

Expand Down Expand Up @@ -54,7 +53,7 @@ export interface LicenceWidgetProps {
/**
* Licence accept handler. Invoked when the user clicks "Accept terms" for the given licence.
*/
onLicenceAccept?: (id: string) => void
onLicenceAccept?: (licence: Licence) => void
/**
* Licence click handler. Invoked when the user clicks the licence title.
*/
Expand Down Expand Up @@ -83,9 +82,7 @@ const LicenceWidget = ({
if (type !== 'LicenceWidget') return null

const handleAccept = (licence: Licence) => {
const { id } = licence

onLicenceAccept && onLicenceAccept(id)
onLicenceAccept && onLicenceAccept(licence)
}

const getLicence = (licence: Licence) => {
Expand Down

0 comments on commit b1c6657

Please sign in to comment.