[WEB-1173] fix: order by for last updated when issue is updated (#4353)

* 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
This commit is contained in:
rahulramesha 2024-05-03 19:08:20 +05:30 committed by GitHub
parent f4cc103238
commit acd8f8d2d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 5 deletions

View File

@ -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();
};

View File

@ -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
@ -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":

View File

@ -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 = {
@ -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]);
});