Skip to content

Commit

Permalink
Merge pull request #217 from pnp/preview
Browse files Browse the repository at this point in the history
generator-teams@3.1.0
  • Loading branch information
wictorwilen authored May 21, 2021
2 parents f66e54e + 93bbee5 commit ce3af7a
Show file tree
Hide file tree
Showing 21 changed files with 3,465 additions and 14,678 deletions.
3 changes: 2 additions & 1 deletion packages/generator-teams/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ temp-templates
webpack.config.js
gulpfile.js
tsconfig.json
.travis.yml
.travis.yml
.editorconfig
14 changes: 13 additions & 1 deletion packages/generator-teams/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [*Unreleased*]- <**>
## [*3.1.0*]- <*2021-05-21*>

### Added

* Support for link unfurling (#200) - @PaoloPia
* Dedicated option for creating a static tab for Viva Connections (manifest schema 1.9 or later)

### Changes

* Microsoft Teams Schema 1.9 set as default schema

### Fixed

* Typo in question for bot (#191)
* Invalid messaging extension description (#192)
* Invalid condition in prompt for Bot Id (#193)
* Fixed state/closure issue on Connector configuration

> *Tests passing: 4.211*
## [*3.0.3*]- <*2021-03-02*>

Expand Down
1,709 changes: 647 additions & 1,062 deletions packages/generator-teams/package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions packages/generator-teams/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-teams",
"version": "3.0.3",
"version": "3.1.0",
"description": "Yeoman generator for Microsoft Teams Apps",
"main": "generators/app/index.js",
"scripts": {
Expand Down Expand Up @@ -34,7 +34,9 @@
"vscode",
"yo teams",
"pnp",
"teams toolkit"
"teams toolkit",
"microsoft viva",
"viva connections"
],
"author": "Wictor Wilén (wictor@wictorwilen.se)",
"maintainers": [
Expand Down Expand Up @@ -63,6 +65,7 @@
"@types/mocha": "^8.0.2",
"@types/npm-run": "^5.0.0",
"@types/semver": "^7.3.3",
"@types/tldjs": "^2.3.0",
"@types/uuid": "^8.3.0",
"@types/uuid-validate": "0.0.1",
"@types/yeoman-assert": "^3.1.1",
Expand Down Expand Up @@ -91,6 +94,7 @@
"dotenv": "^8.0.0",
"lodash": "^4.17.20",
"semver": "^7.3.2",
"tldjs": "^2.3.1",
"ts-morph": "^8.1.2",
"typescript": "^4.0.3",
"uuid": "^8.3.1",
Expand Down
4 changes: 3 additions & 1 deletion packages/generator-teams/src/app/GeneratorTeamsAppOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ export class GeneratorTeamsAppOptions {
tabSharePoint: boolean;
tabSharePointHosts: string[] = [];
tabScopes: string[];
tabType: "configurable" | "static";
tabType: "configurable" | "static" | "viva";
tabSSO: boolean;
tabSSOAppId: string;
tabSSOAppUri: string;
vivaUrl: string | undefined;

/* Bots */
botid: string = '';
Expand Down Expand Up @@ -90,6 +91,7 @@ export class GeneratorTeamsAppOptions {
messagingExtensionActionResponseType?: string;
messagingExtensionCanUpdateConfiguration: boolean = false;
messagingExtensionActionResponseTypeConfig: boolean = false;
messageExtensionLinkDomains?: string[] = undefined;
/* manifest */
existingManifest: any;
/* Localization */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export class ManifestGeneratorFactory {
manifestVersion: ManifestVersions.v18,
schemaUrl: "https://developer.microsoft.com/en-us/json-schemas/teams/v1.8/MicrosoftTeams.schema.json",
manifestValue: "1.8",
default: true,
default: false,
hide: false
},
{
manifestVersion: ManifestVersions.v19,
schemaUrl: "https://developer.microsoft.com/en-us/json-schemas/teams/v1.9/MicrosoftTeams.schema.json",
manifestValue: "1.9",
default: false,
hide: true
default: true,
hide: false
},
{
manifestVersion: ManifestVersions.devPreview,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export class MessageExtensionManifestUpdater implements IManifestUpdater {
manifest.composeExtensions = [];
}

let command: any = {
// In case of queryLink extension, we need an empty command, otherwise a real one
let command: any = options.messagingExtensionType !== "queryLink" ? {
id: options.messageExtensionName,
title: options.messageExtensionTitle,
description: options.messageExtensionDescription,
Expand All @@ -25,7 +26,7 @@ export class MessageExtensionManifestUpdater implements IManifestUpdater {
}
],
type: options.messagingExtensionType // required parameter in devPreview
};
} : undefined;

if (options.messagingExtensionType === "action") {
if (options.messagingExtensionActionContext) {
Expand All @@ -50,23 +51,44 @@ export class MessageExtensionManifestUpdater implements IManifestUpdater {
}
}

if (options.messagingExtensionType !== "queryLink") {

let composeExtension = manifest.composeExtensions.find((ce: { botId: string; }) => ce.botId == options.messageExtensionId);
if (options.existingManifest && composeExtension) {
if (options.messagingExtensionCanUpdateConfiguration) {
// if we have config for this one, it has to be positioned as the first one
composeExtension.commands.unshift(command);
composeExtension.canUpdateConfiguration = options.messagingExtensionCanUpdateConfiguration;
let composeExtension = manifest.composeExtensions.find((ce: { botId: string; }) => ce.botId == options.messageExtensionId);
if (options.existingManifest && composeExtension) {
if (options.messagingExtensionCanUpdateConfiguration) {
// if we have config for this one, it has to be positioned as the first one
composeExtension.commands.unshift(command);
composeExtension.canUpdateConfiguration = options.messagingExtensionCanUpdateConfiguration;
} else {
composeExtension.commands.push(command);
}
} else {
composeExtension.commands.push(command);
// no existing manifest
manifest.composeExtensions.push({
botId: options.messageExtensionId,
canUpdateConfiguration: options.messagingExtensionCanUpdateConfiguration,
commands: [command]
});
}

} else {
// no existing manifest
manifest.composeExtensions.push({
botId: options.messageExtensionId,
canUpdateConfiguration: options.messagingExtensionCanUpdateConfiguration,
commands: [command]
});

if (!options.existingManifest)
{
// no existing manifest
manifest.composeExtensions.push({
botId: options.messageExtensionId,
canUpdateConfiguration: options.messagingExtensionCanUpdateConfiguration,
commands: [],
messageHandlers: [{
type: "link",
value: {
domains: options.messageExtensionLinkDomains
}
}]
});
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT license.

import { BaseManifestGenerator } from "../../BaseManifestGenerator";
import { TabManifestUpdater } from "../generator18/TabManifestUpdater";
import { TabManifestUpdater } from "./TabManifestUpdater";
import { BotManifestUpdater } from "../generator18/BotManifestUpdater";
import { ConnectorManifestUpdater } from "../generator18/ConnectorManifestUpdater";
import { MessageExtensionManifestUpdater } from "../generator18/MessageExtensionManifestUpdater";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) Wictor Wilén. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import { IManifestUpdater } from "../../IManifestUpdater";
import { GeneratorTeamsAppOptions } from "../../../GeneratorTeamsAppOptions";
import { v4 as uuid } from 'uuid';
import { OFFICE_GUID } from "../../../../tab/TabGenerator";
import { parse } from "tldjs";

export class TabManifestUpdater implements IManifestUpdater {

public updateManifest(manifest: any, options: GeneratorTeamsAppOptions): void {
if (options.tabType == "static") {
(<any[]>manifest.staticTabs).push({
entityId: uuid(),
name: options.tabTitle,
contentUrl: `https://{{HOSTNAME}}/${options.tabName}/?name={loginHint}&tenant={tid}&theme={theme}`,
scopes: ["personal"]
});
}
else if (options.tabType == "configurable") {
const tab: any = {
configurationUrl: `https://{{HOSTNAME}}/${options.tabName}/config.html?name={loginHint}&tenant={tid}&group={groupId}&theme={theme}`,
canUpdateConfiguration: true,
scopes: options.tabScopes
};
if (options.tabSharePoint) {
tab.sharePointPreviewImage = `https://{{HOSTNAME}}/assets/${options.tabName}-preview.png`;
tab.supportedSharePointHosts = options.tabSharePointHosts;
}
(<any[]>manifest.configurableTabs).push(tab);
} else if (options.tabType == "viva") {
const tab: any = {
entityId: uuid(),
name: `Portals-${options.tabReactComponentName}`,
contentUrl: options.vivaUrl + "/_layouts/15/teamslogon.aspx?spfx=true&dest=" + options.vivaUrl + "?app=portals",
websiteUrl: options.vivaUrl,
searchUrl: options.vivaUrl + "/_layouts/15/search.aspx?q={searchQuery}",
scopes: [
"personal"
],
supportedPlatform: [
"desktop"
]
};
(<any[]>manifest.staticTabs).push(tab);

const domain = parse(options.vivaUrl as string);

manifest.webApplicationInfo = {
id: OFFICE_GUID,
resource: `https://${domain.hostname as string}`
};

manifest.validDomains.push(
domain.hostname as string,
"*.login.microsoftonline.com",
"*.sharepoint.com",
"*.sharepoint-df.com",
"spoppe-a.akamaihd.net",
"spoprod-a.akamaihd.net",
"resourceseng.blob.core.windows.net",
"msft.spoppe.com");
}
if (options.tabSSO && manifest.webApplicationInfo === undefined) {
// only add SSO the first time
manifest.webApplicationInfo = {
id: `{{${options.tabUpperName}_APP_ID}}`,
resource: `{{${options.tabUpperName}_APP_URI}}`
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT license.

import { BaseManifestGenerator } from "../../BaseManifestGenerator";
import { TabManifestUpdater } from "../generator18/TabManifestUpdater";
import { TabManifestUpdater } from "../generator19/TabManifestUpdater";
import { BotManifestUpdater } from "../generator18/BotManifestUpdater";
import { ConnectorManifestUpdater } from "../generator18/ConnectorManifestUpdater";
import { MessageExtensionManifestUpdater } from "../generator18/MessageExtensionManifestUpdater";
Expand Down
2 changes: 1 addition & 1 deletion packages/generator-teams/src/app/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"vinyl": "2.2.0",
"webpack": "5.0.0",
"yargs": "^16.0.3",
"yoteams-build-core": "^1.0.0",
"yoteams-build-core": "^1.1.0",
"webpack-node-externals": "^2.5.2"
},
"browserslist": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import { Provider, Flex, Header, Dropdown } from "@fluentui/react-northstar";
import { useState, useEffect } from "react";
import { Provider, Flex, Header, Dropdown, ShorthandCollection, DropdownItemProps } from "@fluentui/react-northstar";
import { useState, useEffect, useRef } from "react";
import { useTeams } from "msteams-react-base-component";
import * as microsoftTeams from "@microsoft/teams-js";

Expand All @@ -27,15 +27,17 @@ export const <%=connectorComponentName%>Config = () => {

const [{ theme, context }] = useTeams();
const [color, setColor] = useState<IColor>();
const colorRef = useRef(color);
colorRef.current = color;

useEffect(() => {
if (context) {
microsoftTeams.settings.registerOnSaveHandler((saveEvent: microsoftTeams.settings.SaveEvent) => {
// INFO: Should really be of type microsoftTeams.settings.Settings, but configName does not exist in the Teams JS SDK
const settings: any = {
entityId: color ? color.code : availableColors[0].code,
entityId: colorRef.current ? colorRef.current.code : availableColors[0].code,
contentUrl: `https://${process.env.HOSTNAME}/<%=connectorName%>/config.html?name={loginHint}&tenant={tid}&group={groupId}&theme={theme}`,
configName: color ? color.title : availableColors[0].title
configName: colorRef.current ? colorRef.current.title : availableColors[0].title
};
microsoftTeams.settings.setSettings(settings);

Expand All @@ -50,7 +52,7 @@ export const <%=connectorComponentName%>Config = () => {
user: setting.userObjectId,
appType: setting.appType,
groupName: context.groupId,
color: color ? color.code : availableColors[0].code,
color: colorRef.current ? colorRef.current.code : availableColors[0].code,
state: "myAppsState"
})
}).then(response => {
Expand All @@ -64,15 +66,23 @@ export const <%=connectorComponentName%>Config = () => {
});
});
});
setColor(availableColors.find(c => c.code === context.entityId));
microsoftTeams.settings.setValidityState(color !== undefined);

microsoftTeams.settings.getSettings((settings: any) => {
setColor(availableColors.find(c => c.code === settings.entityId));
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [context]);

const colors = availableColors.map(clr => {
useEffect(() => {
if (context) {
microsoftTeams.settings.setValidityState(color !== undefined);
}
}, [color, context]);

const colors: ShorthandCollection<DropdownItemProps> = availableColors.map(clr => {
return {
header: clr.title,
selected: color && clr.code === color.code,
onClick: () => {
setColor(clr);
microsoftTeams.settings.setValidityState(clr !== undefined);
Expand Down
Loading

0 comments on commit ce3af7a

Please sign in to comment.