จัดรูปแบบแท็บหลายงาน

ใน Microsoft Fabric คุณสามารถใช้การทํางานหลายอย่างพร้อมกันเพื่อเปิดหลายรายการพร้อมกันได้ เมื่อคุณเปิดรายการ แท็บจะถูกปักหมุดไปยังบานหน้าต่างด้านซ้าย ตามค่าเริ่มต้น Fabric รองรับการเปิดหนึ่งรายการในแต่ละครั้ง ชุดของเหตุการณ์วงจรชีวิตจะถูกทริกเกอร์เมื่อมีการเริ่มต้น ใช้งาน และทําลายโดยไม่จําเป็นต้องใช้ปริมาณงานใดๆ

เปลี่ยนคุณสมบัติเริ่มต้นสําหรับหลายงาน

กําหนดส่วน editorTab ภายในรายชื่อแฟ้มรายการสําหรับการแก้ไขคุณสมบัติของแท็บ:

    "editorTab": {

    }

เปิดใช้งานการเปิดมากกว่าหนึ่งรายการในเวลาเดียวกัน

กําหนด maxInstanceCount คุณสมบัติและกําหนดจํานวนรายการที่คุณต้องการเปิดพร้อมกัน (สูงสุด 20 รายการ):

    "editorTab": {
      "maxInstanceCount": "20"
    }

กําหนดการดําเนินการและตัวจัดการ

เมื่อคุณตัดสินใจที่จะใช้การดําเนินการแท็บและตัวจัดการ (หรือบางส่วน) คุณจําเป็นต้องตั้งค่าคุณสมบัติในรายการส่วนหน้าของรายการในส่วนeditorTab คุณสมบัตินั้นจะฟังการดําเนินการเหล่านี้ในโค้ดของตนเอง จัดการการดําเนินการดังกล่าวและส่งกลับผลลัพธ์ ถ้าคุณไม่ได้ตั้งค่าการดําเนินการใดๆ (หรือส่วนหนึ่งของการดําเนินการ) การดําเนินการเริ่มต้นจะถูกจัดการโดยอัตโนมัติ

กําหนดคุณสมบัติสําหรับการดําเนินการของ editorTab แท็บในส่วน:

    "editorTab": {
      "onInit": "item.tab.onInit",
      "onDeactivate": "item.tab.onDeactivate",
      "canDeactivate": "item.tab.canDeactivate",
      "canDestroy": "item.tab.canDestroy",
      "onDestroy": "item.tab.onDestroy",
      "onDelete": "item.tab.onDelete"
    }

เมื่อคุณลงทะเบียนการดําเนินการปริมาณงาน Fabric คาดว่าการดําเนินการจะส่งคืนข้อมูลในรูปแบบบางอย่างเพื่อให้ Fabric สามารถอ่านหรือแสดงข้อมูลนั้นได้:

   /*An OnInit event is triggered when the item is opened for the first
   time. This event contains the ID of the tab being initialized. Based on
   this tab ID, the handler needs to be able to return the display name
   or metadata.*/

   onInit: Action<never>;

   /*A CanDeactivate event is triggered when the user moves away from the tab.
   This event contains the ID of the tab being deactivated. The
   CanDeactivate handler should return a Boolean value that indicates whether
   the item tab can be deactivated. For an ideal multitasking experience,
   the handler should always return True.*/

   canDeactivate: Action<never>;

   /*An OnDeactivate event is triggered immediately after CanDeactivate
   returns True. This event contains the ID of the tab being deactivated.
   The OnDeactivate handler should cache unsaved item changes and
   the UI state.
   The next time the user goes back to the item, the item needs
   to be able to recover its data and UI state. The actual deactivation begins
   only when this handler returns.*/

   onDeactivate: Action<never>;

   /*A CanDestroy event is triggered after the close button is selected,
    before the item tab is closed. The event contains the ID of the tab
    being destroyed and also an allowInteraction parameter.
    The CanDeactivate handler should return a Boolean value that indicates
    whether the given item tab can be destroyed.
    If allowInteraction equals False, the implementation returns True
    if there are no dirty changes, and False otherwise.
    If allowInteraction equals True, a pop-up window can be used to ask
    for the user's opinion. It returns True if the user saves or discards
    dirty changes, and False if the user cancels the pop-up window.
    The OnDestroy handler gives the item the opportunity to do some
    cleanup work.*/

   canDestroy: Action<never>;

   /*An OnDestroy event is triggered when the tab is closed. The event
   contains the ID of the tab being destroyed. The OnDestroy handler gives
   the item the opportunity to do some cleanup work.*/

   onDestroy: Action<never>;

   /*An OnDelete event is triggered when the opened item is deleted.
   The event contains the ID of the item being deleted, just to tell
   the extension that the current item is deleted.*/

   onDelete: Action<never>;

ตัวอย่างของการจัดการการดําเนินการแท็บ

ตัวอย่างนี้จะฟังการดําเนินการทั้งหมดที่เกี่ยวข้องกับ item.tab และจัดการแต่ละรายการตาม:

workloadClient.action.onAction(async function ({ action, data }) {
    switch (action) {
        case 'item.tab.onInit':
            const { id } = data as ItemTabActionContext;
            try{
                const getItemResult = await callItemGet(
                    id,
                    workloadClient
                );
                const item = convertGetItemResultToWorkloadItem<ItemPayload(getItemResult);
                return {title: item.displayName};
            } catch (error) {
                console.error(
                    `Error loading the Item (object ID:${id})`,
                    error
                );
                return {};
            }
        case 'item.tab.canDeactivate':
            return { canDeactivate: true };
        case 'item.tab.onDeactivate':
            return {};
        case 'item.tab.canDestroy':
            return { canDestroy: true };
        case 'item.tab.onDestroy':
            return {};
        case 'item.tab.onDelete':
            return {};
        default:
            throw new Error('Unknown action received');
    }
});
  • item.tab.onInit: ดึงข้อมูลรายการโดยใช้ ID และส่งกลับชื่อเรื่องของรายการ
  • item.tab.canDeactivate: ส่งกลับ { canDeactivate: true }ซึ่งอนุญาตให้สลับระหว่างแท็บได้อย่างง่ายดาย
  • item.tab.onDeactivate, item.tab.onDestroyitem.tab.onDelete, : ส่งกลับวัตถุว่างสําหรับการดําเนินการเหล่านี้
  • item.tab.canDestroy: ส่งกลับ{ canDestroy: true }

สําหรับตัวอย่างแบบเต็มของการจัดการการดําเนินการของแท็บ ดูindex.ui.tsในที่เก็บตัวอย่าง ค้นหาการดําเนินการที่เริ่มต้นด้วยitem.tab