Client: Shared: Connect room index export to api
This commit is contained in:
parent
16f7f3d3d4
commit
3e3d15f715
@ -75,6 +75,8 @@ import {
|
|||||||
} from "@docspace/shared/enums";
|
} from "@docspace/shared/enums";
|
||||||
|
|
||||||
import { copyShareLink } from "@docspace/shared/utils/copy";
|
import { copyShareLink } from "@docspace/shared/utils/copy";
|
||||||
|
import { hideLoader, showLoader } from "@docspace/shared/utils/common";
|
||||||
|
import { combineUrl } from "@docspace/shared/utils/combineUrl";
|
||||||
|
|
||||||
import { CategoryType } from "SRC_DIR/helpers/constants";
|
import { CategoryType } from "SRC_DIR/helpers/constants";
|
||||||
import {
|
import {
|
||||||
@ -445,23 +447,40 @@ const SectionHeaderContent = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onExportRoomIndex = async () => {
|
const onExportRoomIndex = async () => {
|
||||||
const fileTitle = await onClickExportRoomIndex(selectedFolder);
|
try {
|
||||||
|
showLoader();
|
||||||
|
|
||||||
if (!fileTitle) return;
|
const { fileName, fileUrl } =
|
||||||
|
await onClickExportRoomIndex(selectedFolder);
|
||||||
|
|
||||||
const toastMessage = (
|
const urlWithProxy = combineUrl(
|
||||||
<>
|
window.DocSpaceConfig?.proxy?.url,
|
||||||
<Link color="#5299E0" fontSize="12px">
|
fileUrl,
|
||||||
{fileTitle}
|
);
|
||||||
</Link>
|
|
||||||
|
|
||||||
<Text as="span" fontSize="12px">
|
|
||||||
{t("Files:FileExportedToMyDocuments")}
|
|
||||||
</Text>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
toastr.success(toastMessage);
|
if (!fileName) return;
|
||||||
|
|
||||||
|
const toastMessage = (
|
||||||
|
<>
|
||||||
|
<Link
|
||||||
|
color="#5299E0"
|
||||||
|
fontSize="12px"
|
||||||
|
target="_blank"
|
||||||
|
href={urlWithProxy}
|
||||||
|
>
|
||||||
|
{fileName}
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
<Text as="span" fontSize="12px">
|
||||||
|
{t("Files:FileExportedToMyDocuments")}
|
||||||
|
</Text>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
toastr.success(toastMessage);
|
||||||
|
} finally {
|
||||||
|
hideLoader();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onDeleteRoomInArchive = () => {
|
const onDeleteRoomInArchive = () => {
|
||||||
@ -658,7 +677,7 @@ const SectionHeaderContent = (props) => {
|
|||||||
label: t("Files:ExportRoomIndex"),
|
label: t("Files:ExportRoomIndex"),
|
||||||
icon: DownloadReactSvgUrl,
|
icon: DownloadReactSvgUrl,
|
||||||
onClick: onExportRoomIndex,
|
onClick: onExportRoomIndex,
|
||||||
disabled: !isVDRRoomType,
|
disabled: !isVDRRoomType || !selectedFolder.indexing,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "header_option_separator-2",
|
id: "header_option_separator-2",
|
||||||
|
@ -892,10 +892,49 @@ class ContextOptionsStore {
|
|||||||
this.filesActionsStore.setMuteAction(action, item, t);
|
this.filesActionsStore.setMuteAction(action, item, t);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
checkExportRoomIndexProgress = async () => {
|
||||||
|
return await new Promise((resolve, reject) => {
|
||||||
|
setTimeout(async () => {
|
||||||
|
try {
|
||||||
|
const res = await api.rooms.getExportRoomIndexProgress();
|
||||||
|
|
||||||
|
resolve(res);
|
||||||
|
} catch (e) {
|
||||||
|
reject(e);
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
loopExportRoomIndexStatusChecking = async () => {
|
||||||
|
let isCompleted = false;
|
||||||
|
let res;
|
||||||
|
|
||||||
|
while (!isCompleted) {
|
||||||
|
res = await this.checkExportRoomIndexProgress();
|
||||||
|
|
||||||
|
console.log("res", res);
|
||||||
|
|
||||||
|
if (res?.isCompleted) {
|
||||||
|
isCompleted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
onClickExportRoomIndex = async (room) => {
|
onClickExportRoomIndex = async (room) => {
|
||||||
try {
|
try {
|
||||||
await api.rooms.exportRoomIndex(room.id);
|
let res = await api.rooms.exportRoomIndex(room.id);
|
||||||
return `${room.title}_index.xlsx`;
|
|
||||||
|
if (!res.isCompleted) {
|
||||||
|
res = await this.loopExportRoomIndexStatusChecking();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
fileName: res.resultFileName,
|
||||||
|
fileUrl: res.resultFileUrl,
|
||||||
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toastr.error(e);
|
toastr.error(e);
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,8 @@ class SelectedFolderStore {
|
|||||||
|
|
||||||
canShare = false;
|
canShare = false;
|
||||||
|
|
||||||
|
indexing = false;
|
||||||
|
|
||||||
parentRoomType: Nullable<FolderType> = null;
|
parentRoomType: Nullable<FolderType> = null;
|
||||||
|
|
||||||
constructor(settingsStore: SettingsStore) {
|
constructor(settingsStore: SettingsStore) {
|
||||||
@ -185,6 +187,7 @@ class SelectedFolderStore {
|
|||||||
type: this.type,
|
type: this.type,
|
||||||
isRootFolder: this.isRootFolder,
|
isRootFolder: this.isRootFolder,
|
||||||
parentRoomType: this.parentRoomType,
|
parentRoomType: this.parentRoomType,
|
||||||
|
indexing: this.indexing,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -230,6 +233,7 @@ class SelectedFolderStore {
|
|||||||
this.type = null;
|
this.type = null;
|
||||||
this.inRoom = false;
|
this.inRoom = false;
|
||||||
this.parentRoomType = null;
|
this.parentRoomType = null;
|
||||||
|
this.indexing = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
setParentId = (parentId: number) => {
|
setParentId = (parentId: number) => {
|
||||||
|
@ -479,5 +479,15 @@ export function resetRoomQuota(roomIds) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function exportRoomIndex(roomId: number) {
|
export function exportRoomIndex(roomId: number) {
|
||||||
return new Promise((resolve) => setTimeout(() => resolve(), 1000));
|
return request({
|
||||||
|
method: "post",
|
||||||
|
url: `files/rooms/${roomId}/indexexport`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getExportRoomIndexProgress() {
|
||||||
|
return request({
|
||||||
|
method: "get",
|
||||||
|
url: `files/rooms/indexexport`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user