diff --git a/web/components/issues/sub-issues/properties.tsx b/web/components/issues/sub-issues/properties.tsx index 33f346b6d..6c611468a 100644 --- a/web/components/issues/sub-issues/properties.tsx +++ b/web/components/issues/sub-issues/properties.tsx @@ -72,8 +72,8 @@ export const IssueProperty: React.FC = (props) => { } disabled={!disabled} multiple - buttonVariant={issue.assignee_ids.length > 0 ? "transparent-without-text" : "border-without-text"} - buttonClassName={issue.assignee_ids.length > 0 ? "hover:bg-transparent px-0" : ""} + buttonVariant={(issue?.assignee_ids || []).length > 0 ? "transparent-without-text" : "border-without-text"} + buttonClassName={(issue?.assignee_ids || []).length > 0 ? "hover:bg-transparent px-0" : ""} /> diff --git a/web/store/issue/issue-details/sub_issues.store.ts b/web/store/issue/issue-details/sub_issues.store.ts index ca1528928..f4bd20772 100644 --- a/web/store/issue/issue-details/sub_issues.store.ts +++ b/web/store/issue/issue-details/sub_issues.store.ts @@ -1,10 +1,9 @@ import concat from "lodash/concat"; import pull from "lodash/pull"; import set from "lodash/set"; +import uniq from "lodash/uniq"; import update from "lodash/update"; import { action, makeObservable, observable, runInAction } from "mobx"; -// services -import { IssueService } from "@/services/issue"; // types import { TIssue, @@ -13,6 +12,9 @@ import { TIssueSubIssuesIdMap, TSubIssuesStateDistribution, } from "@plane/types"; +// services +import { IssueService } from "@/services/issue"; +// store import { IIssueDetail } from "./root.store"; export interface IIssueSubIssuesStoreActions { @@ -48,6 +50,7 @@ export interface IIssueSubIssuesStore extends IIssueSubIssuesStoreActions { subIssuesByIssueId: (issueId: string) => string[] | undefined; subIssueHelpersByIssueId: (issueId: string) => TSubIssueHelpers; // actions + fetchOtherProjectProperties: (workspaceSlug: string, projectIds: string[]) => Promise; setSubIssueHelpers: (parentIssueId: string, key: TSubIssueHelpersKeys, value: string) => void; } @@ -74,6 +77,7 @@ export class IssueSubIssuesStore implements IIssueSubIssuesStore { updateSubIssue: action, removeSubIssue: action, deleteSubIssue: action, + fetchOtherProjectProperties: action, }); // root store this.rootIssueDetailStore = rootStore; @@ -116,6 +120,12 @@ export class IssueSubIssuesStore implements IIssueSubIssuesStore { this.rootIssueDetailStore.rootIssueStore.issues.addIssue(subIssues); + // fetch other issues states and members when sub-issues are from different project + if (subIssues && subIssues.length > 0) { + const otherProjectIds = uniq(subIssues.map((issue) => issue.project_id).filter((id) => id !== projectId)); + this.fetchOtherProjectProperties(workspaceSlug, otherProjectIds); + } + runInAction(() => { set(this.subIssuesStateDistribution, parentIssueId, subIssuesStateDistribution); set( @@ -140,6 +150,12 @@ export class IssueSubIssuesStore implements IIssueSubIssuesStore { const subIssuesStateDistribution = response?.state_distribution; const subIssues = response.sub_issues as TIssue[]; + // fetch other issues states and members when sub-issues are from different project + if (subIssues && subIssues.length > 0) { + const otherProjectIds = uniq(subIssues.map((issue) => issue.project_id).filter((id) => id !== projectId)); + this.fetchOtherProjectProperties(workspaceSlug, otherProjectIds); + } + runInAction(() => { Object.keys(subIssuesStateDistribution).forEach((key) => { const stateGroup = key as keyof TSubIssuesStateDistribution; @@ -292,4 +308,30 @@ export class IssueSubIssuesStore implements IIssueSubIssuesStore { throw error; } }; + + fetchOtherProjectProperties = async (workspaceSlug: string, projectIds: string[]) => { + try { + if (projectIds.length > 0) { + for (const projectId of projectIds) { + // fetching other project states + this.rootIssueDetailStore.rootIssueStore.rootStore.state.fetchProjectStates(workspaceSlug, projectId); + // fetching other project members + this.rootIssueDetailStore.rootIssueStore.rootStore.memberRoot.project.fetchProjectMembers( + workspaceSlug, + projectId + ); + // fetching other project labels + this.rootIssueDetailStore.rootIssueStore.rootStore.label.fetchProjectLabels(workspaceSlug, projectId); + // fetching other project cycles + this.rootIssueDetailStore.rootIssueStore.rootStore.cycle.fetchAllCycles(workspaceSlug, projectId); + // fetching other project modules + this.rootIssueDetailStore.rootIssueStore.rootStore.module.fetchModules(workspaceSlug, projectId); + // fetching other project estimates + this.rootIssueDetailStore.rootIssueStore.rootStore.estimate.fetchProjectEstimates(workspaceSlug, projectId); + } + } + } catch (error) { + throw error; + } + }; }