-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: convert attribute enums to string unions (#2962)
All enums used as properties on components have been converted to string union types Updates doc comments for better doc generation in Storybook Fixes string casing to match typed string unions refactor: ViewType is now a string union type and not an enum BREAKING CHANGE: ViewType is now a string union type and not an enum refactor: UserType is now a string union type and not an enum BREAKING CHANGE: UserType is now a string union type and not an enum refactor: PersonType is now a string union type and not an enum BREAKING CHANGE: PersonType is now a string union type and not an enum refactor: GroupType is now a string union type and not an enum BREAKING CHANGE: GroupType is now a string union type and not an enum refactor: groupType property on MgtPeoplePicker is now GroupType[] BREAKING CHANGE: groupType property on MgtPeoplePicker is now a GroupType[] not a GroupType that is a bitmask of the desired group types. Developers using the group-type attribute will find the behavior unchanged. refactor: avatarType renamed to AvatarType and converted to string union type BREAKING CHANGE: the avatarType eunm has been renamed to AvatarType for consistency and converted to a string union type refactor: ResponseType for mgt-get converted to string union type from enum BREAKING CHANGE: the ResponseType for mgt-get is now a string union type and not an enum refactor: PersonCardInteraction is now a string union type and not an enum BREAKING CHANGE: PersonCardInteraction is now a string union type and not an enum
- Loading branch information
1 parent
eda4b19
commit 18d0aec
Showing
41 changed files
with
375 additions
and
530 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,13 +73,11 @@ const isDataTransferItem = (item: DataTransferItem | File): item is DataTransfer | |
('getAsFile' in item && typeof item.getAsFile === 'function') || | ||
('webkitGetAsEntry' in item && typeof item.webkitGetAsEntry === 'function'); | ||
|
||
const conflictBehaviors = ['rename', 'replace'] as const; | ||
/** | ||
* Upload conflict behavior status | ||
*/ | ||
export const enum MgtFileUploadConflictBehavior { | ||
rename, | ||
replace | ||
} | ||
export type MgtFileUploadConflictBehavior = (typeof conflictBehaviors)[number]; | ||
|
||
/** | ||
* MgtFileUpload upload item lifecycle object. | ||
|
@@ -243,6 +241,13 @@ export const registerMgtFileUploadComponent = () => { | |
registerComponent('file-upload', MgtFileUpload); | ||
}; | ||
|
||
const calculateConflictBehavior = (behavior: (number | true | MgtFileUploadConflictBehavior)[]) => { | ||
if (behavior?.length > 1) { | ||
return behavior[1] === 'replace' ? 'replace' : 'rename'; | ||
} | ||
return null; | ||
}; | ||
|
||
/** | ||
* A component to upload files to OneDrive or SharePoint Sites | ||
* | ||
|
@@ -429,7 +434,7 @@ export class MgtFileUpload extends MgtBaseComponent { | |
name: fileItem.fullPath.substring(1, fileItem.fullPath.lastIndexOf('/')), | ||
folder: 'Folder' | ||
}} | ||
.view=${ViewType.oneline} | ||
view="oneline" | ||
class="mgt-file-item"> | ||
</mgt-file> | ||
</div> | ||
|
@@ -686,7 +691,7 @@ export class MgtFileUpload extends MgtBaseComponent { | |
if (file.size > this.fileUploadList.maxFileSize * 1024) { | ||
acceptFile = false; | ||
if (this._maximumFileSize === false) { | ||
const maximumFileSize: (number | true)[] = await this.getFileUploadStatus( | ||
const maximumFileSize: (number | true | string)[] = await this.getFileUploadStatus( | ||
file, | ||
fullPath, | ||
'MaxFileSize', | ||
|
@@ -711,7 +716,7 @@ export class MgtFileUpload extends MgtBaseComponent { | |
) { | ||
acceptFile = false; | ||
if (this._excludedFileType === false) { | ||
const excludedFileType: (number | true)[] = await this.getFileUploadStatus( | ||
const excludedFileType: (number | true | string)[] = await this.getFileUploadStatus( | ||
file, | ||
fullPath, | ||
'ExcludedFileType', | ||
|
@@ -729,7 +734,7 @@ export class MgtFileUpload extends MgtBaseComponent { | |
|
||
// Collect accepted files | ||
if (acceptFile) { | ||
const conflictBehavior: (number | true)[] = await this.getFileUploadStatus( | ||
const conflictBehavior: (number | true | MgtFileUploadConflictBehavior)[] = await this.getFileUploadStatus( | ||
file, | ||
fullPath, | ||
'Upload', | ||
|
@@ -752,10 +757,10 @@ export class MgtFileUpload extends MgtBaseComponent { | |
name: file.name | ||
}, | ||
fullPath, | ||
conflictBehavior: conflictBehavior !== null ? (conflictBehavior[1] ? 1 : 0) : null, | ||
conflictBehavior: calculateConflictBehavior(conflictBehavior), | ||
iconStatus: null, | ||
percent: 1, | ||
view: ViewType.image, | ||
view: 'image', | ||
completed, | ||
maxSize: this._maxChunkSize, | ||
minSize: 0 | ||
|
@@ -793,7 +798,7 @@ export class MgtFileUpload extends MgtBaseComponent { | |
fullPath: string, | ||
DialogStatus: string, | ||
fileUploadList: MgtFileUploadConfig | ||
) { | ||
): Promise<(number | true | MgtFileUploadConflictBehavior)[]> { | ||
const fileUploadDialog: HTMLElement = this.renderRoot.querySelector('#file-upload-dialog'); | ||
|
||
switch (DialogStatus) { | ||
|
@@ -811,7 +816,7 @@ export class MgtFileUpload extends MgtBaseComponent { | |
this._dialogSecondaryButton = strings.buttonKeep; | ||
await super.requestStateUpdate(true); | ||
|
||
return new Promise<number[]>(resolve => { | ||
return new Promise<(number | MgtFileUploadConflictBehavior)[]>(resolve => { | ||
const fileUploadDialogClose: HTMLElement = this.renderRoot.querySelector('.file-upload-dialog-close'); | ||
const fileUploadDialogOk: HTMLElement = this.renderRoot.querySelector('.file-upload-dialog-ok'); | ||
const fileUploadDialogCancel: HTMLElement = this.renderRoot.querySelector('.file-upload-dialog-cancel'); | ||
|
@@ -822,13 +827,13 @@ export class MgtFileUpload extends MgtBaseComponent { | |
// Replace File | ||
const onOkDialogClick = () => { | ||
fileUploadDialog.classList.remove('visible'); | ||
resolve([fileUploadDialogCheck.checked ? 1 : 0, MgtFileUploadConflictBehavior.replace]); | ||
resolve([fileUploadDialogCheck.checked ? 1 : 0, 'replace']); | ||
}; | ||
|
||
// Rename File | ||
const onCancelDialogClick = () => { | ||
fileUploadDialog.classList.remove('visible'); | ||
resolve([fileUploadDialogCheck.checked ? 1 : 0, MgtFileUploadConflictBehavior.rename]); | ||
resolve([fileUploadDialogCheck.checked ? 1 : 0, 'rename']); | ||
}; | ||
|
||
// Cancel File | ||
|
@@ -1010,13 +1015,10 @@ export class MgtFileUpload extends MgtBaseComponent { | |
if (fileItem.file.size < this._maxChunkSize) { | ||
try { | ||
if (!fileItem.completed) { | ||
if ( | ||
fileItem.conflictBehavior === null || | ||
fileItem.conflictBehavior === MgtFileUploadConflictBehavior.replace | ||
) { | ||
if (fileItem.conflictBehavior === null || fileItem.conflictBehavior === 'replace') { | ||
graphQuery = `${this.getGrapQuery(fileItem.fullPath)}:/content`; | ||
} | ||
if (fileItem.conflictBehavior === MgtFileUploadConflictBehavior.rename) { | ||
if (fileItem.conflictBehavior === 'rename') { | ||
graphQuery = `${this.getGrapQuery(fileItem.fullPath)}:/[email protected]=rename`; | ||
} | ||
fileItem.driveItem = await sendFileContent(graph, graphQuery, fileItem.file); | ||
|
@@ -1114,7 +1116,7 @@ export class MgtFileUpload extends MgtBaseComponent { | |
void super.requestStateUpdate(true); | ||
setTimeout(() => { | ||
fileUpload.iconStatus = getSvg(SvgIcon.Success); | ||
fileUpload.view = ViewType.twolines; | ||
fileUpload.view = 'twolines'; | ||
fileUpload.fieldUploadResponse = 'lastModifiedDateTime'; | ||
fileUpload.completed = true; | ||
void super.requestStateUpdate(true); | ||
|
@@ -1130,7 +1132,7 @@ export class MgtFileUpload extends MgtBaseComponent { | |
protected setUploadFail(fileUpload: MgtFileUploadItem, errorMessage: string) { | ||
setTimeout(() => { | ||
fileUpload.iconStatus = getSvg(SvgIcon.Fail); | ||
fileUpload.view = ViewType.twolines; | ||
fileUpload.view = 'twolines'; | ||
fileUpload.driveItem.description = errorMessage; | ||
fileUpload.fieldUploadResponse = 'description'; | ||
fileUpload.completed = true; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.