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: add hide column header menu item to explist #8342

Merged
merged 1 commit into from
Nov 9, 2023
Merged
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
75 changes: 44 additions & 31 deletions webui/react/src/pages/F_ExpList/glide-table/GlideTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,51 @@ export const GlideTable: React.FC<GlideTableProps> = ({
setMenuIsOpen(false);
};

const isPinned = col <= pinnedColumnsCount + staticColumns.length - 1;
const items: MenuItem[] = [
// Column is pinned if the index is inside of the frozen columns
col < staticColumns.length || isMobile
? null
: !isPinned
? {
icon: <Icon decorative name="pin" />,
key: 'pin',
label: 'Pin column',
onClick: () => {
const newSortableColumns = sortableColumnIds.filter((c) => c !== column.column);
newSortableColumns.splice(pinnedColumnsCount, 0, column.column);
onSortableColumnChange?.(newSortableColumns);
onPinnedColumnsCountChange?.(
Math.min(pinnedColumnsCount + 1, sortableColumnIds.length),
);
setMenuIsOpen(false);
},
}
: {
disabled: pinnedColumnsCount <= 1,
key: 'unpin',
label: 'Unpin column',
onClick: () => {
const newSortableColumns = sortableColumnIds.filter((c) => c !== column.column);
newSortableColumns.splice(pinnedColumnsCount - 1, 0, column.column);
onSortableColumnChange?.(newSortableColumns);
onPinnedColumnsCountChange?.(Math.max(pinnedColumnsCount - 1, 0));
setMenuIsOpen(false);
},
},
{
icon: <Icon decorative name="eye-close" />,
key: 'hide',
label: 'Hide column',
onClick: () => {
const newSortableColumns = sortableColumnIds.filter((c) => c !== column.column);
onSortableColumnChange?.(newSortableColumns);
if (isPinned) {
onPinnedColumnsCountChange?.(Math.max(pinnedColumnsCount - 1, 0));
}
},
},
{ type: 'divider' as const },
...(BANNED_FILTER_COLUMNS.includes(column.column)
? []
: [
Expand Down Expand Up @@ -399,37 +443,6 @@ export const GlideTable: React.FC<GlideTableProps> = ({
},
}
: null,
// Column is pinned if the index is inside of the frozen columns
col < staticColumns.length || isMobile
? null
: col > pinnedColumnsCount + staticColumns.length - 1
? {
icon: <Icon decorative name="pin" />,
key: 'pin',
label: 'Pin column',
onClick: () => {
const newSortableColumns = sortableColumnIds.filter((c) => c !== column.column);
newSortableColumns.splice(pinnedColumnsCount, 0, column.column);
onSortableColumnChange?.(newSortableColumns);
onPinnedColumnsCountChange?.(
Math.min(pinnedColumnsCount + 1, sortableColumnIds.length),
);
setMenuIsOpen(false);
},
}
: {
disabled: pinnedColumnsCount <= 1,
icon: <Icon decorative name="pin" />,
key: 'unpin',
label: 'Unpin column',
onClick: () => {
const newSortableColumns = sortableColumnIds.filter((c) => c !== column.column);
newSortableColumns.splice(pinnedColumnsCount - 1, 0, column.column);
onSortableColumnChange?.(newSortableColumns);
onPinnedColumnsCountChange?.(Math.max(pinnedColumnsCount - 1, 0));
setMenuIsOpen(false);
},
},
];
setMenuProps((prev) => ({ ...prev, bounds, items, title: `${columnId} menu` }));
setMenuIsOpen(true);
Expand Down