Skip to content

Commit

Permalink
migrate components with MessageBar and type
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnickii committed Dec 4, 2024
1 parent 1f9d50a commit 87a0e4a
Show file tree
Hide file tree
Showing 22 changed files with 222 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Query Action Creators', () => {
ok: false,
statusText: 'Something worked!',
status: 200,
messageType: 1,
messageBarType: 'success',
hint: 'Something worked!'
}

Expand Down
14 changes: 7 additions & 7 deletions src/app/services/actions/revoke-scopes.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const revokeScopes = createAsyncThunk(
const requiredPermissions = REVOKING_PERMISSIONS_REQUIRED_SCOPES.split(' ');
const defaultUserScopes = DEFAULT_USER_SCOPES.split(' ');

dispatchScopesStatus(dispatch, 'Please wait while we revoke this permission', 'Revoking ', 0);
dispatchScopesStatus(dispatch, 'Please wait while we revoke this permission', 'Revoking ', 'info');
const revokePermissionUtil = await RevokePermissionsUtil.initialize(profile.user!.id!);

if (!consentedScopes || consentedScopes.length === 0) {
Expand Down Expand Up @@ -62,7 +62,7 @@ export const revokeScopes = createAsyncThunk(
const updatedScopes = await updatePermissions(permissionsUpdateObject);

if (updatedScopes) {
dispatchScopesStatus(dispatch, 'Permission revoked', 'Success', 4);
dispatchScopesStatus(dispatch, 'Permission revoked', 'Success', 'success');
dispatch(getConsentedScopesSuccess(updatedScopes));
trackRevokeConsentEvent(REVOKE_STATUS.success, permissionToRevoke);
return updatedScopes;
Expand All @@ -77,7 +77,7 @@ export const revokeScopes = createAsyncThunk(
} catch (errorMessage: any) {
if (errorMessage instanceof RevokeScopesError) {
const { errorText, statusText, status, messageType } = errorMessage;
dispatchScopesStatus(dispatch, statusText, status, messageType);
dispatchScopesStatus(dispatch, statusText, status, 'error');
const permissionObject = {
permissionToRevoke,
statusCode: statusText,
Expand All @@ -88,20 +88,20 @@ export const revokeScopes = createAsyncThunk(
} else {
const { code, message } = errorMessage;
trackRevokeConsentEvent(REVOKE_STATUS.failure, 'Failed to revoke consent');
dispatchScopesStatus(dispatch, message ? message : 'Failed to revoke consent', code ? code : 'Failed', 1);
dispatchScopesStatus(dispatch, message ? message : 'Failed to revoke consent', code ? code : 'Failed', 'error');
return rejectWithValue(errorMessage);
}
}
}
);

const dispatchScopesStatus = (dispatch: Function, statusText: string, status: string, messageType: number) => {
const dispatchScopesStatus = (dispatch: Function, statusText: string, status: string, messageBarType: string) => {
dispatch(
setQueryResponseStatus({
statusText: translateMessage(status),
status: translateMessage(statusText),
ok: false,
messageType
messageBarType
})
)
}
Expand Down Expand Up @@ -135,7 +135,7 @@ async function updatePermissions(permissionsUpdateObject: IPermissionUpdate): Pr
}
else if ((retryCount < maxRetryCount) && !isRevokeSuccessful) {
await new Promise(resolve => setTimeout(resolve, retryDelay * 2));
dispatchScopesStatus(dispatch, 'We are retrying the revoking operation', 'Retrying', 5);
dispatchScopesStatus(dispatch, 'We are retrying the revoking operation', 'Retrying', 'info');

permissionsUpdateObject.retryCount += 1;
return updatePermissions(permissionsUpdateObject);
Expand Down
6 changes: 3 additions & 3 deletions src/app/services/slices/auth.slice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BrowserAuthError } from '@azure/msal-browser';
import { MessageBarType } from '@fluentui/react';

import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit';

import { authenticationWrapper } from '../../../modules/authentication';
Expand Down Expand Up @@ -112,7 +112,7 @@ export const consentToScopes = createAsyncThunk(
statusText: translateMessage('Success'),
status: translateMessage('Scope consent successful'),
ok: true,
messageType: MessageBarType.success
messageBarType: 'success'
})
);
dispatch(fetchAllPrincipalGrants());
Expand All @@ -125,7 +125,7 @@ export const consentToScopes = createAsyncThunk(
statusText: translateMessage('Scope consent failed'),
status: errorCode,
ok: false,
messageType: MessageBarType.error,
messageBarType: 'error',
hint: getConsentAuthErrorHint(errorCode)
})
);
Expand Down
8 changes: 4 additions & 4 deletions src/app/services/slices/graph-response.slice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BrowserAuthError } from '@azure/msal-browser';
import { MessageBarType } from '@fluentui/react';

import { createAsyncThunk, createSlice, PayloadAction } from '@reduxjs/toolkit';

import { authenticationWrapper } from '../../../modules/authentication';
Expand Down Expand Up @@ -156,7 +156,7 @@ async function processResponse(response: Response, respHeaders: { [key: string]:

const generateStatus = ({ duration, response }: { duration: number; response: Response }): IStatus => {
const status: IStatus = {
messageType: MessageBarType.error,
messageBarType: 'error',
ok: false,
duration,
status: response.status || 400,
Expand All @@ -171,7 +171,7 @@ const generateStatus = ({ duration, response }: { duration: number; response: Re
if (response && response.ok) {
CURRENT_RETRIES = 0;
status.ok = true;
status.messageType = MessageBarType.success;
status.messageBarType = 'success';
}
return status;
}
Expand Down Expand Up @@ -232,7 +232,7 @@ function generateHistoryItem(
async function handleError(error: Error, query: IQuery) {
let body = null;
const status: IStatus = {
messageType: MessageBarType.error,
messageBarType: 'error',
ok: false,
status: 400,
statusText: 'Bad Request'
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/slices/permission-grants.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const fetchAllPrincipalGrants = createAsyncThunk(
statusText: translateMessage('Permissions'),
status: translateMessage('You require the following permissions to read'),
ok: false,
messageType: 0
messageBarType: 'error'
}));
throw new Error('Permission required');
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/views/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import { toggleSidebar } from '../services/slices/sidebar-properties.slice';
import { changeTheme } from '../services/slices/theme.slice';
import { parseSampleUrl } from '../utils/sample-url-generation';
import { substituteTokens } from '../utils/token-helpers';
import { TermsOfUseMessage } from './app-sections';
import { headerMessaging } from './app-sections/HeaderMessaging';
import { TermsOfUseMessageV9 } from './app-sections';
import { headerMessagingV9 } from './app-sections/HeaderMessagingV9';
import { appStyles } from './App.styles';
import { classNames } from './classnames';
import { KeyboardCopyEvent } from './common/copy-button/KeyboardCopyEvent';
Expand Down Expand Up @@ -466,7 +466,7 @@ class App extends Component<IAppProps, IAppState> {
</Resizable>
)}
{graphExplorerMode === Mode.TryIt &&
headerMessaging(query)}
headerMessagingV9(query)}

{displayContent && (
<Resizable
Expand Down Expand Up @@ -502,7 +502,7 @@ class App extends Component<IAppProps, IAppState> {
)}
</div>
<div style={mobileScreen ? this.statusAreaMobileStyle : this.statusAreaFullScreenStyle}>
<TermsOfUseMessage />
<TermsOfUseMessageV9 />
</div>
</div>
<PopupsWrapper />
Expand Down
49 changes: 49 additions & 0 deletions src/app/views/app-sections/HeaderMessagingV9.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Link, MessageBar, MessageBarBody, makeStyles} from '@fluentui/react-components';

import { getLoginType } from '../../../modules/authentication/authUtils';
import { LoginType } from '../../../types/enums';
import { translateMessage } from '../../utils/translate-messages';

const useHeaderStyles = makeStyles({
root: {
marginBottom: '8',
paddingLeft: '10'
}
});

export const headerMessagingV9 = (query: string): React.ReactNode => {
const loginType = getLoginType();
const headerStyles = useHeaderStyles();

return (
<div className={headerStyles.root}>
{loginType === LoginType.Popup &&
<MessageBar intent={'info'}>
<MessageBarBody>
{translateMessage('To try the full features')},
<Link
tabIndex={0}
inline
href={query}
target='_blank' rel='noopener noreferrer'>
{translateMessage('full Graph Explorer')}.
</Link>
{translateMessage('running the query')}.
</MessageBarBody>
</MessageBar>
}
{loginType === LoginType.Redirect && <MessageBar intent={'warning'}>
<MessageBarBody>
{translateMessage('To try operations other than GET')},
<Link
tabIndex={0}
href={query}
target='_blank'
rel='noopener noreferrer'
inline>
{translateMessage('sign in')}.
</Link>
</MessageBarBody>
</MessageBar>}
</div>);
}
6 changes: 3 additions & 3 deletions src/app/views/app-sections/StatusMessages.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageBar } from '@fluentui/react';
import { MessageBar, MessageBarType } from '@fluentui/react';

import { useAppDispatch, useAppSelector } from '../../../store';
import { IQuery } from '../../../types/query-runner';
Expand All @@ -21,9 +21,9 @@ const StatusMessages = () => {
}

if (queryRunnerStatus) {
const { messageType, statusText, status, duration, hint } = queryRunnerStatus;
const { statusText, status, duration, hint } = queryRunnerStatus;

return <MessageBar messageBarType={messageType}
return <MessageBar messageBarType={MessageBarType.info}
isMultiline={true}
onDismiss={() => dispatch(clearQueryStatus())}
dismissButtonAriaLabel='Close'
Expand Down
67 changes: 67 additions & 0 deletions src/app/views/app-sections/StatusMessagesV9.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { MessageBar, MessageBarBody, MessageBarActions, MessageBarIntent, Button } from '@fluentui/react-components';
import { DismissRegular } from '@fluentui/react-icons';
import { useAppDispatch, useAppSelector } from '../../../store';
import { IQuery } from '../../../types/query-runner';
import { clearQueryStatus } from '../../services/slices/query-status.slice';
import { setSampleQuery } from '../../services/slices/sample-query.slice';
import { translateMessage } from '../../utils/translate-messages';
import MessageDisplay from '../common/message-display/MessageDisplay';

const intentMap: { [key: string]: MessageBarIntent } = {
'info': 'info',
'error': 'error',
'warning': 'warning',
'success': 'success'
};

const StatusMessagesV9 = () => {
const dispatch = useAppDispatch();
const queryRunnerStatus = useAppSelector((state)=> state.queryRunnerStatus);
const sampleQuery = useAppSelector((state)=> state.sampleQuery);

function setQuery(link: string) {
const query: IQuery = { ...sampleQuery };
link = link.replace(/\.$/, '');
query.sampleUrl = link;
query.selectedVerb = 'GET';
dispatch(setSampleQuery(query));
}

if (queryRunnerStatus) {
const { messageBarType, statusText, status, duration, hint } = queryRunnerStatus; return <MessageBar
intent={intentMap[messageBarType]}
politeness='assertive'
>
<MessageBarBody>
<MessageDisplay message={`**${statusText} - **${status.toString()}`} onSetQuery={setQuery} />

{duration && <>
{` - ${duration} ${translateMessage('milliseconds')}`}
</>}

{status === 403 && <>
{translateMessage('consent to scopes')}
<span style={{ fontWeight: 600 }}>
{translateMessage('modify permissions')}
</span>
{translateMessage('tab')}
</>}

{hint && <div>{hint}</div>}
</MessageBarBody>
<MessageBarActions
containerAction={
<Button
onClick={() => dispatch(clearQueryStatus())}
aria-label="dismiss"
appearance="transparent"
icon={<DismissRegular />}
/>
}
/>
</MessageBar>;
}
return <div />;
}

export default StatusMessagesV9;
63 changes: 63 additions & 0 deletions src/app/views/app-sections/TermsOfUseMessageV9.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Link, makeStyles, Button, MessageBar, MessageBarActions, MessageBarBody } from '@fluentui/react-components';
import { DismissRegular } from '@fluentui/react-icons';
import { geLocale } from '../../../appLocale';
import { useAppDispatch, useAppSelector } from '../../../store';
import { componentNames, telemetry } from '../../../telemetry';
import { clearTermsOfUse } from '../../services/slices/terms-of-use.slice';
import { translateMessage } from '../../utils/translate-messages';

const useTermsStyles = makeStyles({
root: {
position: 'relative'
}
});

const TermsOfUseMessageV9 = () => {

const termsOfUse = useAppSelector((state) => state.termsOfUse);
const termsStyles = useTermsStyles();

const dispatch = useAppDispatch();
if (termsOfUse) {
return <MessageBar intent={'info'}
className={termsStyles.root}>
<MessageBarBody>
{translateMessage('use the Microsoft Graph API')}
<Link
onClick={(e) =>
telemetry.trackLinkClickEvent((e.currentTarget as HTMLAnchorElement).href,
componentNames.MICROSOFT_APIS_TERMS_OF_USE_LINK)}
href={'https://learn.microsoft.com/' + geLocale +
'/legal/microsoft-apis/terms-of-use?context=graph/context'}
target='_blank'
rel='noopener noreferrer'
inline>
{translateMessage('Terms of use')}
</Link>.
{translateMessage('View the')}
<Link
onClick={(e) =>
telemetry.trackLinkClickEvent((e.currentTarget as HTMLAnchorElement).href,
componentNames.MICROSOFT_PRIVACY_STATEMENT_LINK)}
href={'https://privacy.microsoft.com/' + geLocale + '/privacystatement'}
target='_blank'
rel='noopener noreferrer'
inline>
{translateMessage('Microsoft Privacy Statement')}</Link>.
</MessageBarBody>
<MessageBarActions
containerAction={
<Button
onClick={() => dispatch(clearTermsOfUse())}
aria-label="dismiss"
appearance="transparent"
icon={<DismissRegular />}
/>
}
/>
</MessageBar>;
}
return <div />;
}

export default TermsOfUseMessageV9;
8 changes: 4 additions & 4 deletions src/app/views/app-sections/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import StatusMessages from './StatusMessages';
import TermsOfUseMessage from './TermsOfUseMessage';
import StatusMessagesV9 from './StatusMessagesV9';
import TermsOfUseMessageV9 from './TermsOfUseMessageV9';

export {
StatusMessages,
TermsOfUseMessage
StatusMessagesV9,
TermsOfUseMessageV9
};
2 changes: 1 addition & 1 deletion src/app/views/authentication/Authentication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const Authentication = (props: any) => {
ok: false,
statusText: translateMessage('Authentication failed'),
status: removeUnderScore(errorCode),
messageType: MessageBarType.error,
messageBarType: 'error',
hint: getSignInAuthErrorHint(errorCode)
})
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/authentication/AuthenticationV9.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const Authentication = (props: any) => {
ok: false,
statusText: translateMessage('Authentication failed'),
status: removeUnderScore(errorCode),
messageType: MessageBarType.error,
messageBarType: 'error',
hint: getSignInAuthErrorHint(errorCode)
})
);
Expand Down
Loading

0 comments on commit 87a0e4a

Please sign in to comment.