From b1c6657bf07f67c41a7218b40b57b93417bde6f3 Mon Sep 17 00:00:00 2001 From: Valentino Gagliardi Date: Wed, 14 Jun 2023 16:53:29 +0200 Subject: [PATCH] Expose licence object in handleAccept --- CHANGELOG.md | 6 ++++++ cypress/component/LicenceWidget.cy.tsx | 19 +++++++++++++------ package.json | 2 +- src/widgets/LicenceWidget.tsx | 7 ++----- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c71e7c6..321a3e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cypress/component/LicenceWidget.cy.tsx b/cypress/component/LicenceWidget.cy.tsx index bf6366a..bdf74d8 100644 --- a/cypress/component/LicenceWidget.cy.tsx +++ b/cypress/component/LicenceWidget.cy.tsx @@ -12,7 +12,7 @@ describe('', () => { licences: [ { id: 'licence-xyz', - revision: '3', + revision: 2, label: 'Licence to use Copernicus products', contents_url: '', attachment_url: '', @@ -20,7 +20,7 @@ describe('', () => { }, { id: 'licence-abc', - revision: '3', + revision: 3, label: 'Additional licence to use non European contributions', contents_url: '', attachment_url: '', @@ -43,7 +43,14 @@ describe('', () => { 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', () => { @@ -56,7 +63,7 @@ describe('', () => { licences: [ { id: 'licence-xyz', - revision: '3', + revision: 3, label: 'Licence to use Copernicus products', contents_url: '', attachment_url: '', @@ -64,7 +71,7 @@ describe('', () => { }, { id: 'licence-abc', - revision: '3', + revision: 3, label: 'Additional licence to use non European contributions', contents_url: '', attachment_url: '', @@ -89,7 +96,7 @@ describe('', () => { .its('firstCall.args.0') .should('deep.equal', { id: 'licence-xyz', - revision: '3', + revision: 3, label: 'Licence to use Copernicus products', contents_url: '', attachment_url: '', diff --git a/package.json b/package.json index 9471353..2f78839 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/widgets/LicenceWidget.tsx b/src/widgets/LicenceWidget.tsx index 1cdf716..a0243b1 100644 --- a/src/widgets/LicenceWidget.tsx +++ b/src/widgets/LicenceWidget.tsx @@ -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' @@ -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. */ @@ -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) => {