diff --git a/src/settings/ShortUrlsList.tsx b/src/settings/ShortUrlsList.tsx index aadbb502..57407afc 100644 --- a/src/settings/ShortUrlsList.tsx +++ b/src/settings/ShortUrlsList.tsx @@ -1,7 +1,7 @@ import { FC } from 'react'; import { FormGroup } from 'reactstrap'; import SortingDropdown from '../utils/SortingDropdown'; -import { SORTABLE_FIELDS } from '../short-urls/data'; +import { SHORT_URLS_ORDERABLE_FIELDS } from '../short-urls/data'; import { SimpleCard } from '../utils/SimpleCard'; import { DEFAULT_SHORT_URLS_ORDERING, Settings, ShortUrlsListSettings } from './reducers/settings'; @@ -15,7 +15,7 @@ export const ShortUrlsList: FC = ({ settings: { shortUrlsLis setShortUrlsListSettings({ defaultOrdering: { field, dir } })} /> diff --git a/src/settings/Tags.tsx b/src/settings/Tags.tsx index cbbd2af8..6fbc2194 100644 --- a/src/settings/Tags.tsx +++ b/src/settings/Tags.tsx @@ -4,7 +4,7 @@ import { SimpleCard } from '../utils/SimpleCard'; import { TagsModeDropdown } from '../tags/TagsModeDropdown'; import { capitalize } from '../utils/utils'; import SortingDropdown from '../utils/SortingDropdown'; -import { SORTABLE_FIELDS } from '../tags/data/TagsListChildrenProps'; +import { TAGS_ORDERABLE_FIELDS } from '../tags/data/TagsListChildrenProps'; import { Settings, TagsSettings } from './reducers/settings'; interface TagsProps { @@ -26,7 +26,7 @@ export const Tags: FC = ({ settings: { tags }, setTagsSettings }) => setTagsSettings({ ...tags, defaultOrdering: { field, dir } })} /> diff --git a/src/short-urls/ShortUrlsList.tsx b/src/short-urls/ShortUrlsList.tsx index 09227fff..a3722d38 100644 --- a/src/short-urls/ShortUrlsList.tsx +++ b/src/short-urls/ShortUrlsList.tsx @@ -14,7 +14,7 @@ import { ShortUrlsList as ShortUrlsListState } from './reducers/shortUrlsList'; import { ShortUrlsTableProps } from './ShortUrlsTable'; import Paginator from './Paginator'; import { ShortUrlListRouteParams, useShortUrlsQuery } from './helpers/hooks'; -import { OrderableFields, ShortUrlsOrder, SORTABLE_FIELDS } from './data'; +import { ShortUrlsOrderableFields, ShortUrlsOrder, SHORT_URLS_ORDERABLE_FIELDS } from './data'; interface ShortUrlsListProps extends RouteComponentProps { selectedServer: SelectedServer; @@ -39,10 +39,10 @@ const ShortUrlsList = (ShortUrlsTable: FC, SearchBar: FC) = const selectedTags = useMemo(() => tags?.split(',') ?? [], [ tags ]); const { pagination } = shortUrlsList?.shortUrls ?? {}; - const handleOrderBy = (field?: OrderableFields, dir?: OrderDir) => setOrder({ field, dir }); - const orderByColumn = (field: OrderableFields) => () => + const handleOrderBy = (field?: ShortUrlsOrderableFields, dir?: OrderDir) => setOrder({ field, dir }); + const orderByColumn = (field: ShortUrlsOrderableFields) => () => handleOrderBy(field, determineOrderDir(field, order.field, order.dir)); - const renderOrderIcon = (field: OrderableFields) => ; + const renderOrderIcon = (field: ShortUrlsOrderableFields) => ; const addTag = pipe( (newTag: string) => [ ...new Set([ ...selectedTags, newTag ]) ].join(','), (tags) => toFirstPage({ tags }), @@ -64,7 +64,7 @@ const ShortUrlsList = (ShortUrlsTable: FC, SearchBar: FC) = <>
- +
() => void; - renderOrderIcon?: (column: OrderableFields) => ReactNode; + orderByColumn?: (column: ShortUrlsOrderableFields) => () => void; + renderOrderIcon?: (column: ShortUrlsOrderableFields) => ReactNode; shortUrlsList: ShortUrlsListState; selectedServer: SelectedServer; onTagClick?: (tag: string) => void; diff --git a/src/short-urls/data/index.ts b/src/short-urls/data/index.ts index f5a001cd..8199497d 100644 --- a/src/short-urls/data/index.ts +++ b/src/short-urls/data/index.ts @@ -52,7 +52,7 @@ export interface ShortUrlIdentifier { domain: OptionalString; } -export const SORTABLE_FIELDS = { +export const SHORT_URLS_ORDERABLE_FIELDS = { dateCreated: 'Created at', shortCode: 'Short URL', longUrl: 'Long URL', @@ -60,6 +60,6 @@ export const SORTABLE_FIELDS = { visits: 'Visits', }; -export type OrderableFields = keyof typeof SORTABLE_FIELDS; +export type ShortUrlsOrderableFields = keyof typeof SHORT_URLS_ORDERABLE_FIELDS; -export type ShortUrlsOrder = Order; +export type ShortUrlsOrder = Order; diff --git a/src/tags/TagsList.tsx b/src/tags/TagsList.tsx index 63832b53..bcc3934f 100644 --- a/src/tags/TagsList.tsx +++ b/src/tags/TagsList.tsx @@ -12,7 +12,12 @@ import { Settings, TagsMode } from '../settings/reducers/settings'; import { determineOrderDir, sortList } from '../utils/helpers/ordering'; import SortingDropdown from '../utils/SortingDropdown'; import { TagsList as TagsListState } from './reducers/tagsList'; -import { OrderableFields, SORTABLE_FIELDS, TagsListChildrenProps, TagsOrder } from './data/TagsListChildrenProps'; +import { + TagsOrderableFields, + TAGS_ORDERABLE_FIELDS, + TagsListChildrenProps, + TagsOrder, +} from './data/TagsListChildrenProps'; import { TagsModeDropdown } from './TagsModeDropdown'; import { NormalizedTag } from './data'; import { TagsTableProps } from './TagsTable'; @@ -55,7 +60,7 @@ const TagsList = (TagsCards: FC, TagsTable: FC () => { + const orderByColumn = (field: TagsOrderableFields) => () => { const dir = determineOrderDir(field, order.field, order.dir); setOrder({ field: dir ? field : undefined, dir }); @@ -88,7 +93,11 @@ const TagsList = (TagsCards: FC, TagsTable: FC
- setOrder({ field, dir })} /> + setOrder({ field, dir })} + />
{renderContent()} diff --git a/src/tags/TagsTable.tsx b/src/tags/TagsTable.tsx index cf24542c..94876b65 100644 --- a/src/tags/TagsTable.tsx +++ b/src/tags/TagsTable.tsx @@ -6,12 +6,12 @@ import SimplePaginator from '../common/SimplePaginator'; import { useQueryState } from '../utils/helpers/hooks'; import { parseQuery } from '../utils/helpers/query'; import { TableOrderIcon } from '../utils/table/TableOrderIcon'; -import { OrderableFields, TagsListChildrenProps, TagsOrder } from './data/TagsListChildrenProps'; +import { TagsOrderableFields, TagsListChildrenProps, TagsOrder } from './data/TagsListChildrenProps'; import { TagsTableRowProps } from './TagsTableRow'; import './TagsTable.scss'; export interface TagsTableProps extends TagsListChildrenProps { - orderByColumn: (field: OrderableFields) => () => void; + orderByColumn: (field: TagsOrderableFields) => () => void; currentOrder: TagsOrder; } diff --git a/src/tags/data/TagsListChildrenProps.ts b/src/tags/data/TagsListChildrenProps.ts index e8e476a8..54837ac7 100644 --- a/src/tags/data/TagsListChildrenProps.ts +++ b/src/tags/data/TagsListChildrenProps.ts @@ -2,15 +2,15 @@ import { SelectedServer } from '../../servers/data'; import { Order } from '../../utils/helpers/ordering'; import { NormalizedTag } from './index'; -export const SORTABLE_FIELDS = { +export const TAGS_ORDERABLE_FIELDS = { tag: 'Tag', shortUrls: 'Short URLs', visits: 'Visits', }; -export type OrderableFields = keyof typeof SORTABLE_FIELDS; +export type TagsOrderableFields = keyof typeof TAGS_ORDERABLE_FIELDS; -export type TagsOrder = Order; +export type TagsOrder = Order; export interface TagsListChildrenProps { sortedTags: NormalizedTag[]; diff --git a/test/short-urls/ShortUrlsList.test.tsx b/test/short-urls/ShortUrlsList.test.tsx index 3602667e..81871a48 100644 --- a/test/short-urls/ShortUrlsList.test.tsx +++ b/test/short-urls/ShortUrlsList.test.tsx @@ -4,7 +4,7 @@ import { Mock } from 'ts-mockery'; import { History, Location } from 'history'; import { match } from 'react-router'; import shortUrlsListCreator from '../../src/short-urls/ShortUrlsList'; -import { OrderableFields, ShortUrl, ShortUrlsOrder } from '../../src/short-urls/data'; +import { ShortUrlsOrderableFields, ShortUrl, ShortUrlsOrder } from '../../src/short-urls/data'; import { MercureBoundProps } from '../../src/mercure/helpers/boundToMercureHub'; import { ShortUrlsList as ShortUrlsListModel } from '../../src/short-urls/reducers/shortUrlsList'; import SortingDropdown from '../../src/utils/SortingDropdown'; @@ -75,8 +75,8 @@ describe('', () => { }); it('invokes order icon rendering', () => { - const renderIcon = (field: OrderableFields) => - (wrapper.find(ShortUrlsTable).prop('renderOrderIcon') as (field: OrderableFields) => ReactElement)(field); + const renderIcon = (field: ShortUrlsOrderableFields) => + (wrapper.find(ShortUrlsTable).prop('renderOrderIcon') as (field: ShortUrlsOrderableFields) => ReactElement)(field); expect(renderIcon('visits').props.currentOrder).toEqual({}); @@ -88,7 +88,7 @@ describe('', () => { }); it('handles order through table', () => { - const orderByColumn: (field: OrderableFields) => Function = wrapper.find(ShortUrlsTable).prop('orderByColumn'); + const orderByColumn: (field: ShortUrlsOrderableFields) => Function = wrapper.find(ShortUrlsTable).prop('orderByColumn'); expect(wrapper.find(SortingDropdown).prop('order')).toEqual({}); diff --git a/test/short-urls/ShortUrlsTable.test.tsx b/test/short-urls/ShortUrlsTable.test.tsx index bcbccd23..a0be282e 100644 --- a/test/short-urls/ShortUrlsTable.test.tsx +++ b/test/short-urls/ShortUrlsTable.test.tsx @@ -5,7 +5,7 @@ import { ShortUrlsTable as shortUrlsTableCreator } from '../../src/short-urls/Sh import { ShortUrlsList } from '../../src/short-urls/reducers/shortUrlsList'; import { ReachableServer, SelectedServer } from '../../src/servers/data'; import { SemVer } from '../../src/utils/helpers/version'; -import { OrderableFields, SORTABLE_FIELDS } from '../../src/short-urls/data'; +import { ShortUrlsOrderableFields, SHORT_URLS_ORDERABLE_FIELDS } from '../../src/short-urls/data'; describe('', () => { let wrapper: ShallowWrapper; @@ -51,8 +51,8 @@ describe('', () => { .find('thead') .find('tr') .find('th') - .filterWhere((e) => e.text().includes(SORTABLE_FIELDS[orderableField as OrderableFields])); - const sortableFields = Object.keys(SORTABLE_FIELDS).filter((sortableField) => sortableField !== 'title'); + .filterWhere((e) => e.text().includes(SHORT_URLS_ORDERABLE_FIELDS[orderableField as ShortUrlsOrderableFields])); + const sortableFields = Object.keys(SHORT_URLS_ORDERABLE_FIELDS).filter((sortableField) => sortableField !== 'title'); expect.assertions(sortableFields.length); sortableFields.forEach((sortableField) => { diff --git a/test/tags/TagsList.test.tsx b/test/tags/TagsList.test.tsx index 4c5848b6..1378e97c 100644 --- a/test/tags/TagsList.test.tsx +++ b/test/tags/TagsList.test.tsx @@ -9,7 +9,7 @@ import { Result } from '../../src/utils/Result'; import { TagsModeDropdown } from '../../src/tags/TagsModeDropdown'; import SearchField from '../../src/utils/SearchField'; import { Settings } from '../../src/settings/reducers/settings'; -import { OrderableFields } from '../../src/tags/data/TagsListChildrenProps'; +import { TagsOrderableFields } from '../../src/tags/data/TagsListChildrenProps'; import SortingDropdown from '../../src/utils/SortingDropdown'; describe('', () => { @@ -98,7 +98,7 @@ describe('', () => { it('can update current order via orderByColumn from table component', () => { const wrapper = createWrapper({ filteredTags: [ 'foo', 'bar' ], stats: {} }); - const callOrderBy = (field: OrderableFields) => { + const callOrderBy = (field: TagsOrderableFields) => { ((wrapper.find(TagsTable).prop('orderByColumn') as Function)(field) as Function)(); };