8000 fix dialog message · BeverCRM/PCF-DragAndDropArea@da50482 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
fix dialog message
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur-Sahakyan committed Oct 28, 2022
1 parent 4ef4fe5 commit da50482
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
12 changes: 8 additions & 4 deletions DragAndDropArea/components/FileUploadArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Icon } from '@fluentui/react/lib/Icon';
export interface IFileUploadAreaProps { }

interface IFileUploadAreaState {
entityName: string,
dragCounter: number;
isLoading: boolean;
importedFilesCount: number
Expand All @@ -19,6 +20,7 @@ export class FileUploadArea extends React.Component<IFileUploadAreaProps, IFileU
super(props);

this.state = {
entityName: '',
dragCounter: 0,
isLoading: false,
importedFilesCount: 0,
Expand Down Expand Up @@ -54,11 +56,12 @@ export class FileUploadArea extends React.Component<IFileUploadAreaProps, IFileU

async checkNotes() {
const hasNotes = await CrmService.hasNotes();
this.setState({ isDisabled: hasNotes, isRenderedOneTime: true });
const entityDisplayName = await CrmService.getEntityDisplayName();
this.setState({ entityName: entityDisplayName, isDisabled: hasNotes, isRenderedOneTime: true });
}

public render(): React.ReactNode {
const { filesCount, importedFilesCount, isLoading, isDisabled } = this.state;
const { filesCount, importedFilesCount, isLoading, isDisabled, entityName } = this.state;
if (!this.state.isRenderedOneTime) this.checkNotes();

return (
Expand All @@ -84,8 +87,9 @@ export class FileUploadArea extends React.Component<IFileUploadAreaProps, IFileU
<p> Drag and drop files here to upload</p></div>}
</div>
</div> : <div className='errorContainer'>
<Icon className='errorIcone' iconName="error"></Icon>
<p className='errorMessage'>Notes (including attachments) are disabled</p>
<Icon className='errorIcone' iconName="error"></Icon> <p className='errorMessage'>
Can&apos;t show control, because notes are not enabled for the {entityName} entity
</p>
</div>
}
</div>
Expand Down
24 changes: 17 additions & 7 deletions DragAndDropArea/services/CrmService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@ export default {
return entityMetadata.EntitySetName;
},

async getEntityDisplayName() {
// @ts-ignore
const { entityTypeName } = _context.page;
const entityMetadata = await _context.utils.getEntityMetadata(entityTypeName);
return entityMetadata._displayName;
},

async hasNotes() {
// @ts-ignore
const contextPage = _context.page;
const entityMetadataResponse =
await fetch(`${contextPage.getClientUrl()}/api/data/v9.0/EntityDefinitions(LogicalName='${contextPage.entityTypeName}')`);
await fetch(`${contextPage.getClientUrl()}/api/data/v9.0/EntityDefinitions(LogicalName='` +
`${contextPage.entityTypeName}')`);
const entityMetadata = await entityMetadataResponse.json();
return entityMetadata.HasNotes;
},
Expand Down Expand Up @@ -67,19 +75,21 @@ export default {

showNotificationPopup() {
if (notificationOptions.errorsCount === 0) {
const message = notificationOptions.importedSucsessCount > 1
? `${notificationOptions.importedSucsessCount} of ${notificationOptions.importedSucsessCount} files imported successfully`
: `${notificationOptions.importedSucsessCount} of ${notificationOptions.importedSucsessCount} file imported successfully`;
const message = notificationOptions.filesCount === 1
? `${notificationOptions.importedSucsessCount} of ` +
`${notificationOptions.importedSucsessCount} file imported successfully`
: `${notificationOptions.importedSucsessCount} of ` +
`${notificationOptions.importedSucsessCount} files imported successfully`;

_context.navigation.openConfirmDialog({ text: message });
notificationOptions.importedSucsessCount = 0;
}
else {
notificationOptions.message = notificationOptions.errorsCount > 1
notificationOptions.message = notificationOptions.filesCount === 1
? `${notificationOptions.errorsCount}
of ${notificationOptions.filesCount} files errored during import`
of ${notificationOptions.filesCount} file errored during import`
: `${notificationOptions.errorsCount}
of ${notificationOptions.filesCount} file errored during import`;
of ${notificationOptions.filesCount} files errored during import`;

_context.navigation.openErrorDialog(notificationOptions);
notificationOptions.errorsCount = 0, notificationOptions.importedSucsessCount = 0;
Expand Down

0 comments on commit da50482

Please sign in to comment.
0