extensions icon indicating copy to clipboard operation
extensions copied to clipboard

Adding Team functionality in Asana

Open stanty522 opened this issue 3 years ago • 4 comments
trafficstars

Description

Made changes to the Asana extension to include Teams. This creates a filter for Projects to only be searched under the selected Team.

This addresses an earlier issue where the query for Projects would time out if a workspace had too many existing Projects.

Screencast

CleanShot 2022-10-17 at 14 31 14

Checklist

[ ✅] I read the extension guidelines [ ✅] I read the documentation about publishing [ ✅] I ran npm run build and tested this distribution build in Raycast [✅ ] I checked that files in the assets folder are used by the extension itself [ ✅] I checked that assets used by the README are placed outside of the metadata folder

stanty522 avatar Oct 17 '22 06:10 stanty522

Thank you for your first contribution! :tada:

🔔 @thomaslombart you might want to have a look.

raycastbot avatar Oct 17 '22 06:10 raycastbot

The documentation makes the distinction that if it's just a personal workspace there's just one team possible.

image

Maybe a logic check if the person is in an organisation or a workspace and therefore changes it accordingly?

Or another clunky solution - have an Asana for organisations extension and another one for personal workspaces.

stanty522 avatar Oct 18 '22 12:10 stanty522

Oh, didn't know that. Then I guess, the team's field can simply be hidden if there's only one team available for the user and if the experience is the same when you add a task to a team instead of a workspace for a personal use 🙂

thomaslombart avatar Oct 19 '22 13:10 thomaslombart

Hey here's my attempt at trying to fix this. Unfortunately I'm running into some basic syntax error :(

However I think the logic will work. Basically in the Asana documentation there is a boolean property for workspaces that informs us if its an organization or not. So basically I've added this to the workspaces.ts and then I plan to use this as a variable in the CreatTaskForm.tsx which will be a conditional if statement to return the form drop down for teams or not. If true (i,e, workspace is an organization) then return teams form drop down, else don't return.

const isOrganization = workspaces?.map((workspace) => workspace.is_organization);

  if (isOrganization === true) {
      return 
        <Form.Dropdown title="Teams" storeValue {...itemProps.team}>
        {teams?.map((teams) => {
          return (
          <Form.Dropdown.Item 
            key={teams.gid} 
            value={teams.gid} 
            title={teams.name} 
            />
          );
        })}
      </Form.Dropdown>

stanty522 avatar Oct 24 '22 12:10 stanty522

@thomaslombart

I figured out the logic of checking if the workspace is an organisation or not. While this works, it unfortunately creates a new issue whereby the workspaces that are NOT organisations cannot select a team, and if a team is not selected a project cannot be selected.

        {workspaces?.map((workspace) => {
            if (workspace.is_organization) {
              return (
                <Form.Dropdown title="Teams" storeValue {...itemProps.team}>
                {teams?.map((teams) => {
                  return (
                  <Form.Dropdown.Item 
                    key={teams.gid} 
                    value={teams.gid} 
                    title={teams.name} 
                    />
                  );
                })}
              </Form.Dropdown>
              );
            }
          })
        }

      <Form.TagPicker title="Projects" placeholder="Select one or more projects" storeValue {...itemProps.projects}>
        {allProjects?.map((project) => {
          return (
            <Form.TagPicker.Item
              key={project.gid}
              icon={getProjectIcon(project)}
              title={project.name}
              value={project.gid}
            />
          );
        })}
      </Form.TagPicker>

stanty522 avatar Oct 31 '22 06:10 stanty522

and if a team is not selected a project cannot be selected.

But in that case, the projects can be retrieved based on a workspace instead of a team?

thomaslombart avatar Nov 02 '22 10:11 thomaslombart

But in that case, the projects can be retrieved based on a workspace instead of a team?

Yes that's possible but I'm not sure how I'd go about that without over complicating the structure :(

stanty522 avatar Nov 03 '22 07:11 stanty522

Then, I'll take a look at that probably end of next week. I'm focusing on another project at the moment 😊

thomaslombart avatar Nov 03 '22 08:11 thomaslombart

After taking a look, I think it can be done in a few steps:

  • useProjects and getProjects should be modified to handle an additional workspace parameter. The algorithm would be pretty simple: the team is used first to retrieve the projects. But, if it's undefined (in the case you mentioned), then the workspace is used to retrieve it.
  • Then in CreateTaskForm, you could pass the workspace and the team to useProjects: useProjects({ workspace, team })

Otherwise, someone from the Raycast team told me the API call to retrieve the projects in the native extension was different than the one used here. Here we use the /projects endpoint whereas in the native extension it's /workspaces/{workspaceId}/typeahead with the resource_type param specified as project. It may be easier to switch to it to remove the project's pagination issue here.

thomaslombart avatar Nov 10 '22 10:11 thomaslombart

So I tried the typeahead thing first, and I'm not sure if I did it correctly, but I just ended up with the same issue of having too many projects and for it to even work I had to put the optional parameter of limit. I'm not sure if there's a way to only start the query after X characters have been typed so it won't try to query everything from the start.

The steps you suggested, I only got as far as to add the additional workspace parameter to getProjects and useProjects. Im still quite new to typescript and async programming so not exactly sure how to implement the if then statement check that would retrieve workspace. Is there a similar piece of code where this is done so I can learn from that?

stanty522 avatar Nov 14 '22 09:11 stanty522

Hey there, I'm not sure where this could have been done... Unfortunately, I won't have enough bandwidth to work on that this week. I'll take another look at it probably next week or maybe the week after.

thomaslombart avatar Nov 15 '22 17:11 thomaslombart