Skip to content

Commit

Permalink
Merge pull request #2853 from microsoftgraph/merge/main-to-chat
Browse files Browse the repository at this point in the history
merge main to next/mgt-chat
  • Loading branch information
gavinbarron authored Nov 14, 2023
2 parents 63c72dc + 61da237 commit d50ace9
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 55 deletions.
7 changes: 7 additions & 0 deletions .storybook/addons/codeEditorAddon/codeAddon.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ export const withCodeEditor = makeDecorator({
loadEditorContent();
});

const componentRegistration = `
`;

const loadEditorContent = () => {
const storyElement = document.createElement('iframe');

Expand All @@ -238,6 +241,10 @@ export const withCodeEditor = makeDecorator({
<html>
<head>
<script type="module" src="${resolveScript()}"></script>
<script type="module">
import { registerMgtComponents } from "${mgtScriptName}";
registerMgtComponents();
</script>
<script type="module">
${providerInitCode}
</script>
Expand Down
33 changes: 12 additions & 21 deletions .storybook/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,17 @@ import { Msal2Provider } from '../packages/providers/mgt-msal2-provider/dist/es6
import { CLIENTID, SETPROVIDER_EVENT, AUTH_PAGE } from './env';
import { MockProvider } from '@microsoft/mgt-element';
import { PACKAGE_VERSION } from '../packages/mgt-element/dist/es6/utils/version';
import '../packages/mgt-components/dist/es6/components/mgt-login/mgt-login';
import '../packages/mgt-components/dist/es6/components/mgt-person/mgt-person';
import { registerMgtPersonComponent } from '../packages/mgt-components/dist/es6/components/mgt-person/mgt-person';
import { registerMgtLoginComponent } from '../packages/mgt-components/dist/es6/components/mgt-login/mgt-login';

const isLoginEnabled = () => {
const urlParams = new window.URL(window.location.href).searchParams;
const canLogin = urlParams.get('login');

return canLogin === 'true';
};
registerMgtPersonComponent();
registerMgtLoginComponent();

const getClientId = () => {
const urlParams = new window.URL(window.location.href).searchParams;
const customClientId = urlParams.get('clientId');

return isLoginEnabled() && customClientId ? customClientId : CLIENTID;
return customClientId ? customClientId : CLIENTID;
};

document.getElementById('mgt-version').innerText = PACKAGE_VERSION;
Expand Down Expand Up @@ -67,7 +63,6 @@ Providers.globalProvider = msal2Provider;

const SignInPanel = () => {
const [state, setState] = useState(Providers.globalProvider.state);
const [loginEnabled] = useState(isLoginEnabled());

const emit = useChannel({
STORY_RENDERED: id => {
Expand Down Expand Up @@ -96,18 +91,14 @@ const SignInPanel = () => {

return (
<>
{loginEnabled && (
{Providers.globalProvider.state !== ProviderState.SignedIn ? (
<mgt-login login-view="compact" style={{ marginTop: '3px' }}></mgt-login>
) : (
<>
{Providers.globalProvider.state !== ProviderState.SignedIn ? (
<mgt-login login-view="compact" style={{ marginTop: '3px' }}></mgt-login>
) : (
<>
<mgt-person person-query="me" style={{ marginTop: '8px' }}></mgt-person>
<fluent-button appearance="lightweight" style={{ marginTop: '3px' }} onClick={onSignOut}>
Sign Out
</fluent-button>
</>
)}
<mgt-person person-query="me" style={{ marginTop: '8px' }}></mgt-person>
<fluent-button appearance="lightweight" style={{ marginTop: '3px' }} onClick={onSignOut}>
Sign Out
</fluent-button>
</>
)}
</>
Expand Down
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

<script src="https://unpkg.com/@microsoft/teams-js@2/dist/MicrosoftTeams.min.js" crossorigin="anonymous"></script>

<!-- <script src="./packages/mgt/dist/bundle/mgt-loader.js"></script> -->
<script src="./packages/mgt/dist/bundle/mgt-loader.js"></script>

<script type="module" src="./packages/mgt-element/dist/es6/index.js"></script>
<!-- <script type="module" src="./packages/mgt-element/dist/es6/index.js"></script>
<script type="module" src="./packages/mgt-components/dist/es6/index.js"></script>
<script type="module" src="./packages/providers/mgt-msal2-provider/dist/es6/index.js"></script>
<script type="module" src="./packages/providers/mgt-mock-provider/dist/es6/index.js"></script>
<script type="module" src="./packages/providers/mgt-mock-provider/dist/es6/index.js"></script> -->

<style>
header {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ export class MgtPerson extends MgtTemplatedComponent {
}
}

details = details ? details : this.fallbackDetails;
details = this.personDetailsInternal || this.personDetails || this.fallbackDetails;

// populate presence
const defaultPresence: Presence = {
Expand Down
6 changes: 1 addition & 5 deletions packages/mgt-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { registerMgtComponents } from './registerMgtComponents';
export * from './registerMgtComponents';

export * from './exports';

// this side effect will register all components
// this is to prevent a breaking change as we enable tree shaking
registerMgtComponents();
24 changes: 15 additions & 9 deletions packages/mgt/src/bundle/mgt-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,26 @@

var rootPath = getScriptPath();

function onScriptLoaded() {
console.log('script loaded');
// register all the components to ensure that they are available in the browser
mgt.registerMgtComponents();
mgt.registerMgtMockProvider();
mgt.registerMgtMsal2Provider();
mgt.registerMgtProxyProvider();
}

// decide es5 or es6
if (es6()) {
window.WebComponents = window.WebComponents || {};
window.WebComponents.root = rootPath + 'wc/';

addScript(rootPath + 'wc/webcomponents-loader.js');
addScript(rootPath + 'mgt.es6.js');
addScript(rootPath + 'mgt.es6.js', onScriptLoaded);
} else {
// es5 bundle already includes all the polyfills
addScript(rootPath + 'mgt.es5.js');
addScript(rootPath + 'mgt.es5.js', onScriptLoaded);
}

function getScriptPath() {
var scripts = document.getElementsByTagName('script');
var path = scripts[scripts.length - 1].src.split('?')[0];
Expand All @@ -59,12 +67,10 @@

function addScript(src, onload) {
var tag = document.createElement('script');
document.head.append(tag);
if (onload) {
tag.addEventListener('load', onload);
}
tag.src = src;

// if (onload) {
// tag.addEventListener("load", onload);
// }

document.write(tag.outerHTML);
}
})();
13 changes: 13 additions & 0 deletions packages/mgt/src/exports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/

export * from '@microsoft/mgt-element';
export * from '@microsoft/mgt-components';
export * from '@microsoft/mgt-proxy-provider';
export * from '@microsoft/mgt-sharepoint-provider';
export * from '@microsoft/mgt-msal2-provider';
export * from '@microsoft/mgt-mock-provider';
7 changes: 1 addition & 6 deletions packages/mgt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@
* -------------------------------------------------------------------------------------------
*/

export * from '@microsoft/mgt-element';
export * from '@microsoft/mgt-components';
export * from '@microsoft/mgt-proxy-provider';
export * from '@microsoft/mgt-sharepoint-provider';
export * from '@microsoft/mgt-msal2-provider';
export * from '@microsoft/mgt-mock-provider';
export * from './exports';
5 changes: 1 addition & 4 deletions packages/providers/mgt-mock-provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { registerMgtMockProvider } from './mgt-mock-provider';

registerMgtMockProvider();

export * from './mgt-mock-provider';
export * from './mgt-mock-provider';
3 changes: 1 addition & 2 deletions packages/providers/mgt-msal2-provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { registerMgtMsal2Provider } from './mgt-msal2-provider';
registerMgtMsal2Provider();
export * from './mgt-msal2-provider';
export * from './exports';
5 changes: 1 addition & 4 deletions packages/providers/mgt-proxy-provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
import { registerMgtProxyProvider } from './mgt-proxy-provider';

registerMgtProxyProvider();

export * from './mgt-proxy-provider';
export * from './exports';

0 comments on commit d50ace9

Please sign in to comment.