Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move constants to packages and refactor empty state #6137

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/constants/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"name": "@plane/constants",
"version": "0.24.0",
"private": true,
"main": "./src/index.ts"
"main": "./src/index.ts",
"dependencies": {
"@plane/types": "*"
}
}
9 changes: 9 additions & 0 deletions packages/constants/src/ce/ai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum AI_EDITOR_TASKS {
ASK_ANYTHING = "ASK_ANYTHING",
}

export const LOADING_TEXTS: {
[key in AI_EDITOR_TASKS]: string;
} = {
[AI_EDITOR_TASKS.ASK_ANYTHING]: "Pi is generating response",
};
4 changes: 4 additions & 0 deletions packages/constants/src/ce/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum EAuthModes {
SIGN_IN = "SIGN_IN",
SIGN_UP = "SIGN_UP",
}
26 changes: 26 additions & 0 deletions packages/constants/src/ce/empty-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { mergeEnums } from "../helper";
import {
EmptyStateDetails,
ECoreEmptyState,
coreEmptyStateDetails,
} from "../core/empty-state";

enum EEmptyState {}

// Create a combined enum
export const EmptyStateType = mergeEnums(ECoreEmptyState, EEmptyState);

const emptyStateDetails: Record<
EEmptyState,
EmptyStateDetails<EEmptyState>
> = {} as const;
Comment on lines +13 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve type safety of emptyStateDetails constant.

The current implementation uses type assertion (as const). Consider using a proper type guard or initialization with an empty object that matches the type.

-const emptyStateDetails: Record<
-  EEmptyState,
-  EmptyStateDetails<EEmptyState>
-> = {} as const;
+const emptyStateDetails: Record<
+  EEmptyState,
+  EmptyStateDetails<EEmptyState>
+> = Object.create(null);

Committable suggestion skipped: line range outside the PR's diff.


export type TEmptyStateType = ECoreEmptyState | EEmptyState;

export const EMPTY_STATE_DETAILS: Record<
TEmptyStateType,
EmptyStateDetails<TEmptyStateType>
> = {
...coreEmptyStateDetails,
...emptyStateDetails,
};
125 changes: 125 additions & 0 deletions packages/constants/src/ce/estimates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// types
import { TEstimateSystems } from "@plane/types";

export const MAX_ESTIMATE_POINT_INPUT_LENGTH = 20;

export enum EEstimateSystem {
POINTS = "points",
CATEGORIES = "categories",
TIME = "time",
}

export enum EEstimateUpdateStages {
CREATE = "create",
EDIT = "edit",
SWITCH = "switch",
}

export const estimateCount = {
min: 2,
max: 6,
};

export const ESTIMATE_SYSTEMS: TEstimateSystems = {
points: {
name: "Points",
templates: {
fibonacci: {
title: "Fibonacci",
values: [
{ id: undefined, key: 1, value: "1" },
{ id: undefined, key: 2, value: "2" },
{ id: undefined, key: 3, value: "3" },
{ id: undefined, key: 4, value: "5" },
{ id: undefined, key: 5, value: "8" },
{ id: undefined, key: 6, value: "13" },
],
},
linear: {
title: "Linear",
values: [
{ id: undefined, key: 1, value: "1" },
{ id: undefined, key: 2, value: "2" },
{ id: undefined, key: 3, value: "3" },
{ id: undefined, key: 4, value: "4" },
{ id: undefined, key: 5, value: "5" },
{ id: undefined, key: 6, value: "6" },
],
},
squares: {
title: "Squares",
values: [
{ id: undefined, key: 1, value: "1" },
{ id: undefined, key: 2, value: "4" },
{ id: undefined, key: 3, value: "9" },
{ id: undefined, key: 4, value: "16" },
{ id: undefined, key: 5, value: "25" },
{ id: undefined, key: 6, value: "36" },
],
},
custom: {
title: "Custom",
values: [
{ id: undefined, key: 1, value: "1" },
{ id: undefined, key: 2, value: "2" },
],
hide: true,
},
},
is_available: true,
is_ee: false,
},
categories: {
name: "Categories",
templates: {
t_shirt_sizes: {
title: "T-Shirt Sizes",
values: [
{ id: undefined, key: 1, value: "XS" },
{ id: undefined, key: 2, value: "S" },
{ id: undefined, key: 3, value: "M" },
{ id: undefined, key: 4, value: "L" },
{ id: undefined, key: 5, value: "XL" },
{ id: undefined, key: 6, value: "XXL" },
],
},
easy_to_hard: {
title: "Easy to hard",
values: [
{ id: undefined, key: 1, value: "Easy" },
{ id: undefined, key: 2, value: "Medium" },
{ id: undefined, key: 3, value: "Hard" },
{ id: undefined, key: 4, value: "Very Hard" },
],
},
custom: {
title: "Custom",
values: [
{ id: undefined, key: 1, value: "Easy" },
{ id: undefined, key: 2, value: "Hard" },
],
hide: true,
},
},
is_available: true,
is_ee: false,
},
time: {
name: "Time",
templates: {
hours: {
title: "Hours",
values: [
{ id: undefined, key: 1, value: "1" },
{ id: undefined, key: 2, value: "2" },
{ id: undefined, key: 3, value: "3" },
{ id: undefined, key: 4, value: "4" },
{ id: undefined, key: 5, value: "5" },
{ id: undefined, key: 6, value: "6" },
],
},
},
is_available: false,
is_ee: true,
},
};
5 changes: 5 additions & 0 deletions packages/constants/src/ce/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from "./ai";
export * from "./estimates";
export * from "./empty-state";
export * from "./issues";
export * from "./user-permissions";
34 changes: 34 additions & 0 deletions packages/constants/src/ce/issues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { TIssueActivityComment } from "@plane/types";

export enum EActivityFilterType {
ACTIVITY = "ACTIVITY",
COMMENT = "COMMENT",
}

export type TActivityFilters = EActivityFilterType;

export const ACTIVITY_FILTER_TYPE_OPTIONS: Record<EActivityFilterType, { label: string }> = {
[EActivityFilterType.ACTIVITY]: {
label: "Updates",
},
[EActivityFilterType.COMMENT]: {
label: "Comments",
},
};

export const defaultActivityFilters: TActivityFilters[] = [EActivityFilterType.ACTIVITY, EActivityFilterType.COMMENT];

export type TActivityFilterOption = {
key: EActivityFilterType;
label: string;
isSelected: boolean;
onClick: () => void;
};

export const filterActivityOnSelectedFilters = (
activity: TIssueActivityComment[],
filter: TActivityFilters[]
): TIssueActivityComment[] =>
activity.filter((activity) => filter.includes(activity.activity_type as TActivityFilters));
Comment on lines +28 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add input validation and error handling

The filterActivityOnSelectedFilters function should validate its inputs and handle edge cases.

 export const filterActivityOnSelectedFilters = (
   activity: TIssueActivityComment[],
   filter: TActivityFilters[]
 ): TIssueActivityComment[] => {
+  if (!Array.isArray(activity) || !Array.isArray(filter)) {
+    throw new TypeError('Both arguments must be arrays');
+  }
+  if (filter.length === 0) return activity;
   return activity.filter((activity) => filter.includes(activity.activity_type as TActivityFilters));
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const filterActivityOnSelectedFilters = (
activity: TIssueActivityComment[],
filter: TActivityFilters[]
): TIssueActivityComment[] =>
activity.filter((activity) => filter.includes(activity.activity_type as TActivityFilters));
export const filterActivityOnSelectedFilters = (
activity: TIssueActivityComment[],
filter: TActivityFilters[]
): TIssueActivityComment[] => {
if (!Array.isArray(activity) || !Array.isArray(filter)) {
throw new TypeError('Both arguments must be arrays');
}
if (filter.length === 0) return activity;
return activity.filter((activity) => filter.includes(activity.activity_type as TActivityFilters));
}


export const ENABLE_ISSUE_DEPENDENCIES = false;
36 changes: 36 additions & 0 deletions packages/constants/src/ce/user-permissions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export enum EUserPermissionsLevel {
WORKSPACE = "WORKSPACE",
PROJECT = "PROJECT",
}
export type TUserPermissionsLevel = EUserPermissionsLevel;

export enum EUserPermissions {
ADMIN = 20,
MEMBER = 15,
GUEST = 5,
}
export type TUserPermissions = EUserPermissions;

export type TUserAllowedPermissionsObject = {
create: TUserPermissions[];
update: TUserPermissions[];
delete: TUserPermissions[];
read: TUserPermissions[];
};
export type TUserAllowedPermissions = {
workspace: {
[key: string]: Partial<TUserAllowedPermissionsObject>;
};
project: {
[key: string]: Partial<TUserAllowedPermissionsObject>;
};
};

export const USER_ALLOWED_PERMISSIONS: TUserAllowedPermissions = {
workspace: {
dashboard: {
read: [EUserPermissions.ADMIN, EUserPermissions.MEMBER, EUserPermissions.GUEST],
},
},
project: {},
};
71 changes: 71 additions & 0 deletions packages/constants/src/core/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// types
import { TXAxisValues, TYAxisValues } from "@plane/types";

export const ANALYTICS_TABS = [
{ key: "scope_and_demand", title: "Scope and Demand" },
{ key: "custom", title: "Custom Analytics" },
];

export const ANALYTICS_X_AXIS_VALUES: { value: TXAxisValues; label: string }[] = [
{
value: "state_id",
label: "State name",
},
{
value: "state__group",
label: "State group",
},
{
value: "priority",
label: "Priority",
},
{
value: "labels__id",
label: "Label",
},
{
value: "assignees__id",
label: "Assignee",
},
{
value: "estimate_point__value",
label: "Estimate point",
},
{
value: "issue_cycle__cycle_id",
label: "Cycle",
},
{
value: "issue_module__module_id",
label: "Module",
},
{
value: "completed_at",
label: "Completed date",
},
{
value: "target_date",
label: "Due date",
},
{
value: "start_date",
label: "Start date",
},
{
value: "created_at",
label: "Created date",
},
];

export const ANALYTICS_Y_AXIS_VALUES: { value: TYAxisValues; label: string }[] = [
{
value: "issue_count",
label: "Issue Count",
},
{
value: "estimate",
label: "Estimate",
},
];

export const DATE_KEYS = ["completed_at", "target_date", "start_date", "created_at"];
File renamed without changes.
Loading
Loading