[WEB-2443] fix: role validation and code refactor (#5596)

* chore: delete cycle toast message updated

* fix: view page empty state

* fix: project settings automation

* fix: intake delete action

* fix: project label validation

* fix: project label validation

* fix: project state permission updated

* chore: code refactor
This commit is contained in:
Anmol Singh Bhatia 2024-09-12 20:08:13 +05:30 committed by GitHub
parent 5f1939cdeb
commit 441385fc95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 134 additions and 77 deletions

View file

@ -25,7 +25,7 @@ const ProjectViewIssuesPage = observer(() => {
const project = projectId ? getProjectById(projectId.toString()) : undefined; const project = projectId ? getProjectById(projectId.toString()) : undefined;
const pageTitle = project?.name && projectView?.name ? `${project?.name} - ${projectView?.name}` : undefined; const pageTitle = project?.name && projectView?.name ? `${project?.name} - ${projectView?.name}` : undefined;
const { error } = useSWR( const { error, isLoading } = useSWR(
workspaceSlug && projectId && viewId ? `VIEW_DETAILS_${viewId.toString()}` : null, workspaceSlug && projectId && viewId ? `VIEW_DETAILS_${viewId.toString()}` : null,
workspaceSlug && projectId && viewId workspaceSlug && projectId && viewId
? () => fetchViewDetails(workspaceSlug.toString(), projectId.toString(), viewId.toString()) ? () => fetchViewDetails(workspaceSlug.toString(), projectId.toString(), viewId.toString())

View file

@ -33,7 +33,7 @@ export const AutoArchiveAutomation: React.FC<Props> = observer((props) => {
const isAdmin = allowPermissions( const isAdmin = allowPermissions(
[EUserPermissions.ADMIN], [EUserPermissions.ADMIN],
EUserPermissionsLevel.PROJECT, EUserPermissionsLevel.PROJECT,
currentProjectDetails?.workspace_detail.slug, currentProjectDetails?.workspace_detail?.slug,
currentProjectDetails?.id currentProjectDetails?.id
); );

View file

@ -67,7 +67,7 @@ export const InboxContentRoot: FC<TInboxContentRoot> = observer((props) => {
EUserPermissionsLevel.PROJECT EUserPermissionsLevel.PROJECT
); );
const isGuest = projectPermissionsByWorkspaceSlugAndProjectId(workspaceSlug, projectId) === EUserPermissions.GUEST; const isGuest = projectPermissionsByWorkspaceSlugAndProjectId(workspaceSlug, projectId) === EUserPermissions.GUEST;
const isOwner = inboxIssue.issue.created_by === currentUser?.id; const isOwner = inboxIssue?.issue.created_by === currentUser?.id;
const readOnly = !isOwner && isGuest; const readOnly = !isOwner && isGuest;
if (!inboxIssue) return <></>; if (!inboxIssue) return <></>;

View file

@ -91,7 +91,6 @@ export const InboxIssueProperties: FC<TInboxIssueProperties> = observer((props)
{/* labels */} {/* labels */}
<div className="h-7"> <div className="h-7">
<IssueLabelSelect <IssueLabelSelect
createLabelEnabled={false}
setIsOpen={() => {}} setIsOpen={() => {}}
value={data?.label_ids || []} value={data?.label_ids || []}
onChange={(labelIds) => handleData("label_ids", labelIds)} onChange={(labelIds) => handleData("label_ids", labelIds)}

View file

@ -26,10 +26,11 @@ import { ETabIndices } from "@/constants/tab-indices";
import { getDate, renderFormattedPayloadDate } from "@/helpers/date-time.helper"; import { getDate, renderFormattedPayloadDate } from "@/helpers/date-time.helper";
import { getTabIndex } from "@/helpers/tab-indices.helper"; import { getTabIndex } from "@/helpers/tab-indices.helper";
// hooks // hooks
import { useProjectEstimates, useProject } from "@/hooks/store"; import { useProjectEstimates, useProject, useUserPermissions } from "@/hooks/store";
import { usePlatformOS } from "@/hooks/use-platform-os"; import { usePlatformOS } from "@/hooks/use-platform-os";
// plane web components // plane web components
import { IssueIdentifier } from "@/plane-web/components/issues"; import { IssueIdentifier } from "@/plane-web/components/issues";
import { EUserPermissions, EUserPermissionsLevel } from "@/plane-web/constants/user-permissions";
type TIssueDefaultPropertiesProps = { type TIssueDefaultPropertiesProps = {
control: Control<TIssue>; control: Control<TIssue>;
@ -67,11 +68,14 @@ export const IssueDefaultProperties: React.FC<TIssueDefaultPropertiesProps> = ob
const { areEstimateEnabledByProjectId } = useProjectEstimates(); const { areEstimateEnabledByProjectId } = useProjectEstimates();
const { getProjectById } = useProject(); const { getProjectById } = useProject();
const { isMobile } = usePlatformOS(); const { isMobile } = usePlatformOS();
const { allowPermissions } = useUserPermissions();
// derived values // derived values
const projectDetails = getProjectById(projectId); const projectDetails = getProjectById(projectId);
const { getIndex } = getTabIndex(ETabIndices.ISSUE_FORM, isMobile); const { getIndex } = getTabIndex(ETabIndices.ISSUE_FORM, isMobile);
const canCreateLabel = allowPermissions([EUserPermissions.ADMIN], EUserPermissionsLevel.PROJECT);
const minDate = getDate(startDate); const minDate = getDate(startDate);
minDate?.setDate(minDate.getDate()); minDate?.setDate(minDate.getDate());
@ -150,6 +154,7 @@ export const IssueDefaultProperties: React.FC<TIssueDefaultPropertiesProps> = ob
}} }}
projectId={projectId ?? undefined} projectId={projectId ?? undefined}
tabIndex={getIndex("label_ids")} tabIndex={getIndex("label_ids")}
createLabelEnabled={canCreateLabel}
/> />
</div> </div>
)} )}

View file

@ -35,7 +35,7 @@ export const IssueLabelSelect: React.FC<Props> = observer((props) => {
label, label,
disabled = false, disabled = false,
tabIndex, tabIndex,
createLabelEnabled = true, createLabelEnabled = false,
buttonClassName, buttonClassName,
} = props; } = props;
// router // router

View file

@ -28,10 +28,19 @@ interface ILabelItemBlock {
handleLabelDelete: (label: IIssueLabel) => void; handleLabelDelete: (label: IIssueLabel) => void;
isLabelGroup?: boolean; isLabelGroup?: boolean;
dragHandleRef: MutableRefObject<HTMLButtonElement | null>; dragHandleRef: MutableRefObject<HTMLButtonElement | null>;
disabled?: boolean;
} }
export const LabelItemBlock = (props: ILabelItemBlock) => { export const LabelItemBlock = (props: ILabelItemBlock) => {
const { label, isDragging, customMenuItems, handleLabelDelete, isLabelGroup, dragHandleRef } = props; const {
label,
isDragging,
customMenuItems,
handleLabelDelete,
isLabelGroup,
dragHandleRef,
disabled = false,
} = props;
// states // states
const [isMenuActive, setIsMenuActive] = useState(false); const [isMenuActive, setIsMenuActive] = useState(false);
// refs // refs
@ -42,15 +51,18 @@ export const LabelItemBlock = (props: ILabelItemBlock) => {
return ( return (
<div className="group flex items-center"> <div className="group flex items-center">
<div className="flex items-center"> <div className="flex items-center">
{!disabled && (
<DragHandle <DragHandle
className={cn("opacity-0 group-hover:opacity-100", { className={cn("opacity-0 group-hover:opacity-100", {
"opacity-100": isDragging, "opacity-100": isDragging,
})} })}
ref={dragHandleRef} ref={dragHandleRef}
/> />
)}
<LabelName color={label.color} name={label.name} isGroup={isLabelGroup ?? false} /> <LabelName color={label.color} name={label.name} isGroup={isLabelGroup ?? false} />
</div> </div>
{!disabled && (
<div <div
ref={actionSectionRef} ref={actionSectionRef}
className={`absolute right-2.5 flex items-start gap-3.5 px-4 ${ className={`absolute right-2.5 flex items-start gap-3.5 px-4 ${
@ -74,12 +86,16 @@ export const LabelItemBlock = (props: ILabelItemBlock) => {
</CustomMenu> </CustomMenu>
{!isLabelGroup && ( {!isLabelGroup && (
<div className="py-0.5"> <div className="py-0.5">
<button className="flex h-4 w-4 items-center justify-start gap-2" onClick={() => handleLabelDelete(label)}> <button
className="flex h-4 w-4 items-center justify-start gap-2"
onClick={() => handleLabelDelete(label)}
>
<X className="h-4 w-4 flex-shrink-0 text-custom-sidebar-text-400" /> <X className="h-4 w-4 flex-shrink-0 text-custom-sidebar-text-400" />
</button> </button>
</div> </div>
)} )}
</div> </div>
)}
</div> </div>
); );
}; };

View file

@ -23,10 +23,20 @@ type Props = {
droppedLabelId: string | undefined, droppedLabelId: string | undefined,
dropAtEndOfList: boolean dropAtEndOfList: boolean
) => void; ) => void;
isEditable?: boolean;
}; };
export const ProjectSettingLabelItem: React.FC<Props> = (props) => { export const ProjectSettingLabelItem: React.FC<Props> = (props) => {
const { label, setIsUpdating, handleLabelDelete, isChild, isLastChild, isParentDragging = false, onDrop } = props; const {
label,
setIsUpdating,
handleLabelDelete,
isChild,
isLastChild,
isParentDragging = false,
onDrop,
isEditable = false,
} = props;
// states // states
const [isEditLabelForm, setEditLabelForm] = useState(false); const [isEditLabelForm, setEditLabelForm] = useState(false);
// router // router
@ -91,6 +101,7 @@ export const ProjectSettingLabelItem: React.FC<Props> = (props) => {
customMenuItems={customMenuItems} customMenuItems={customMenuItems}
handleLabelDelete={handleLabelDelete} handleLabelDelete={handleLabelDelete}
dragHandleRef={dragHandleRef} dragHandleRef={dragHandleRef}
disabled={!isEditable}
/> />
)} )}
</div> </div>

View file

@ -14,7 +14,8 @@ import {
ProjectSettingLabelItem, ProjectSettingLabelItem,
} from "@/components/labels"; } from "@/components/labels";
import { EmptyStateType } from "@/constants/empty-state"; import { EmptyStateType } from "@/constants/empty-state";
import { useLabel } from "@/hooks/store"; import { useLabel, useUserPermissions } from "@/hooks/store";
import { EUserPermissions, EUserPermissionsLevel } from "@/plane-web/constants/user-permissions";
// components // components
// ui // ui
// types // types
@ -31,6 +32,10 @@ export const ProjectSettingsLabelList: React.FC = observer(() => {
const { workspaceSlug, projectId } = useParams(); const { workspaceSlug, projectId } = useParams();
// store hooks // store hooks
const { projectLabels, updateLabelPosition, projectLabelsTree } = useLabel(); const { projectLabels, updateLabelPosition, projectLabelsTree } = useLabel();
const { allowPermissions } = useUserPermissions();
// derived values
const isEditable = allowPermissions([EUserPermissions.ADMIN], EUserPermissionsLevel.PROJECT);
const newLabel = () => { const newLabel = () => {
setIsUpdating(false); setIsUpdating(false);
@ -65,9 +70,11 @@ export const ProjectSettingsLabelList: React.FC = observer(() => {
/> />
<div className="flex items-center justify-between border-b border-custom-border-100 pb-3.5"> <div className="flex items-center justify-between border-b border-custom-border-100 pb-3.5">
<h3 className="text-xl font-medium">Labels</h3> <h3 className="text-xl font-medium">Labels</h3>
{isEditable && (
<Button variant="primary" onClick={newLabel} size="sm"> <Button variant="primary" onClick={newLabel} size="sm">
Add label Add label
</Button> </Button>
)}
</div> </div>
<div className="w-full py-2"> <div className="w-full py-2">
{showLabelForm && ( {showLabelForm && (

View file

@ -6,6 +6,8 @@ import { Plus } from "lucide-react";
import { IState, TStateGroups } from "@plane/types"; import { IState, TStateGroups } from "@plane/types";
// components // components
import { StateList, StateCreate } from "@/components/project-states"; import { StateList, StateCreate } from "@/components/project-states";
import { useUserPermissions } from "@/hooks/store";
import { EUserPermissions, EUserPermissionsLevel } from "ee/constants/user-permissions";
type TGroupItem = { type TGroupItem = {
workspaceSlug: string; workspaceSlug: string;
@ -17,22 +19,28 @@ type TGroupItem = {
export const GroupItem: FC<TGroupItem> = observer((props) => { export const GroupItem: FC<TGroupItem> = observer((props) => {
const { workspaceSlug, projectId, groupKey, groupedStates, states } = props; const { workspaceSlug, projectId, groupKey, groupedStates, states } = props;
// store hooks
const { allowPermissions } = useUserPermissions();
// state // state
const [createState, setCreateState] = useState(false); const [createState, setCreateState] = useState(false);
const isEditable = allowPermissions([EUserPermissions.ADMIN], EUserPermissionsLevel.PROJECT);
return ( return (
<div className="space-y-3"> <div className="space-y-3">
<div className="flex justify-between items-center"> <div className="flex justify-between items-center">
<div className="text-base font-medium text-custom-text-200 capitalize">{groupKey}</div> <div className="text-base font-medium text-custom-text-200 capitalize">{groupKey}</div>
{isEditable && (
<div <div
className="flex-shrink-0 w-6 h-6 rounded flex justify-center items-center overflow-hidden transition-colors hover:bg-custom-background-80 cursor-pointer text-custom-primary-100/80 hover:text-custom-primary-100" className="flex-shrink-0 w-6 h-6 rounded flex justify-center items-center overflow-hidden transition-colors hover:bg-custom-background-80 cursor-pointer text-custom-primary-100/80 hover:text-custom-primary-100"
onClick={() => !createState && setCreateState(true)} onClick={() => !createState && setCreateState(true)}
> >
<Plus className="w-4 h-4" /> <Plus className="w-4 h-4" />
</div> </div>
)}
</div> </div>
{createState && ( {isEditable && createState && (
<StateCreate <StateCreate
workspaceSlug={workspaceSlug} workspaceSlug={workspaceSlug}
projectId={projectId} projectId={projectId}
@ -48,6 +56,7 @@ export const GroupItem: FC<TGroupItem> = observer((props) => {
groupKey={groupKey} groupKey={groupKey}
groupedStates={groupedStates} groupedStates={groupedStates}
states={states} states={states}
disabled={!isEditable}
/> />
</div> </div>
</div> </div>

View file

@ -24,10 +24,11 @@ type TStateItem = {
groupedStates: Record<string, IState[]>; groupedStates: Record<string, IState[]>;
totalStates: number; totalStates: number;
state: IState; state: IState;
disabled?: boolean;
}; };
export const StateItem: FC<TStateItem> = observer((props) => { export const StateItem: FC<TStateItem> = observer((props) => {
const { workspaceSlug, projectId, groupKey, groupedStates, totalStates, state } = props; const { workspaceSlug, projectId, groupKey, groupedStates, totalStates, state, disabled = false } = props;
// hooks // hooks
const { moveStatePosition } = useProjectState(); const { moveStatePosition } = useProjectState();
// states // states
@ -131,7 +132,7 @@ export const StateItem: FC<TStateItem> = observer((props) => {
)} )}
> >
{/* draggable indicator */} {/* draggable indicator */}
{totalStates != 1 && ( {!disabled && totalStates != 1 && (
<div className="flex-shrink-0 w-3 h-3 rounded-sm absolute left-0 hidden group-hover:flex justify-center items-center transition-colors bg-custom-background-90 cursor-pointer text-custom-text-200 hover:text-custom-text-100"> <div className="flex-shrink-0 w-3 h-3 rounded-sm absolute left-0 hidden group-hover:flex justify-center items-center transition-colors bg-custom-background-90 cursor-pointer text-custom-text-200 hover:text-custom-text-100">
<GripVertical className="w-3 h-3" /> <GripVertical className="w-3 h-3" />
</div> </div>
@ -148,6 +149,7 @@ export const StateItem: FC<TStateItem> = observer((props) => {
<p className="text-xs text-custom-text-200">{state.description}</p> <p className="text-xs text-custom-text-200">{state.description}</p>
</div> </div>
{!disabled && (
<div className="hidden group-hover:flex items-center gap-2"> <div className="hidden group-hover:flex items-center gap-2">
{/* state mark as default option */} {/* state mark as default option */}
<div className="flex-shrink-0 text-xs transition-all"> <div className="flex-shrink-0 text-xs transition-all">
@ -167,9 +169,15 @@ export const StateItem: FC<TStateItem> = observer((props) => {
> >
<Pencil className="w-3 h-3" /> <Pencil className="w-3 h-3" />
</button> </button>
<StateDelete workspaceSlug={workspaceSlug} projectId={projectId} totalStates={totalStates} state={state} /> <StateDelete
workspaceSlug={workspaceSlug}
projectId={projectId}
totalStates={totalStates}
state={state}
/>
</div> </div>
</div> </div>
)}
</div> </div>
{/* draggable drop bottom indicator */} {/* draggable drop bottom indicator */}

View file

@ -12,10 +12,11 @@ type TStateList = {
groupKey: TStateGroups; groupKey: TStateGroups;
groupedStates: Record<string, IState[]>; groupedStates: Record<string, IState[]>;
states: IState[]; states: IState[];
disabled?: boolean;
}; };
export const StateList: FC<TStateList> = observer((props) => { export const StateList: FC<TStateList> = observer((props) => {
const { workspaceSlug, projectId, groupKey, groupedStates, states } = props; const { workspaceSlug, projectId, groupKey, groupedStates, states, disabled = false } = props;
return ( return (
<> <>
@ -28,6 +29,7 @@ export const StateList: FC<TStateList> = observer((props) => {
groupedStates={groupedStates} groupedStates={groupedStates}
totalStates={states.length || 0} totalStates={states.length || 0}
state={state} state={state}
disabled={disabled}
/> />
))} ))}
</> </>

View file

@ -100,7 +100,7 @@ export const PROJECT_ERROR_MESSAGES = {
}, },
cycleDeleteError: { cycleDeleteError: {
title: "Error", title: "Error",
message: "Failed to delete project", message: "Failed to delete cycle",
}, },
moduleDeleteError: { moduleDeleteError: {
title: "Error", title: "Error",