Skip to content

Commit

Permalink
[WEB-1173] fix: order by for last updated when issue is updated (#4353)
Browse files Browse the repository at this point in the history
* update the issue's updated at date when issue is updated

* sort issue's updated and created at regardless of the date format.

* move the logic to date time helpers

* revert back the third variable in update issue
  • Loading branch information
rahulramesha authored May 3, 2024
1 parent f4cc103 commit acd8f8d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
22 changes: 22 additions & 0 deletions web/helpers/date-time.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,29 @@ export const getDate = (date: string | Date | undefined | null): Date | undefine
return undefined;
}
};

export const isInDateFormat = (date: string) => {
const datePattern = /^\d{4}-\d{2}-\d{2}$/;
return datePattern.test(date);
};

/**
* returns the date string in ISO format regardless of the timezone in input date string
* @param dateString
* @returns
*/
export const convertToISODateString = (dateString: string | undefined) => {
if (!dateString) return dateString;

const date = new Date(dateString);
return date.toISOString();
};

/**
* get current Date time in UTC ISO format
* @returns
*/
export const getCurrentDateTimeInISO = () => {
const date = new Date();
return date.toISOString();
};
10 changes: 5 additions & 5 deletions web/store/issue/helpers/issue-helper.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import values from "lodash/values";
import { ISSUE_PRIORITIES } from "@/constants/issue";
import { STATE_GROUPS } from "@/constants/state";
// helpers
import { renderFormattedPayloadDate } from "@/helpers/date-time.helper";
import { convertToISODateString, renderFormattedPayloadDate } from "@/helpers/date-time.helper";
// types
import { TIssue, TIssueMap, TIssueGroupByOptions, TIssueOrderByOptions } from "@plane/types";
// store
Expand Down Expand Up @@ -262,13 +262,13 @@ export class IssueHelperStore implements TIssueHelperStore {
return orderBy(array, (issue) => this.populateIssueDataForSorting("state_id", issue["state_id"]), ["desc"]);
// dates
case "created_at":
return orderBy(array, "created_at");
return orderBy(array, (issue) => convertToISODateString(issue["created_at"]));
case "-created_at":
return orderBy(array, "created_at", ["desc"]);
return orderBy(array, (issue) => convertToISODateString(issue["created_at"]), ["desc"]);
case "updated_at":
return orderBy(array, "updated_at");
return orderBy(array, (issue) => convertToISODateString(issue["updated_at"]));
case "-updated_at":
return orderBy(array, "updated_at", ["desc"]);
return orderBy(array, (issue) => convertToISODateString(issue["updated_at"]), ["desc"]);
case "start_date":
return orderBy(array, [this.getSortOrderToFilterEmptyValues.bind(null, "start_date"), "start_date"]); //preferring sorting based on empty values to always keep the empty values below
case "-start_date":
Expand Down
2 changes: 2 additions & 0 deletions web/store/issue/issue.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { computedFn } from "mobx-utils";
// types
import { IssueService } from "@/services/issue";
import { TIssue } from "@plane/types";
import { getCurrentDateTimeInISO } from "@/helpers/date-time.helper";
//services

export type IIssueStore = {
Expand Down Expand Up @@ -76,6 +77,7 @@ export class IssueStore implements IIssueStore {
updateIssue = (issueId: string, issue: Partial<TIssue>) => {
if (!issue || !issueId || isEmpty(this.issuesMap) || !this.issuesMap[issueId]) return;
runInAction(() => {
set(this.issuesMap, [issueId, "updated_at"], getCurrentDateTimeInISO());
Object.keys(issue).forEach((key) => {
set(this.issuesMap, [issueId, key], issue[key as keyof TIssue]);
});
Expand Down

0 comments on commit acd8f8d

Please sign in to comment.