Skip to content

Commit da90c5b

Browse files
Mnickiimusale
andauthored
fix: display only a person's shared files in mgt-person-card (#3238)
* fix shared files in person-card * remove inintended click events, apply review suggestions * Update packages/mgt-components/src/components/mgt-file-list/mgt-file-list.ts Use a more desciptive name Co-authored-by: Musale Martin <[email protected]> * fix build * remove unnecessary else --------- Co-authored-by: Musale Martin <[email protected]>
1 parent 25a6a37 commit da90c5b

File tree

4 files changed

+117
-9
lines changed

4 files changed

+117
-9
lines changed

packages/mgt-components/src/components/mgt-file-list/mgt-file-list.scss

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,55 @@ $progress-ring-size: var(--progress-ring-size, 24px);
101101
font-size: $show-more-button-font-size;
102102
}
103103
}
104+
105+
.shared_insight_file {
106+
display: flex;
107+
align-items: center;
108+
padding: 11px 20px;
109+
110+
&:hover {
111+
background-color: var(--file-item-background-color, var(--neutral-layer-1));
112+
cursor: pointer;
113+
}
114+
115+
&:last-child {
116+
margin-bottom: unset;
117+
}
118+
119+
.shared_insight_file__icon {
120+
width: 28px;
121+
min-width: 28px;
122+
height: 28px;
123+
margin-inline-end: 12px;
124+
display: flex;
125+
align-items: center;
126+
justify-content: center;
127+
128+
img {
129+
height: 28px;
130+
width: 28px;
131+
}
132+
}
133+
134+
.shared_insight_file__details {
135+
min-width: 0;
136+
margin-inline-end: 40px;
137+
138+
.shared_insight_file__name {
139+
font-size: var(--file-line1-font-size, var(--size-font-size, #{$ms-font-size-12}));
140+
color: var(--file-line1-color, var(--neutral-foreground-rest));
141+
}
142+
143+
.shared_insight_file__last-modified {
144+
font-size: var(--file-line3-font-size, var(--size-font-size, #{$ms-font-size-12}));
145+
color: var(--file-line3-color, var(--secondary-text-color));
146+
}
147+
148+
> div {
149+
white-space: nowrap;
150+
overflow: hidden;
151+
text-overflow: ellipsis;
152+
}
153+
}
154+
}
104155
}

packages/mgt-components/src/components/mgt-file-list/mgt-file-list.ts

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import {
1010
Providers,
1111
ProviderState,
1212
mgtHtml,
13-
MgtTemplatedTaskComponent
13+
MgtTemplatedTaskComponent,
14+
registerComponent
1415
} from '@microsoft/mgt-element';
15-
import { DriveItem } from '@microsoft/microsoft-graph-types';
16+
import { DriveItem, SharedInsight } from '@microsoft/microsoft-graph-types';
1617
import { html, TemplateResult } from 'lit';
1718
import { property, state } from 'lit/decorators.js';
1819
import { repeat } from 'lit/directives/repeat.js';
@@ -46,7 +47,8 @@ import { MgtFileUploadConfig, registerMgtFileUploadComponent } from './mgt-file-
4647
import { fluentProgressRing } from '@fluentui/web-components';
4748
import { registerFluentComponents } from '../../utils/FluentComponents';
4849
import { CardSection } from '../BasePersonCardSection';
49-
import { registerComponent } from '@microsoft/mgt-element';
50+
import { getRelativeDisplayDate } from '../../utils/Utils';
51+
import { getFileTypeIconUri } from '../../styles/fluent-icons';
5052

5153
export const registerMgtFileListComponent = () => {
5254
registerFluentComponents(fluentProgressRing);
@@ -56,6 +58,10 @@ export const registerMgtFileListComponent = () => {
5658
registerComponent('file-list', MgtFileList);
5759
};
5860

61+
const isSharedInsight = (sharedInsightFile: SharedInsight): sharedInsightFile is SharedInsight => {
62+
return 'lastShared' in sharedInsightFile;
63+
};
64+
5965
/**
6066
* The File List component displays a list of multiple folders and files by
6167
* using the file/folder name, an icon, and other properties specified by the developer.
@@ -96,6 +102,10 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
96102
return strings;
97103
}
98104

105+
// files from the person card component
106+
@state()
107+
private _personCardFiles: DriveItem[];
108+
99109
/**
100110
* allows developer to provide query for a file list
101111
*
@@ -369,8 +379,9 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
369379

370380
@state() private _isLoadingMore: boolean;
371381

372-
constructor() {
382+
constructor(files?: DriveItem[]) {
373383
super();
384+
this._personCardFiles = files;
374385
}
375386

376387
/**
@@ -381,6 +392,7 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
381392
protected clearState(): void {
382393
super.clearState();
383394
this.files = null;
395+
this._personCardFiles = null;
384396
}
385397

386398
/**
@@ -440,6 +452,9 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
440452
if (!this.files || this.files.length === 0) {
441453
return this.renderNoData();
442454
}
455+
if (this._personCardFiles) {
456+
this.files = this._personCardFiles;
457+
}
443458
return this._isCompact ? this.renderCompactView() : this.renderFullView();
444459
};
445460

@@ -540,8 +555,12 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
540555
* @returns {TemplateResult}
541556
* @memberof mgtFileList
542557
*/
543-
protected renderFile(file: DriveItem): TemplateResult {
558+
protected renderFile(file: DriveItem | SharedInsight): TemplateResult {
544559
const view = this.itemView;
560+
// if file is type SharedInsight, render Shared Insight File
561+
if (isSharedInsight(file)) {
562+
return this.renderSharedInsightFile(file);
563+
}
545564
return (
546565
this.renderTemplate('file', { file }, file.id) ||
547566
mgtHtml`
@@ -550,6 +569,40 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
550569
);
551570
}
552571

572+
/**
573+
* Render a file item of Shared Insight Type
574+
*
575+
* @protected
576+
* @param {IFile} file
577+
* @returns {TemplateResult}
578+
* @memberof MgtFileList
579+
*/
580+
protected renderSharedInsightFile(file: SharedInsight): TemplateResult {
581+
const lastModifiedTemplate = file.lastShared
582+
? html`
583+
<div class="shared_insight_file__last-modified">
584+
${this.strings.sharedTextSubtitle} ${getRelativeDisplayDate(new Date(file.lastShared.sharedDateTime))}
585+
</div>
586+
`
587+
: null;
588+
589+
return html`
590+
<div class="shared_insight_file" @click=${(e: MouseEvent) => this.handleFileClick(file, e)} tabindex="0">
591+
<div class="shared_insight_file__icon">
592+
<img alt="${file.resourceVisualization.title}" src=${getFileTypeIconUri(
593+
file.resourceVisualization.type,
594+
48,
595+
'svg'
596+
)} />
597+
</div>
598+
<div class="shared_insight_file__details">
599+
<div class="shared_insight_file__name">${file.resourceVisualization.title}</div>
600+
${lastModifiedTemplate}
601+
</div>
602+
</div>
603+
`;
604+
}
605+
553606
/**
554607
* Render the button when clicked will show more files.
555608
*
@@ -841,11 +894,14 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
841894
this.requestUpdate();
842895
}
843896

844-
private handleFileClick(file: DriveItem) {
845-
if (file?.webUrl && !this.disableOpenOnClick) {
897+
private readonly handleFileClick = (file: DriveItem | SharedInsight, e?: MouseEvent) => {
898+
if (e && isSharedInsight(file) && file.resourceReference?.webUrl && !this.disableOpenOnClick) {
899+
e.preventDefault();
900+
window.open(file.resourceReference.webUrl, '_blank', 'noreferrer');
901+
} else if (!isSharedInsight(file) && file?.webUrl && !this.disableOpenOnClick) {
846902
window.open(file.webUrl, '_blank', 'noreferrer');
847903
}
848-
}
904+
};
849905

850906
/**
851907
* Get file extension string from file name

packages/mgt-components/src/components/mgt-organization/mgt-organization.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ $organization-direct-report-person-avatar-size: var(--organization-direct-report
138138

139139
.direct-report {
140140
margin-right: 4px;
141+
cursor: pointer;
141142
}
142143
}
143144

packages/mgt-components/src/components/mgt-person-card/mgt-person-card.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ export class MgtPersonCard extends MgtTemplatedTaskComponent implements IHistory
12421242
}
12431243

12441244
if (MgtPersonCardConfig.sections.files && files?.length) {
1245-
this.sections.push(new MgtFileList());
1245+
this.sections.push(new MgtFileList(files));
12461246
}
12471247

12481248
if (MgtPersonCardConfig.sections.profile && profile) {

0 commit comments

Comments
 (0)