-
Notifications
You must be signed in to change notification settings - Fork 377
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: Added copy from profile button and dialog #7465
Changes from 3 commits
34444c7
68d7319
65990eb
faba814
d4fa13a
3000054
f7b27e0
937e829
ef49a95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** @jsx jsx */ | ||
import React, { Fragment, useState, useEffect } from 'react'; | ||
import { jsx } from '@emotion/core'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { PublishTarget } from '@bfc/shared'; | ||
import formatMessage from 'format-message'; | ||
import { DefaultButton, PrimaryButton } from 'office-ui-fabric-react/lib/Button'; | ||
import Dialog, { DialogFooter } from 'office-ui-fabric-react/lib/Dialog'; | ||
import { Dropdown, IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown'; | ||
|
||
import { settingsState } from '../../recoilModel/atoms/botState'; | ||
|
||
type AppInfo = { | ||
appId: string; | ||
appPassword?: string; | ||
}; | ||
|
||
type Props = { | ||
projectId: string; | ||
hidden?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is it? Do you mean should hidden be required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the dialog is rendered conditionally, controlling hidden from outside almost never happens, so it's not needed. |
||
onOK: (info: AppInfo) => void; | ||
onCancel: () => void; | ||
}; | ||
|
||
export const GetAppInfoFromPublishProfileDialog: React.FC<Props> = (props) => { | ||
const { projectId, hidden, onOK: onAdd, onCancel } = props; | ||
const { publishTargets } = useRecoilValue(settingsState(projectId)); | ||
const [publishTargetOptions, setPublishTargetOptions] = useState<IDropdownOption[]>([]); | ||
GeoffCoxMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const [publishTargetsErrorMessage, setPublishTargetsErrorMessage] = useState<string | undefined>(); | ||
const [selectedKey, setSelectedKey] = useState<string | number | undefined>(); | ||
|
||
const dialogTitle = { | ||
title: formatMessage('Add from publishing profile'), | ||
subText: formatMessage('Select the publishing profile you’d like to add a Microsoft App ID and Password from.'), | ||
}; | ||
|
||
const getAppInfo = (profile: PublishTarget) => { | ||
if (profile) { | ||
const config = JSON.parse(profile.configuration); | ||
GeoffCoxMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const appId = config?.settings?.MicrosoftAppId; | ||
const appPassword = config?.settings?.MicrosoftAppPassword; | ||
|
||
if (appId) { | ||
GeoffCoxMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return { appId, appPassword }; | ||
} | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
// reset the ui back to no selection | ||
setPublishTargetOptions([]); | ||
|
||
// generate options | ||
const options: IDropdownOption[] = | ||
publishTargets | ||
?.map((p) => { | ||
return { key: p.name, text: p.name, data: getAppInfo(p) }; | ||
}) | ||
.filter((p) => p.data !== undefined) || []; | ||
|
||
setPublishTargetOptions(options); | ||
}, [publishTargets, projectId]); | ||
GeoffCoxMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
useEffect(() => { | ||
if (publishTargetOptions.length === 0) { | ||
GeoffCoxMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
setPublishTargetsErrorMessage('No profiles were found containing a Microsoft App ID.'); | ||
} else { | ||
setPublishTargetsErrorMessage(undefined); | ||
} | ||
}, [publishTargetOptions]); | ||
|
||
const handleAdd = () => { | ||
const opt = publishTargetOptions?.find((p) => p.key === selectedKey); | ||
if (opt) { | ||
onAdd(opt.data); | ||
} | ||
}; | ||
|
||
return ( | ||
<Fragment> | ||
<Dialog | ||
dialogContentProps={{ | ||
title: dialogTitle.title, | ||
subText: dialogTitle.subText, | ||
}} | ||
hidden={hidden} | ||
minWidth={500} | ||
modalProps={{ | ||
isBlocking: true, | ||
}} | ||
onDismiss={onCancel} | ||
> | ||
<div css={{ height: '100px' }}> | ||
<Dropdown | ||
errorMessage={publishTargetsErrorMessage} | ||
options={publishTargetOptions} | ||
placeholder={formatMessage('Select publishing profile')} | ||
selectedKey={selectedKey} | ||
styles={{ | ||
root: { marginBottom: 10 }, | ||
dropdown: { width: 450 }, | ||
}} | ||
onChange={(_, opt) => { | ||
setSelectedKey(opt?.key); | ||
}} | ||
/> | ||
</div> | ||
<DialogFooter> | ||
<PrimaryButton | ||
disabled={!!publishTargetsErrorMessage || !selectedKey} | ||
text={formatMessage('Add App ID and Password')} | ||
onClick={handleAdd} | ||
/> | ||
<DefaultButton text={formatMessage('Cancel')} onClick={onCancel} /> | ||
</DialogFooter> | ||
</Dialog> | ||
</Fragment> | ||
GeoffCoxMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
}; | ||
|
||
//onChange={onSelectProfile} | ||
GeoffCoxMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//onRenderOption={renderDropdownOption} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use backtick ``
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For line continuation or for string templating? (formatMessage.rich can take a regular string). I moved it to be a single line.