Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable sorting in sources and destinations page #11308

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 82 additions & 7 deletions airbyte-webapp/src/components/EntityTable/ImplementationTable.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import React from "react";
import React, { useCallback } from "react";
import styled from "styled-components";
import { FormattedMessage } from "react-intl";
import { CellProps } from "react-table";
import queryString from "query-string";

import Table from "components/Table";

import LastSyncCell from "./components/LastSyncCell";
import ConnectorCell from "./components/ConnectorCell";
import NameCell from "./components/NameCell";
import ConnectEntitiesCell from "./components/ConnectEntitiesCell";
import { EntityTableDataItem } from "./types";
import { EntityTableDataItem, SortOrderEnum } from "./types";
import AllConnectionsStatusCell from "./components/AllConnectionsStatusCell";
import useRouter from "hooks/useRouter";
import SortButton from "./components/SortButton";

const Content = styled.div`
margin: 0 32px 0 27px;
Expand All @@ -27,10 +30,64 @@ const ImplementationTable: React.FC<IProps> = ({
entity,
onClickRow,
}) => {
const { query, push } = useRouter();
const sortBy = query.sortBy || "entity";
const sortOrder = query.order || SortOrderEnum.ASC;

const onSortClick = useCallback(
(field: string) => {
const order =
sortBy !== field
? SortOrderEnum.ASC
: sortOrder === SortOrderEnum.ASC
? SortOrderEnum.DESC
: SortOrderEnum.ASC;
push({
search: queryString.stringify(
{
sortBy: field,
order: order,
},
{ skipNull: true }
),
});
},
[push, sortBy, sortOrder]
);

const sortData = useCallback(
(a, b) => {
const result = a[`${sortBy}Name`]
.toLowerCase()
.localeCompare(b[`${sortBy}Name`].toLowerCase());

if (sortOrder === SortOrderEnum.DESC) {
return -1 * result;
}

return result;
},
[sortBy, sortOrder]
);

const sortingData = React.useMemo(() => data.sort(sortData), [
sortData,
data,
]);

const columns = React.useMemo(
() => [
{
Header: <FormattedMessage id="tables.name" />,
Header: (
<>
<FormattedMessage id="tables.name" />
<SortButton
wasActive={sortBy === "entity"}
lowToLarge={sortOrder === SortOrderEnum.ASC}
onClick={() => onSortClick("entity")}
/>
</>
),
headerHighlighted: true,
accessor: "entityName",
customWidth: 40,
Expand All @@ -39,7 +96,16 @@ const ImplementationTable: React.FC<IProps> = ({
),
},
{
Header: <FormattedMessage id="tables.connector" />,
Header: (
<>
<FormattedMessage id="tables.connector" />
<SortButton
wasActive={sortBy === "connector"}
lowToLarge={sortOrder === SortOrderEnum.ASC}
onClick={() => onSortClick("connector")}
/>
</>
),
accessor: "connectorName",
Cell: ({ cell, row }: CellProps<EntityTableDataItem>) => (
<ConnectorCell
Expand All @@ -50,7 +116,16 @@ const ImplementationTable: React.FC<IProps> = ({
),
},
{
Header: <FormattedMessage id={`tables.${entity}ConnectWith`} />,
Header: (
<>
<FormattedMessage id={`tables.${entity}ConnectWith`} />
<SortButton
wasActive={sortBy === "destination"}
lowToLarge={sortOrder === SortOrderEnum.ASC}
onClick={() => onSortClick("destination")}
/>
</>
),
accessor: "connectEntities",
Cell: ({ cell, row }: CellProps<EntityTableDataItem>) => (
<ConnectEntitiesCell
Expand Down Expand Up @@ -79,14 +154,14 @@ const ImplementationTable: React.FC<IProps> = ({
),
},
],
[entity]
[entity, onSortClick, sortBy, sortOrder]
);

return (
<Content>
<Table
columns={columns}
data={data}
data={sortingData}
onClickRow={onClickRow}
erroredRows
/>
Expand Down
1 change: 1 addition & 0 deletions airbyte-webapp/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const Table: React.FC<IProps> = ({
}
return [pl, plConfig];
}, [sortBy]);

const {
getTableProps,
getTableBodyProps,
Expand Down