Skip to content

Commit

Permalink
Merge pull request #2738 from daostack/CW-sync-all-roles
Browse files Browse the repository at this point in the history
Sync all roles downward by default
  • Loading branch information
matanfield authored Oct 8, 2024
2 parents ef235f2 + e540465 commit 105c698
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { UnsavedChangesPrompt } from "../UnsavedChangesPrompt";
import { getConfiguration } from "./configuration";
import { ProjectCreationFormValues } from "./types";
import styles from "./ProjectCreationForm.module.scss";
import { sortByTierDesc } from "@/shared/utils";

const NOTION_INTEGRATION_TOKEN_MASK = "************";

Expand Down Expand Up @@ -186,39 +187,46 @@ const ProjectCreationForm: FC<ProjectCreationFormProps> = (props) => {
const advancedSettings: SpaceAdvancedSettingsIntermediate = useMemo(() => {
const initialCircles = Object.values(governance?.circles || {});

const sortedRootCommonRoles = sortByTierDesc(rootCommonRoles);

const sortedParentCommonRoles = sortByTierDesc(parentCommonRoles);

const circlesWithInheritRoles = sortedRootCommonRoles.map((rootCommonRole, index) => {
const initialCircle = initialCircles.find(
(circle) => circle.derivedFrom?.circleId === rootCommonRole.circleId,
);

const isSelected = Boolean(!isEditing || initialCircle);
const roleForInheritance =
sortedParentCommonRoles.slice(0,2).find(
(parentRole) => parentRole.circleId === initialCircle?.inheritFrom?.circleId,
) || sortedParentCommonRoles[index];


return {
circleId: rootCommonRole.circleId,
circleName: `${rootCommonRole.circleName}s`,
selected: isSelected,
synced: Boolean(
isEditing ? initialCircle?.inheritGovernanceId : roleForInheritance ? true : false,
),
...(parentGovernanceId &&
roleForInheritance && {
inheritFrom: {
governanceId: parentGovernanceId,
circleId: roleForInheritance.circleId,
circleName: `${roleForInheritance.circleName}s`,
tier: roleForInheritance.tier,
},
}),
};
});

return {
permissionGovernanceId: isParentIsRoot
? parentGovernanceId
: rootGovernance?.id,
circles: rootCommonRoles.map((rootCommonRole, index) => {
const initialCircle = initialCircles.find(
(circle) => circle.derivedFrom?.circleId === rootCommonRole.circleId,
);
const isSelected = Boolean(!isEditing || initialCircle);
const roleForInheritance =
parentCommonRoles.find(
(parentRole) =>
parentRole.circleId === initialCircle?.inheritFrom?.circleId,
) || parentCommonRoles[index];

return {
circleId: rootCommonRole.circleId,
circleName: `${rootCommonRole.circleName}s`,
selected: isSelected,
synced: Boolean(
isEditing ? initialCircle?.inheritGovernanceId : index === 0,
),
...(parentGovernanceId &&
roleForInheritance && {
inheritFrom: {
governanceId: parentGovernanceId,
circleId: roleForInheritance.circleId,
circleName: `${roleForInheritance.circleName}s`,
tier: roleForInheritance.tier,
},
}),
};
}),
circles: circlesWithInheritRoles.reverse(),
};
}, [
rootGovernance?.id,
Expand Down
1 change: 1 addition & 0 deletions src/shared/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ export * from "./joinWithLast";
export * from "./getResizedFileUrl";
export * from "./areTimestampsEqual";
export * from "./parseMessageLink";
export * from "./sortByTierDesc";
export * from "./generateOptimisticFeedItem";
export * from "./generateFirstMessage";
8 changes: 8 additions & 0 deletions src/shared/utils/sortByTierDesc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type TierSortable = {
tier?: number | null;
};

export function sortByTierDesc<T extends TierSortable>(array: T[]): T[] {
return [...array].sort((a, b) => (b.tier ?? 0) - (a.tier ?? 0));
}

0 comments on commit 105c698

Please sign in to comment.