Skip to content
Merged
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
3 changes: 0 additions & 3 deletions web/ce/constants/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,4 @@ export const filterActivityOnSelectedFilters = (
): TIssueActivityComment[] =>
activity.filter((activity) => filter.includes(activity.activity_type as TActivityFilters));

// boolean to decide if the local db cache is enabled
export const ENABLE_LOCAL_DB_CACHE = false;

export const ENABLE_ISSUE_DEPENDENCIES = false;
38 changes: 18 additions & 20 deletions web/core/components/workspace/sidebar/help-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { usePlatformOS } from "@/hooks/use-platform-os";
// plane web components
import { PlaneVersionNumber } from "@/plane-web/components/global";
import { WorkspaceEditionBadge } from "@/plane-web/components/workspace";
import { ENABLE_LOCAL_DB_CACHE } from "@/plane-web/constants/issues";

export interface WorkspaceHelpSectionProps {
setSidebarActive?: React.Dispatch<React.SetStateAction<boolean>>;
Expand Down Expand Up @@ -111,23 +110,21 @@ export const SidebarHelpSection: React.FC<WorkspaceHelpSectionProps> = observer(
</a>
</CustomMenu.MenuItem>
<div className="my-1 border-t border-custom-border-200" />
{ENABLE_LOCAL_DB_CACHE && (
<CustomMenu.MenuItem>
<div
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
className="flex w-full items-center justify-between text-xs hover:bg-custom-background-80"
>
<span className="racking-tight">Local Cache</span>
<ToggleSwitch
value={canUseLocalDB}
onChange={() => toggleLocalDB(workspaceSlug?.toString(), projectId?.toString())}
/>
</div>
</CustomMenu.MenuItem>
)}
<CustomMenu.MenuItem>
<div
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
className="flex w-full items-center justify-between text-xs hover:bg-custom-background-80"
>
<span className="racking-tight">Local Cache</span>
<ToggleSwitch
value={canUseLocalDB}
onChange={() => toggleLocalDB(workspaceSlug?.toString(), projectId?.toString())}
/>
</div>
</CustomMenu.MenuItem>
<CustomMenu.MenuItem>
<button
type="button"
Expand Down Expand Up @@ -173,8 +170,9 @@ export const SidebarHelpSection: React.FC<WorkspaceHelpSectionProps> = observer(
<Tooltip tooltipContent={`${isCollapsed ? "Expand" : "Hide"}`} isMobile={isMobile}>
<button
type="button"
className={`grid place-items-center rounded-md p-1 text-custom-text-200 outline-none hover:bg-custom-background-90 hover:text-custom-text-100 ${isCollapsed ? "w-full" : ""
}`}
className={`grid place-items-center rounded-md p-1 text-custom-text-200 outline-none hover:bg-custom-background-90 hover:text-custom-text-100 ${
isCollapsed ? "w-full" : ""
}`}
onClick={() => toggleSidebar()}
>
<MoveLeft className={`h-4 w-4 duration-300 ${isCollapsed ? "rotate-180" : ""}`} />
Expand Down
5 changes: 2 additions & 3 deletions web/core/services/issue/issue.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { startSpan } from "@sentry/nextjs";
import isEmpty from "lodash/isEmpty";
// types
import type {
IIssueDisplayProperties,
Expand All @@ -12,6 +10,7 @@ import type {
} from "@plane/types";
// helpers
import { API_BASE_URL } from "@/helpers/common.helper";
import { getIssuesShouldFallbackToServer } from "@/helpers/issue.helper";
import { persistence } from "@/local-db/storage.sqlite";
// services

Expand Down Expand Up @@ -68,7 +67,7 @@ export class IssueService extends APIService {
}

async getIssues(workspaceSlug: string, projectId: string, queries?: any, config = {}): Promise<TIssuesResponse> {
if (!isEmpty(queries.expand as string) && !queries.group_by)
if (getIssuesShouldFallbackToServer(queries))
return await this.getIssuesFromServer(workspaceSlug, projectId, queries, config);

const response = await persistence.getIssues(workspaceSlug, projectId, queries, config);
Expand Down
3 changes: 1 addition & 2 deletions web/core/store/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { TUserPermissions } from "@plane/types/src/enums";
import { API_BASE_URL } from "@/helpers/common.helper";
// local
import { persistence } from "@/local-db/storage.sqlite";
import { ENABLE_LOCAL_DB_CACHE } from "@/plane-web/constants/issues";
import { EUserPermissions } from "@/plane-web/constants/user-permissions";
// services
import { AuthService } from "@/services/auth.service";
Expand Down Expand Up @@ -278,6 +277,6 @@ export class UserStore implements IUserStore {
}

get localDBEnabled() {
return ENABLE_LOCAL_DB_CACHE && this.userSettings.canUseLocalDB;
return this.userSettings.canUseLocalDB;
}
}
15 changes: 15 additions & 0 deletions web/helpers/issue.helper.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import differenceInCalendarDays from "date-fns/differenceInCalendarDays";
import isEmpty from "lodash/isEmpty";
import set from "lodash/set";
import { v4 as uuidv4 } from "uuid";
// types
Expand Down Expand Up @@ -308,3 +309,17 @@ export const getComputedDisplayProperties = (
cycle: displayProperties?.cycle ?? true,
issue_type: displayProperties?.issue_type ?? true,
});

/**
* This is to check if the issues list api should fall back to server or use local db
* @param queries
* @returns
*/
export const getIssuesShouldFallbackToServer = (queries: any) => {
// If there is expand query and is not grouped then fallback to server
if (!isEmpty(queries.expand as string) && !queries.group_by) return true;
// If query has mentions then fallback to server
if (!isEmpty(queries.mentions)) return true;

return false;
};
Comment on lines +318 to +325
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 and input validation for the new function.

The function implementation looks correct for its purpose, but there are several improvements that could make it more robust:

Consider applying these improvements:

-export const getIssuesShouldFallbackToServer = (queries: any) => {
+interface IssueQueries {
+  expand?: string;
+  group_by?: string;
+  mentions?: string[];
+}
+
+export const getIssuesShouldFallbackToServer = (queries: IssueQueries): boolean => {
+  if (!queries) return false;
+
   // If there is expand query and is not grouped then fallback to server
   if (!isEmpty(queries.expand as string) && !queries.group_by) return true;
   // If query has mentions then fallback to server
   if (!isEmpty(queries.mentions)) return true;

   return false;
 };

This refactor:

  • Adds type safety by replacing any with a proper interface
  • Adds null check for the queries parameter
  • Makes the return type explicit
📝 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 getIssuesShouldFallbackToServer = (queries: any) => {
// If there is expand query and is not grouped then fallback to server
if (!isEmpty(queries.expand as string) && !queries.group_by) return true;
// If query has mentions then fallback to server
if (!isEmpty(queries.mentions)) return true;
return false;
};
interface IssueQueries {
expand?: string;
group_by?: string;
mentions?: string[];
}
export const getIssuesShouldFallbackToServer = (queries: IssueQueries): boolean => {
if (!queries) return false;
// If there is expand query and is not grouped then fallback to server
if (!isEmpty(queries.expand as string) && !queries.group_by) return true;
// If query has mentions then fallback to server
if (!isEmpty(queries.mentions)) return true;
return false;
};