Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command.disabled not always respected #7845

Closed
1 of 9 tasks
kkazala opened this issue Mar 31, 2022 · 5 comments
Closed
1 of 9 tasks

command.disabled not always respected #7845

kkazala opened this issue Mar 31, 2022 · 5 comments
Labels
area:spfx Category: SharePoint Framework (not extensions related) status:fixed-next-drop Issue planned to be fixed in an upcoming release.
Milestone

Comments

@kkazala
Copy link
Contributor

kkazala commented Mar 31, 2022

Target SharePoint environment

SharePoint Online

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Developer environment

Windows

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

  • browser version
    • Chrome: 99.0.4844.51 (Official Build) (64-bit)
    • Edge 99.0.4844.51 (Official Build) (64-bit)
  • SPFx version: 1.14.0
  • Node.js version: 14.15.0

Describe the bug / error

Thank you for fixing #7795!

I now changed my CommandSet logic to:

  • Show the command buttons only for the "Travel requests" list
  • Disable the "Submit report" by default
  • Enable the "Submit report" only if exactly one item is selected AND the "Submitted" == "No"
//onInit executes **CORRECTLY**
public onInit(): Promise<void> {
  const setCommandsState = (isVisible:boolean) => {
    const compareOneCommand: Command = this.tryGetCommand('COMMAND_1');
    if (compareOneCommand) {
      //Visible for registered lists, does not depend on selected item
      compareOneCommand.visible = isVisible;
    }
    const compareTwoCommand: Command = this.tryGetCommand('COMMAND_2');
    if (compareTwoCommand) {
      //Visible for registered lists, enabled if 1 item selected, so disable by default
      compareTwoCommand.visible = isVisible;
      compareTwoCommand.disabled = true;
    }
  }
  const getListUrl = (listUrl: string): string => {
    let result = listUrl.match(/Lists\/(?<ListName>.*)/);
    return result.groups["ListName"];
  }
  
  setCommandsState( registeredList.includes(getListUrl(this.context.listView.list.serverRelativeUrl)));
  this.context.listView.listViewStateChangedEvent.add(this, this.onListViewUpdatedv2);
  return Promise.resolve();
}

public onListViewUpdatedv2(args: ListViewStateChangedEventArgs): void{

  const isSubmitEnabled= (this.context.listView.selectedRows.length == 1) && (this.context.listView.selectedRows[0].getValueByName("Submitted") == "No")
  console.log(`isSubmitEnabled: ${isSubmitEnabled}`)

  const compareTwoCommand: Command = this.tryGetCommand('COMMAND_2');
  compareTwoCommand.disabled = !isSubmitEnabled;
  this.raiseOnChange();

  console.log(`compareTwoCommand.disabled: ${compareTwoCommand.disabled}`)
  console.log("refresh")
}

When debugging, the 'COMMAND_2' button is not enabled/disabled when switching between two items with different Submitted values.
I think that this.raiseOnChange() is not required for the disabled state (?). I called it anyway hoping it would fix the issue but it doesn't have any impact.

Steps to reproduce

TEST 1

  1. Create new ListView CommandSet solution, keep the two default buttons
  2. Update the _CommandSet.ts as presented above
  3. Ensure that you have a "Submitted" (Yes/No) column in the list
  4. Ensure you have two items in the list, one with Submitted=Yes and the other with Submitted=No
  5. Debug
  6. Ensure that both buttons are visible, and button "COMMAND_1" is enabled, while "COMMAND_2" is disabled
  7. In the list, select the item where Submitted=No
  8. Ensure that you get the following console output:
    image
  9. Ensure that the button "COMMAND_2 is enabled
  10. Select the item where Submitted=Yes
  11. Ensure that you get the following console output:
    image
  12. The button "COMMAND_2 should be disabled but it's still enabled

TEST 2

Execute the above steps 1-10, and then
11. Click "outside" of the list to unselect the row
12. Ensure that you get the following console output:
image
14. The button "COMMAND_2 should be disabled but it's still enabled

Expected behavior

In the step 14 in the tests described above, the COMMAND_2 button should be disabled

@kkazala kkazala added the type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs. label Mar 31, 2022
@msftbot
Copy link
Contributor

msftbot bot commented Mar 31, 2022

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@msftbot msftbot bot added the Needs: Triage 🔍 Awaiting categorization and initial review. label Mar 31, 2022
@kkazala
Copy link
Contributor Author

kkazala commented Mar 31, 2022

UPDATE: also a much easier logic has the same effect.

public onListViewUpdatedv2(args: ListViewStateChangedEventArgs): void{

   // const isSubmitEnabled= (this.context.listView.selectedRows.length == 1) && (this.context.listView.selectedRows[0].getValueByName("Submitted") == "No")
   // console.log(`isSubmitEnabled: ${isSubmitEnabled}`)

    const compareTwoCommand: Command = this.tryGetCommand('COMMAND_2');
    compareTwoCommand.disabled = !(this.context.listView.selectedRows.length == 1); // !isSubmitEnabled;
    this.raiseOnChange();

    console.log(`compareTwoCommand.disabled: ${compareTwoCommand.disabled}`)
    console.log("refresh")
  }

Test:

  1. Create new ListView CommandSet solution, keep the two default buttons
  2. Update the _CommandSet.ts with onInit from the first example, and onListViewUpdatedv2 as presented above
  3. Debug
  4. Ensure that both buttons are visible, and button "COMMAND_1" is enabled, while "COMMAND_2" is disabled
  5. Select an item (any item) on the list
  6. See that the COMMAND_2 button is not enabled and the following is printed to the console:
    image
  7. Unselect the item and ensure that no items are selected
  8. See that COMMAND_2 button is still enabled, even though the following is printed to the console:
    image

@kkazala kkazala closed this as completed Mar 31, 2022
@kkazala kkazala reopened this Mar 31, 2022
@AJIXuMuK AJIXuMuK added area:spfx Category: SharePoint Framework (not extensions related) and removed Needs: Triage 🔍 Awaiting categorization and initial review. labels Mar 31, 2022
@AJIXuMuK AJIXuMuK added this to the 04-08 milestone Apr 1, 2022
@AJIXuMuK
Copy link
Collaborator

AJIXuMuK commented Apr 1, 2022

Thanks @kkazala for reporting this one!
The fix has been done and will be rolled out in the next few weeks.
You will still need to call raiseOnChange if the property is modified out of execute.

@AJIXuMuK AJIXuMuK added status:fixed-next-drop Issue planned to be fixed in an upcoming release. and removed type:bug-suspected Suspected bug (not working as designed/expected). See “type:bug-confirmed” for confirmed bugs. labels Apr 1, 2022
@AJIXuMuK
Copy link
Collaborator

This should be rolled out WW by now.

@msftbot
Copy link
Contributor

msftbot bot commented Apr 29, 2022

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

@msftbot msftbot bot locked as resolved and limited conversation to collaborators Apr 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area:spfx Category: SharePoint Framework (not extensions related) status:fixed-next-drop Issue planned to be fixed in an upcoming release.
Projects
None yet
Development

No branches or pull requests

2 participants