Skip to content

Commit 5b45ebf

Browse files
authored
Webfile fix for old data model file load (#688)
* Mimetype regression hotfix (#685) * In case of multiple annotations/attachments associated with a pick the latest modified by the user (#687)
1 parent b2e07c5 commit 5b45ebf

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/web/client/dal/remoteFetchProvider.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
isWebfileContentLoadNeeded,
1313
setFileContent,
1414
} from "../utilities/commonUtil";
15-
import { getCustomRequestURL, getMappingEntityContent, getMappingEntityId, getRequestURL } from "../utilities/urlBuilderUtil";
15+
import { getCustomRequestURL, getMappingEntityContent, getMappingEntityId, getMimeType, getRequestURL } from "../utilities/urlBuilderUtil";
1616
import { getCommonHeaders } from "../common/authenticationProvider";
1717
import * as Constants from "../common/constants";
1818
import { ERRORS, showErrorDialog } from "../common/errorHandler";
@@ -413,6 +413,7 @@ async function createFile(
413413
attribute
414414
);
415415
let fileContent = Constants.NO_CONTENT;
416+
let mimeType = undefined;
416417
let mappingEntityId = null
417418
// By default content is preloaded for all the files except for non-text webfiles for V2
418419
const isPreloadedContent = mappingEntityFetchQuery ? isWebfileContentLoadNeeded(fileNameWithExtension, fileUri) : true;
@@ -432,6 +433,7 @@ async function createFile(
432433
dataverseOrgUrl
433434
);
434435
mappingEntityId = getMappingEntityId(entityName, mappingContent);
436+
mimeType = getMimeType(mappingContent);
435437
fileContent = getMappingEntityContent(entityName, mappingContent, attribute);
436438
} else {
437439
fileContent = GetFileContent(result, attributePath, entityName, entityId);
@@ -449,7 +451,7 @@ async function createFile(
449451
result[attributePath.source] ?? Constants.NO_CONTENT,
450452
fileExtension,
451453
result[Constants.ODATA_ETAG],
452-
result[Constants.MIMETYPE],
454+
mimeType ?? result[Constants.MIMETYPE],
453455
isPreloadedContent,
454456
mappingEntityId
455457
);
@@ -513,7 +515,7 @@ async function fetchMappingEntityContent(
513515

514516
const result = await response.json();
515517
const data = result.value ?? result;
516-
if (result[Constants.ODATA_COUNT] !== 0 && data.length === 1) {
518+
if (result[Constants.ODATA_COUNT] !== 0 && data.length >= 1) {
517519
return data[0];
518520
}
519521

src/web/client/schema/portalSchema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const portal_schema_V1 = {
108108
_mappingEntityId: "annotationid", // Webfile in old schema are maintained with two dataverse entity adx_webfile and annotations. This Id acts as foreign key for that mapping
109109
_mappingEntity: "annotations",
110110
_mappingEntityFetchQuery: new Map([
111-
["documentbody", "?$filter=_objectid_value eq {entityId} &$select=mimetype,documentbody,filename,annotationid,_objectid_value&$count=true"],
111+
["documentbody", "?$filter=_objectid_value eq {entityId} &$select=mimetype,documentbody,filename,annotationid,_objectid_value &$count=true &$orderby=modifiedon desc"],
112112
]),
113113
},
114114
{

src/web/client/utilities/urlBuilderUtil.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import {
7+
MIMETYPE,
78
httpMethod,
89
queryParameters,
910
} from "../common/constants";
@@ -191,6 +192,12 @@ export function getMappingEntityContent(entity: string, result: any, attribute:
191192
return result;
192193
}
193194

195+
// TODO - Make Json for different response type and update any here
196+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
197+
export function getMimeType(result: any) {
198+
return result[MIMETYPE];
199+
}
200+
194201
export function pathHasEntityFolderName(uri: string): boolean {
195202
for (const entry of WebExtensionContext.entitiesFolderNameMap.entries()) {
196203
if (uri.includes(entry[1])) {

0 commit comments

Comments
 (0)