Skip to content

Commit 59f2221

Browse files
committed
Use file list in nesting and add styling
Fixes for disambiguation and adds version bump
1 parent 1fbbce5 commit 59f2221

File tree

4 files changed

+35
-46
lines changed

4 files changed

+35
-46
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"stylelint.packageManager": "yarn",
2020
"stylelint.snippet": ["css", "less", "postcss", "scss"],
2121
"stylelint.validate": ["css", "less", "postcss", "scss"],
22-
"cSpell.words": ["mailenabledsecurity"],
22+
"cSpell.words": ["mailenabledsecurity", "noreferrer"],
2323
"liveServer.settings.root": "storybook-static",
2424
"liveServer.settings.port": 6006
2525
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ $show-more-button-border-bottom-left-radius: var(
2626
);
2727
$progress-ring-size: var(--progress-ring-size, 24px);
2828

29+
@mixin nested-file-list($margin: 0) {
30+
margin-inline-start: calc(#{$margin} * 2);
31+
}
32+
2933
:host {
3034
font-size: $font-size;
3135

@@ -61,7 +65,7 @@ $progress-ring-size: var(--progress-ring-size, 24px);
6165
.file-list-children {
6266
&-show {
6367
display: block;
64-
margin-inline-start: calc($file-list-margin + 32px);
68+
@include nested-file-list(16px);
6569

6670
ul {
6771
list-style: none;

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

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
ProviderState,
1212
mgtHtml,
1313
MgtTemplatedTaskComponent,
14-
registerComponent
14+
registerComponent,
15+
customElementHelper
1516
} from '@microsoft/mgt-element';
1617
import { DriveItem, SharedInsight } from '@microsoft/microsoft-graph-types';
1718
import { html, TemplateResult } from 'lit';
@@ -589,7 +590,7 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
589590
: null;
590591

591592
return html`
592-
<div class="shared_insight_file" @click=${(e: MouseEvent) => this.handleFileClick(file, e)} tabindex="0">
593+
<div class="shared_insight_file" @click=${(e: MouseEvent) => this.handleSharedInsightClick(file, e)} tabindex="0">
593594
<div class="shared_insight_file__icon">
594595
<img alt="${file.resourceVisualization.title}" src=${getFileTypeIconUri(
595596
file.resourceVisualization.type,
@@ -667,17 +668,16 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
667668
* @param event
668669
*/
669670
private readonly onFileListKeyDown = (event: KeyboardEvent): void => {
670-
console.log(event.target);
671+
const target = event.target as HTMLElement;
671672
let fileList: HTMLElement;
672-
if (!event.target.classList) {
673+
if (!target.classList) {
673674
fileList = this.renderRoot.querySelector('.file-list-children');
674675
} else {
675676
fileList = this.renderRoot.querySelector('.file-list');
676677
}
677678
let focusedItem: HTMLElement;
678679

679680
if (!fileList?.children.length) {
680-
console.log('no children for ', fileList);
681681
return;
682682
}
683683

@@ -915,57 +915,42 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
915915
this.requestUpdate();
916916
}
917917

918-
private readonly handleFileClick = (file: DriveItem | SharedInsight, e?: MouseEvent) => {
918+
private readonly handleSharedInsightClick = (file: SharedInsight, e?: MouseEvent) => {
919+
if (file.resourceReference?.webUrl && !this.disableOpenOnClick) {
920+
e.preventDefault();
921+
window.open(file.resourceReference.webUrl, '_blank', 'noreferrer');
922+
}
923+
};
924+
925+
private readonly handleFileClick = (file: DriveItem) => {
919926
const hasChildFolders = file?.folder?.childCount > 0 && file?.children;
920927
// the item has child folders, on click should get the child folders and render them
921928
if (hasChildFolders) {
922-
this.showChildren(file, e);
929+
this.showChildren(file.id);
923930
return;
924931
}
925932

926-
if (e && isSharedInsight(file) && file.resourceReference?.webUrl && !this.disableOpenOnClick) {
927-
e.preventDefault();
928-
window.open(file.resourceReference.webUrl, '_blank', 'noreferrer');
929-
} else if (!isSharedInsight(file) && file?.webUrl && !this.disableOpenOnClick) {
933+
if (file?.webUrl && !this.disableOpenOnClick) {
930934
window.open(file.webUrl, '_blank', 'noreferrer');
931935
}
932936
};
933937

934-
private readonly showChildren = (file: DriveItem | SharedInsight, e?: MouseEvent) => {
935-
const itemDOM = this.renderRoot.querySelector(`#file-list-item-${file.id}`);
936-
this.renderChildren(file, itemDOM);
938+
private readonly showChildren = (fileId: string) => {
939+
const itemDOM = this.renderRoot.querySelector(`#file-list-item-${fileId}`);
940+
this.renderChildren(fileId, itemDOM);
937941
};
938942

939-
private readonly renderChildren = (file: DriveItem | SharedInsight, itemDOM: Element) => {
940-
const childrenContainer = this.renderRoot.querySelector(`#file-list-children-${file?.id}`);
943+
private readonly renderChildren = (itemId: string, itemDOM: Element) => {
944+
const fileListName = customElementHelper.isDisambiguated
945+
? `${customElementHelper.prefix}-file-list`
946+
: 'mgt-file-list';
947+
const childrenContainer = this.renderRoot.querySelector(`#file-list-children-${itemId}`);
941948
if (!childrenContainer) {
942-
// create and show the children container
943-
const container = document.createElement('div');
944-
container.setAttribute('id', `file-list-children-${file?.id}`);
945-
container.setAttribute('class', 'file-list-children-show');
946-
947-
const itemListDOM = document.createElement('ul');
948-
itemListDOM.setAttribute('class', 'file-list-children');
949-
container.appendChild(itemListDOM);
950-
const children = file?.children ?? [];
951-
for (const f of children) {
952-
const li = document.createElement('li');
953-
// TODO: fix for disambiguation
954-
const fileDOM = document.createElement('mgt-file');
955-
fileDOM.setAttribute('fileDetails', JSON.stringify(f));
956-
fileDOM.setAttribute('view', this.itemView);
957-
// add key down/up on the list
958-
li.addEventListener('keydown', this.onFileListKeyDown);
959-
li.setAttribute('class', 'file-item');
960-
li.appendChild(fileDOM);
961-
itemListDOM.appendChild(li);
962-
}
963-
964-
// a11y - set tabindex on first element
965-
itemListDOM.firstElementChild.setAttribute('tabindex', '0');
966-
itemListDOM.firstElementChild.setAttribute('focus', '0');
967-
this._focusedItemIndex = 0;
968-
itemDOM.after(container);
949+
const fl = document.createElement(fileListName);
950+
fl.setAttribute('item-id', itemId);
951+
fl.setAttribute('id', `file-list-children-${itemId}`);
952+
fl.setAttribute('class', 'file-list-children-show');
953+
itemDOM.after(fl);
969954
} else {
970955
// toggle to show/hide the children container
971956
if (childrenContainer.classList.contains('file-list-children-hide')) {

packages/mgt-element/src/utils/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
// THIS FILE IS AUTO GENERATED
99
// ANY CHANGES WILL BE LOST DURING BUILD
1010

11-
export const PACKAGE_VERSION = '4.2.4';
11+
export const PACKAGE_VERSION = '4.3.0';

0 commit comments

Comments
 (0)