Skip to content

Commit

Permalink
always show "create from scratch" button in "from url modal" (#4662)
Browse files Browse the repository at this point in the history
Co-authored-by: Dong Lei <donglei@microsoft.com>
  • Loading branch information
zhixzhan and boydc2014 authored Nov 4, 2020
1 parent 22882eb commit 365d837
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { fireEvent } from '@botframework-composer/test-utils';

import { renderWithRecoil } from '../testUtils/renderWithRecoil';
import CreateQnAFromUrlModal from '../../src/components/QnA/CreateQnAFromUrlModal';
import { showCreateQnAFromUrlDialogState, showCreateQnAFromUrlDialogWithScratchState } from '../../src/recoilModel';
import { showCreateQnAFromUrlDialogState } from '../../src/recoilModel';

describe('<CreateQnAFromUrlModal />', () => {
const onDismiss = jest.fn(() => {});
Expand All @@ -24,7 +24,6 @@ describe('<CreateQnAFromUrlModal />', () => {
/>,
({ set }) => {
set(showCreateQnAFromUrlDialogState(projectId), true);
set(showCreateQnAFromUrlDialogWithScratchState(projectId), true);
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import { PrimaryButton, DefaultButton } from 'office-ui-fabric-react/lib/Button'
import { Link } from 'office-ui-fabric-react/lib/Link';

import { FieldConfig, useForm } from '../../hooks/useForm';
import {
dispatcherState,
onCreateQnAFromUrlDialogCompleteState,
showCreateQnAFromUrlDialogWithScratchState,
} from '../../recoilModel';
import { dispatcherState, onCreateQnAFromUrlDialogCompleteState } from '../../recoilModel';

import {
knowledgeBaseSourceUrl,
Expand Down Expand Up @@ -67,7 +63,6 @@ export const CreateQnAFromUrlModal: React.FC<CreateQnAFromModalProps> = (props)
const { onDismiss, onSubmit, dialogId, projectId, qnaFiles } = props;
const actions = useRecoilValue(dispatcherState);
const onComplete = useRecoilValue(onCreateQnAFromUrlDialogCompleteState(projectId));
const showWithScratch = useRecoilValue(showCreateQnAFromUrlDialogWithScratchState(projectId));

formConfig.name.validate = validateName(qnaFiles);
const { formData, updateField, hasErrors, formErrors } = useForm(formConfig);
Expand Down Expand Up @@ -123,17 +118,15 @@ export const CreateQnAFromUrlModal: React.FC<CreateQnAFromModalProps> = (props)
</Stack>
</div>
<DialogFooter>
{showWithScratch && (
<DefaultButton
data-testid={'createKnowledgeBaseFromScratch'}
styles={{ root: { float: 'left' } }}
text={formatMessage('Create knowledge base from scratch')}
onClick={() => {
// switch to create from scratch flow, pass onComplete callback.
actions.createQnAFromScratchDialogBegin({ projectId, onComplete: onComplete?.func });
}}
/>
)}
<DefaultButton
data-testid={'createKnowledgeBaseFromScratch'}
styles={{ root: { float: 'left' } }}
text={formatMessage('Create knowledge base from scratch')}
onClick={() => {
// switch to create from scratch flow, pass onComplete callback.
actions.createQnAFromScratchDialogBegin({ projectId, onComplete: onComplete?.func });
}}
/>
<DefaultButton
text={formatMessage('Cancel')}
onClick={() => {
Expand Down
1 change: 0 additions & 1 deletion Composer/packages/client/src/pages/design/DesignPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ const DesignPage: React.FC<RouteComponentProps<{ dialogId: string; projectId: st
onClick: () => {
createQnAFromUrlDialogBegin({
projectId,
showFromScratch: true,
});
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const QnAPage: React.FC<QnAPageProps> = (props) => {
key: 'Create KB from URL or file',
onClick: () => {
setCreateOnDialogId(dialog.id);
actions.createQnAFromUrlDialogBegin({ projectId, showFromScratch: false });
actions.createQnAFromUrlDialogBegin({ projectId });
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ const TableView: React.FC<TableViewProps> = (props) => {
data-testid={'createKnowledgeBase'}
text={formatMessage('Create new KB')}
onClick={() => {
actions.createQnAFromUrlDialogBegin({ projectId, showFromScratch: true });
actions.createQnAFromUrlDialogBegin({ projectId });
}}
/>
</div>
Expand Down
5 changes: 0 additions & 5 deletions Composer/packages/client/src/recoilModel/atoms/botState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,6 @@ export const showCreateQnAFromUrlDialogState = atomFamily<boolean, string>({
default: false,
});

export const showCreateQnAFromUrlDialogWithScratchState = atomFamily<boolean, string>({
key: getFullyQualifiedKey('showCreateQnAFromUrlDialogWithScratch'),
default: false,
});

export const showCreateQnAFromScratchDialogState = atomFamily<boolean, string>({
key: getFullyQualifiedKey('showCreateQnAFromScratchDialog'),
default: false,
Expand Down
8 changes: 0 additions & 8 deletions Composer/packages/client/src/recoilModel/dispatchers/qna.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
settingsState,
showCreateQnAFromScratchDialogState,
showCreateQnAFromUrlDialogState,
showCreateQnAFromUrlDialogWithScratchState,
onCreateQnAFromScratchDialogCompleteState,
onCreateQnAFromUrlDialogCompleteState,
} from '../atoms/botState';
Expand Down Expand Up @@ -203,18 +202,11 @@ export const qnaDispatcher = () => {
({ set }: CallbackInterface) => async ({
onComplete,
projectId,
showFromScratch,
}: {
onComplete?: () => void;
showFromScratch: boolean;
projectId: string;
}) => {
set(showCreateQnAFromUrlDialogState(projectId), true);
if (showFromScratch) {
set(showCreateQnAFromUrlDialogWithScratchState(projectId), true);
} else {
set(showCreateQnAFromUrlDialogWithScratchState(projectId), false);
}
set(onCreateQnAFromUrlDialogCompleteState(projectId), { func: onComplete });
}
);
Expand Down

0 comments on commit 365d837

Please sign in to comment.