1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-17 13:46:47 +02:00

fix: date should sort asc/desc properly (#5335)

This commit is contained in:
Jaanus Sellin 2023-11-14 14:47:28 +02:00 committed by GitHub
parent fd3a7f12cb
commit 069d90d8cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 22 additions and 52 deletions

View File

@ -89,7 +89,6 @@ export const BannersTable = () => {
Header: 'Created', Header: 'Created',
accessor: 'createdAt', accessor: 'createdAt',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
width: 120, width: 120,
maxWidth: 120, maxWidth: 120,
}, },
@ -134,7 +133,7 @@ export const BannersTable = () => {
); );
const [initialState] = useState({ const [initialState] = useState({
sortBy: [{ id: 'createdAt' }], sortBy: [{ id: 'createdAt', desc: true }],
}); });
const { data, getSearchText } = useSearch(columns, searchValue, banners); const { data, getSearchText } = useSearch(columns, searchValue, banners);

View File

@ -40,14 +40,12 @@ const columns = [
Header: 'Created date', Header: 'Created date',
accessor: 'created', accessor: 'created',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
disableGlobalFilter: true, disableGlobalFilter: true,
}, },
{ {
Header: 'Due date', Header: 'Due date',
accessor: 'dueDate', accessor: 'dueDate',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
disableGlobalFilter: true, disableGlobalFilter: true,
}, },
{ {
@ -76,7 +74,7 @@ export const BillingHistory: VFC<IBillingHistoryProps> = ({
}) => { }) => {
const initialState = useMemo( const initialState = useMemo(
() => ({ () => ({
sortBy: [{ id: 'created' }], sortBy: [{ id: 'created', desc: true }],
}), }),
[], [],
); );

View File

@ -44,7 +44,7 @@ export type PageQueryType = Partial<
Record<'sort' | 'order' | 'search', string> Record<'sort' | 'order' | 'search', string>
>; >;
const defaultSort: SortingRule<string> = { id: 'joinedAt' }; const defaultSort: SortingRule<string> = { id: 'joinedAt', desc: true };
const { value: storedParams, setValue: setStoredParams } = createLocalStorage( const { value: storedParams, setValue: setStoredParams } = createLocalStorage(
'Group:v1', 'Group:v1',
@ -91,7 +91,6 @@ export const Group: VFC = () => {
Header: 'Joined', Header: 'Joined',
accessor: 'joinedAt', accessor: 'joinedAt',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
{ {
@ -112,7 +111,6 @@ export const Group: VFC = () => {
title={(date) => `Last login: ${date}`} title={(date) => `Last login: ${date}`}
/> />
), ),
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
{ {

View File

@ -19,7 +19,7 @@ export const RoleDeleteDialogGroups = ({
groups, groups,
}: IRoleDeleteDialogGroupsProps) => { }: IRoleDeleteDialogGroupsProps) => {
const [initialState] = useState(() => ({ const [initialState] = useState(() => ({
sortBy: [{ id: 'createdAt' }], sortBy: [{ id: 'createdAt', desc: true }],
})); }));
const columns = useMemo( const columns = useMemo(
@ -41,7 +41,6 @@ export const RoleDeleteDialogGroups = ({
Header: 'Created', Header: 'Created',
accessor: 'createdAt', accessor: 'createdAt',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
width: 120, width: 120,
maxWidth: 120, maxWidth: 120,
}, },

View File

@ -20,7 +20,7 @@ export const RoleDeleteDialogServiceAccounts = ({
serviceAccounts, serviceAccounts,
}: IRoleDeleteDialogServiceAccountsProps) => { }: IRoleDeleteDialogServiceAccountsProps) => {
const [initialState] = useState(() => ({ const [initialState] = useState(() => ({
sortBy: [{ id: 'seenAt' }], sortBy: [{ id: 'seenAt', desc: true }],
})); }));
const columns = useMemo( const columns = useMemo(
@ -63,7 +63,6 @@ export const RoleDeleteDialogServiceAccounts = ({
Header: 'Created', Header: 'Created',
accessor: 'createdAt', accessor: 'createdAt',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
width: 120, width: 120,
maxWidth: 120, maxWidth: 120,
}, },
@ -77,7 +76,6 @@ export const RoleDeleteDialogServiceAccounts = ({
return bSeenAt?.getTime() - aSeenAt?.getTime(); return bSeenAt?.getTime() - aSeenAt?.getTime();
})[0]?.seenAt, })[0]?.seenAt,
Cell: TimeAgoCell, Cell: TimeAgoCell,
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
] as Column<IServiceAccount>[], ] as Column<IServiceAccount>[],

View File

@ -19,7 +19,7 @@ export const RoleDeleteDialogUsers = ({
users, users,
}: IRoleDeleteDialogUsersProps) => { }: IRoleDeleteDialogUsersProps) => {
const [initialState] = useState(() => ({ const [initialState] = useState(() => ({
sortBy: [{ id: 'last-login' }], sortBy: [{ id: 'last-login', desc: true }],
})); }));
const columns = useMemo( const columns = useMemo(
@ -41,7 +41,6 @@ export const RoleDeleteDialogUsers = ({
Header: 'Created', Header: 'Created',
accessor: 'createdAt', accessor: 'createdAt',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
width: 120, width: 120,
maxWidth: 120, maxWidth: 120,
}, },
@ -56,7 +55,6 @@ export const RoleDeleteDialogUsers = ({
title={(date) => `Last login: ${date}`} title={(date) => `Last login: ${date}`}
/> />
), ),
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
] as Column<IUser>[], ] as Column<IUser>[],

View File

@ -81,7 +81,7 @@ export type PageQueryType = Partial<
Record<'sort' | 'order' | 'search', string> Record<'sort' | 'order' | 'search', string>
>; >;
const defaultSort: SortingRule<string> = { id: 'createdAt' }; const defaultSort: SortingRule<string> = { id: 'createdAt', desc: true };
interface IServiceAccountTokensProps { interface IServiceAccountTokensProps {
serviceAccount: IServiceAccount; serviceAccount: IServiceAccount;
@ -179,21 +179,18 @@ export const ServiceAccountTokens = ({
} }
return <DateCell value={value} />; return <DateCell value={value} />;
}, },
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
{ {
Header: 'Created', Header: 'Created',
accessor: 'createdAt', accessor: 'createdAt',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
{ {
Header: 'Last seen', Header: 'Last seen',
accessor: 'seenAt', accessor: 'seenAt',
Cell: TimeAgoCell, Cell: TimeAgoCell,
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
{ {

View File

@ -131,7 +131,6 @@ export const ServiceAccountsTable = () => {
Header: 'Created', Header: 'Created',
accessor: 'createdAt', accessor: 'createdAt',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
width: 120, width: 120,
maxWidth: 120, maxWidth: 120,
}, },
@ -145,7 +144,6 @@ export const ServiceAccountsTable = () => {
return bSeenAt?.getTime() - aSeenAt?.getTime(); return bSeenAt?.getTime() - aSeenAt?.getTime();
})[0]?.seenAt, })[0]?.seenAt,
Cell: TimeAgoCell, Cell: TimeAgoCell,
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
{ {
@ -178,7 +176,7 @@ export const ServiceAccountsTable = () => {
); );
const [initialState] = useState({ const [initialState] = useState({
sortBy: [{ id: 'createdAt' }], sortBy: [{ id: 'createdAt', desc: true }],
hiddenColumns: ['username'], hiddenColumns: ['username'],
}); });

View File

@ -144,7 +144,6 @@ const UsersList = () => {
Header: 'Created', Header: 'Created',
accessor: 'createdAt', accessor: 'createdAt',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
width: 120, width: 120,
maxWidth: 120, maxWidth: 120,
}, },
@ -159,7 +158,6 @@ const UsersList = () => {
title={(date) => `Last login: ${date}`} title={(date) => `Last login: ${date}`}
/> />
), ),
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
{ {
@ -206,7 +204,7 @@ const UsersList = () => {
const initialState = useMemo(() => { const initialState = useMemo(() => {
return { return {
sortBy: [{ id: 'createdAt' }], sortBy: [{ id: 'createdAt', desc: true }],
hiddenColumns: isBillingUsers hiddenColumns: isBillingUsers
? ['username', 'email'] ? ['username', 'email']
: ['type', 'username', 'email'], : ['type', 'username', 'email'],

View File

@ -146,14 +146,12 @@ export const ArchiveTable = ({
accessor: 'createdAt', accessor: 'createdAt',
width: 150, width: 150,
Cell: DateCell, Cell: DateCell,
sortType: 'date',
}, },
{ {
Header: 'Archived', Header: 'Archived',
accessor: 'archivedAt', accessor: 'archivedAt',
width: 150, width: 150,
Cell: FeatureArchivedCell, Cell: FeatureArchivedCell,
sortType: 'date',
}, },
...(!projectId ...(!projectId
? [ ? [

View File

@ -38,7 +38,7 @@ export interface IChangeRequestTableProps {
const defaultSort: SortingRule<string> & { const defaultSort: SortingRule<string> & {
columns?: string[]; columns?: string[];
} = { id: 'createdAt' }; } = { id: 'createdAt', desc: true };
const StyledTabContainer = styled('div')({ const StyledTabContainer = styled('div')({
paddingLeft: 0, paddingLeft: 0,
@ -162,7 +162,6 @@ export const ChangeRequestsTabs = ({
accessor: 'createdAt', accessor: 'createdAt',
maxWidth: 100, maxWidth: 100,
Cell: TimeAgoCell, Cell: TimeAgoCell,
sortType: 'date',
}, },
{ {
Header: 'Environment', Header: 'Environment',

View File

@ -13,7 +13,10 @@ export const useApiTokenTable = (
tokens: IApiToken[], tokens: IApiToken[],
getActionCell: (props: any) => JSX.Element, getActionCell: (props: any) => JSX.Element,
) => { ) => {
const initialState = useMemo(() => ({ sortBy: [{ id: 'createdAt' }] }), []); const initialState = useMemo(
() => ({ sortBy: [{ id: 'createdAt', desc: true }] }),
[],
);
const COLUMNS = useMemo(() => { const COLUMNS = useMemo(() => {
return [ return [
@ -72,7 +75,6 @@ export const useApiTokenTable = (
Header: 'Last seen', Header: 'Last seen',
accessor: 'seenAt', accessor: 'seenAt',
Cell: TimeAgoCell, Cell: TimeAgoCell,
sortType: 'date',
minWidth: 150, minWidth: 150,
disableGlobalFilter: true, disableGlobalFilter: true,
}, },

View File

@ -52,7 +52,7 @@ export type PageQueryType = Partial<
Record<'sort' | 'order' | 'search' | 'favorites', string> Record<'sort' | 'order' | 'search' | 'favorites', string>
>; >;
const defaultSort: SortingRule<string> = { id: 'createdAt' }; const defaultSort: SortingRule<string> = { id: 'createdAt', desc: true };
const { value: storedParams, setValue: setStoredParams } = createLocalStorage( const { value: storedParams, setValue: setStoredParams } = createLocalStorage(
'FeatureToggleListTable:v1', 'FeatureToggleListTable:v1',
@ -177,7 +177,6 @@ export const FeatureToggleListTable: VFC = () => {
Header: 'Created', Header: 'Created',
accessor: 'createdAt', accessor: 'createdAt',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
{ {

View File

@ -27,7 +27,7 @@ export type PageQueryType = Partial<
Record<'sort' | 'order' | 'search', string> Record<'sort' | 'order' | 'search', string>
>; >;
const defaultSort: SortingRule<string> = { id: 'created_at' }; const defaultSort: SortingRule<string> = { id: 'created_at', desc: true };
const { value: storedParams, setValue: setStoredParams } = createLocalStorage( const { value: storedParams, setValue: setStoredParams } = createLocalStorage(
'LoginHistoryTable:v1', 'LoginHistoryTable:v1',
@ -72,7 +72,6 @@ export const LoginHistoryTable = () => {
Cell: ({ value }: { value: Date }) => ( Cell: ({ value }: { value: Date }) => (
<TimeAgoCell value={value} dateFormat={formatDateYMDHMS} /> <TimeAgoCell value={value} dateFormat={formatDateYMDHMS} />
), ),
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
{ {

View File

@ -84,7 +84,7 @@ const staticColumns = ['Select', 'Actions', 'name', 'favorite'];
const defaultSort: SortingRule<string> & { const defaultSort: SortingRule<string> & {
columns?: string[]; columns?: string[];
} = { id: 'createdAt' }; } = { id: 'createdAt', desc: true };
export const PaginatedProjectFeatureToggles = ({ export const PaginatedProjectFeatureToggles = ({
features, features,
@ -266,7 +266,6 @@ export const PaginatedProjectFeatureToggles = ({
Header: 'Created', Header: 'Created',
accessor: 'createdAt', accessor: 'createdAt',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
minWidth: 120, minWidth: 120,
}, },
...environments.map((value: ProjectEnvironmentType | string) => { ...environments.map((value: ProjectEnvironmentType | string) => {

View File

@ -79,7 +79,7 @@ const staticColumns = ['Select', 'Actions', 'name', 'favorite'];
const defaultSort: SortingRule<string> & { const defaultSort: SortingRule<string> & {
columns?: string[]; columns?: string[];
} = { id: 'createdAt' }; } = { id: 'createdAt', desc: true };
/** /**
* @deprecated remove when flag `featureSearchFrontend` is removed * @deprecated remove when flag `featureSearchFrontend` is removed
@ -259,7 +259,6 @@ export const ProjectFeatureToggles = ({
Header: 'Created', Header: 'Created',
accessor: 'createdAt', accessor: 'createdAt',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
minWidth: 120, minWidth: 120,
}, },
...environments.map((value: ProjectEnvironmentType | string) => { ...environments.map((value: ProjectEnvironmentType | string) => {

View File

@ -78,7 +78,7 @@ export const ReportTable = ({ projectId, features }: IReportTableProps) => {
const initialState = useMemo( const initialState = useMemo(
() => ({ () => ({
hiddenColumns: [], hiddenColumns: [],
sortBy: [{ id: 'createdAt' }], sortBy: [{ id: 'createdAt', desc: true }],
}), }),
[], [],
); );
@ -116,7 +116,6 @@ export const ReportTable = ({ projectId, features }: IReportTableProps) => {
{ {
Header: 'Created', Header: 'Created',
accessor: 'createdAt', accessor: 'createdAt',
sortType: 'date',
Cell: DateCell, Cell: DateCell,
disableGlobalFilter: true, disableGlobalFilter: true,
maxWidth: 150, maxWidth: 150,

View File

@ -54,7 +54,7 @@ export type PageQueryType = Partial<
Record<'sort' | 'order' | 'search', string> Record<'sort' | 'order' | 'search', string>
>; >;
const defaultSort: SortingRule<string> = { id: 'added' }; const defaultSort: SortingRule<string> = { id: 'added', desc: true };
const { value: storedParams, setValue: setStoredParams } = createLocalStorage( const { value: storedParams, setValue: setStoredParams } = createLocalStorage(
'ProjectAccess:v1', 'ProjectAccess:v1',
@ -176,7 +176,6 @@ export const ProjectAccessTable: VFC = () => {
Cell: ({ value }: { value: Date }) => ( Cell: ({ value }: { value: Date }) => (
<TimeAgoCell value={value} emptyText='Never' /> <TimeAgoCell value={value} emptyText='Never' />
), ),
sortType: 'date',
maxWidth: 130, maxWidth: 130,
}, },
{ {
@ -196,7 +195,6 @@ export const ProjectAccessTable: VFC = () => {
Cell: ({ value }: { value: Date }) => ( Cell: ({ value }: { value: Date }) => (
<TimeAgoCell value={value} emptyText='Never' /> <TimeAgoCell value={value} emptyText='Never' />
), ),
sortType: 'date',
maxWidth: 130, maxWidth: 130,
}, },
{ {

View File

@ -48,7 +48,7 @@ const StyledTitle = styled('div')(({ theme }) => ({
}, },
})); }));
const defaultSort: SortingRule<string> = { id: 'joinedAt' }; const defaultSort: SortingRule<string> = { id: 'joinedAt', desc: true };
const columns = [ const columns = [
{ {
@ -77,7 +77,6 @@ const columns = [
Header: 'Joined', Header: 'Joined',
accessor: 'joinedAt', accessor: 'joinedAt',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
{ {
@ -91,7 +90,6 @@ const columns = [
title={(date) => `Last login: ${date}`} title={(date) => `Last login: ${date}`}
/> />
), ),
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
// Always hidden -- for search // Always hidden -- for search

View File

@ -75,7 +75,7 @@ export type PageQueryType = Partial<
Record<'sort' | 'order' | 'search', string> Record<'sort' | 'order' | 'search', string>
>; >;
const defaultSort: SortingRule<string> = { id: 'createdAt' }; const defaultSort: SortingRule<string> = { id: 'createdAt', desc: true };
const { value: storedParams, setValue: setStoredParams } = createLocalStorage( const { value: storedParams, setValue: setStoredParams } = createLocalStorage(
'PersonalAPITokensTable:v1', 'PersonalAPITokensTable:v1',
@ -132,21 +132,18 @@ export const PersonalAPITokensTab = () => {
} }
return <DateCell value={value} />; return <DateCell value={value} />;
}, },
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
{ {
Header: 'Created', Header: 'Created',
accessor: 'createdAt', accessor: 'createdAt',
Cell: DateCell, Cell: DateCell,
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
{ {
Header: 'Last seen', Header: 'Last seen',
accessor: 'seenAt', accessor: 'seenAt',
Cell: TimeAgoCell, Cell: TimeAgoCell,
sortType: 'date',
maxWidth: 150, maxWidth: 150,
}, },
{ {