Skip to content

Commit

Permalink
fix: datatable invalid sort key
Browse files Browse the repository at this point in the history
  • Loading branch information
wwills2 committed Apr 24, 2024
1 parent 8eba8c1 commit 875a264
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/renderer/components/blocks/tables/ProjectsListTable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo } from 'react';
import { FormattedMessage } from 'react-intl';
import { DebouncedFunc } from 'lodash';
import { DataTable, PageCounter, Pagination, ProjectAndUnitActions, Tooltip } from '@/components';
import { Column, DataTable, PageCounter, Pagination, ProjectAndUnitActions, Tooltip } from '@/components';
import { Project } from '@/schemas/Project.schema';
import { Badge } from 'flowbite-react';

Expand Down Expand Up @@ -31,16 +31,17 @@ const ProjectsListTable: React.FC<TableProps> = ({
totalCount,
}) => {
const columns = useMemo(() => {
const editColumn: any = [
const editColumn: Column[] = [
{
title: '',
key: 'actionColumn',
ignoreChildEvents: true,
ignoreOrderChange: true,
render: (row: Project) => <ProjectAndUnitActions type="project" warehouseId={row?.warehouseProjectId || ''} />,
},
];

const staticColumns: any = [
const staticColumns: Column[] = [
{
title: <FormattedMessage id={'current-registry'} />,
key: 'currentRegistry',
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/components/blocks/tables/UnitsListTable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useMemo } from 'react';
import { FormattedMessage } from 'react-intl';
import { DebouncedFunc } from 'lodash';
import { DataTable, PageCounter, Pagination, ProjectAndUnitActions } from '@/components';
import { Column, DataTable, PageCounter, Pagination, ProjectAndUnitActions } from '@/components';
import { Unit } from '@/schemas/Unit.schema';

interface TableProps {
Expand Down Expand Up @@ -30,16 +30,17 @@ const UnitsListTable: React.FC<TableProps> = ({
totalCount,
}) => {
const columns = useMemo(() => {
const editColumn: any = [
const editColumn: Column[] = [
{
title: '',
key: 'actionColumn',
ignoreChildEvents: true,
ignoreOrderChange: true,
render: (row: Unit) => <ProjectAndUnitActions type="unit" warehouseId={row.warehouseUnitId} />,
},
];

const staticColumns: any = [
const staticColumns: Column[] = [
{
title: <FormattedMessage id={'unit-owner'} />,
key: 'unitOwner',
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/components/layout/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import 'simplebar/dist/simplebar.min.css';
import { AiOutlineSortAscending, AiOutlineSortDescending } from 'react-icons/ai';
import React from 'react';

interface Column {
export interface Column {
key: string;
title: string | JSX.Element;
ignoreChildEvents?: boolean;
ignoreOrderChange?: boolean;
render?: (row: any) => JSX.Element;
renderHeader?: (column: any) => JSX.Element;
width?: string;
Expand Down Expand Up @@ -103,7 +104,7 @@ const DataTable: React.FC<DataTableProps> = ({
? 'bg-gray-200 dark:bg-gray-600 text-gray-800 dark:text-white'
: 'text-gray-500 dark:text-gray-400'
}`}
onClick={() => onChangeOrder && onChangeOrder(column.key)}
onClick={() => !column.ignoreOrderChange && onChangeOrder && onChangeOrder(column.key)}
>
<div className="flex items-center justify-between">
<span>{column.renderHeader ? column.renderHeader(column) : column.title}</span>
Expand Down
12 changes: 6 additions & 6 deletions src/renderer/pages/MyProjectsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { useGetOrganizationsListQuery } from '@/api';
import { useQueryParamState, useWildCardUrlHash } from '@/hooks';
import { useQueryParamState, useUrlHash, useWildCardUrlHash } from '@/hooks';
import { debounce } from 'lodash';
import {
Button,
Expand All @@ -9,11 +9,11 @@ import {
IndeterminateProgressOverlay,
OrgUidBadge,
SearchBox,
StagedProjectSuccessModal,
StagingTableTab,
SyncIndicator,
Tabs,
UpsertProjectModal,
StagedProjectSuccessModal
} from '@/components';
import { FormattedMessage } from 'react-intl';
import { useGetOrganizationsMapQuery } from '@/api/cadt/v1/organizations';
Expand Down Expand Up @@ -42,8 +42,6 @@ const MyProjectsPage: React.FC = () => {
const [, editProjectModalActive] = useWildCardUrlHash('edit-project');
const [createProjectModalActive, setCreateProjectModalActive] = useUrlHash('create-project');
const [projectStagedSuccess, setProjectStagedSuccess] = useUrlHash('success-stage-project');
const [, createProjectModalActive, setCreateProjectModalActive] = useWildCardUrlHash('create-project');
const [, editProjectModalActive] = useWildCardUrlHash('edit-project');
const [activeTab, setActiveTab] = useState<TabTypes>(TabTypes.COMMITTED);
const [committedDataLoading, setCommittedDataLoading] = useState<boolean>(false);
const { data: organizationsMap } = useGetOrganizationsMapQuery(null, {
Expand Down Expand Up @@ -111,7 +109,7 @@ const MyProjectsPage: React.FC = () => {
<div className="m-2">
{contentsLoading && <IndeterminateProgressOverlay />}
<div className="flex flex-col md:flex-row gap-6 my-2.5 relative z-30 items-center">
<Button disabled={contentsLoading} onClick={() => setCreateProjectModalActive(true, '')}>
<Button disabled={contentsLoading} onClick={() => setCreateProjectModalActive(true)}>
<FormattedMessage id="create-project" />
</Button>
{activeTab === TabTypes.COMMITTED && <SearchBox defaultValue={search} onChange={handleSearchChange} />}
Expand Down Expand Up @@ -161,7 +159,9 @@ const MyProjectsPage: React.FC = () => {
</Tabs>
</div>
{(createProjectModalActive || editProjectModalActive) && <UpsertProjectModal onClose={handleCloseUpsertModal} />}
{projectStagedSuccess && <StagedProjectSuccessModal showModal={true} onClose={() => setProjectStagedSuccess(false)} />}
{projectStagedSuccess && (
<StagedProjectSuccessModal showModal={true} onClose={() => setProjectStagedSuccess(false)} />
)}
</>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/pages/MyUnitsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { useGetOrganizationsListQuery } from '@/api';
import { useQueryParamState, useWildCardUrlHash, useUrlHash } from '@/hooks';
import { useQueryParamState, useUrlHash, useWildCardUrlHash } from '@/hooks';
import { debounce } from 'lodash';
import {
Button,
Expand Down Expand Up @@ -39,7 +39,7 @@ const MyUnitsPage: React.FC = () => {
const [orgUid, setOrgUid] = useQueryParamState('orgUid', undefined);
const [search, setSearch] = useQueryParamState('search', undefined);
const [, editUnitModalActive] = useWildCardUrlHash('edit-unit');
const [, createUnitModalActive, setCreateUnitModalActive] = useWildCardUrlHash('create-unit');
const [createUnitModalActive, setCreateUnitModalActive] = useUrlHash('create-unit');
const [activeTab, setActiveTab] = useState<TabTypes>(TabTypes.COMMITTED);
const [committedDataLoading, setCommittedDataLoading] = useState<boolean>(false);
const { data: organizationsMap } = useGetOrganizationsMapQuery(null, {
Expand Down

0 comments on commit 875a264

Please sign in to comment.