Skip to content

Commit

Permalink
header item scalability
Browse files Browse the repository at this point in the history
  • Loading branch information
anamontiaga committed Aug 31, 2023
1 parent b0870b9 commit 3950c58
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,16 @@ import { cn } from 'utils/cn';

import { HeaderItem } from './types';

const HeaderItem = ({
className,
text,
name,
columns,
sorting,
onClick,
}: HeaderItem): JSX.Element => {
const HeaderItem = ({ className, text, name, sorting, onClick }: HeaderItem): JSX.Element => {
const sortingMatches = /^(-?)(.+)$/.exec(sorting);
const sortField = sortingMatches[2];
const sortOrder = sortingMatches[1] === '-' ? 'desc' : 'asc';

const isActive = columns[name] === sortField;
const isActive = name === sortField;

const handleClick = useCallback(() => {
onClick(columns[name]);
}, [onClick, columns, name]);
onClick(name);
}, [onClick, name]);

return (
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ export type HeaderItem = {
className?: string;
text: string;
name: string;
columns: {
[key: string]: string;
};
sorting: string;
onClick?: (field: string) => void;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Checkbox from 'components/forms/checkbox';
import Loading from 'components/loading';
import { cn } from 'utils/cn';

import HeaderItem from './header-item';
import RowItem from './row-item';
Expand Down Expand Up @@ -43,29 +44,24 @@ const InventoryTable = ({
onChange={onSelectAll}
/>
</th>
{columns['name'] && (
<th className="flex-1 pl-2">
<HeaderItem
text={'Name'}
name={'name'}
columns={columns}
sorting={sorting}
onClick={onSortChange}
/>
</th>
)}
{columns['tag'] && (
<th className="flex flex-1 justify-start py-2 pl-14">
<HeaderItem
className="justify-center"
text={'Type'}
name={'tag'}
columns={columns}
sorting={sorting}
onClick={onSortChange}
/>
</th>
)}
{columns.map((column) => {
return (
<th
key={column.name}
className={cn({
'flex-1 border pl-2': true,
[column.className]: !!column.className,
})}
>
<HeaderItem
text={column.text}
name={column.name}
sorting={sorting}
onClick={onSortChange}
/>
</th>
);
})}
</tr>
</thead>
<tbody className="block max-h-[calc(100vh-430px)] divide-y divide-gray-400 overflow-y-auto overflow-x-hidden pl-1 align-baseline text-sm">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ const RowItem = ({
checked={selectedIds.includes(id)}
/>
</td>
<td className="px-1 pb-2 pt-5">
<td
className={cn({
'flex flex-col px-1 pb-2 pt-5': true,
'w-52': tag,
})}
>
<span className="inline-flex">{name}</span>
<div className="mt-1.5 text-xs text-gray-300">
Currently in use in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export type InventoryTable = {
data: DataItem[];
noDataMessage: string;
columns: {
[key: string]: string;
};
name: string;
text: string;
className?: string;
}[];
sorting: string;
selectedIds: string[];
onSortChange: (field: string) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ import { Feature } from 'types/api/feature';

import InventoryTable, { type DataItem } from '../components/inventory-table';

const FEATURES_TABLE_COLUMNS = {
name: 'featureClassName',
tag: 'tag',
};
const FEATURES_TABLE_COLUMNS = [
{
name: 'featureClassName',
text: 'Name',
},
{
name: 'tag',
text: 'Type',
className: 'flex flex-1 justify-start py-2 pl-14',
},
];

const InventoryPanelFeatures = ({ noData: noDataMessage }: { noData: string }): JSX.Element => {
const dispatch = useAppDispatch();
Expand All @@ -26,7 +33,7 @@ const InventoryPanelFeatures = ({ noData: noDataMessage }: { noData: string }):
);

const [filters, setFilters] = useState<Parameters<typeof useAllFeatures>[1]>({
sort: 'featureClassName',
sort: FEATURES_TABLE_COLUMNS[0].name,
});
const [selectedFeaturesIds, setSelectedFeaturesIds] = useState<Feature['id'][]>([]);
const { query } = useRouter();
Expand Down

0 comments on commit 3950c58

Please sign in to comment.