OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
685 stars 95 forks source link

Enable/Disable Commands in Excel add-in Task-pane using Officejs #1148

Closed Murugananths closed 7 months ago

Murugananths commented 4 years ago

Message from office-js bot: We’re closing this issue because it has been inactive for a long time. We’re doing this to keep the issues list manageable and useful for everyone. If this issue is still relevant for you, please create a new issue. Thank you for your understanding and continued feedback.

Implementing Enable/Disable feature in Excel add-in

@Rick-Kirkham

I have attached MANIFEST FILE for review and confirm. Please find below are summarized scenario mentioned in stack-overflow.

## Expected Behavior

1) we could be able to open multiple task-pane at same time that means : i) if we click Login command button it should open Login.html page then ii) if we click Logout command it should open Logout.html page on which case no other button become on the right side of the task pane area. 2) If we apply shared run time on above scenario it should be getting uploaded manifest file with shared run time on the task-pane's on which case task-pane's are getting refreshed data.

## Current Behavior

1) When we are having common TaskpaneId for multiple task-pane html pages then getting error as "Error in manifest file" when trying to upload manifest file with shared runtime but in this scenario only, task-pane's are getting refreshed and loading updated data which this scenario is our requirement.

2) As another option when we are having unique TaskpaneId for multiple task-panes it could be able to upload the manifest file with shared runtime but when we open one and then open the other, the first one closes and becomes a button on the right side of the task pane area and also first task-pane is not getting refreshed and it is loading cached data when opening again.

Steps to Reproduce, or Live Example

Manifest.txt

Context

Your Environment

Useful logs

Murugananths commented 4 years ago

@Rick-Kirkham..Have you had a chance to look into attached manifest file....

Murugananths commented 4 years ago

Hi Team, Can you please check and confirm ASAP as we are waiting for the response to continue this implementation.

Murugananths commented 4 years ago

Hi Team,

Any update on this request?

Murugananths commented 4 years ago

Hi Team,

Can you please review attached manifest file and let me know if any issue so that I can proceed.

Murugananths commented 4 years ago

@keyur32 ....As discussed with call any findings? Can we have status update if any?.. Thanks

keyur32 commented 4 years ago

thanks for the additional information. We are investigating and @sohailzafar will revert back with questions/update.

sohailzafar commented 4 years ago

I got a chance to think through your scenario. The behavior you currently see id because one task pane is opening up in shared runtime and the other task pane opens up in regular runtime which does not support enable/ disable button, because it is a different URL. The recommendation is to use a single URL and then use some sort of query string parameter or other single page app model. The following sample is a good resource to use.

https://github.com/OfficeDev/PnP-OfficeAddins/tree/master/Samples/excel-shared-runtime-scenario

Thanks Sohail

Murugananths commented 4 years ago

@sohailzafar ...Thank you for the update but already i referred the sample provided you. 1) To achieve the scenario we have to merge all functionalities of other taskpane's into one taskpane (taskpane.html in our sample). 2) But in this case we have to get the button id of commands from manifest file to taskpane.html (ShowTaskPane method) but i could not find the option for the same that how works for (Execute-Action method where we can able to get button id of commands). 3) If we are able to get button id using which it can be achieve respective logic in single task-pane. For ex: If i am having logout functionality (logout.html), if i could able to get button id of logout command from manifest file then using which it can be achieved logout in single taskpane.html by validating logout id then logout.html page can be removed. Kindly advise about the scenario. Kindly let me know if i am not making clear.

How to get button id of custom commands from manifest into taskpane using (ShowTaskPane)

Murugananths commented 4 years ago

@sohailzafar ... I tried with single task pane url as sample and enable/disable of commands working fine. But below are the other issues am facing.

1) Once Clicks login button enabled the ribbon commands whatever set to disabled. 2) But in that scenario if again i clicked Login button the page not getting reloaded and idle. 3) Even not sure how to use query string to distinguish single url for multiple task in single taskpane.

The only option is it can be achieve getting button id of custom commands from manifest into taskpane using (ShowTaskPane)

Murugananths commented 4 years ago

Hi Team... Have you had a chance looking into this scenario?

Murugananths commented 4 years ago

Hi Team,

Based on sample provided tried below work around.

I have Login command (ExecuteFunction ) and logout command(Execute function)

1) Initially when I am clicking Login Command i was able to enable the commands which are disabled and open the taskpane with respective commands's event id using Office.addin.showAsTaskpane. 2) But if i am trying to click the same Login command or any of other commands (Logout) nothing happened and taskpane page not getting refreshed. 3) When refreshing the browser only taskpane getting refreshed every time on above scenario (Shared Runtime). 4) During normal runtime only taskpane getting refreshed.

SUMARIZATION

Now i am able to get command event's id in task pane but once task pane rendered again not getting refreshed for any action.

Murugananths commented 4 years ago

Hi Team... Any update on this?

Murugananths commented 4 years ago

Enabledisablemanifest.txt

@sohailzafar ... I have attached sample manifest file where it has two execute functions getLogin and getLogin1 to show and hide task pane. ---> If user clicks getLogin then taskpane is displayed with rendering data. ---> if user clicks getLogin1 then taskpane is able to hide. ---> But when user again trying to clicks getLogin then taskpane is showing with cached data and does not getting refreshed.

Below are the sample code :

function getLogin(event: Office.AddinCommands.Event) {
  // Your code goes here
  localStorage.setItem("isEvent",event.source.id.toString());

   SetRuntimeVisibleHelper(true); 

   g.state.isTaskpaneOpen = true;
   enableButton();
  //  SetStartupBehaviorHelper(true);

  // Be sure to indicate when the add-in command function is complete
  event.completed();
}

 function getLogin1(event: Office.AddinCommands.Event) {
  // Your code goes here
  localStorage.setItem("isEvent",event.source.id.toString());
   SetRuntimeVisibleHelper(false); 

   enableButton();
  // Be sure to indicate when the add-in command function is complete
  event.completed();
}

Please confirm if anything i am missing on my implementation or is this known issues?...

Murugananths commented 4 years ago

Hi Team,

I tried Enable/Disable with UI-less in manifest which is attached with this request and below are the sample logic tried.

EnableDisableManifest.txt taskpane.txt port.txt

Kindly go through the files and let me know anything wrong/missing.

Murugananths commented 4 years ago

Hi Team,

I tried with another example attached files. Kindly have a look and advise. Manifest.txt commands.txt taskpane.txt

Commands.ts ---> It is called execute action from manifest and performing show/hide task-pane but not sure how to pass the messages to taskpane.html with that. taskpane.ts --> Where trying to register event handler to show different messages based on different ribbon command clicks but not sure how to implement. manifest ----> Implemented shared-runtime to achieve enable/disable commands with rendering different taskpane UX

ElizabethSamuel-MSFT commented 2 years ago

@preethikakiru Can you take a look? Thanks.