[WEB-383] fix: rendering state and members from different projects in sub-issues (#3996)

* fix: rendering the state and memebers from different projects in sub issues and exception handling while creating an issue from different project

* chore: handled different project issue properties in a new function handler
This commit is contained in:
guru_sainath 2024-03-20 18:07:35 +05:30 committed by GitHub
parent 4ea616f1cd
commit 621624e29f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 4 deletions

View File

@ -72,8 +72,8 @@ export const IssueProperty: React.FC<IIssueProperty> = (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" : ""}
/>
</div>
</div>

View File

@ -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<void>;
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;
}
};
}