Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlong9278 committed Apr 29, 2021
1 parent 6f9267a commit 86f8d05
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import { actionButton } from './styles';

type CreatePublishProfileDialogProps = {
projectId: string;
setIsCreateProfileFromSkill: (isCreateProfileFromSkill: boolean) => void;
OnUpdateIsCreateProfileFromSkill: (isCreateProfileFromSkill: boolean) => void;
};

export const CreatePublishProfileDialog: React.FC<CreatePublishProfileDialogProps> = (props) => {
const { projectId, setIsCreateProfileFromSkill } = props;
const { projectId, OnUpdateIsCreateProfileFromSkill } = props;
const { publishTargets } = useRecoilValue(settingsState(projectId));
const { getPublishTargetTypes, setPublishTargets } = useRecoilValue(dispatcherState);
const publishTypes = useRecoilValue(publishTypesState(projectId));
Expand Down Expand Up @@ -100,7 +100,7 @@ export const CreatePublishProfileDialog: React.FC<CreatePublishProfileDialogProp
}}
current={currentPublishProfile}
projectId={projectId}
setIsCreateProfileFromSkill={setIsCreateProfileFromSkill}
OnUpdateIsCreateProfileFromSkill={OnUpdateIsCreateProfileFromSkill}
setPublishTargets={setPublishTargets}
targets={publishTargets || []}
types={publishTypes}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type PublishProfileDialogProps = {
types: PublishType[];
projectId: string;
setPublishTargets: (targets: PublishTarget[], projectId: string) => Promise<void>;
setIsCreateProfileFromSkill?: (isCreateProfileFromSkill: boolean) => void;
OnUpdateIsCreateProfileFromSkill?: (isCreateProfileFromSkill: boolean) => void;
};

const Page = {
Expand All @@ -39,7 +39,15 @@ const Page = {
};

export const PublishProfileDialog: React.FC<PublishProfileDialogProps> = (props) => {
const { current, types, projectId, closeDialog, targets, setPublishTargets, setIsCreateProfileFromSkill } = props;
const {
current,
types,
projectId,
closeDialog,
targets,
setPublishTargets,
OnUpdateIsCreateProfileFromSkill,
} = props;
const [name, setName] = useState(current?.item.name || '');
const [targetType, setTargetType] = useState<string>(current?.item.type || '');

Expand Down Expand Up @@ -196,7 +204,7 @@ export const PublishProfileDialog: React.FC<PublishProfileDialogProps> = (props)
graph = getTokenFromCache('graphToken');
}
await provisionToTarget(fullConfig, config.type, projectId, arm, graph, current?.item);
setIsCreateProfileFromSkill?.(true);
OnUpdateIsCreateProfileFromSkill?.(true);
};
}, [name, targetType, types, savePublishTarget]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export interface ContentProps {
setSelectedDialogs: (dialogs: any[]) => void;
setSelectedTriggers: (selectedTriggers: any[]) => void;
setSkillManifest: (_: Partial<SkillManifestFile>) => void;
setIsCreateProfileFromSkill: (isCreateProfileFromSkill: boolean) => void;
OnUpdateIsCreateProfileFromSkill: (isCreateProfileFromSkill: boolean) => void;
schema: JSONSchema7;
selectedDialogs: any[];
selectedTriggers: any[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const SelectProfile: React.FC<ContentProps> = ({
value,
onChange,
projectId,
setIsCreateProfileFromSkill,
OnUpdateIsCreateProfileFromSkill,
}) => {
const [publishingTargets, setPublishingTargets] = useState<PublishTarget[]>([]);
const [currentTarget, setCurrentTarget] = useState<PublishTarget>();
Expand Down Expand Up @@ -210,8 +210,8 @@ export const SelectProfile: React.FC<ContentProps> = ({
<div>
<CreatePublishProfileDialog
projectId={projectId}
setIsCreateProfileFromSkill={setIsCreateProfileFromSkill}
></CreatePublishProfileDialog>
OnUpdateIsCreateProfileFromSkill={OnUpdateIsCreateProfileFromSkill}
/>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ import { getTokenFromCache } from '../../../utils/auth';
import { ApiStatus, PublishStatusPollingUpdater } from '../../../utils/publishStatusPollingUpdater';
import {
getSkillPublishedNotificationCardProps,
getSkilPendingNotificationCardProps,
getSkillPendingNotificationCardProps,
} from '../../publish/Notifications';
import { createNotification } from '../../../recoilModel/dispatchers/notification';

import { editorSteps, ManifestEditorSteps, order } from './constants';
import { generateSkillManifest } from './generateSkillManifest';
import { styles } from './styles';
import { getManifestUrl } from '../../../utils/skillManifestUtil';

interface ExportSkillModalProps {
isOpen: boolean;
Expand Down Expand Up @@ -90,66 +91,73 @@ const ExportSkillModal: React.FC<ExportSkillModalProps> = ({ onSubmit, onDismiss
);

const [isCreateProfileFromSkill, setIsCreateProfileFromSkill] = useState(false);
let publishUpdater: PublishStatusPollingUpdater;
let publishUpdaterRef = useRef<PublishStatusPollingUpdater>();
const publishNotificationRef = useRef<Notification>();
// stop polling updater & delete pending notification
const stopUpdater = async (updater) => {
updater.stop();
const stopUpdater = () => {
publishUpdaterRef.current && publishUpdaterRef.current.stop();
publishUpdaterRef.current = undefined;

handleDismiss();
setIsHidden(false);
};

const deleteNotificationCard = async () => {
const notification = publishNotificationRef.current;
notification && (await deleteNotification(notification.id));
publishNotificationRef.current = undefined;
handleDismiss();
setIsHidden(false);
};
const changeNotificationStatus = async (data) => {
const { apiResponse } = data;
if (!apiResponse) {
stopUpdater(publishUpdater);
stopUpdater();
deleteNotificationCard();
return;
}
const responseData = apiResponse.data;

if (responseData.status !== ApiStatus.Publishing) {
// Show result notifications
const displayedNotification = publishNotificationRef.current;
if (displayedNotification) {
const publishUpdater = publishUpdaterRef.current;
if (displayedNotification && publishUpdater) {
const currentTarget = publishTargets?.find((target) => target.name === publishUpdater.getPublishTargetName());
const url = currentTarget
? `https://${JSON.parse(currentTarget.configuration).hostname}.azurewebsites.net/manifests/${
skillManifest.id
}.json`
? getManifestUrl(JSON.parse(currentTarget.configuration).hostname, skillManifest)
: '';
const notificationCard = getSkillPublishedNotificationCardProps({ ...responseData }, url);
updateNotification(displayedNotification.id, notificationCard);
}
stopUpdater(publishUpdater);
navigate(`bot/${projectId}/publish/all`);
stopUpdater();
}
};

useEffect(() => {
const publish = async () => {
if (!publishTargets || publishTargets.length === 0) return;
const currentTarget = publishTargets.find((item) => {
const config = JSON.parse(item.configuration);
return (
config.settings &&
config.settings.MicrosoftAppId &&
config.hostname &&
config.settings.MicrosoftAppId.length > 0 &&
config.hostname.length > 0
);
});
if (isCreateProfileFromSkill && currentTarget) {
const skillPublishPenddingNotificationCard = getSkilPendingNotificationCardProps();
publishNotificationRef.current = createNotification(skillPublishPenddingNotificationCard);
addNotification(publishNotificationRef.current);
const sensitiveSettings = getSensitiveProperties(settings);
const token = getTokenFromCache('accessToken');
await publishToTarget(projectId, currentTarget, { comment: '' }, sensitiveSettings, token);
publishUpdater = new PublishStatusPollingUpdater(projectId, currentTarget.name);
publishUpdater.start(changeNotificationStatus);
try {
if (!publishTargets || publishTargets.length === 0) return;
const currentTarget = publishTargets.find((item) => {
const config = JSON.parse(item.configuration);
return (
config.settings &&
config.settings.MicrosoftAppId &&
config.hostname &&
config.settings.MicrosoftAppId.length > 0 &&
config.hostname.length > 0
);
});
if (isCreateProfileFromSkill && currentTarget) {
const skillPublishPenddingNotificationCard = getSkillPendingNotificationCardProps();
publishNotificationRef.current = createNotification(skillPublishPenddingNotificationCard);
addNotification(publishNotificationRef.current);
const sensitiveSettings = getSensitiveProperties(settings);
const token = getTokenFromCache('accessToken');
await publishToTarget(projectId, currentTarget, { comment: '' }, sensitiveSettings, token);
publishUpdaterRef.current = new PublishStatusPollingUpdater(projectId, currentTarget.name);
publishUpdaterRef.current.start(changeNotificationStatus);
}
} catch (e) {
console.log(e.message);
}
};
publish();
Expand All @@ -161,8 +169,11 @@ const ExportSkillModal: React.FC<ExportSkillModalProps> = ({ onSubmit, onDismiss
useEffect(() => {
// Clear intervals when unmount
return () => {
if (publishUpdater) {
stopUpdater(publishUpdater);
if (publishUpdaterRef.current) {
stopUpdater();
}
if (publishNotificationRef.current) {
deleteNotificationCard();
}
};
}, []);
Expand Down Expand Up @@ -299,7 +310,7 @@ const ExportSkillModal: React.FC<ExportSkillModalProps> = ({ onSubmit, onDismiss
selectedDialogs={selectedDialogs}
selectedTriggers={selectedTriggers}
setErrors={setErrors}
setIsCreateProfileFromSkill={setIsCreateProfileFromSkill}
OnUpdateIsCreateProfileFromSkill={setIsCreateProfileFromSkill}
setSchema={setSchema}
setSelectedDialogs={setSelectedDialogs}
setSelectedTriggers={setSelectedTriggers}
Expand Down
4 changes: 2 additions & 2 deletions Composer/packages/client/src/pages/publish/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const getPublishedNotificationCardProps = (item: BotStatus): CardProps =>
};

export const getSkillPublishedNotificationCardProps = (
item: { status: number; [key: string]: any },
item: { status: number } & Record<string, any>,
url?: string
): CardProps => {
const skillCardContent = css`
Expand Down Expand Up @@ -188,7 +188,7 @@ export const getPendingNotificationCardProps = (items: BotStatus[], isSkill = fa
};
};

export const getSkilPendingNotificationCardProps = (): CardProps => {
export const getSkillPendingNotificationCardProps = (): CardProps => {
return {
title: '',
description: formatMessage('Publishing your skill...'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { PublishTarget, SkillManifestFile } from '@bfc/shared';

import { ApiStatus } from '../../utils/publishStatusPollingUpdater';
import { getManifestUrl } from '../../utils/skillManifestUtil';

import { Bot, BotStatus, BotPublishHistory, BotProjectType, BotPropertyType } from './type';

Expand Down Expand Up @@ -35,11 +36,9 @@ const findSkillManifestUrl = (skillManifests: SkillManifestFile[], hostname: str
const urls: string[] = [];
for (const skillManifest of skillManifests || []) {
for (const endpoint of skillManifest?.content?.endpoints || []) {
if (
endpoint?.msAppId === appId &&
!urls.includes(`https://${hostname}.azurewebsites.net/manifests/${skillManifest.id}.json`)
) {
urls.push(`https://${hostname}.azurewebsites.net/manifests/${skillManifest.id}.json`);
const url = getManifestUrl(hostname, skillManifest);
if (endpoint?.msAppId === appId && !urls.includes(url)) {
urls.push(url);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const DispatcherWrapper = ({ children }) => {
if (filePersistence.isErrorHandlerEmpty()) {
filePersistence.registerErrorHandler(setProjectError);
}
await filePersistence.notify(assets, previousAssets);
filePersistence.notify(assets, previousAssets);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const deleteNotificationInternal = ({ reset, set }: CallbackInterface, id
return notifications.filter((notification) => notification !== id);
});
};
export const updateNotificationInternal = ({ set }: CallbackInterface, id: string, newValue: CardProps) => {
set(notificationsState(id), { ...newValue, id: id });
export const updateNotificationInternal = ({ set }: CallbackInterface, id: string, newValue: Partial<CardProps>) => {
set(notificationsState(id), (current) => ({ ...current, ...newValue }));
// check if notification exist
set(notificationIdsState, (notificationIds) => {
if (notificationIds.some((notificationId) => notificationId === id)) {
Expand Down Expand Up @@ -54,7 +54,7 @@ export const notificationDispatcher = () => {
});

const updateNotification = useRecoilCallback(
(callbackHelper: CallbackInterface) => (id: string, newValue: CardProps) => {
(callbackHelper: CallbackInterface) => (id: string, newValue: Partial<CardProps>) => {
updateNotificationInternal(callbackHelper, id, newValue);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const provisionDispatcher = () => {
});

// update publishTargets
await callbackHelpers.set(settingsState(projectId), (settings) => {
callbackHelpers.set(settingsState(projectId), (settings) => {
const profile = {
configuration: JSON.stringify(response.data.config, null, 2),
name: targetName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ export const publisherDispatcher = () => {
const qnaFiles = await snapshot.getPromise(qnaFilesSelectorFamily(projectId));
const referredLuFiles = luUtil.checkLuisBuild(luFiles, dialogs);
const referredQnaFiles = qnaUtil.checkQnaBuild(qnaFiles, dialogs);
const filePersistence = await snapshot.getPromise(filePersistenceState(projectId));
await filePersistence.flush();
const response = await httpClient.post(`/publish/${projectId}/publish/${target.name}`, {
publishTarget: target,
accessToken: token,
Expand All @@ -193,7 +191,7 @@ export const publisherDispatcher = () => {
// add job id to storage
const publishJobIds = publishStorage.get('jobIds') || {};
publishJobIds[`${projectId}-${target.name}`] = response.data.id;
await publishStorage.set('jobIds', publishJobIds);
publishStorage.set('jobIds', publishJobIds);

await publishSuccess(callbackHelpers, projectId, response.data, target);
} catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/client/src/utils/skillManifestUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const getManifestUrl = (hostname, skillManifest) =>
`https://${hostname}.azurewebsites.net/manifests/${skillManifest.id}.json`;
12 changes: 4 additions & 8 deletions Composer/packages/server/src/controllers/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ export const PublishController = {
const allTargets = [defaultPublishConfig, ...publishTargets];

const profiles = allTargets.filter((t) => t.name === target);
let profile: PublishTarget;
if (profiles.length === 0) {
let profile: PublishTarget = profiles[0];
if (!profile) {
profile = publishTarget;
currentProject.settings?.publishTargets && currentProject.settings?.publishTargets.push(publishTarget);
} else {
profile = profiles[0];
}
const extensionName = profile ? profile.type : ''; // get the publish plugin key

Expand Down Expand Up @@ -151,12 +149,10 @@ export const PublishController = {
const allTargets = [defaultPublishConfig, ...publishTargets];

const profiles = allTargets.filter((t) => t.name === target);
let profile: PublishTarget;
if (profiles.length === 0) {
let profile: PublishTarget = profiles[0];
if (!profile) {
profile = currentPublishTarget;
currentProject.settings?.publishTargets && currentProject.settings?.publishTargets.push(currentPublishTarget);
} else {
profile = profiles[0];
}
// get the publish plugin key
const extensionName = profile ? profile.type : '';
Expand Down

0 comments on commit 86f8d05

Please sign in to comment.