Updated short URL list params so that it requests dateCreated DESC ordering by default

This commit is contained in:
Alejandro Celaya
2020-09-12 17:59:58 +02:00
parent bd88e56331
commit f36cf1e7b9
4 changed files with 24 additions and 18 deletions

View File

@@ -1,7 +1,7 @@
import { faCaretDown as caretDownIcon, faCaretUp as caretUpIcon } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { head, isEmpty, keys, values } from 'ramda';
import React, { useState, useEffect, FC } from 'react';
import React, { FC, useEffect, useState } from 'react';
import qs from 'qs';
import { RouteComponentProps } from 'react-router';
import SortingDropdown from '../utils/SortingDropdown';
@@ -11,17 +11,9 @@ import { boundToMercureHub } from '../mercure/helpers/boundToMercureHub';
import { ShortUrlsList as ShortUrlsListState } from './reducers/shortUrlsList';
import { ShortUrlsRowProps } from './helpers/ShortUrlsRow';
import { ShortUrl } from './data';
import { ShortUrlsListParams } from './reducers/shortUrlsListParams';
import { OrderableFields, ShortUrlsListParams, SORTABLE_FIELDS } from './reducers/shortUrlsListParams';
import './ShortUrlsList.scss';
export const SORTABLE_FIELDS = {
dateCreated: 'Created at',
shortCode: 'Short URL',
longUrl: 'Long URL',
visits: 'Visits',
};
type OrderableFields = keyof typeof SORTABLE_FIELDS;
interface RouteParams {
page: string;
serverId: string;

View File

@@ -4,16 +4,28 @@ import { LIST_SHORT_URLS, ListShortUrlsAction } from './shortUrlsList';
export const RESET_SHORT_URL_PARAMS = 'shlink/shortUrlsListParams/RESET_SHORT_URL_PARAMS';
export const SORTABLE_FIELDS = {
dateCreated: 'Created at',
shortCode: 'Short URL',
longUrl: 'Long URL',
visits: 'Visits',
};
export type OrderableFields = keyof typeof SORTABLE_FIELDS;
export interface ShortUrlsListParams {
page?: string;
tags?: string[];
searchTerm?: string;
startDate?: string;
endDate?: string;
orderBy?: Record<string, OrderDir>;
orderBy?: Partial<Record<OrderableFields, OrderDir>>;
}
const initialState: ShortUrlsListParams = { page: '1' };
const initialState: ShortUrlsListParams = {
page: '1',
orderBy: { dateCreated: 'DESC' },
};
export default buildReducer<ShortUrlsListParams, ListShortUrlsAction>({
[LIST_SHORT_URLS]: (state, { params }) => ({ ...state, ...params }),