Skip to content

Commit

Permalink
refactor: sw-2861 hideGlobalFilter legacy chrome method (#1395)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Sep 9, 2024
1 parent 096933f commit 288ce86
Show file tree
Hide file tree
Showing 13 changed files with 7 additions and 114 deletions.
2 changes: 0 additions & 2 deletions src/components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ Initialize an app, and return a combined state store that includes authorization
</tr><tr>
<td>options.authorizeUser</td><td><code>function</code></td>
</tr><tr>
<td>options.hideGlobalFilter</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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ exports[`AuthenticationContext should apply a hook for retrieving auth data from
[
[Function],
],
[
[
{
"payload": Promise {},
"type": "PLATFORM_GLOBAL_FILTER_HIDE",
},
],
],
]
`;

Expand Down
6 changes: 2 additions & 4 deletions src/components/authentication/authenticationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const useAuthContext = () => useContext(AuthenticationContext);
* @param {object} options
* @param {string} options.appName
* @param {Function} options.authorizeUser
* @param {Function} options.hideGlobalFilter
* @param {Function} options.useChrome
* @param {Function} options.useDispatch
* @param {Function} options.useSelectorsResponse
Expand All @@ -41,13 +40,12 @@ const useAuthContext = () => useContext(AuthenticationContext);
const useGetAuthorization = ({
appName = routerHelpers.appName,
authorizeUser = reduxActions.platform.authorizeUser,
hideGlobalFilter = reduxActions.platform.hideGlobalFilter,
useChrome: useAliasChrome = useChrome,
useDispatch: useAliasDispatch = storeHooks.reactRedux.useDispatch,
useSelectorsResponse: useAliasSelectorsResponse = storeHooks.reactRedux.useSelectorsResponse
} = {}) => {
const dispatch = useAliasDispatch();
const { updateDocumentTitle = helpers.noop } = useAliasChrome();
const { updateDocumentTitle = helpers.noop, hideGlobalFilter = helpers.noop } = useAliasChrome();
const { data, error, fulfilled, pending, responses } = useAliasSelectorsResponse([
{ id: 'auth', selector: ({ app }) => app?.auth },
{ id: 'locale', selector: ({ app }) => app?.locale },
Expand All @@ -60,7 +58,7 @@ const useGetAuthorization = ({
useMount(async () => {
await dispatch(authorizeUser());
updateDocumentTitle(appName);
dispatch([hideGlobalFilter()]);
hideGlobalFilter();
});

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 @@ -69,7 +69,6 @@ Platform service wrappers for dispatch, state update.
* [~deleteExistingExports(existingExports, notifications)](#Actions.module_PlatformActions..deleteExistingExports) ⇒ <code>function</code>
* [~getExistingExportsStatus(notifications)](#Actions.module_PlatformActions..getExistingExportsStatus) ⇒ <code>function</code>
* [~createExport(id, data, options, notifications)](#Actions.module_PlatformActions..createExport) ⇒ <code>function</code>
* [~hideGlobalFilter(isHidden)](#Actions.module_PlatformActions..hideGlobalFilter) ⇒ <code>Object</code>

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

Expand Down Expand Up @@ -217,24 +216,6 @@ Create an export for download. Includes toast notifications.
</tr> </tbody>
</table>

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

### PlatformActions~hideGlobalFilter(isHidden) ⇒ <code>Object</code>
Hide platform global filter.

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

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

## RhsmActions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`PlatformActions Should return a dispatch object for the hideGlobalFilter method: dispatch object 1`] = `
{
"payload": Promise {},
"type": "PLATFORM_GLOBAL_FILTER_HIDE",
}
`;

exports[`PlatformActions Should return response content for createExport method: dispatch object 1`] = `
[
[
Expand Down
4 changes: 0 additions & 4 deletions src/redux/actions/__tests__/platformActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ describe('PlatformActions', () => {
expect(mockDispatch.mock.calls).toMatchSnapshot('dispatch object');
});

it('Should return a dispatch object for the hideGlobalFilter method', () => {
expect(platformActions.hideGlobalFilter()).toMatchSnapshot('dispatch object');
});

it('Should return response content for removeExistingExports method', () => {
const mockDispatch = jest.fn();
platformActions.deleteExistingExports([])(mockDispatch);
Expand Down
17 changes: 2 additions & 15 deletions src/redux/actions/platformActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,6 @@ const createExport =
}
});

/**
* Hide platform global filter.
*
* @param {boolean} isHidden
* @returns {{Function}}
*/
const hideGlobalFilter = isHidden => ({
type: platformTypes.PLATFORM_GLOBAL_FILTER_HIDE,
payload: platformServices.hideGlobalFilter(isHidden)
});

const platformActions = {
addNotification,
removeNotification,
Expand All @@ -150,8 +139,7 @@ const platformActions = {
createExport,
deleteExistingExports,
getExistingExports,
getExistingExportsStatus,
hideGlobalFilter
getExistingExportsStatus
};

export {
Expand All @@ -164,6 +152,5 @@ export {
createExport,
deleteExistingExports,
getExistingExports,
getExistingExportsStatus,
hideGlobalFilter
getExistingExportsStatus
};
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 @@ -40,7 +40,6 @@ exports[`ReduxTypes should have specific type properties: all redux types 1`] =
"GET_PLATFORM_EXPORT_EXISTING": "GET_PLATFORM_EXPORT_EXISTING",
"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_REMOVE_NOTIFICATION": "@@INSIGHTS-CORE/NOTIFICATIONS/REMOVE_NOTIFICATION",
"PLATFORM_USER_AUTH": "PLATFORM_USER_AUTH",
"SET_PLATFORM_EXPORT_CREATE": "SET_PLATFORM_EXPORT_CREATE",
Expand Down Expand Up @@ -86,7 +85,6 @@ exports[`ReduxTypes should have specific type properties: all redux types 1`] =
"GET_PLATFORM_EXPORT_EXISTING": "GET_PLATFORM_EXPORT_EXISTING",
"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_REMOVE_NOTIFICATION": "@@INSIGHTS-CORE/NOTIFICATIONS/REMOVE_NOTIFICATION",
"PLATFORM_USER_AUTH": "PLATFORM_USER_AUTH",
"SET_PLATFORM_EXPORT_CREATE": "SET_PLATFORM_EXPORT_CREATE",
Expand Down Expand Up @@ -132,7 +130,6 @@ exports[`ReduxTypes should have specific type properties: all redux types 1`] =
"GET_PLATFORM_EXPORT_EXISTING": "GET_PLATFORM_EXPORT_EXISTING",
"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_REMOVE_NOTIFICATION": "@@INSIGHTS-CORE/NOTIFICATIONS/REMOVE_NOTIFICATION",
"PLATFORM_USER_AUTH": "PLATFORM_USER_AUTH",
"SET_PLATFORM_EXPORT_CREATE": "SET_PLATFORM_EXPORT_CREATE",
Expand Down Expand Up @@ -205,7 +202,6 @@ exports[`ReduxTypes should have specific type properties: specific types 1`] = `
"GET_PLATFORM_EXPORT_EXISTING": "GET_PLATFORM_EXPORT_EXISTING",
"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_REMOVE_NOTIFICATION": "@@INSIGHTS-CORE/NOTIFICATIONS/REMOVE_NOTIFICATION",
"PLATFORM_USER_AUTH": "PLATFORM_USER_AUTH",
"SET_PLATFORM_EXPORT_CREATE": "SET_PLATFORM_EXPORT_CREATE",
Expand Down
8 changes: 3 additions & 5 deletions src/redux/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,14 @@ const messageTypes = {
* Platform action, reducer types.
*
* @type {{PLATFORM_USER_AUTH: string, DELETE_PLATFORM_EXPORT_EXISTING: string, SET_PLATFORM_EXPORT_EXISTING_STATUS:
* string, SET_PLATFORM_EXPORT_STATUS: string, PLATFORM_GLOBAL_FILTER_HIDE: string, PLATFORM_CLEAR_NOTIFICATIONS:
* string, GET_PLATFORM_EXPORT_EXISTING: string, SET_PLATFORM_EXPORT_RESET: string, PLATFORM_ADD_NOTIFICATION:
* string, PLATFORM_REMOVE_NOTIFICATION: string, SET_PLATFORM_EXPORT_CREATE:
* string}}
* string, SET_PLATFORM_EXPORT_STATUS: string, PLATFORM_CLEAR_NOTIFICATIONS: string, GET_PLATFORM_EXPORT_EXISTING:
* string, SET_PLATFORM_EXPORT_RESET: string, PLATFORM_ADD_NOTIFICATION: string, PLATFORM_REMOVE_NOTIFICATION:
* string, SET_PLATFORM_EXPORT_CREATE: string}}
*/
const platformTypes = {
PLATFORM_ADD_NOTIFICATION: ADD_NOTIFICATION,
PLATFORM_REMOVE_NOTIFICATION: REMOVE_NOTIFICATION,
PLATFORM_CLEAR_NOTIFICATIONS: CLEAR_NOTIFICATIONS,
PLATFORM_GLOBAL_FILTER_HIDE: 'PLATFORM_GLOBAL_FILTER_HIDE',
PLATFORM_USER_AUTH: 'PLATFORM_USER_AUTH',
DELETE_PLATFORM_EXPORT_EXISTING: 'DELETE_PLATFORM_EXPORT_EXISTING',
GET_PLATFORM_EXPORT_EXISTING: 'GET_PLATFORM_EXPORT_EXISTING',
Expand Down
19 changes: 0 additions & 19 deletions src/services/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ Emulated service calls for platform globals.
* [PlatformServices](#Platform.module_PlatformServices)
* [~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>
* [~deleteExport(id, options)](#Platform.module_PlatformServices..deleteExport) ⇒ <code>Promise.&lt;\*&gt;</code>
* [~getExistingExportsStatus(id, params, options)](#Platform.module_PlatformServices..getExistingExportsStatus) ⇒ <code>Promise.&lt;\*&gt;</code>
* [~getExport(id, options)](#Platform.module_PlatformServices..getExport) ⇒ <code>Promise.&lt;\*&gt;</code>
Expand Down Expand Up @@ -470,24 +469,6 @@ Basic user permissions.
</tr> </tbody>
</table>

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

### PlatformServices~hideGlobalFilter(isHidden) ⇒ <code>Promise.&lt;\*&gt;</code>
Disables the Platform's global filter display.

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

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

### PlatformServices~deleteExport(id, options) ⇒ <code>Promise.&lt;\*&gt;</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exports[`PlatformServices should export a specific properties, methods and clas
"getExport": [Function],
"getUser": [Function],
"getUserPermissions": [Function],
"hideGlobalFilter": [Function],
"postExport": [Function],
}
`;
Expand All @@ -31,8 +30,6 @@ exports[`PlatformServices should return a failed getUserPermissions: failed user
}
`;

exports[`PlatformServices should return a failed hideGlobalFilter: failed hideGlobalFilter 1`] = `[Error: { on } = insights.chrome, insights.chrome.hideGlobalFilter is not a function]`;

exports[`PlatformServices should return a successful getUser with a specific response: specific success for authorized user 1`] = `
{
"data": {
Expand Down
7 changes: 0 additions & 7 deletions src/services/platform/__tests__/platformServices.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,4 @@ describe('PlatformServices', () => {

expect({ status, statusText, data, message }).toMatchSnapshot('failed user permissions');
});

it('should return a failed hideGlobalFilter', async () => {
window.insights.chrome.hideGlobalFilter = undefined;
const response = await returnPromiseAsync(platformServices.hideGlobalFilter);

expect(response).toMatchSnapshot('failed hideGlobalFilter');
});
});
17 changes: 0 additions & 17 deletions src/services/platform/platformServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,6 @@ const getUserPermissions = (appName = Object.keys(rbacConfig), options = {}) =>
});
};

/**
* Disables the Platform's global filter display.
*
* @param {boolean} isHidden
* @returns {Promise<*>}
*/
const hideGlobalFilter = async (isHidden = true) => {
const { insights } = window;
try {
await insights.chrome.hideGlobalFilter(isHidden);
} catch (e) {
throw new Error(`{ on } = insights.chrome, ${e.message}`);
}
};

/**
* @apiMock {ForceStatus} 202
* @api {delete} /api/export/v1/exports/:id
Expand Down Expand Up @@ -545,7 +530,6 @@ const platformServices = {
getExport,
getUser,
getUserPermissions,
hideGlobalFilter,
postExport
};

Expand All @@ -563,6 +547,5 @@ export {
getExport,
getUser,
getUserPermissions,
hideGlobalFilter,
postExport
};

0 comments on commit 288ce86

Please sign in to comment.