From ce97896faaf463483bdb60db6dd020f5b3f9ec61 Mon Sep 17 00:00:00 2001 From: agatha197 Date: Wed, 15 Jan 2025 19:46:36 +0900 Subject: [PATCH] feat(FR-372): support id based object resolution --- react/src/components/ModelCardModal.tsx | 4 ++-- src/components/backend-ai-data-view.ts | 14 +++++++----- src/components/backend-ai-folder-explorer.ts | 18 +++++++++------ src/components/backend-ai-storage-list.ts | 23 +++++++++++++++----- src/lib/backend.ai-client-esm.ts | 3 +++ 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/react/src/components/ModelCardModal.tsx b/react/src/components/ModelCardModal.tsx index 9e22386ab7..809c9ff8d2 100644 --- a/react/src/components/ModelCardModal.tsx +++ b/react/src/components/ModelCardModal.tsx @@ -217,8 +217,8 @@ const ModelCardModal: React.FC = ({ onClick={() => { // const event = new CustomEvent('backend-ai-vfolder-cloning', { // detail: { - // // TODO: change this to vfolder name - // name: mode_card?.name, + // // TODO: change this to vfolder id + // name: mode_card?.id, // }, // }); // onRequestClose(); diff --git a/src/components/backend-ai-data-view.ts b/src/components/backend-ai-data-view.ts index 8c247922f2..74f97a502a 100644 --- a/src/components/backend-ai-data-view.ts +++ b/src/components/backend-ai-data-view.ts @@ -92,7 +92,7 @@ export default class BackendAIData extends BackendAIPage { @property({ type: Object }) _helpDescriptionStorageProxyInfo = Object(); @property({ type: Object }) options; @property({ type: Number }) capacity; - @property({ type: String }) cloneFolderName = ''; + @property({ type: String }) cloneFolderID = ''; @property({ type: Object }) storageProxyInfo = Object(); @property({ type: String }) folderType = 'user'; @property({ type: Number }) currentGroupIdx = 0; @@ -550,7 +550,7 @@ export default class BackendAIData extends BackendAIPage { { if (e.detail) { const selectedItems = e.detail; - this.cloneFolderName = selectedItems.name; + this.cloneFolderID = globalThis.backendaiclient.supports( + 'vfolder-id-based', + ) + ? selectedItems.id + : selectedItems.name; this._cloneFolderDialog(); } }); @@ -976,7 +980,7 @@ export default class BackendAIData extends BackendAIPage { this.allowedGroups = group_info.groups; } this.cloneFolderNameInput.value = await this._checkFolderNameAlreadyExists( - this.cloneFolderName, + this.cloneFolderID, ); this.openDialog('clone-folder-dialog'); } @@ -1267,7 +1271,7 @@ export default class BackendAIData extends BackendAIPage { }; const job = globalThis.backendaiclient.vfolder.clone( input, - this.cloneFolderName, + this.cloneFolderID, ); job .then(() => { diff --git a/src/components/backend-ai-folder-explorer.ts b/src/components/backend-ai-folder-explorer.ts index 691408d6d4..177de23deb 100644 --- a/src/components/backend-ai-folder-explorer.ts +++ b/src/components/backend-ai-folder-explorer.ts @@ -53,6 +53,7 @@ export default class BackendAIFolderExplorer extends BackendAIPage { // [target vfolder information] @property({ type: String }) vfolderID = ''; @property({ type: String }) vfolderName = ''; + @property({ type: String }) vfolder = ''; @property({ type: Array }) vfolderFiles = []; @property({ type: String }) vhost = ''; @property({ type: Boolean }) isWritable = false; @@ -496,7 +497,7 @@ export default class BackendAIFolderExplorer extends BackendAIPage { const path = this.breadcrumb.concat(fn).join('/'); const job = globalThis.backendaiclient.vfolder.request_download_token( path, - this.vfolderName, + this.vfolder, archive, ); job @@ -777,6 +778,9 @@ export default class BackendAIFolderExplorer extends BackendAIPage { return vfolder.id === this.vfolderID; }); this.vfolderName = vfolder.name; + this.vfolder = globalThis.backendaiclient.supports('vfolder-id-based') + ? vfolder.id + : vfolder.name; this.vhost = vfolder.host; this.isWritable = vfolder.permission.includes('w'); @@ -791,7 +795,7 @@ export default class BackendAIFolderExplorer extends BackendAIPage { this.fileListGrid.selectedItems = []; const filesInfo = await globalThis.backendaiclient.vfolder.list_files( this.breadcrumb.join('/'), - this.vfolderName, + this.vfolder, ); const details = filesInfo.items; @@ -968,7 +972,7 @@ export default class BackendAIFolderExplorer extends BackendAIPage { const job = globalThis.backendaiclient.vfolder.rename_file( path, newName, - this.vfolderName, + this.vfolder, this.is_dir, ); job @@ -1034,7 +1038,7 @@ export default class BackendAIFolderExplorer extends BackendAIPage { const job = globalThis.backendaiclient.vfolder.delete_files( filenames, true, - this.vfolderName, + this.vfolder, ); job.then((res) => { this.notification.text = @@ -1054,7 +1058,7 @@ export default class BackendAIFolderExplorer extends BackendAIPage { const job = globalThis.backendaiclient.vfolder.delete_files( [path], true, - this.vfolderName, + this.vfolder, ); job .then((res) => { @@ -1121,7 +1125,7 @@ export default class BackendAIFolderExplorer extends BackendAIPage { this.mkdirNameInput.reportValidity(); if (this.mkdirNameInput.checkValidity()) { const job = globalThis.backendaiclient.vfolder - .mkdir([...this.breadcrumb, newfolder].join('/'), this.vfolderName) + .mkdir([...this.breadcrumb, newfolder].join('/'), this.vfolder) .catch((err) => { if (err & err.message) { this.notification.text = PainKiller.relieve(err.title); @@ -1290,7 +1294,7 @@ export default class BackendAIFolderExplorer extends BackendAIPage { const job = globalThis.backendaiclient.vfolder.create_upload_session( path, fileObj, - this.vfolderName, + this.vfolder, ); job.then((url) => { const start_date = new Date().getTime(); diff --git a/src/components/backend-ai-storage-list.ts b/src/components/backend-ai-storage-list.ts index 04d334b562..65bf738c68 100644 --- a/src/components/backend-ai-storage-list.ts +++ b/src/components/backend-ai-storage-list.ts @@ -1932,8 +1932,10 @@ export default class BackendAiStorageList extends BackendAIPage { * @param {Event} e - click the info icon button * */ _infoFolder(e) { - const folderName = this._getControlName(e); - const job = globalThis.backendaiclient.vfolder.info(folderName); + const folder = globalThis.backendaiclient.supports('vfolder-id-based') + ? this._getControlID(e) + : this._getControlName(e); + const job = globalThis.backendaiclient.vfolder.info(folder); job .then((value) => { this.folderInfo = value; @@ -1955,7 +1957,10 @@ export default class BackendAiStorageList extends BackendAIPage { * @param {Event} e - click the settings icon button * */ _modifyFolderOptionDialog(e) { - globalThis.backendaiclient.vfolder.name = this._getControlName(e); + globalThis.backendaiclient.vfolder.name = + globalThis.backendaiclient.supports('vfolder-id-based') + ? this._getControlID(e) + : this._getControlName(e); const job = globalThis.backendaiclient.vfolder.info( globalThis.backendaiclient.vfolder.name, ); @@ -2101,7 +2106,11 @@ export default class BackendAiStorageList extends BackendAIPage { * @param {Event} e - click the */ _renameFolderDialog(e) { - this.renameFolderName = this._getControlName(e); + this.renameFolderName = globalThis.backendaiclient.supports( + 'vfolder-id-based', + ) + ? this._getControlID(e) + : this._getControlName(e); this.newFolderNameInput.value = ''; this.openDialog('modify-folder-name-dialog'); } @@ -2427,7 +2436,11 @@ export default class BackendAiStorageList extends BackendAIPage { * @param {Event} e - click the share button * */ _shareFolderDialog(e) { - this.selectedFolder = this._getControlName(e); + this.selectedFolder = globalThis.backendaiclient.supports( + 'vfolder-id-based', + ) + ? this._getControlID(e) + : this._getControlName(e); this.selectedFolderType = this._getControlType(e); this._initializeSharingFolderDialogLayout(); this.openDialog('share-folder-dialog'); diff --git a/src/lib/backend.ai-client-esm.ts b/src/lib/backend.ai-client-esm.ts index cc862b4de5..a75b659da5 100644 --- a/src/lib/backend.ai-client-esm.ts +++ b/src/lib/backend.ai-client-esm.ts @@ -734,6 +734,9 @@ class Client { this._features['max_network_count'] = true; this._features['replicas'] = true; } + if (this.isManagerVersionCompatibleWith(['25.1.0', '24.09.6', '24.03.12'])) { + this._features['vfolder-id-based'] = true; + } } /**