Building Microsoft Graph Toolkit apps with React

Microsoft Community Learning
30 Mar 202214:19

Summary

TLDRこのビデオスクリプトでは、Microsoft Graph Toolkitの活用方法について紹介しています。Reactフレームワークと統合してアプリを作成する方法に焦点を当て、ツールキットの使いやすさと柔軟性を強調しています。ツールキットは、Microsoft Graph APIにアクセスするための再利用可能なコンポーネントとプロバイダーを提供し、開発時間を短縮し、カスタマイズ性に優れています。また、Reactと組み合わせることで、M365のエクスペリエンスを再現しながらも、独自のブランドを組み込むことができるという利点を説明しています。

Takeaways

  • 🌐 マイクロソフトグラフツールキットは、再利用可能なフレームワークに依存しないコンポーネントとプロバイダーのコレクションで、Microsoft Graphにアクセスして操作することができます。
  • 🛠️ ツールキットは完全に機能的なコンポーネントで、コードの数行でカスタマイズ可能なエクスペリエンスを構築できます。
  • 📈 グラフツールキットは開発時間を短縮し、UIコンポーネントを簡単に追加できるため、生産性が向上します。
  • 🎨 柔軟性があり、M365の外観に似せることができますが、完全にカスタマイズ可能です。
  • 📱 モダンなブラウザであればどこでも動作し、Teams、SharePoint、単一ページアプリケーション、Electronで使用可能です。
  • 🔄 ReactとMGTの組み合わせはコミュニティで人気があり、Reactラッパーがリリースされてから大きなアップテイクがあります。
  • 🚀 Create React Appを使用してアプリを作成し、MGT Reactコンポーネントを簡単に追加できます。
  • 🔑 認証設定は、コードで行い、MSAL2プロバイダーを介してクライアントIDやスコープを設定します。
  • 🔍 MGT ReactコンポーネントはReactに自然に組み込まれており、プロパティや属性が豊富に用意されています。
  • 📂 各コンポーネントのプロパティは、MGTのドキュメントで確認でき、Reactの属性として使用できます。
  • 🌟 カスタムコンポーネントを作成することで、MGTの機能セットにない場合でも、Graph APIを活用してデータを取得できます。

Q & A

  • マイクロソフトグラフツールキットとは何ですか?

    -マイクロソフトグラフツールキットは、再利用可能なフレームワークに依存しないコンポーネントとプロバイダーのコレクションで、Microsoft Graphにアクセスして操作することができます。

  • マイクロソフトグラフツールキットをReactアプリで使用することの利点は何ですか?

    -Reactアプリでグラフツールキットを使用することで、開発時間を短縮し、非常に少ないコードでMicrosoft GraphにアクセスするためのUIコンポーネントを簡単に追加できます。

  • マイクロソフトグラフツールキットはどの程度のカスタマイズが可能ですか?

    -マイクロソフトグラフツールキットは、M365の外観を模したものですが、完全にカスタマイズ可能です。独自のブランドをコンポーネントに取り込むことができます。

  • マイクロソフトグラフツールキットはどのブラウザで動作しますか?

    -マイクロソフトグラフツールキットは、すべての現代のブラウザで動作します。

  • Reactでマイクロソフトグラフツールキットを使用する際のセットアップ手順は何ですか?

    -Reactプロジェクトを作成し、`@microsoft/mgt-react`をインストールして、MGTのReactコンポーネントを利用できるようにします。その後、お好みのプロバイダーをインストールします。

  • 認証を設定するために必要なプロパティは何ですか?

    -認証を設定するためには、クライアントIDと必要な一連のスコープが必要なプロパティです。

  • MGT Reactラッパーはどのくらいの期間で採用されていますか?

    -MGT Reactラッパーは18ヶ月前にリリースされ、大きな採用が見られています。

  • MGTのカスタムコンポーネントを使用する場合、どのような利点がありますか?

    -MGTのカスタムコンポーネントを使用することで、グラフツールキットの機能セットに必要な機能がない場合でも、Microsoft Graphからデータを取得し、独自のコンポーネントを作成できます。

  • MGTのカスタムテンプレートを使用する際の利点は何ですか?

    -カスタムテンプレートを使用することで、コンポーネントの外観を変更したり、コンポーネントの実際のHTMLを変更したりできます。

  • MGTの使用例として紹介された3つのコンポーネントは何ですか?

    -紹介された3つのコンポーネントは、アジェンダ、ファイルリスト、およびカスタムのメールコンポーネントです。

  • MGT Reactコンポーネントを使用する際に提供されるReact Hooksとは何ですか?

    -提供されるReact Hooksの1つは`useIsSignedIn`で、ログイン状態の変化を理解するために使用できます。

  • MGTのReactコンポーネントをカスタマイズするためのアプローチはどのようなものですか?

    -MGTのReactコンポーネントをカスタマイズするためには、ネイティブのReactコンポーネントを活用し、必要なHTMLを構築することが重要です。

Outlines

00:00

😀 ReactとMicrosoft Graph Toolkitの統合

第11週のMicrosoft Graph Toolkitの紹介では、Reactフレームワークと統合する方法が中心になります。これまではHTMLでツールキットの多用途性を見せてきたが、Reactなどの他のフレームワークではWebコンポーネントを活用するのが難しい場合があると指摘。Microsoft Graph Toolkitは、再利用可能なコンポーネントとプロバイダーのコレクションで、Microsoft Graphにアクセスして操作することができます。このツールキットは非常に少数のコードでカスタマイズ可能なUIコンポーネントを簡単に追加できるため、開発時間を短縮できます。また、M365の外観を模したが完全にカスタマイズ可能なコンポーネントで、TeamsやSharePoint、Electronアプリなど、あらゆる環境で動作します。ReactとMGTの組み合わせはコミュニティで人気があり、簡単に始められることが示されています。

05:01

🛠️ ReactアプリでMicrosoft Graph Toolkitを使う方法

ReactアプリでMicrosoft Graph Toolkitを使う方法について説明されています。Create React Appを使用してアプリを作成し、Microsoft Graph ToolkitのReactラッパーをインストールすることで、MGTの機能をReactコンポーネントとして利用できるようになります。認証の設定を行い、必要なスコープを定義することで、MGTコンポーネントがMicrosoft Graphにアクセスできるようになります。また、MGTのReactラッパーは、Reactの属性とプロパティを活用して、完全にReactに統合されたコンポーネントを提供しています。ログインコンポーネントの例を挙げ、その属性とプロパティ、そしてReactのHooksを使用してログイン状態を検出するようにしています。

10:01

📅 MGTのReactコンポーネントを使ったカスタマイズ

Microsoft Graph ToolkitのReactコンポーネントを使ってカスタマイズする方法が紹介されています。アジェンダ、ファイルリスト、カスタムコンポーネントの例を挙げ、これらのコンポーネントがReactでどのように使われるかを説明しています。アジェンダコンポーネントでは、日ごとにグループ化するオプションを設定する方法が示されています。ファイルリストコンポーネントでは、複数のプロパティを使ってファイルのリストを表示する方法が説明されています。さらに、MGTのカスタムコンポーネントである'get'コンポーネントを使って、任意のGraphエンドポイントにアクセスする方法も紹介されています。また、Reactコンポーネントのテンプレートをカスタマイズして、独自のコンポーネントを作成する方法も触れられています。

Mindmap

Keywords

💡Microsoft Graph Toolkit

Microsoft Graph Toolkitは、Microsoft Graph APIを利用してデータを取得し、ユーザーインターフェースを作成するための再利用可能なコンポーネントとプロバイダーの集まりです。このツールキットは、フレームワークに依存しないため、様々な環境で使用することができます。ビデオでは、このツールキットがReactアプリにどのように統合されるかが説明されています。

💡React

Reactは、Facebookによって開発されたJavaScriptライブラリで、ユーザーインターフェースの構築に使われます。ビデオでは、Microsoft Graph ToolkitをReactと組み合わせてアプリを作成する方法が紹介されています。Reactのコンポーネントベースのアプローチは、MGTの機能を活用する際に非常に適しています。

💡Web Components

Web Componentsは、カスタム要素を作成し、再利用可能なUIコードを構築するためのウェブ標準技術です。ビデオでは、Microsoft Graph ToolkitがWeb Componentsを提供していることと、それらがReactアプリでどのように使用されるかが説明されています。

💡create-react-app

create-react-appは、Reactアプリケーションを素早く作成するためのコマンドラインツールです。ビデオでは、このツールを使用して新しいReactプロジェクトを立ち上げ、Microsoft Graph Toolkitを統合する方法が紹介されています。

💡TypeScript

TypeScriptは、JavaScriptのスーパーセットで、静的型付けをサポートする言語です。ビデオでは、TypeScriptを使用してMicrosoft Graph ToolkitをReactと統合する例が示されています。これにより、開発者はより安全でスケーラブルなコードを書くことができます。

💡Authentication

認証は、システムやサービスへのアクセスを制限するために使用されるプロセスです。ビデオでは、Microsoft Graph Toolkitを使用する際に認証を設定する方法が説明されています。これは、Microsoft Graph APIに安全にアクセスするために必要です。

💡MSAL (Microsoft Authentication Library)

MSALは、Microsoft IDプラットフォームを介してトークンを取得し、認証フローを管理するためのライブラリです。ビデオでは、MSAL2プロバイダーを使用してReactアプリの認証を設定する方法が紹介されています。

💡Custom Components

カスタムコンポーネントは、開発者が特定のニーズに合わせて作成するコンポーネントのことです。ビデオでは、Microsoft Graph Toolkitのカスタムコンポーネントを使用して、Graph APIのエンドポイントにアクセスし、データの取得や表示を行う方法が説明されています。

💡Hooks

ReactのHooksは、Reactの関数コンポーネント内で状態やライフサイクルメソッドなどの機能を利用するための特殊な関数です。ビデオでは、useIsSignedInというカスタムフックを使用して、ユーザーの認証状態を監視する方法が紹介されています。

💡Template

テンプレートは、コンポーネントの外観や構造を定義するもので、ReactではJSXを使用して作成されます。ビデオでは、Microsoft Graph Toolkitのコンポーネントのテンプレートをカスタマイズする方法が説明されています。これにより、開発者はUIをより自分たちのブランドに合わせることができます。

Highlights

第11周的Microsoft Graph Toolkit教程,专注于如何将工具包集成到常用的框架中,首先介绍React。

Microsoft Graph Toolkit是一套可重用的、框架无关的组件和提供程序,用于访问和操作Microsoft Graph。

工具包组件完全功能化,只需很少的代码即可构建可定制的体验。

工具包支持任何现代浏览器,并且可以与React等框架一起使用。

使用Microsoft Graph Toolkit可以减少开发时间,通过几行代码轻松添加UI组件。

工具包组件具有M365体验的外观,但完全可定制。

社区反馈显示,MGT与React结合使用非常受欢迎,易于上手。

创建React项目时,推荐使用create-react-app,并可以结合TypeScript或JavaScript。

通过npm安装@microsoft/mgt-react,将MGT作为React组件引入项目。

安装提供程序以准备项目进行身份验证,例如使用MSAL提供程序。

演示如何在index.ts中设置MSAL2提供程序进行身份验证。

展示如何在React应用中使用MGT的登录组件,并介绍其属性。

使用useIsSignedIn钩子来检测登录状态变化,以保护React应用中的特定区域。

展示如何使用MGT的日程、文件列表等组件,并介绍它们的配置方式。

介绍如何使用MGT的自定义组件和模板,以创建自定义的电子邮件组件。

强调MGT组件的底层逻辑,如缓存、分页和批处理,开发者只需关注组件的HTML结构。

预告接下来的教程将深入探讨Teams、Angular和SharePoint Framework的集成。

Transcripts

play00:00

[Music]

play00:03

well folks

play00:04

we are now at week 11 of doing a grand

play00:08

tour of the microsoft graph toolkit

play00:12

for the next couple of sessions we will

play00:14

be looking at

play00:15

how you can integrate a toolkit in some

play00:18

of the frameworks that you might already

play00:20

be using today we're going to start with

play00:24

how can we build apps

play00:26

using mgt but with react since the

play00:29

beginning we've been using plain html to

play00:32

showcase

play00:33

the

play00:34

versatility of the graph toolkit but

play00:37

sometimes

play00:38

your

play00:39

framework of choice might be something

play00:40

else in just plain html and you know how

play00:44

in some of these frameworks it might be

play00:46

difficult

play00:47

to actually leverage

play00:49

native html elements and custom elements

play00:51

that web components are providing so

play00:53

today our focus will really be about

play00:56

react and what does it mean for you to

play00:58

utilize the graph toolkit within

play01:02

a react app

play01:04

so as a reminder what is the microsoft

play01:07

graph toolkit the toolkit is a

play01:09

collection of reusable framework

play01:11

agnostic components and off providers

play01:15

that let you access and work with the

play01:17

microsoft graph

play01:19

so it is a set of fully functional

play01:22

components that are already made that

play01:24

are drop

play01:25

components you can use

play01:27

in your apps that requires basically

play01:30

very very very few lines of code where

play01:32

you can build customizable

play01:35

experiences and that work with any

play01:37

frameworks and today will be a great

play01:39

example of this because we're going to

play01:40

use it with react

play01:43

it also works on any modern browsers

play01:45

today

play01:46

why would you care about the the

play01:49

graph toolkit well first

play01:51

it helps you cut on development time you

play01:54

can easily add ui components

play01:57

to

play01:57

um

play01:58

access graph to your app with just a few

play02:00

lines of code we could even probably

play02:03

make it a single line of code a very

play02:05

long single line but it could be

play02:07

possible to do it in just one line it's

play02:09

beautiful but it's flexible

play02:12

it is built to look like an m365

play02:15

experience but it's still fully

play02:17

customizable so if you want to bring

play02:19

your own brand inside these components

play02:21

it's absolutely possible it's up to you

play02:24

to make it happen and finally it just

play02:26

works everywhere you want to work in

play02:28

teams you want to work in sharepoint you

play02:30

want to work in your own single page

play02:32

application or even you want to host it

play02:35

within electron well it's up to you you

play02:38

do whatever you want it works everywhere

play02:40

on every single browser

play02:43

mgd loves react

play02:45

and not only it's

play02:48

it's something that we see but it's

play02:49

something that we're hearing a lot from

play02:51

the community

play02:53

18 months ago we launched our react

play02:55

wrappers for mgt and we have seen

play02:58

huge uptake on mgt and react together

play03:03

what does it mean it means that it's so

play03:05

easy to get it started that

play03:07

i'm not gonna even go through how to set

play03:10

up a react project or whatsoever i'm

play03:12

just gonna show you the three

play03:14

common lines you should be using

play03:17

and that is it afterwards we're going to

play03:19

jump into code so first when you're

play03:22

thinking about creating an app

play03:24

well one of the ways i really like to

play03:26

create apps is to use the create react

play03:28

app

play03:30

a set of functionality so you just

play03:32

create an app that you would create an

play03:34

app in any for any of your react apps or

play03:37

you can even just leverage an existing

play03:38

app that has already been created um in

play03:41

our case we love to use typescript but

play03:43

you can also use plain javascript here

play03:45

absolutely

play03:47

you install at microsoft slash ngt react

play03:51

which will bring

play03:53

all the capabilities from mgt as react

play03:56

components

play03:57

that afterwards you install your

play03:59

favorite

play04:00

provider so if you want to use msl

play04:02

provider you might want to use a teams

play04:04

provider we're going to see that in the

play04:06

future

play04:07

example

play04:08

well these will allow you

play04:11

to

play04:12

be ready to get started

play04:14

that's the only thing you need to add to

play04:16

your project to get access

play04:19

to um into these so

play04:21

let me

play04:22

go straight into code

play04:25

and let's show the demo

play04:28

so the first thing that i want to

play04:30

mention

play04:31

is

play04:32

that

play04:33

the root of your project which is

play04:34

usually an index.js or an index of ts in

play04:38

my case

play04:39

is where you want to do the setup for

play04:42

everything regarding authentication

play04:44

you want to make sure that the auth is

play04:47

is all prepared for all the components

play04:50

that will actually use uh microsoft

play04:53

craft will get so how do we do that in

play04:56

previous demos you were adding a

play04:58

component to a page that was called the

play05:00

mgt msol 2 provider where we're setting

play05:04

up some of the scope some of the ids

play05:06

here we're going to do it through code

play05:08

because we don't want just to drag a

play05:10

component that would not really work in

play05:12

a react world it's not really how react

play05:15

works so how do we do it well we are

play05:18

creating a new msl2 provider that is

play05:22

coming from our mgtm cell to provider

play05:25

package

play05:26

and we're assigning it a couple of

play05:28

properties the first one being the

play05:30

client id the client id

play05:33

that could

play05:34

either here be hard-coded or be part of

play05:37

your environment variables that you

play05:39

would be using

play05:40

with react

play05:41

and then a series of scopes these scopes

play05:45

are the different scopes that you want

play05:46

to use in your application

play05:49

here i'm predefining these scopes but if

play05:52

you want you can also leverage

play05:54

a very very minimal set of scopes here

play05:57

and have the dynamic consent or

play05:59

incremental consent to pop up

play06:02

when you're using capabilities when

play06:04

you're going uh deeper into your

play06:06

application so let's say you want to use

play06:07

files in a specific area of your app you

play06:11

could ask for that scope at that moment

play06:13

and not beforehand

play06:15

so in my index at ts that's the only

play06:18

thing i have to do it's going to set up

play06:21

everything we need from an

play06:22

authentication standpoint it's going to

play06:23

know what's what's over there uh our app

play06:27

is already pre-configured our azure ad

play06:29

app is already pre-configured with

play06:31

basically just the url back to this

play06:34

local host that i'm using here localhost

play06:37

2000 and that's it

play06:39

so now your app is ready to be used it's

play06:42

preconfigured with mgt and now what

play06:46

we're going to do is we're going to

play06:48

import some of these components from mgt

play06:50

to leverage them

play06:52

in

play06:52

our application

play06:54

our app here

play06:56

we'll start with

play06:58

this here

play07:00

we will be providing a login component

play07:03

and this login component is a react

play07:06

component it's fully

play07:08

entirely rich it has all the

play07:10

capabilities that you need from

play07:13

a react standpoint so if you want to add

play07:16

some of these properties you're going to

play07:17

be able to leverage or autocomplete

play07:19

right there

play07:20

you can see everything that is here

play07:23

all of the different properties that are

play07:25

available

play07:27

you can even go to

play07:28

aka rms slash mgt slash dots where you

play07:33

can find

play07:34

the the all the components that we have

play07:36

for example the login component and you

play07:38

want to see all the different properties

play07:41

well you're going to see them here well

play07:43

in in our

play07:45

case we don't have a lot of properties

play07:46

here on the on the login component where

play07:49

there's basically only the user details

play07:52

but here you see the attribute will be

play07:55

for plain html and the property would be

play07:57

the one to be used with react

play08:00

so very simple way of documenting

play08:03

everything is in a single place

play08:05

super easy to get that going

play08:07

and now when i do the login

play08:09

automatically i can actually let me just

play08:11

remove all of this so we

play08:15

don't have to

play08:16

see it happening and now when i refresh

play08:20

i just see my component right here and i

play08:22

see the component showing up

play08:25

right in here nothing to change it just

play08:28

logs you in in my case i was already

play08:30

logged in i was i already consented to

play08:32

my app but besides that it's the same

play08:35

component that was

play08:37

used

play08:38

when

play08:39

we were using the html components now

play08:43

we're using the full

play08:44

on

play08:45

um react components and the second thing

play08:48

i want to show is

play08:50

how we have built this these

play08:53

these components in a way that they feel

play08:56

native to react something that we did is

play08:58

we provided

play09:01

border play code to get

play09:03

some of the hooks that you might want

play09:05

for example here we provided a use is

play09:07

signed in hook

play09:08

where you can create the hook and

play09:11

understand when there are some changes

play09:13

in the login capability so when i'm

play09:15

signed in now i'm going to receive is

play09:18

signed in to true

play09:21

what will that

play09:22

deliver to my app i will be able to get

play09:25

a reference

play09:26

this is signed in and i will be able to

play09:29

use react to protect areas of my app i

play09:32

want the user to be signed in before you

play09:36

can showcase this component

play09:38

and that's exactly what we're doing here

play09:40

so when i i save this

play09:43

now

play09:44

and i

play09:45

save this actually

play09:47

if i do something bad oh it's good and

play09:49

now automatically because i'm signed in

play09:51

i can have all of these components show

play09:53

up what are these components first

play09:56

there's the agenda component all the

play09:58

components we have in mtt are available

play10:00

as react components so don't think that

play10:03

there's one or the other all of them are

play10:05

available and today i want to showcase

play10:07

three of them

play10:08

so the agenda

play10:10

um where i could also see for example

play10:13

group by day

play10:15

i can just say this is true

play10:17

and i want to do it right there saving

play10:19

this and now i have it grouped by day

play10:23

so depending on

play10:25

your use cases you can configure the

play10:28

components the exact same way you do it

play10:30

in html but now you're doing it natively

play10:33

with react

play10:35

the second component that i wanted to

play10:36

share is the file list the file list is

play10:39

here i have a really really good file

play10:41

list right here where i can show more

play10:43

items where i can see all of them so

play10:46

this file list with all the properties

play10:49

that you can find is also available this

play10:51

is a composition of multiple components

play10:54

we have including the file the file list

play10:56

and all of that so it really feels

play10:58

natural when you're using them within

play11:02

react

play11:04

something that we also showed a couple

play11:06

of weeks ago was the use of custom

play11:09

components

play11:11

namely the get component that was

play11:13

allowing you

play11:14

to basically get access to

play11:16

any

play11:17

endpoints and graph when you're thinking

play11:20

that oh i might not have all the

play11:22

capabilities i need with the feature set

play11:24

of the graph toolkit but i want to still

play11:27

use graph

play11:28

to get data for example from my emails

play11:31

but mgt doesn't have an email component

play11:33

how do i do that

play11:35

well this is where

play11:37

we now have a way to have a get

play11:39

component with the exact same

play11:41

capabilities that we have on the mgt get

play11:46

custom

play11:47

element which is our web component so

play11:49

here you just need to specify some of

play11:51

the resources you need in that case the

play11:53

resource the max pages all of them in in

play11:56

a very react way and we also support

play12:01

custom templating of every single react

play12:04

components in mgt components

play12:06

so you've seen already in the past

play12:08

in some of our session that you we could

play12:10

change the way it looks or even we could

play12:13

change the actual html for sections of

play12:16

the components well in our case that's

play12:19

exactly what we're doing here so what

play12:21

we're doing is we are leveraging

play12:23

native

play12:24

react components so for example here i

play12:26

have my email component

play12:29

that will overwrite the template that is

play12:32

called value if you go to the

play12:33

documentation you're going to see that

play12:35

we're going to have a value compo or

play12:37

value template

play12:38

that is

play12:39

used for every single item

play12:42

of an array

play12:43

so in my case what i did i created a

play12:46

very simple emails component

play12:49

all built in react

play12:51

where i can embed all my logic here

play12:54

i can have all my different divs i can

play12:56

even use other mgt component here i'm

play12:59

using the person component again i can

play13:02

do all the

play13:04

really normal things that i would do

play13:07

with react

play13:08

and when i go to the emails tab now

play13:10

you're going to see

play13:12

that we have a great experience here

play13:15

because we have all of these great

play13:17

components showing up all using the

play13:22

underlying foundation of the graph

play13:24

toolkit which will do all the caching

play13:27

all the logic all the paging all the

play13:29

batching for you

play13:30

the only thing you have to care about is

play13:32

to build the html of your component so

play13:35

don't stop at looking at the current

play13:37

feature set of mgt you can always build

play13:39

your own components when you feel that

play13:41

this is absolutely required so how do we

play13:44

do that here we just need to provide a

play13:47

property

play13:49

here that

play13:50

would be an ng template props and

play13:52

automatically you will be able to

play13:54

identify what's happening once the data

play13:56

is being passed to you and you're going

play13:58

to be able to display that

play14:00

straight on the screen so

play14:03

a couple of resources before we end and

play14:05

i give it uh it back to you

play14:07

vesa

play14:08

thanks for today our next couple of

play14:10

sessions we'll continue building on top

play14:12

of this we're gonna talk about teams

play14:13

angular sharepoint framework

play14:16

[Music]

Rate This

5.0 / 5 (0 votes)

Related Tags
ReactMicrosoftGraphToolkit開発チュートリアルフレームワークWebComponent認証UIコンポーネントカスタムテンプレート
Do you need a summary in English?