From 674f4edb52d4fc06c89f1129fb45f7795e0fc15f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Poizat?= Date: Mon, 6 Jan 2025 16:27:31 +0100 Subject: [PATCH] feat: Remove deprecated slug prop from AppLinker BREAKING CHANGE: Use app={{ slug: 'drive' }} instead of slug='drive' as AppLinker prop. Also, `name` is not passed anymore as render prop. --- react/AppLinker/Readme.md | 34 +-------- .../index.deprecated.spec.jsx.snap | 13 ---- react/AppLinker/index.deprecated.spec.jsx | 71 ------------------- react/AppLinker/index.jsx | 18 +---- 4 files changed, 4 insertions(+), 132 deletions(-) delete mode 100644 react/AppLinker/__snapshots__/index.deprecated.spec.jsx.snap delete mode 100644 react/AppLinker/index.deprecated.spec.jsx diff --git a/react/AppLinker/Readme.md b/react/AppLinker/Readme.md index d18d74eddb..da55fce984 100644 --- a/react/AppLinker/Readme.md +++ b/react/AppLinker/Readme.md @@ -1,15 +1,10 @@ Render-props component that provides onClick/href handler to apply to an anchor that needs to open an app. -If the app is known to Cozy (for example Drive or Banks), and -the user has installed it on its device, the native app will -be opened. - The app's manifest can be set in the `app` prop. Then, in a ReactNative environment, the AppLinker will be able to send `openApp` message to the native environment with this `app` -data. Ideally the `mobile` member should be set with all data -needed to open the native app ([more info](https://github.com/cozy/cozy-stack/blob/master/docs/apps.md#mobile)) +data. Handles several cases: @@ -28,32 +23,9 @@ const app = { }; { - ({ onClick, href, name }) => ( - - Open { name } - - ) -} -``` - -### Exemple with mobile data - -```jsx -import AppLinker from 'cozy-ui/transpiled/react/AppLinker'; - -const app = { - slug: 'passwords', - mobile: { - schema: 'cozypass://', - id_playstore: 'io.cozy.pass', - id_appstore: 'cozy-pass/id1502262449' - } -}; - -{ - ({ onClick, href, name }) => ( + ({ onClick, href }) => ( - Open { name } + Open ) } diff --git a/react/AppLinker/__snapshots__/index.deprecated.spec.jsx.snap b/react/AppLinker/__snapshots__/index.deprecated.spec.jsx.snap deleted file mode 100644 index c40db496bf..0000000000 --- a/react/AppLinker/__snapshots__/index.deprecated.spec.jsx.snap +++ /dev/null @@ -1,13 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`app icon should render correctly 1`] = ` -
-
- - Open - -
-
-`; diff --git a/react/AppLinker/index.deprecated.spec.jsx b/react/AppLinker/index.deprecated.spec.jsx deleted file mode 100644 index e7fb9e4462..0000000000 --- a/react/AppLinker/index.deprecated.spec.jsx +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Those tests are here to test previous AppLinker implementation base on - * `slug` prop. - * Now that AppLinkers implements `app` prop and uses `app.slug`, the old - * `slug` prop is deprecated - * Those tests should be kept until `slug` prop is completely removed - */ - -import { render } from '@testing-library/react' -import userEvent from '@testing-library/user-event' -import React from 'react' - -import AppLinker from '.' - -jest.useFakeTimers() - -const setup = ({ app, onAppSwitch }) => { - return { - user: userEvent.setup({ delay: null }), - ...render( - - {({ onClick, href, name }) => ( -
- - Open {name} - -
- )} -
- ) - } -} - -const app = { - slug: 'drive', - name: 'Drive' -} - -describe('app icon', () => { - let spyConsoleError, spyConsoleWarn, appSwitchMock - - beforeEach(() => { - spyConsoleError = jest.spyOn(console, 'error') - spyConsoleError.mockImplementation(() => {}) - spyConsoleWarn = jest.spyOn(console, 'warn') - spyConsoleWarn.mockImplementation(() => {}) - appSwitchMock = jest.fn() - }) - - afterEach(() => { - spyConsoleError.mockRestore() - spyConsoleWarn.mockRestore() - jest.restoreAllMocks() - }) - - it('should render correctly', () => { - const { container } = setup({ app }) - expect(container).toMatchSnapshot() - }) - - it('should work for web -> web', async () => { - const { container, user } = setup({ app, onAppSwitch: appSwitchMock }) - const link = container.querySelector('a') - await user.click(link) - expect(appSwitchMock).not.toHaveBeenCalled() - }) -}) diff --git a/react/AppLinker/index.jsx b/react/AppLinker/index.jsx index 109152ab73..9ba3a52add 100644 --- a/react/AppLinker/index.jsx +++ b/react/AppLinker/index.jsx @@ -29,19 +29,7 @@ export class AppLinker extends React.Component { } static getSlug(props) { - if (props.app && props.app.slug) { - return props.app.slug - } - - return props.slug - } - - static deprecateSlug(props) { - if (props.slug) { - console.warn( - `AppLinker's 'slug' prop is deprecated, please use 'app.slug' instead` - ) - } + return props.app.slug } static getOnClickHref(props, context, imgRef) { @@ -95,8 +83,6 @@ export class AppLinker extends React.Component { render() { const { children } = this.props - AppLinker.deprecateSlug(this.props) - const { href, onClick } = AppLinker.getOnClickHref( this.props, this.context, @@ -112,8 +98,6 @@ export class AppLinker extends React.Component { } AppLinker.propTypes = { - /** DEPRECATED: please use app.slug prop */ - slug: PropTypes.string, /* Full web url : Used by default on desktop browser Used as a fallback_uri on mobile web