Skip to content

Commit 5ed32eb

Browse files
Artur-SahakyanHovhannes Dilanyan
andauthored
fixed bugs related to "error message" and "column width" (#20)
* fixed bugs related to "error message" and "column width" --------- Co-authored-by: Hovhannes Dilanyan <hovhannes@bevercrm.com>
1 parent a16d20a commit 5ed32eb

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

FetchToSubgrid/components/AppWrapper.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ export const AppWrapper: React.FC<IAppWrapperProps> = props => {
2222
const [error, setError] = React.useState<Error | undefined>(undefined);
2323

2424
const fetchToSubgridProps: IFetchToSubgridProps = parseRawInput(props);
25-
if (fetchToSubgridProps.error) setError(error);
2625

2726
React.useEffect(() => {
28-
setError(undefined);
27+
setError(fetchToSubgridProps.error);
2928
}, [props.fetchXmlOrJson]);
3029

3130
return (

FetchToSubgrid/components/FetchToSubgrid.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ export const FetchToSubgrid: React.FC<IFetchToSubgridProps> = props => {
5353

5454
React.useLayoutEffect(() => {
5555
if (allocatedWidth === -1) return;
56-
5756
listInputsHashCode.current = hashCode(`${allocatedWidth}${fetchXml}`);
58-
}, [allocatedWidth]);
57+
}, [allocatedWidth, columns]);
5958

6059
React.useEffect(() => setCurrentPage(1), [pageSize, fetchXml]);
6160

@@ -79,10 +78,10 @@ export const FetchToSubgrid: React.FC<IFetchToSubgridProps> = props => {
7978
const fetchItems = async () => {
8079
isButtonActive = false;
8180
setIsLoading(true);
82-
totalRecordsCount.current = await dataverseService.getRecordsCount(fetchXml ?? '');
8381
if (isDialogAccepted) return;
8482

8583
try {
84+
totalRecordsCount.current = await dataverseService.getRecordsCount(fetchXml ?? '');
8685
const newFetchXml = addOrderToFetch(fetchXml, sortingData);
8786

8887
const data: IItemsData = {

FetchToSubgrid/services/dataverseService.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class DataverseService implements IDataverseService {
5959

6060
public async getEntityDisplayName(entityName: string): Promise<string> {
6161
const entityMetadata: EntityMetadata = await this._context.utils.getEntityMetadata(entityName);
62-
return entityMetadata._displayName;
62+
return entityMetadata?._displayName;
6363
}
6464

6565
public async getTimeZoneDefinitions(): Promise<Object> {
@@ -105,6 +105,9 @@ export class DataverseService implements IDataverseService {
105105
}
106106

107107
public async getRecordsCount(fetchXml: string): Promise<number> {
108+
const top: number = this.getTopInFetchXml(fetchXml);
109+
if (top) return top;
110+
108111
let numberOfRecords = 0;
109112
let page = 0;
110113
let pagingCookie: string | null = null;
@@ -117,6 +120,7 @@ export class DataverseService implements IDataverseService {
117120
const xmlDoc: Document = parser.parseFromString(xml, 'text/xml');
118121
const fetch: Element = xmlDoc.getElementsByTagName('fetch')?.[0];
119122

123+
fetch?.removeAttribute('top');
120124
fetch?.removeAttribute('count');
121125
fetch?.removeAttribute('page');
122126

@@ -188,7 +192,7 @@ export class DataverseService implements IDataverseService {
188192

189193
const confirmOptions = { height: 200, width: 450 };
190194
const confirmStrings = {
191-
text: `Do you want to delete this ${entityMetadata._displayName}?
195+
text: `Do you want to delete this ${entityMetadata?._displayName}?
192196
You can't undo this action.`, title: 'Confirm Deletion',
193197
};
194198

@@ -219,4 +223,16 @@ export class DataverseService implements IDataverseService {
219223
private getAllocatedWidth(): number {
220224
return this._context.mode.allocatedWidth;
221225
}
226+
227+
private getTopInFetchXml(fetchXml: string): number {
228+
const parser: DOMParser = new DOMParser();
229+
const xmlDoc: Document = parser.parseFromString(fetchXml, 'text/xml');
230+
231+
const top: string | null | undefined = xmlDoc.querySelector('fetch')?.getAttribute('top');
232+
233+
if (top) {
234+
return Number(top);
235+
}
236+
return 0;
237+
}
222238
}

FetchToSubgrid/utilities/d365Utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ const createColumnsForEntity = (
116116
const columns: IColumn[] = [];
117117

118118
attributesFieldNames.forEach((name, index) => {
119+
if (!displayNameCollection) return;
120+
119121
let displayName = name === `${entityName}id`
120122
? 'Primary Key'
121123
: displayNameCollection[name].DisplayName;
@@ -167,7 +169,7 @@ export const getEntityData = (props: IItemProps, dataverseService: IDataverseSer
167169
} = props;
168170

169171
if (attributeType === AttributeType.Number) {
170-
const format: string = entityMetadata.Attributes._collection[fieldName].Format;
172+
const format: string = entityMetadata?.Attributes?._collection[fieldName]?.Format;
171173
const field: string = dataverseService.getWholeNumberFieldName(
172174
format,
173175
entity,
@@ -324,7 +326,7 @@ export const getColumns = async (
324326
entityName,
325327
attributesFieldNames);
326328

327-
const displayNameCollection: Dictionary<EntityMetadata> = entityMetadata.Attributes._collection;
329+
const displayNameCollection: Dictionary<EntityMetadata> = entityMetadata?.Attributes._collection;
328330

329331
const linkEntityAttFieldNames: Dictionary<EntityAttribute[]> = getLinkEntitiesNamesFromFetchXml(
330332
fetchXml ?? '');

0 commit comments

Comments
 (0)