Skip to content

Commit b3cbd15

Browse files
authored
XML import/export issues (#1616)
1 parent d94629c commit b3cbd15

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

src/commands/compile.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,25 @@ export async function importLocalFilesToServerSideFolder(wsFolderUri: vscode.Uri
713713
})
714714
)
715715
).then((results) => results.map((result) => (result.status == "fulfilled" ? result.value : null)).filter(notNull));
716-
// The user is importing into a server-side folder, so fire source control hook
717-
await new StudioActions().fireImportUserAction(
718-
api,
719-
docs.map((e) => e.name)
716+
// The user is importing into a server-side folder, so fire the import list User Action
717+
const docNames = docs.map((e) => e.name).join(",");
718+
await new StudioActions().fireImportUserAction(api, docNames);
719+
// Check the status of the documents to be imported and skip any that are read-only
720+
await api.actionQuery("select * from %Atelier_v1_Utils.Extension_GetStatus(?)", [docNames]).then((data) =>
721+
data?.result?.content?.forEach((e) => {
722+
if (!e.editable) {
723+
const idx = docs.findIndex((d) => {
724+
const nameSplit = d.name.split(".");
725+
return e.name == `${nameSplit.slice(0, -1).join(".")}.${nameSplit.pop().toUpperCase()}`;
726+
});
727+
if (idx != -1) {
728+
docs.splice(idx, 1);
729+
outputChannel.appendLine(
730+
`Skipping '${e.name}' because it has been marked read-only by server-side source control.`
731+
);
732+
}
733+
}
734+
})
720735
);
721736
// Import the files
722737
const rateLimiter = new RateLimiter(50);
@@ -862,7 +877,7 @@ export async function importXMLFiles(): Promise<any> {
862877
return items;
863878
});
864879
// Prompt the user for documents to import
865-
const docsToImport = await vscode.window.showQuickPick(quickPickItems, {
880+
let docsToImport = await vscode.window.showQuickPick(quickPickItems, {
866881
canPickMany: true,
867882
ignoreFocusOut: true,
868883
title: `Select the documents to import into namespace '${api.ns}' on server '${api.serverId}'`,
@@ -872,8 +887,28 @@ export async function importXMLFiles(): Promise<any> {
872887
}
873888
const isIsfs = filesystemSchemas.includes(wsFolder.uri.scheme);
874889
if (isIsfs) {
875-
// The user is importing into a server-side folder, so fire source control hook
876-
await new StudioActions().fireImportUserAction(api, [...new Set(docsToImport.map((qpi) => qpi.label))]);
890+
// The user is importing into a server-side folder
891+
const docNames = [...new Set(docsToImport.map((qpi) => qpi.label))].join(",");
892+
// Fire the import list User Action
893+
await new StudioActions().fireImportUserAction(api, docNames);
894+
// Check the status of the documents to be imported and skip any that are read-only
895+
await api.actionQuery("select * from %Atelier_v1_Utils.Extension_GetStatus(?)", [docNames]).then((data) => {
896+
const readOnly: string[] = [];
897+
data?.result?.content?.forEach((e) => {
898+
if (!e.editable) {
899+
readOnly.push(e.name);
900+
outputChannel.appendLine(
901+
`Skipping '${e.name}' because it has been marked read-only by server-side source control.`
902+
);
903+
}
904+
});
905+
if (readOnly.length) {
906+
docsToImport = docsToImport.filter((qpi) => {
907+
const nameSplit = qpi.label.split(".");
908+
return !readOnly.includes(`${nameSplit.slice(0, -1).join(".")}.${nameSplit.pop().toUpperCase()}`);
909+
});
910+
}
911+
});
877912
}
878913
// Import the selected documents
879914
const filesToLoad: { file: string; content: string[]; selected: string[] }[] = filesToList.map((f) => {

src/commands/export.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ export async function exportDocumentsToXMLFile(): Promise<void> {
352352
quickPick.title = `Export the following ${documents.length > 1 ? `${documents.length} documents` : "document"}?`;
353353
quickPick.placeholder = "Click any item to confirm, or 'Escape' to cancel";
354354
quickPick.ignoreFocusOut = true;
355-
quickPick.onDidChangeSelection((e) => outputChannel.appendLine(JSON.stringify(e)));
356355
quickPick.onDidAccept(() => {
357356
resolve(true);
358357
quickPick.hide();
@@ -381,6 +380,7 @@ export async function exportDocumentsToXMLFile(): Promise<void> {
381380
const xmlContent = await api.actionXMLExport(documents).then((data) => data.result.content);
382381
// Save the file
383382
await replaceFile(uri, xmlContent);
383+
outputChannel.appendLine(`Exported to ${uri.scheme == "file" ? uri.fsPath : uri.toString(true)}`);
384384
}
385385
} catch (error) {
386386
handleError(error, "Error executing 'Export Documents to XML File...' command.");

src/commands/studio.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ export class StudioActions {
7575
}
7676

7777
/** Fire UserAction 6 on server `api` for document list `documents` */
78-
public async fireImportUserAction(api: AtelierAPI, documents: string[]): Promise<void> {
78+
public async fireImportUserAction(api: AtelierAPI, documents: string): Promise<void> {
7979
this.api = api;
80-
this.name = documents.join(",");
80+
this.name = documents;
8181
return this.userAction(
8282
{
8383
id: OtherStudioAction.ImportListOfDocuments.toString(),

0 commit comments

Comments
 (0)