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

ui: fix 3rd click on sorting table column #75473

Merged
merged 1 commit into from
Jan 25, 2022
Merged
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
17 changes: 16 additions & 1 deletion pkg/ui/workspaces/cluster-ui/src/sessions/sessionsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import emptyTableResultsIcon from "../assets/emptyState/empty-table-results.svg"
import SQLActivityError from "../sqlActivity/errorComponent";

import { Pagination, ResultsPerPageLabel } from "src/pagination";
import { SortSetting, ISortedTablePagination } from "src/sortedtable";
import {
SortSetting,
ISortedTablePagination,
updateSortSettingQueryParamsOnTab,
} from "src/sortedtable";
import { Loading } from "src/loading";
import { Anchor } from "src/anchor";
import { EmptyTable } from "src/empty";
Expand Down Expand Up @@ -137,7 +141,18 @@ export class SessionsPage extends React.Component<
}

componentDidUpdate = (): void => {
const { history, sortSetting } = this.props;

this.props.refreshSessions();
updateSortSettingQueryParamsOnTab(
"Sessions",
sortSetting,
{
ascending: false,
columnTitle: "statementAge",
},
history,
);
};

onChangePage = (current: number): void => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,18 @@ export const TableHead: React.FC<TableHeadProps> = ({
const cellContentWrapper = cx("inner-content-wrapper");
const arrowsClass = cx("sortable__actions");

function handleSort(picked: boolean, columnTitle: string) {
function handleSort(
newColumnSelected: boolean,
columnTitle: string,
prevValue: boolean,
) {
// If the columnTitle is different than the previous value, initial sort
// descending. If the same columnTitle is clicked multiple times consecutively,
// first change to ascending, then remove the sort key.
const ASCENDING = true;
const DESCENDING = false;

const direction = picked ? ASCENDING : DESCENDING;
const sortElementColumnTitle =
picked && sortSetting.ascending ? null : columnTitle;
// descending. If is the same columnTitle the value is updated.

const ascending = newColumnSelected ? false : !prevValue;
onChangeSortSetting({
ascending: direction,
columnTitle: sortElementColumnTitle,
ascending,
columnTitle,
});
}

Expand All @@ -58,15 +56,21 @@ export const TableHead: React.FC<TableHeadProps> = ({
{expandableConfig && <th className={thClass} />}
{columns.map((c: SortableColumn, idx: number) => {
const sortable = c.columnTitle !== (null || undefined);
const picked = c.name === sortSetting.columnTitle;
const newColumnSelected = c.name !== sortSetting.columnTitle;
const style = { textAlign: c.titleAlign };
const cellAction = sortable ? () => handleSort(picked, c.name) : null;
const cellAction = sortable
? () => handleSort(newColumnSelected, c.name, sortSetting.ascending)
: null;
const cellClasses = cx(
"head-wrapper__cell",
"sorted__cell",
sortable && "sorted__cell--sortable",
sortSetting.ascending && picked && "sorted__cell--ascending",
!sortSetting.ascending && picked && "sorted__cell--descending",
sortSetting.ascending &&
!newColumnSelected &&
"sorted__cell--ascending",
!sortSetting.ascending &&
!newColumnSelected &&
"sorted__cell--descending",
firstCellBordered && idx === 0 && "cell-header",
);
const titleClasses = c.hideTitleUnderline ? "" : cx("column-title");
Expand Down