Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(platformServices): sw-625 remove onNavigate #1092

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,10 @@ Initialize an app, and return a combined state store that includes authorization
</tr><tr>
<td>options.hideGlobalFilter</td><td><code>function</code></td>
</tr><tr>
<td>options.onNavigation</td><td><code>function</code></td>
</tr><tr>
<td>options.useChrome</td><td><code>function</code></td>
</tr><tr>
<td>options.useDispatch</td><td><code>function</code></td>
</tr><tr>
<td>options.useNavigate</td><td><code>function</code></td>
</tr><tr>
<td>options.useSelectorsResponse</td><td><code>function</code></td>
</tr> </tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ exports[`AuthenticationContext should apply a hook for retrieving auth data from
},
],
],
[
[Function],
],
]
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ describe('AuthenticationContext', () => {
it('should apply a hook for retrieving auth data from multiple selectors', async () => {
const { result: errorResponse } = shallowHook(() =>
useGetAuthorization({
useNavigate: () => jest.fn(),
useSelectorsResponse: () => ({
error: true,
data: {
Expand All @@ -34,7 +33,6 @@ describe('AuthenticationContext', () => {
const { result: successResponse } = await mountHook(() =>
useGetAuthorization({
useDispatch: () => mockDispatch,
useNavigate: () => jest.fn(),
useSelectorsResponse: () => ({
fulfilled: true,
data: {
Expand All @@ -54,66 +52,57 @@ describe('AuthenticationContext', () => {
expect(mockDispatch.mock.calls).toMatchSnapshot('success dispatch');
expect(successResponse).toMatchSnapshot('success response');

const { result: mockStoreSuccessResponse } = shallowHook(
() => useGetAuthorization({ useNavigate: () => jest.fn() }),
{
state: {
user: {
auth: {
fulfilled: true,
data: [
{ isAdmin: true, isEntitled: true },
{
permissions: [
{
subscriptions: {
all: true,
resources: {
'*': {
'*': [],
loremCustom: [],
read: []
}
const { result: mockStoreSuccessResponse } = shallowHook(() => useGetAuthorization(), {
state: {
user: {
auth: {
fulfilled: true,
data: [
{ isAdmin: true, isEntitled: true },
{
permissions: [
{
subscriptions: {
all: true,
resources: {
'*': {
'*': [],
loremCustom: [],
read: []
}
}
}
],
authorized: {
subscriptions: true
}
],
authorized: {
subscriptions: true
}
]
},
locale: { fulfilled: true, data: {} },
errors: {}
}
}
]
},
locale: { fulfilled: true, data: {} },
errors: {}
}
}
);
});

expect(mockStoreSuccessResponse).toMatchSnapshot('mock store success response');

const { result: mockStoreErrorResponse } = shallowHook(
() =>
useGetAuthorization({
useNavigate: () => jest.fn()
}),
{
state: {
user: {
auth: {
error: true,
data: []
},
locale: { fulfilled: true, data: {} },
errors: {
error: true,
data: ['lorem', 'ipsum']
}
const { result: mockStoreErrorResponse } = shallowHook(() => useGetAuthorization(), {
state: {
user: {
auth: {
error: true,
data: []
},
locale: { fulfilled: true, data: {} },
errors: {
error: true,
data: ['lorem', 'ipsum']
}
}
}
);
});

expect(mockStoreErrorResponse).toMatchSnapshot('mock store error response');
});
Expand Down
17 changes: 3 additions & 14 deletions src/components/authentication/authenticationContext.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useContext, useState } from 'react';
import { useMount, useUnmount } from 'react-use';
import React, { useContext } from 'react';
import { useMount } from 'react-use';
import { useChrome } from '@redhat-cloud-services/frontend-components/useChrome';
import { reduxActions, storeHooks } from '../../redux';
import { helpers } from '../../common';
import { routerContext, routerHelpers } from '../router';
import { routerHelpers } from '../router';

/**
* @memberof Authentication
Expand Down Expand Up @@ -33,25 +33,19 @@ const useAuthContext = () => useContext(AuthenticationContext);
* @param {string} options.appName
* @param {Function} options.authorizeUser
* @param {Function} options.hideGlobalFilter
* @param {Function} options.onNavigation
* @param {Function} options.useChrome
* @param {Function} options.useDispatch
* @param {Function} options.useNavigate
* @param {Function} options.useSelectorsResponse
* @returns {{data: {errorCodes, errorStatus: *, locale}, pending: boolean, fulfilled: boolean, error: boolean}}
*/
const useGetAuthorization = ({
appName = routerHelpers.appName,
authorizeUser = reduxActions.platform.authorizeUser,
hideGlobalFilter = reduxActions.platform.hideGlobalFilter,
onNavigation = reduxActions.platform.onNavigation,
useChrome: useAliasChrome = useChrome,
useDispatch: useAliasDispatch = storeHooks.reactRedux.useDispatch,
useNavigate: useAliasNavigate = routerContext.useNavigate,
useSelectorsResponse: useAliasSelectorsResponse = storeHooks.reactRedux.useSelectorsResponse
} = {}) => {
const [unregister, setUnregister] = useState(() => helpers.noop);
const navigate = useAliasNavigate();
const dispatch = useAliasDispatch();
const { updateDocumentTitle = helpers.noop } = useAliasChrome();
const { data, error, fulfilled, pending, responses } = useAliasSelectorsResponse([
Expand All @@ -67,11 +61,6 @@ const useGetAuthorization = ({
await dispatch(authorizeUser());
updateDocumentTitle(appName);
dispatch([hideGlobalFilter()]);
setUnregister(() => dispatch(onNavigation(event => navigate(event.navId))));
});

useUnmount(() => {
unregister();
});

const [user = {}, app = {}] = (Array.isArray(data.auth) && data.auth) || [];
Expand Down
19 changes: 0 additions & 19 deletions src/redux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Platform service wrappers for dispatch, state update.
* [~clearNotifications()](#Actions.module_PlatformActions..clearNotifications) ⇒ <code>\*</code>
* [~authorizeUser(appName)](#Actions.module_PlatformActions..authorizeUser) ⇒ <code>function</code>
* [~hideGlobalFilter(isHidden)](#Actions.module_PlatformActions..hideGlobalFilter) ⇒ <code>Object</code>
* [~onNavigation(callback)](#Actions.module_PlatformActions..onNavigation) ⇒ <code>function</code>

<a name="Actions.module_PlatformActions..addNotification"></a>

Expand Down Expand Up @@ -160,24 +159,6 @@ Hide platform global filter.
</tr> </tbody>
</table>

<a name="Actions.module_PlatformActions..onNavigation"></a>

### PlatformActions~onNavigation(callback) ⇒ <code>function</code>
Apply platform method for updating routing history on "navigating" with the left-nav.

**Kind**: inner method of [<code>PlatformActions</code>](#Actions.module_PlatformActions)
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>callback</td><td><code>function</code></td>
</tr> </tbody>
</table>

<a name="Actions.module_RhsmActions"></a>

## RhsmActions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ exports[`PlatformActions Should return a dispatch object for the hideGlobalFilte
"type": "PLATFORM_GLOBAL_FILTER_HIDE",
}
`;

exports[`PlatformActions Should return a function for the onNavigation method: expected process 1`] = `"lorem ipsum"`;

exports[`PlatformActions Should return a function for the onNavigation method: function 1`] = `[Function]`;
8 changes: 0 additions & 8 deletions src/redux/actions/__tests__/platformActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,4 @@ describe('PlatformActions', () => {
it('Should return a dispatch object for the hideGlobalFilter method', () => {
expect(platformActions.hideGlobalFilter()).toMatchSnapshot('dispatch object');
});

it('Should return a function for the onNavigation method', () => {
expect(platformActions.onNavigation()).toMatchSnapshot('function');

window.insights.chrome.on = jest.fn().mockImplementation((id, value) => value('lorem'));
const dispatch = obj => obj;
expect(platformActions.onNavigation(event => `${event} ipsum`)(dispatch)).toMatchSnapshot('expected process');
});
});
19 changes: 2 additions & 17 deletions src/redux/actions/platformActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,12 @@ const hideGlobalFilter = isHidden => ({
payload: platformServices.hideGlobalFilter(isHidden)
});

/**
* Apply platform method for updating routing history on "navigating" with the left-nav.
*
* @param {Function} callback
* @returns {Function}
*/
const onNavigation = callback => dispatch => {
dispatch({
type: platformTypes.PLATFORM_ON_NAV
});
return platformServices.onNavigation(callback);
};

const platformActions = {
addNotification,
removeNotification,
clearNotifications,
authorizeUser,
hideGlobalFilter,
onNavigation
hideGlobalFilter
};

export {
Expand All @@ -88,6 +74,5 @@ export {
removeNotification,
clearNotifications,
authorizeUser,
hideGlobalFilter,
onNavigation
hideGlobalFilter
};
4 changes: 0 additions & 4 deletions src/redux/types/__tests__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ exports[`ReduxTypes should have specific type properties: all redux types 1`] =
"PLATFORM_ADD_NOTIFICATION": "@@INSIGHTS-CORE/NOTIFICATIONS/ADD_NOTIFICATION",
"PLATFORM_CLEAR_NOTIFICATIONS": "@@INSIGHTS-CORE/NOTIFICATIONS/CLEAR_NOTIFICATIONS",
"PLATFORM_GLOBAL_FILTER_HIDE": "PLATFORM_GLOBAL_FILTER_HIDE",
"PLATFORM_ON_NAV": "PLATFORM_ON_NAV",
"PLATFORM_REMOVE_NOTIFICATION": "@@INSIGHTS-CORE/NOTIFICATIONS/REMOVE_NOTIFICATION",
"PLATFORM_USER_AUTH": "PLATFORM_USER_AUTH",
},
Expand Down Expand Up @@ -94,7 +93,6 @@ exports[`ReduxTypes should have specific type properties: all redux types 1`] =
"PLATFORM_ADD_NOTIFICATION": "@@INSIGHTS-CORE/NOTIFICATIONS/ADD_NOTIFICATION",
"PLATFORM_CLEAR_NOTIFICATIONS": "@@INSIGHTS-CORE/NOTIFICATIONS/CLEAR_NOTIFICATIONS",
"PLATFORM_GLOBAL_FILTER_HIDE": "PLATFORM_GLOBAL_FILTER_HIDE",
"PLATFORM_ON_NAV": "PLATFORM_ON_NAV",
"PLATFORM_REMOVE_NOTIFICATION": "@@INSIGHTS-CORE/NOTIFICATIONS/REMOVE_NOTIFICATION",
"PLATFORM_USER_AUTH": "PLATFORM_USER_AUTH",
},
Expand Down Expand Up @@ -148,7 +146,6 @@ exports[`ReduxTypes should have specific type properties: all redux types 1`] =
"PLATFORM_ADD_NOTIFICATION": "@@INSIGHTS-CORE/NOTIFICATIONS/ADD_NOTIFICATION",
"PLATFORM_CLEAR_NOTIFICATIONS": "@@INSIGHTS-CORE/NOTIFICATIONS/CLEAR_NOTIFICATIONS",
"PLATFORM_GLOBAL_FILTER_HIDE": "PLATFORM_GLOBAL_FILTER_HIDE",
"PLATFORM_ON_NAV": "PLATFORM_ON_NAV",
"PLATFORM_REMOVE_NOTIFICATION": "@@INSIGHTS-CORE/NOTIFICATIONS/REMOVE_NOTIFICATION",
"PLATFORM_USER_AUTH": "PLATFORM_USER_AUTH",
},
Expand Down Expand Up @@ -249,7 +246,6 @@ exports[`ReduxTypes should have specific type properties: specific types 1`] = `
"PLATFORM_ADD_NOTIFICATION": "@@INSIGHTS-CORE/NOTIFICATIONS/ADD_NOTIFICATION",
"PLATFORM_CLEAR_NOTIFICATIONS": "@@INSIGHTS-CORE/NOTIFICATIONS/CLEAR_NOTIFICATIONS",
"PLATFORM_GLOBAL_FILTER_HIDE": "PLATFORM_GLOBAL_FILTER_HIDE",
"PLATFORM_ON_NAV": "PLATFORM_ON_NAV",
"PLATFORM_REMOVE_NOTIFICATION": "@@INSIGHTS-CORE/NOTIFICATIONS/REMOVE_NOTIFICATION",
"PLATFORM_USER_AUTH": "PLATFORM_USER_AUTH",
},
Expand Down
5 changes: 1 addition & 4 deletions src/redux/types/platformTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@ const PLATFORM_ADD_NOTIFICATION = ADD_NOTIFICATION;
const PLATFORM_REMOVE_NOTIFICATION = REMOVE_NOTIFICATION;
const PLATFORM_CLEAR_NOTIFICATIONS = CLEAR_NOTIFICATIONS;
const PLATFORM_GLOBAL_FILTER_HIDE = 'PLATFORM_GLOBAL_FILTER_HIDE';
const PLATFORM_ON_NAV = 'PLATFORM_ON_NAV';
const PLATFORM_USER_AUTH = 'PLATFORM_USER_AUTH';

/**
* Platform action, reducer types.
*
* @type {{PLATFORM_USER_AUTH: string, PLATFORM_GLOBAL_FILTER_HIDE: string, PLATFORM_CLEAR_NOTIFICATIONS: string,
* PLATFORM_ADD_NOTIFICATION: string, PLATFORM_REMOVE_NOTIFICATION: string, PLATFORM_ON_NAV: string}}
* PLATFORM_ADD_NOTIFICATION: string, PLATFORM_REMOVE_NOTIFICATION: string}}
*/
const platformTypes = {
PLATFORM_ADD_NOTIFICATION,
PLATFORM_REMOVE_NOTIFICATION,
PLATFORM_CLEAR_NOTIFICATIONS,
PLATFORM_GLOBAL_FILTER_HIDE,
PLATFORM_ON_NAV,
PLATFORM_USER_AUTH
};

Expand All @@ -38,6 +36,5 @@ export {
PLATFORM_REMOVE_NOTIFICATION,
PLATFORM_CLEAR_NOTIFICATIONS,
PLATFORM_GLOBAL_FILTER_HIDE,
PLATFORM_ON_NAV,
PLATFORM_USER_AUTH
};
19 changes: 0 additions & 19 deletions src/services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ Emulated service calls for platform globals.
* [~getUser(options)](#Platform.module_PlatformServices..getUser) ⇒ <code>Promise.&lt;\*&gt;</code>
* [~getUserPermissions(appName, options)](#Platform.module_PlatformServices..getUserPermissions) ⇒ <code>Promise.&lt;\*&gt;</code>
* [~hideGlobalFilter(isHidden)](#Platform.module_PlatformServices..hideGlobalFilter) ⇒ <code>Promise.&lt;\*&gt;</code>
* [~onNavigation(callback)](#Platform.module_PlatformServices..onNavigation) ⇒ <code>function</code>

<a name="Platform.module_PlatformServices..getUser"></a>

Expand Down Expand Up @@ -383,24 +382,6 @@ Disables the Platform's global filter display.
</tr> </tbody>
</table>

<a name="Platform.module_PlatformServices..onNavigation"></a>

### PlatformServices~onNavigation(callback) ⇒ <code>function</code>
Apply on "app_navigation" event. Return an un-listener.

**Kind**: inner method of [<code>PlatformServices</code>](#Platform.module_PlatformServices)
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>callback</td><td><code>function</code></td>
</tr> </tbody>
</table>

<a name="Platform.module_PlatformTransformers"></a>

## PlatformTransformers
Expand Down
Loading