Transcript
Let's take a closer look at conditional statements, because I would like to improve how projects are edited on my app.
What I'd like to enable is that only the project owner can edit a project, but everyone can view a project.
Now, I'm currently logged in as a user called Zara, and let's see, by default, the projects that she can view and edit.
Okay, so Zara works on a large team, and here are all the ongoing projects.
She can filter them by Upcoming, In Progress, and Completed. Excellent.
Now, Zara is only the creator of some of these projects, but she can go ahead and edit any project that she would like.
I'd like to restrict this, and that will be set up using conditional logic.
There are two approaches we could adopt here:
We could make the button not clickable when the user is not the owner of a project.
Or we could hide the edit button altogether.
Let's explore both options.
I'm going to click on the Edit button and then Edit Workflow. And what we're going to do is have a look at this Only When input field. This is where we create the workflow conditional logic.
What I'm going to say is that: Only when the current user is the current row's project's owner — that's when this button is clickable.
And if it's not — if the person is not the owner — well, we could show them a popup, a warning message, etc.
Let's first see if this will work. But to understand what's going on — to know which one should work and which shouldn't — we need to look at the database first.
So let's have a look to see where Zara is the owner. Zara is the owner of Build AI App, but she's not the owner of Product Launch.
Okay, good. So let's test this.
So, Build AI App — it's at the bottom. Edit button — looks like it is working. Fantastic.
What about Product Launch? You can see that it is not working.
So, I kind of like the edit button to be there at all times,
but why don't we visually show a conditional design change when the button isn't clickable?
So let's do this:
Let's go to this button and let's define another condition.
We already have other conditions here — in actual fact, we can just delete that one there.
So let's just delete all of these conditions and start again.
I'm going to reinstate the hover — When this button is hovered, then I'm going to change the background color.
And I'm going to add a second one.
For this one, I'm going to say: When current user is not current row project's owner, and when that statement is true, then I want this element not to be clickable, and I'm going to change the background color to something lighter and the font color to something lighter as well.
Let's have a look at the results.
I can clearly see now, logged in as Zara, that I'm the owner of these particular ones.
But you can see that this hand icon has remained a pointer — because these buttons are not clickable — but these ones are.
Now, we don't need the workflow conditional step, so I'm just going to clean that up by running this workflow again and just removing this particular expression.
Nice and clean.