Skip to content

Commit 46c0b6a

Browse files
aaclagenmetulev
andauthored
Include fix remove highlighted #1140 , included refresh method of FileList #1029 (#1151)
* Include fix remove highlighted #1140 , included refresh method of FileList #1029 * rename of refresh to reload. * Removed focused when item is clicked * Update packages/mgt-components/src/components/mgt-file-list/mgt-file-list.ts Yes agree method is already exist on filelist, "reload" will be ok and no duplication of names. Also agree with option to clear cache, already exist a method to clear the cache for fileList or should be included like in ticket #1029? Co-authored-by: Nikola Metulev <[email protected]> * Update Method reload with fileLists clear cache. * Update packages/mgt-components/src/components/mgt-file-list/mgt-file-list.ts Co-authored-by: Nikola Metulev <[email protected]> * Added Method clearFilesCache in graph.files.ts and used in method reload on mgt-file-list when clearcache is selected * added reload story Co-authored-by: Nikola Metulev <[email protected]> Co-authored-by: Nikola Metulev <[email protected]>
1 parent e2d6d4f commit 46c0b6a

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

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

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { DriveItem } from '@microsoft/microsoft-graph-types';
1616
import { customElement, html, property, TemplateResult } from 'lit-element';
1717
import { repeat } from 'lit-html/directives/repeat';
1818
import {
19+
clearFilesCache,
1920
fetchNextAndCacheForFilesPageIterator,
2021
getDriveFilesByIdIterator,
2122
getDriveFilesByPathIterator,
@@ -478,6 +479,7 @@ export class MgtFileList extends MgtTemplatedComponent {
478479
tabindex="0"
479480
@keydown="${this.onFileListKeyDown}"
480481
@keyup="${this.onFileListKeyUp}"
482+
@blur="${this.onFileListOut}"
481483
>
482484
${repeat(
483485
this.files,
@@ -558,13 +560,13 @@ export class MgtFileList extends MgtTemplatedComponent {
558560
if (event.code === 'Enter' || event.code === 'Space') {
559561
event.preventDefault();
560562

561-
focusedItem.classList.remove('selected');
562-
focusedItem.classList.add('focused');
563+
focusedItem?.classList.remove('selected');
564+
focusedItem?.classList.add('focused');
563565
}
564566
}
565567

566568
/**
567-
* Handle accessibility keyboard keydown events (arrow up, arrow down, enter) on file list
569+
* Handle accessibility keyboard keydown events (arrow up, arrow down, enter, tab) on file list
568570
*
569571
* @param event
570572
*/
@@ -600,6 +602,21 @@ export class MgtFileList extends MgtTemplatedComponent {
600602

601603
this.updateItemBackgroundColor(fileList, focusedItem, 'selected');
602604
}
605+
606+
if (event.code === 'Tab') {
607+
focusedItem = fileList.children[this._focusedItemIndex];
608+
focusedItem?.classList.remove('focused');
609+
}
610+
}
611+
612+
/**
613+
* Remove accessibility keyboard focused when out of file list
614+
*
615+
*/
616+
private onFileListOut() {
617+
const fileList = this.renderRoot.querySelector('.file-list');
618+
const focusedItem = fileList.children[this._focusedItemIndex];
619+
focusedItem?.classList.remove('focused');
603620
}
604621

605622
/**
@@ -737,9 +754,10 @@ export class MgtFileList extends MgtTemplatedComponent {
737754
const li = event.target.closest('li');
738755
const index = nodes.indexOf(li);
739756
this._focusedItemIndex = index;
740-
const focusedItem = fileList.children[this._focusedItemIndex];
741757

742-
this.updateItemBackgroundColor(fileList, focusedItem, 'focused');
758+
for (let i = 0; i < fileList.children.length; i++) {
759+
fileList.children[i].classList.remove('focused');
760+
}
743761
}
744762
}
745763

@@ -820,4 +838,18 @@ export class MgtFileList extends MgtTemplatedComponent {
820838
focusedItem.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'start' });
821839
}
822840
}
841+
842+
/**
843+
* Handle reload of File List and condition to clear cache
844+
*
845+
* @param clearCache boolean, if true clear cache
846+
*/
847+
public reload(clearCache = false) {
848+
if (clearCache) {
849+
// clear cache File List
850+
clearFilesCache();
851+
}
852+
853+
this.requestStateUpdate(true);
854+
}
823855
}

packages/mgt-components/src/graph/graph.files.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ interface CacheFileList extends CacheItem {
3333
nextLink?: string;
3434
}
3535

36+
/**
37+
* Clear Cache of FileList
38+
*/
39+
export function clearFilesCache() {
40+
let cache: CacheStore<CacheFileList>;
41+
cache = CacheService.getCache<CacheFileList>(schemas.fileLists, schemas.fileLists.stores.fileLists);
42+
cache.clearStore();
43+
}
44+
3645
/**
3746
* Defines the time it takes for objects in the cache to expire
3847
*/

stories/components/fileList/fileList.properties.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,15 @@ export const fileListItemView = () => html`
108108
<mgt-file-list item-view="threeLines" page-size=3></mgt-file-list>
109109
`;
110110

111+
export const clearCacheAndReload = () => html`
112+
<button>Reload files!</button>
113+
<mgt-file-list></mgt-file-list>
114+
<script>
115+
const fileList = document.querySelector('mgt-file-list');
116+
document.querySelector('button').addEventListener('click', () => {
117+
// passing true will clear file cache before reloading
118+
fileList.reload(true);
119+
})
120+
</script>
121+
`;
111122

0 commit comments

Comments
 (0)