mgwdev-m365-components 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/{dist → lib}/App.d.ts +3 -3
  2. package/lib/App.js +212 -0
  3. package/{dist → lib}/components/Test.d.ts +4 -4
  4. package/lib/components/Test.js +37 -0
  5. package/lib/components/common/GraphPersona.d.ts +10 -0
  6. package/lib/components/common/GraphPersona.js +125 -0
  7. package/lib/components/common/graphEntityPicker/AbstractGraphEntityPicker.d.ts +16 -0
  8. package/lib/components/common/graphEntityPicker/AbstractGraphEntityPicker.js +117 -0
  9. package/lib/components/common/graphEntityPicker/ChannelPicker.d.ts +11 -0
  10. package/lib/components/common/graphEntityPicker/ChannelPicker.js +83 -0
  11. package/lib/components/common/graphEntityPicker/DrivePicker.d.ts +11 -0
  12. package/lib/components/common/graphEntityPicker/DrivePicker.js +77 -0
  13. package/lib/components/common/graphEntityPicker/ListPicker.d.ts +11 -0
  14. package/lib/components/common/graphEntityPicker/ListPicker.js +77 -0
  15. package/lib/components/common/graphEntityPicker/PeoplePicker.d.ts +8 -0
  16. package/lib/components/common/graphEntityPicker/PeoplePicker.js +76 -0
  17. package/lib/components/common/graphEntityPicker/SitePicker.d.ts +8 -0
  18. package/lib/components/common/graphEntityPicker/SitePicker.js +73 -0
  19. package/lib/components/common/graphEntityPicker/TeamPicker.d.ts +8 -0
  20. package/lib/components/common/graphEntityPicker/TeamPicker.js +77 -0
  21. package/lib/components/common/graphEntityPicker/index.d.ts +6 -0
  22. package/lib/components/common/graphEntityPicker/index.js +6 -0
  23. package/lib/components/common/index.d.ts +2 -0
  24. package/lib/components/common/index.js +2 -0
  25. package/lib/components/index.d.ts +2 -0
  26. package/lib/components/index.js +2 -0
  27. package/lib/components/provisioning/GetSiteTemplate.d.ts +6 -0
  28. package/lib/components/provisioning/GetSiteTemplate.js +41 -0
  29. package/lib/components/search/DefaultDocumentCard.d.ts +7 -0
  30. package/lib/components/search/DefaultDocumentCard.js +59 -0
  31. package/lib/components/search/M365Search.d.ts +18 -0
  32. package/lib/components/search/M365Search.js +69 -0
  33. package/lib/components/search/SearchDefaults.d.ts +1 -0
  34. package/lib/components/search/SearchDefaults.js +17 -0
  35. package/lib/components/search/index.d.ts +2 -0
  36. package/lib/components/search/index.js +2 -0
  37. package/{dist → lib}/context/AuthenticationContext.d.ts +11 -13
  38. package/lib/context/AuthenticationContext.js +50 -0
  39. package/lib/context/DataverseContext.d.ts +13 -0
  40. package/lib/context/DataverseContext.js +29 -0
  41. package/{dist → lib}/context/GraphContext.d.ts +11 -11
  42. package/lib/context/GraphContext.js +26 -0
  43. package/{dist → lib}/context/SPContext.d.ts +13 -13
  44. package/lib/context/SPContext.js +30 -0
  45. package/{dist → lib}/context/index.d.ts +4 -3
  46. package/lib/context/index.js +4 -0
  47. package/lib/index.d.ts +2 -0
  48. package/lib/index.js +2 -0
  49. package/{dist → lib}/main.d.ts +1 -1
  50. package/lib/main.js +6 -0
  51. package/lib/model/IEntityWithIdAndDisplayName.d.ts +4 -0
  52. package/lib/model/IEntityWithIdAndDisplayName.js +1 -0
  53. package/lib/model/ISearchResult.d.ts +19 -0
  54. package/lib/model/ISearchResult.js +1 -0
  55. package/lib/model/index.d.ts +1 -0
  56. package/lib/model/index.js +1 -0
  57. package/lib/model/infra/ICacheEntry.d.ts +4 -0
  58. package/lib/model/infra/ICacheEntry.js +1 -0
  59. package/lib/service-worker/sw.d.ts +3 -0
  60. package/lib/service-worker/sw.js +20 -0
  61. package/lib/services/PersonaService.d.ts +12 -0
  62. package/lib/services/PersonaService.js +134 -0
  63. package/lib/utils/FileUtils.d.ts +29 -0
  64. package/lib/utils/FileUtils.js +200 -0
  65. package/lib/utils/StringUtils.d.ts +1 -0
  66. package/lib/utils/StringUtils.js +10 -0
  67. package/lib/utils/ThumbnailUtils.d.ts +7 -0
  68. package/lib/utils/ThumbnailUtils.js +92 -0
  69. package/lib/utils/index.d.ts +3 -0
  70. package/lib/utils/index.js +3 -0
  71. package/package.json +2 -5
  72. package/dist/components/index.d.ts +0 -0
  73. package/dist/index.d.ts +0 -1
  74. package/dist/mwdev-m365-components.es.js +0 -10570
  75. package/dist/mwdev-m365-components.umd.js +0 -57
  76. package/dist/vite.svg +0 -1
@@ -1,3 +1,3 @@
1
- import * as React from 'react';
2
- declare function App(): React.JSX.Element;
3
- export default App;
1
+ import * as React from 'react';
2
+ declare function App(): React.JSX.Element;
3
+ export default App;
package/lib/App.js ADDED
@@ -0,0 +1,212 @@
1
+ import * as React from 'react';
2
+ import { AuthenticationContextProvider, GraphContextProvider, SPContextProvider } from './context';
3
+ import { DrivePicker, PeoplePicker, TeamPicker } from './components/common/graphEntityPicker';
4
+ import { SitePicker } from './components/common/graphEntityPicker/SitePicker';
5
+ import { Msal2AuthenticationService } from 'mgwdev-m365-helpers/lib/services/Msal2AuthenticationService';
6
+ import { ListPickerPicker } from './components/common/graphEntityPicker/ListPicker';
7
+ import { GetSiteTemplateContext } from './components/provisioning/GetSiteTemplate';
8
+ function App() {
9
+ var pnpSearchWPConfig = {
10
+ "queryTemplate": "{searchTerms}",
11
+ "selectedProperties": "Title,Path,Created,Filename,SiteLogo,PreviewUrl,PictureThumbnailURL,ServerRedirectedPreviewURL,ServerRedirectedURL,HitHighlightedSummary,FileType,contentclass,ServerRedirectedEmbedURL,ParentLink,DefaultEncodingURL,owstaxidmetadataalltagsinfo,Author,AuthorOWSUSER,SPSiteUrl,SiteTitle,IsContainer,IsListItem,HtmlFileType,SiteId,WebId,UniqueID,OriginalPath,FileExtension,IsDocument,NormSiteID,NormWebID,NormListID,NormUniqueID",
12
+ "enableQueryRules": false,
13
+ "includeOneDriveResults": false,
14
+ "showBlank": true,
15
+ "showResultsCount": true,
16
+ "webPartTitle": "",
17
+ "enableLocalization": true,
18
+ "useDefaultSearchQuery": false,
19
+ "resultTypes@odata.type": "#Collection(String)",
20
+ "resultTypes": [],
21
+ "useExternalRefinersDisplay": false,
22
+ "useExternalPaginationDisplay": false,
23
+ "appliedRefiners@odata.type": "#Collection(String)",
24
+ "appliedRefiners": [],
25
+ "refinersConfiguration@odata.type": "#Collection(String)",
26
+ "refinersConfiguration": [],
27
+ "sortableFields@odata.type": "#Collection(String)",
28
+ "sortableFields": [],
29
+ "synonymList@odata.type": "#Collection(String)",
30
+ "synonymList": [],
31
+ "searchQueryLanguage": -1,
32
+ "queryModifiers@odata.type": "#Collection(String)",
33
+ "queryModifiers": [],
34
+ "refinementFilters": "",
35
+ "selectedLayout": 2,
36
+ "defaultSearchQuery": "",
37
+ "inlineTemplateText": "<content id=\"template\">\n\n <style>\n \n /* Insert your CSS overrides here */\n\n </style>\n\n <div class=\"template_root\">\n <span>Test</span>\n <div class=\"template_defaultCard\">\n {{#if showResultsCount}}\n <div class=\"template_resultCount\">\n <label class=\"ms-fontWeight-semibold\">{{getCountMessage @root.paging.totalItemsCount keywords}}</label>\n </div>\n {{/if}}\n <div class=\"document-card-container\">\n {{#each items as |item|}}\n <div class=\"document-card-item\">\n {{#> resultTypes item=item}}\n\n <pnp-document-card data-item=\"{{JSONstringify item}}\" data-fields-configuration=\"{{JSONstringify @root.documentCardFields}}\" data-enable-preview=\"{{@root.enablePreview}}\" data-show-file-icon=\"{{@root.showFileIcon}}\" data-is-compact=\"{{@root.isCompact}}\"></pnp-document-card>\n {{/resultTypes}}\n </div>\n {{/each}}\n </div>\n </div>\n {{#if @root.paging.showPaging}}\n <pnp-pagination \n data-total-items=\"{{@root.paging.totalItemsCount}}\" \n data-hide-first-last-pages=\"{{@root.paging.hideFirstLastPages}}\"\n data-hide-disabled=\"{{@root.paging.hideDisabled}}\"\n data-hide-navigation=\"{{@root.paging.hideNavigation}}\"\n data-range=\"{{@root.paging.pagingRange}}\" \n data-items-count-per-page=\"{{@root.paging.itemsCountPerPage}}\" \n data-current-page-number=\"{{@root.paging.currentPageNumber}}\"\n >\n </pnp-pagination>\n {{/if}}\n </div>\n</content>\n\n<content id=\"placeholder\"> \n <div class=\"placeholder_root\">\n <div class=\"template_defaultCard\">\n {{#if showResultsCount}}\n <div class=\"template_resultCount\">\n <span class=\"shimmer line\" style=\"width: 20%\"></span>\n </div>\n {{/if}}\n <div class=\"document-card-container\"> \n {{#times @root.paging.totalItemsCount}}\n <div class=\"document-card-item\">\n <pnp-document-card-shimmers data-is-compact=\"{{@root.isCompact}}\"></pnp-document-card-shimmers>\n </div>\n {{/times}}\n </div>\n </div>\n </div>\n</content>",
38
+ "externalTemplateUrl": "",
39
+ "paging": {
40
+ "@odata.type": "#graph.Json",
41
+ "itemsCountPerPage": 10,
42
+ "pagingRange": 5,
43
+ "showPaging": true,
44
+ "hideDisabled": true,
45
+ "hideFirstLastPages": false,
46
+ "hideNavigation": false
47
+ },
48
+ "sortList@odata.type": "#Collection(graph.Json)",
49
+ "sortList": [
50
+ {
51
+ "sortField": "Created",
52
+ "sortDirection": 1
53
+ },
54
+ {
55
+ "sortField": "Size",
56
+ "sortDirection": 2
57
+ }
58
+ ],
59
+ "templateParameters": {
60
+ "@odata.type": "#graph.Json",
61
+ "showFileIcon": false,
62
+ "documentCardFields@odata.type": "#Collection(graph.Json)",
63
+ "documentCardFields": [
64
+ {
65
+ "name": "Title",
66
+ "field": "title",
67
+ "value": "Title",
68
+ "useHandlebarsExpr": false,
69
+ "supportHtml": false
70
+ },
71
+ {
72
+ "name": "Location",
73
+ "field": "location",
74
+ "value": "<a style=\"color:{{@themeVariant.palette.themePrimary}}\" href=\"{{SPSiteUrl}}\">{{SiteTitle}}</a>",
75
+ "useHandlebarsExpr": true,
76
+ "supportHtml": true
77
+ },
78
+ {
79
+ "name": "Tags",
80
+ "field": "tags",
81
+ "value": "{{#if owstaxidmetadataalltagsinfo}}<i class='ms-Icon ms-Icon--Tag' aria-hidden='true'></i> {{#each (split owstaxidmetadataalltagsinfo ',') as |tag| }}<a class=\"ms-Link\" href=\"#owstaxidmetadataalltagsinfo:'{{trim tag}}'\">{{tag}}</a>{{/each}}{{/if}}",
82
+ "useHandlebarsExpr": true,
83
+ "supportHtml": true
84
+ },
85
+ {
86
+ "name": "Preview Image",
87
+ "field": "previewImage",
88
+ "value": "{{{getPreviewSrc item}}}",
89
+ "useHandlebarsExpr": true,
90
+ "supportHtml": false
91
+ },
92
+ {
93
+ "name": "Preview URL",
94
+ "field": "previewUrl",
95
+ "value": "{{#eq contentclass 'STS_ListItem_851'}}{{{DefaultEncodingURL}}}{{else}}{{#eq FileType 'pdf'}}{{#contains Path '-my.sharepoint'}}{{{ServerRedirectedEmbedURL}}}{{else}}{{{Path}}}{{/contains}}{{else}}{{{ServerRedirectedEmbedURL}}}{{/eq}}{{/eq}} ",
96
+ "useHandlebarsExpr": true,
97
+ "supportHtml": false
98
+ },
99
+ {
100
+ "name": "Date",
101
+ "field": "date",
102
+ "value": "{{getDate item.Created 'LL'}}",
103
+ "useHandlebarsExpr": true,
104
+ "supportHtml": false
105
+ },
106
+ {
107
+ "name": "URL",
108
+ "field": "href",
109
+ "value": "{{getUrl item}}",
110
+ "useHandlebarsExpr": true,
111
+ "supportHtml": false
112
+ },
113
+ {
114
+ "name": "Author",
115
+ "field": "author",
116
+ "value": "Author",
117
+ "useHandlebarsExpr": false,
118
+ "supportHtml": false
119
+ },
120
+ {
121
+ "name": "Profile Image",
122
+ "field": "profileImage",
123
+ "value": "{{#with (split AuthorOWSUSER '|')}}/_layouts/15/userphoto.aspx?size=L&username={{[0]}}{{/with}}",
124
+ "useHandlebarsExpr": true,
125
+ "supportHtml": false
126
+ },
127
+ {
128
+ "name": "IconSrc",
129
+ "field": "iconSrc",
130
+ "value": "{{IconSrc}}",
131
+ "useHandlebarsExpr": true,
132
+ "supportHtml": false
133
+ },
134
+ {
135
+ "name": "IconExt",
136
+ "field": "iconExt",
137
+ "value": "{{IconExt}}",
138
+ "useHandlebarsExpr": true,
139
+ "supportHtml": false
140
+ },
141
+ {
142
+ "name": "File Extension",
143
+ "field": "fileExtension",
144
+ "value": "FileType",
145
+ "useHandlebarsExpr": false,
146
+ "supportHtml": false
147
+ }
148
+ ],
149
+ "detailsListColumns@odata.type": "#Collection(graph.Json)",
150
+ "detailsListColumns": [
151
+ {
152
+ "name": "Title",
153
+ "value": "Title",
154
+ "useHandlebarsExpr": false,
155
+ "minWidth": "80",
156
+ "maxWidth": "300",
157
+ "enableSorting": false,
158
+ "isMultiline": false,
159
+ "isResizable": true,
160
+ "isResultItemLink": true,
161
+ "sortIdx": 1
162
+ },
163
+ {
164
+ "name": "Created",
165
+ "value": "{{getDate Created 'LL'}}",
166
+ "useHandlebarsExpr": true,
167
+ "minWidth": "80",
168
+ "maxWidth": "120",
169
+ "enableSorting": false,
170
+ "isMultiline": false,
171
+ "isResizable": false,
172
+ "isResultItemLink": false,
173
+ "sortIdx": 2
174
+ },
175
+ {
176
+ "name": "Summary",
177
+ "value": "{{getSummary HitHighlightedSummary}}",
178
+ "useHandlebarsExpr": true,
179
+ "minWidth": "80",
180
+ "maxWidth": "300",
181
+ "enableSorting": false,
182
+ "isMultiline": true,
183
+ "isResizable": false,
184
+ "isResultItemLink": false,
185
+ "sortIdx": 3
186
+ },
187
+ {
188
+ "uniqueId": "9c4eb969-17ac-4bf0-928e-7eb916688378",
189
+ "name": "Author",
190
+ "value": "Author",
191
+ "minWidth": "50",
192
+ "maxWidth": "310",
193
+ "enableSorting": true
194
+ }
195
+ ]
196
+ }
197
+ };
198
+ var clientId = import.meta.env.VITE_FRONTEND_CLIENT_ID;
199
+ var authService = new Msal2AuthenticationService({ clientId: clientId }, false);
200
+ var _a = React.useState(), site = _a[0], setSite = _a[1];
201
+ return (React.createElement(AuthenticationContextProvider, { authProvider: authService },
202
+ React.createElement(GraphContextProvider, null,
203
+ React.createElement(SPContextProvider, { siteUrl: import.meta.env.VITE_SITE_URL },
204
+ React.createElement(React.Fragment, null,
205
+ React.createElement(PeoplePicker, { key: "people-picker", label: "People picker", description: "Pick some people here" }),
206
+ React.createElement(TeamPicker, { key: "team-picker", label: "Team picker", description: "Pick a team here" }),
207
+ React.createElement(DrivePicker, { key: "drive-picker", label: "Drive picker", description: "Pick a drive here" }),
208
+ React.createElement(SitePicker, { onEntitySelected: function (site) { return setSite(site[0]); }, label: "Site picker", description: "Pick a site " }),
209
+ site && React.createElement(ListPickerPicker, { siteId: site.id, label: "List picker", description: "Pick a list from ".concat(site.displayName) }),
210
+ React.createElement(GetSiteTemplateContext, null))))));
211
+ }
212
+ export default App;
@@ -1,4 +1,4 @@
1
- import * as React from "react";
2
- export interface ITestProps {
3
- }
4
- export declare function Test(props: ITestProps): React.JSX.Element;
1
+ import * as React from "react";
2
+ export interface ITestProps {
3
+ }
4
+ export declare function Test(props: ITestProps): React.JSX.Element;
@@ -0,0 +1,37 @@
1
+ import * as React from "react";
2
+ import { useGraph, useSP } from "../context";
3
+ export function Test(props) {
4
+ var graphClient = useGraph().graphClient;
5
+ var _a = useSP(), spClient = _a.spClient, siteUrl = _a.siteUrl;
6
+ var _b = React.useState(true), loading = _b[0], setLoading = _b[1];
7
+ var _c = React.useState(undefined), user = _c[0], setUser = _c[1];
8
+ var _d = React.useState(undefined), web = _d[0], setWeb = _d[1];
9
+ React.useEffect(function () {
10
+ if (graphClient) {
11
+ graphClient.get("https://graph.microsoft.com/v1.0/me").then(function (resp) {
12
+ resp.json().then(function (response) {
13
+ setUser(response);
14
+ setLoading(false);
15
+ });
16
+ });
17
+ }
18
+ if (spClient) {
19
+ spClient.get("".concat(siteUrl, "/_api/web"), {
20
+ headers: {
21
+ "Accept": "application/json;odata=nometadata"
22
+ }
23
+ }).then(function (resp) {
24
+ resp.json().then(function (response) {
25
+ setWeb(response);
26
+ setLoading(false);
27
+ });
28
+ });
29
+ }
30
+ }, [graphClient]);
31
+ if (loading) {
32
+ return React.createElement("div", null, "Loading...");
33
+ }
34
+ return React.createElement("div", null,
35
+ React.createElement("div", null, user === null || user === void 0 ? void 0 : user.displayName),
36
+ React.createElement("div", null, web === null || web === void 0 ? void 0 : web.Title));
37
+ }
@@ -0,0 +1,10 @@
1
+ import { IHttpClient, IUser } from "mgwdev-m365-helpers";
2
+ import * as React from "react";
3
+ import { PersonaProps } from "@fluentui/react-components";
4
+ export interface IGraphPersonaProps extends PersonaProps {
5
+ id?: string;
6
+ user?: IUser;
7
+ showPresence?: boolean;
8
+ graphClient?: IHttpClient;
9
+ }
10
+ export declare function GraphPersona(props: IGraphPersonaProps): React.JSX.Element;
@@ -0,0 +1,125 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (_) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import * as React from "react";
49
+ import { Persona, Spinner } from "@fluentui/react-components";
50
+ import { PersonaService } from "../../services/PersonaService";
51
+ import { useGraph } from "../../context";
52
+ export function GraphPersona(props) {
53
+ var _this = this;
54
+ var _a, _b, _c, _d, _e;
55
+ var id = props.id;
56
+ var graphClient = props.graphClient;
57
+ if (!graphClient) {
58
+ graphClient = (useGraph()).graphClient;
59
+ }
60
+ var getPresence = function (presenceString) {
61
+ switch (presenceString) {
62
+ case "":
63
+ return "offline";
64
+ case "Available":
65
+ return "available";
66
+ case "Busy":
67
+ return "busy";
68
+ case "Away":
69
+ return "away";
70
+ case "DoNotDisturb":
71
+ return "do-not-disturb";
72
+ case "Offline":
73
+ return "offline";
74
+ case "PresenceUnknown":
75
+ return "unknown";
76
+ case "OutOfOffice":
77
+ return "out-of-office";
78
+ case "Blocked":
79
+ return "blocked";
80
+ case "BeRightBack":
81
+ return "away";
82
+ case "BusyIdle":
83
+ return "busy";
84
+ case "AvailableIdle":
85
+ return "available";
86
+ default:
87
+ return presenceString === null || presenceString === void 0 ? void 0 : presenceString.toLowerCase();
88
+ }
89
+ };
90
+ var personaService = React.useRef(new PersonaService(graphClient, props.showPresence));
91
+ var _f = React.useState(!props.user), loading = _f[0], setLoading = _f[1];
92
+ var _g = React.useState(props.user), user = _g[0], setUser = _g[1];
93
+ var getUserInfo = function () { return __awaiter(_this, void 0, void 0, function () {
94
+ var userResult;
95
+ return __generator(this, function (_a) {
96
+ switch (_a.label) {
97
+ case 0: return [4 /*yield*/, personaService.current.getUser(id)];
98
+ case 1:
99
+ userResult = _a.sent();
100
+ setUser(__assign(__assign({}, props.user), userResult));
101
+ setLoading(false);
102
+ return [2 /*return*/];
103
+ }
104
+ });
105
+ }); };
106
+ React.useEffect(function () {
107
+ if (!props.user) {
108
+ getUserInfo();
109
+ }
110
+ // eslint-disable-next-line react-hooks/exhaustive-deps
111
+ }, [id]);
112
+ if (loading) {
113
+ return React.createElement(Spinner, null);
114
+ }
115
+ var primaryText = (user === null || user === void 0 ? void 0 : user.displayName) || props.name || props.title || props.id;
116
+ return (React.createElement(Persona, __assign({ primaryText: primaryText, secondaryText: user === null || user === void 0 ? void 0 : user.jobTitle, avatar: {
117
+ image: { src: user === null || user === void 0 ? void 0 : user.photo },
118
+ initials: ((_a = user === null || user === void 0 ? void 0 : user.displayName) === null || _a === void 0 ? void 0 : _a.split(" ").map(function (x) { return x[0]; }).join("")) || ((_b = props.name) === null || _b === void 0 ? void 0 : _b.split(" ").map(function (x) { return x[0]; }).join("")),
119
+ }, presence: props.showPresence
120
+ ? {
121
+ status: getPresence((_c = user === null || user === void 0 ? void 0 : user.presence) === null || _c === void 0 ? void 0 : _c.availability),
122
+ outOfOffice: (_e = (_d = user === null || user === void 0 ? void 0 : user.presence) === null || _d === void 0 ? void 0 : _d.outOfOfficeSettings) === null || _e === void 0 ? void 0 : _e.isOutOfOffice
123
+ }
124
+ : undefined }, props)));
125
+ }
@@ -0,0 +1,16 @@
1
+ import * as React from "react";
2
+ import { IEntityWithIdAndDisplayName } from "../../../model/IEntityWithIdAndDisplayName";
3
+ export interface IAbstractGraphEntityPickerProps<T> {
4
+ onDataRequested: (searchText: string) => Promise<T[]>;
5
+ value?: T[];
6
+ label?: string;
7
+ description?: string;
8
+ multiSelect?: boolean;
9
+ disabled?: boolean;
10
+ additionalKey?: string;
11
+ onEntitySelected?: (entities: T[]) => void;
12
+ size?: "small" | "medium" | "large";
13
+ onSuggestionRendering?: (entity: T) => React.ReactNode;
14
+ renderOverride?: (entities: T[], isLoading: boolean, loadData: (query?: string) => Promise<void>) => JSX.Element;
15
+ }
16
+ export declare function AbstractGraphEntityPicker<T extends IEntityWithIdAndDisplayName>(props: IAbstractGraphEntityPickerProps<T>): React.JSX.Element;
@@ -0,0 +1,117 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
+ if (ar || !(i in from)) {
40
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
+ ar[i] = from[i];
42
+ }
43
+ }
44
+ return to.concat(ar || Array.prototype.slice.call(from));
45
+ };
46
+ import { Combobox, Field, ProgressBar, Option } from "@fluentui/react-components";
47
+ import { DebounceHandler } from "mgwdev-m365-helpers/lib/utils/DebounceHandler";
48
+ import * as React from "react";
49
+ export function AbstractGraphEntityPicker(props) {
50
+ var _this = this;
51
+ var _a = React.useState(props.value || []), entities = _a[0], setEntities = _a[1];
52
+ var _b = React.useState(false), isLoading = _b[0], setIsLoading = _b[1];
53
+ var _c = React.useState(""), inputValue = _c[0], setInputValue = _c[1];
54
+ var _d = React.useState(props.value || []), selectedEntities = _d[0], setSelectedEntities = _d[1];
55
+ var loadEntities = function (searchText) {
56
+ return DebounceHandler.debounce("entityPicker-".concat(props.additionalKey), function () { return __awaiter(_this, void 0, void 0, function () {
57
+ var queriedEntities, e_1;
58
+ return __generator(this, function (_a) {
59
+ switch (_a.label) {
60
+ case 0:
61
+ setIsLoading(true);
62
+ _a.label = 1;
63
+ case 1:
64
+ _a.trys.push([1, 3, , 4]);
65
+ return [4 /*yield*/, props.onDataRequested(searchText)];
66
+ case 2:
67
+ queriedEntities = _a.sent();
68
+ //get distinct entities
69
+ setEntities(__spreadArray(__spreadArray([], queriedEntities, true), selectedEntities, true).reduce(function (acc, current) {
70
+ var x = acc.find(function (item) { return item.id === current.id; });
71
+ if (!x) {
72
+ return acc.concat([current]);
73
+ }
74
+ else {
75
+ return acc;
76
+ }
77
+ }, []));
78
+ setIsLoading(false);
79
+ return [3 /*break*/, 4];
80
+ case 3:
81
+ e_1 = _a.sent();
82
+ console.error(e_1);
83
+ setIsLoading(false);
84
+ return [3 /*break*/, 4];
85
+ case 4: return [2 /*return*/];
86
+ }
87
+ });
88
+ }); }, 500);
89
+ };
90
+ React.useEffect(function () {
91
+ loadEntities(inputValue);
92
+ }, [inputValue]);
93
+ if (props.renderOverride) {
94
+ return props.renderOverride(entities, isLoading, loadEntities);
95
+ }
96
+ return React.createElement(Field, { label: props.label, hint: props.description },
97
+ React.createElement(Combobox, { value: inputValue, multiselect: props.multiSelect, freeform: true, onChange: function (e) {
98
+ setInputValue(e.target.value);
99
+ }, size: props.size, disabled: props.disabled, onOptionSelect: function (e, data) {
100
+ var newSelected = [];
101
+ var selectedEntity = entities.find(function (x) { return x.id === data.optionValue; });
102
+ if (selectedEntities.some(function (x) { return x.id === data.optionValue; })) {
103
+ newSelected = selectedEntities.filter(function (x) { return x.id !== data.optionValue; });
104
+ }
105
+ else if (props.multiSelect) {
106
+ newSelected = __spreadArray(__spreadArray([], selectedEntities, true), [selectedEntity], false);
107
+ }
108
+ else {
109
+ newSelected = [selectedEntity];
110
+ }
111
+ newSelected = newSelected.filter(function (x) { return !!x; });
112
+ props.onEntitySelected && props.onEntitySelected(newSelected);
113
+ setSelectedEntities(newSelected);
114
+ setInputValue(newSelected.map(function (x) { return x.displayName; }).join(", "));
115
+ }, defaultSelectedOptions: selectedEntities.map(function (x) { return x.id; }) }, entities.map(function (x) { return React.createElement(Option, { key: encodeURIComponent(x.id), text: x.displayName, value: x.id }, props.onSuggestionRendering ? props.onSuggestionRendering(x) : x.displayName); })),
116
+ isLoading && React.createElement(ProgressBar, null));
117
+ }
@@ -0,0 +1,11 @@
1
+ import * as React from "react";
2
+ import { IEntityWithIdAndDisplayName } from "../../../model/IEntityWithIdAndDisplayName";
3
+ import { IAbstractGraphEntityPickerProps } from "./AbstractGraphEntityPicker";
4
+ import { IHttpClient } from "mgwdev-m365-helpers";
5
+ export interface IChannelPickerProps extends Partial<IAbstractGraphEntityPickerProps<IEntityWithIdAndDisplayName>> {
6
+ teamId: string;
7
+ }
8
+ export declare function ChannelPicker(props: IChannelPickerProps): React.JSX.Element;
9
+ export declare function ChannelPickerStandalone(props: IChannelPickerProps & {
10
+ graphClient: IHttpClient;
11
+ }): React.JSX.Element;
@@ -0,0 +1,83 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (_) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import * as React from "react";
49
+ import { AbstractGraphEntityPicker } from "./AbstractGraphEntityPicker";
50
+ import { useGraph } from "../../../context";
51
+ export function ChannelPicker(props) {
52
+ var graphClient = useGraph().graphClient;
53
+ return React.createElement(ChannelPickerStandalone, __assign({}, props, { graphClient: graphClient }));
54
+ }
55
+ export function ChannelPickerStandalone(props) {
56
+ var _this = this;
57
+ var loadChannels = function () { return __awaiter(_this, void 0, void 0, function () {
58
+ var response, result;
59
+ return __generator(this, function (_a) {
60
+ switch (_a.label) {
61
+ case 0: return [4 /*yield*/, props.graphClient.get("/teams/".concat(props.teamId, "/channels?$select=id,displayName"))];
62
+ case 1:
63
+ response = _a.sent();
64
+ return [4 /*yield*/, response.json()];
65
+ case 2:
66
+ result = _a.sent();
67
+ return [2 /*return*/, result.value];
68
+ }
69
+ });
70
+ }); };
71
+ React.useEffect(function () {
72
+ loadChannels();
73
+ }, [props.teamId]);
74
+ var getData = function (search) { return __awaiter(_this, void 0, void 0, function () {
75
+ return __generator(this, function (_a) {
76
+ switch (_a.label) {
77
+ case 0: return [4 /*yield*/, loadChannels()];
78
+ case 1: return [2 /*return*/, _a.sent()];
79
+ }
80
+ });
81
+ }); };
82
+ return React.createElement(AbstractGraphEntityPicker, __assign({ additionalKey: "team-".concat(props.teamId, "-channels") }, props, { onDataRequested: getData }));
83
+ }
@@ -0,0 +1,11 @@
1
+ import * as React from "react";
2
+ import { IAbstractGraphEntityPickerProps } from "./AbstractGraphEntityPicker";
3
+ import { IEntityWithIdAndDisplayName } from "../../../model/IEntityWithIdAndDisplayName";
4
+ import { IHttpClient } from "mgwdev-m365-helpers";
5
+ export declare function DrivePicker(props: Partial<IAbstractGraphEntityPickerProps<IEntityWithIdAndDisplayName>> & {
6
+ siteId?: string;
7
+ }): React.JSX.Element;
8
+ export declare function DrivePickerStandalone(props: Partial<IAbstractGraphEntityPickerProps<IEntityWithIdAndDisplayName>> & {
9
+ graphClient: IHttpClient;
10
+ siteId?: string;
11
+ }): React.JSX.Element;