mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-18 09:02:11 +03:00
fix: allow access to the Update View button when a table column can be persisted (#1433)
Closes #1432
This commit is contained in:
parent
85156ce9ae
commit
a1e6e46388
@ -21,6 +21,7 @@ import { FilterDropdownButton } from './FilterDropdownButton';
|
|||||||
import SortOrFilterChip from './SortOrFilterChip';
|
import SortOrFilterChip from './SortOrFilterChip';
|
||||||
|
|
||||||
type OwnProps<SortField> = {
|
type OwnProps<SortField> = {
|
||||||
|
canToggle?: boolean;
|
||||||
context: Context<string | null>;
|
context: Context<string | null>;
|
||||||
sorts: Array<SelectedSortType<SortField>>;
|
sorts: Array<SelectedSortType<SortField>>;
|
||||||
onRemoveSort: (sortId: SelectedSortType<SortField>['key']) => void;
|
onRemoveSort: (sortId: SelectedSortType<SortField>['key']) => void;
|
||||||
@ -93,6 +94,7 @@ const StyledSeperator = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
function SortAndFilterBar<SortField>({
|
function SortAndFilterBar<SortField>({
|
||||||
|
canToggle,
|
||||||
context,
|
context,
|
||||||
sorts,
|
sorts,
|
||||||
onRemoveSort,
|
onRemoveSort,
|
||||||
@ -136,7 +138,7 @@ function SortAndFilterBar<SortField>({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(!filtersWithDefinition.length && !sorts.length) ||
|
(!canToggle && !filtersWithDefinition.length && !sorts.length) ||
|
||||||
!isSortAndFilterBarOpen
|
!isSortAndFilterBarOpen
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -3,6 +3,7 @@ import styled from '@emotion/styled';
|
|||||||
import { useRecoilCallback, useRecoilState } from 'recoil';
|
import { useRecoilCallback, useRecoilState } from 'recoil';
|
||||||
|
|
||||||
import { IconButton } from '@/ui/button/components/IconButton';
|
import { IconButton } from '@/ui/button/components/IconButton';
|
||||||
|
import { sortAndFilterBarScopedState } from '@/ui/filter-n-sort/states/sortAndFilterBarScopedState';
|
||||||
import { IconPlus } from '@/ui/icon';
|
import { IconPlus } from '@/ui/icon';
|
||||||
import { useTrackPointer } from '@/ui/utilities/pointer-event/hooks/useTrackPointer';
|
import { useTrackPointer } from '@/ui/utilities/pointer-event/hooks/useTrackPointer';
|
||||||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
||||||
@ -88,6 +89,10 @@ export function EntityTableHeader() {
|
|||||||
visibleTableColumnsScopedSelector,
|
visibleTableColumnsScopedSelector,
|
||||||
TableRecoilScopeContext,
|
TableRecoilScopeContext,
|
||||||
);
|
);
|
||||||
|
const [, setIsSortAndFilterBarOpen] = useRecoilScopedState(
|
||||||
|
sortAndFilterBarScopedState,
|
||||||
|
TableRecoilScopeContext,
|
||||||
|
);
|
||||||
|
|
||||||
const [initialPointerPositionX, setInitialPointerPositionX] = useState<
|
const [initialPointerPositionX, setInitialPointerPositionX] = useState<
|
||||||
number | null
|
number | null
|
||||||
@ -128,13 +133,20 @@ export function EntityTableHeader() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
setColumns(nextColumns);
|
setColumns(nextColumns);
|
||||||
|
setIsSortAndFilterBarOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
set(resizeFieldOffsetState, 0);
|
set(resizeFieldOffsetState, 0);
|
||||||
setInitialPointerPositionX(null);
|
setInitialPointerPositionX(null);
|
||||||
setResizedFieldKey(null);
|
setResizedFieldKey(null);
|
||||||
},
|
},
|
||||||
[resizedFieldKey, columnsByKey, columns, setColumns],
|
[
|
||||||
|
resizedFieldKey,
|
||||||
|
columnsByKey,
|
||||||
|
columns,
|
||||||
|
setColumns,
|
||||||
|
setIsSortAndFilterBarOpen,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
useTrackPointer({
|
useTrackPointer({
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
import type { ViewFieldMetadata } from '@/ui/editable-field/types/ViewField';
|
import type { ViewFieldMetadata } from '@/ui/editable-field/types/ViewField';
|
||||||
|
import { sortAndFilterBarScopedState } from '@/ui/filter-n-sort/states/sortAndFilterBarScopedState';
|
||||||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
||||||
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
|
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
|
||||||
|
|
||||||
@ -18,6 +19,10 @@ export const useTableColumns = () => {
|
|||||||
tableColumnsByKeyScopedSelector,
|
tableColumnsByKeyScopedSelector,
|
||||||
TableRecoilScopeContext,
|
TableRecoilScopeContext,
|
||||||
);
|
);
|
||||||
|
const [, setIsSortAndFilterBarOpen] = useRecoilScopedState(
|
||||||
|
sortAndFilterBarScopedState,
|
||||||
|
TableRecoilScopeContext,
|
||||||
|
);
|
||||||
|
|
||||||
const handleColumnVisibilityChange = useCallback(
|
const handleColumnVisibilityChange = useCallback(
|
||||||
(column: ColumnDefinition<ViewFieldMetadata>) => {
|
(column: ColumnDefinition<ViewFieldMetadata>) => {
|
||||||
@ -32,8 +37,14 @@ export const useTableColumns = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
setTableColumns(nextColumns);
|
setTableColumns(nextColumns);
|
||||||
|
setIsSortAndFilterBarOpen(true);
|
||||||
},
|
},
|
||||||
[setTableColumns, tableColumns, tableColumnsByKey],
|
[
|
||||||
|
setIsSortAndFilterBarOpen,
|
||||||
|
setTableColumns,
|
||||||
|
tableColumns,
|
||||||
|
tableColumnsByKey,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
return { handleColumnVisibilityChange };
|
return { handleColumnVisibilityChange };
|
||||||
|
@ -138,10 +138,7 @@ export function TableOptionsDropdownContent({
|
|||||||
const currentColumns = await snapshot.getPromise(
|
const currentColumns = await snapshot.getPromise(
|
||||||
tableColumnsScopedState(tableScopeId),
|
tableColumnsScopedState(tableScopeId),
|
||||||
);
|
);
|
||||||
set(
|
set(savedTableColumnsScopedState(viewToCreate.id), currentColumns);
|
||||||
savedTableColumnsScopedState(viewToCreate.id),
|
|
||||||
currentColumns.map((column) => ({ ...column, id: v4() })),
|
|
||||||
);
|
|
||||||
|
|
||||||
const selectedFilters = await snapshot.getPromise(
|
const selectedFilters = await snapshot.getPromise(
|
||||||
filtersScopedState(tableScopeId),
|
filtersScopedState(tableScopeId),
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
import { DropdownRecoilScopeContext } from '@/ui/dropdown/states/recoil-scope-contexts/DropdownRecoilScopeContext';
|
import { DropdownRecoilScopeContext } from '@/ui/dropdown/states/recoil-scope-contexts/DropdownRecoilScopeContext';
|
||||||
import { FilterDropdownButton } from '@/ui/filter-n-sort/components/FilterDropdownButton';
|
import { FilterDropdownButton } from '@/ui/filter-n-sort/components/FilterDropdownButton';
|
||||||
@ -9,13 +10,19 @@ import { FiltersHotkeyScope } from '@/ui/filter-n-sort/types/FiltersHotkeyScope'
|
|||||||
import { SelectedSortType, SortType } from '@/ui/filter-n-sort/types/interface';
|
import { SelectedSortType, SortType } from '@/ui/filter-n-sort/types/interface';
|
||||||
import { TopBar } from '@/ui/top-bar/TopBar';
|
import { TopBar } from '@/ui/top-bar/TopBar';
|
||||||
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
import { RecoilScope } from '@/ui/utilities/recoil-scope/components/RecoilScope';
|
||||||
|
import { useContextScopeId } from '@/ui/utilities/recoil-scope/hooks/useContextScopeId';
|
||||||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
||||||
|
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
|
||||||
|
|
||||||
import { TableOptionsDropdown } from '../../options/components/TableOptionsDropdown';
|
import { TableOptionsDropdown } from '../../options/components/TableOptionsDropdown';
|
||||||
import { TableUpdateViewButtonGroup } from '../../options/components/TableUpdateViewButtonGroup';
|
import { TableUpdateViewButtonGroup } from '../../options/components/TableUpdateViewButtonGroup';
|
||||||
import { TableViewsDropdownButton } from '../../options/components/TableViewsDropdownButton';
|
import { TableViewsDropdownButton } from '../../options/components/TableViewsDropdownButton';
|
||||||
import { TableRecoilScopeContext } from '../../states/recoil-scope-contexts/TableRecoilScopeContext';
|
import { TableRecoilScopeContext } from '../../states/recoil-scope-contexts/TableRecoilScopeContext';
|
||||||
import type { TableView } from '../../states/tableViewsState';
|
import { canPersistTableColumnsScopedSelector } from '../../states/selectors/canPersistTableColumnsScopedSelector';
|
||||||
|
import {
|
||||||
|
currentTableViewIdState,
|
||||||
|
type TableView,
|
||||||
|
} from '../../states/tableViewsState';
|
||||||
import { TableOptionsHotkeyScope } from '../../types/TableOptionsHotkeyScope';
|
import { TableOptionsHotkeyScope } from '../../types/TableOptionsHotkeyScope';
|
||||||
import { TableViewsHotkeyScope } from '../../types/TableViewsHotkeyScope';
|
import { TableViewsHotkeyScope } from '../../types/TableViewsHotkeyScope';
|
||||||
|
|
||||||
@ -34,10 +41,19 @@ export function TableHeader<SortField>({
|
|||||||
onViewSubmit,
|
onViewSubmit,
|
||||||
onImport,
|
onImport,
|
||||||
}: OwnProps<SortField>) {
|
}: OwnProps<SortField>) {
|
||||||
|
const tableScopeId = useContextScopeId(TableRecoilScopeContext);
|
||||||
|
|
||||||
|
const currentTableViewId = useRecoilScopedValue(
|
||||||
|
currentTableViewIdState,
|
||||||
|
TableRecoilScopeContext,
|
||||||
|
);
|
||||||
const [sorts, setSorts] = useRecoilScopedState<SelectedSortType<SortField>[]>(
|
const [sorts, setSorts] = useRecoilScopedState<SelectedSortType<SortField>[]>(
|
||||||
sortsScopedState,
|
sortsScopedState,
|
||||||
TableRecoilScopeContext,
|
TableRecoilScopeContext,
|
||||||
);
|
);
|
||||||
|
const canPersistTableColumns = useRecoilValue(
|
||||||
|
canPersistTableColumnsScopedSelector([tableScopeId, currentTableViewId]),
|
||||||
|
);
|
||||||
|
|
||||||
const sortSelect = useCallback(
|
const sortSelect = useCallback(
|
||||||
(newSort: SelectedSortType<SortField>) => {
|
(newSort: SelectedSortType<SortField>) => {
|
||||||
@ -90,6 +106,7 @@ export function TableHeader<SortField>({
|
|||||||
}
|
}
|
||||||
bottomComponent={
|
bottomComponent={
|
||||||
<SortAndFilterBar
|
<SortAndFilterBar
|
||||||
|
canToggle={canPersistTableColumns}
|
||||||
context={TableRecoilScopeContext}
|
context={TableRecoilScopeContext}
|
||||||
sorts={sorts}
|
sorts={sorts}
|
||||||
onRemoveSort={sortUnselect}
|
onRemoveSort={sortUnselect}
|
||||||
|
Loading…
Reference in New Issue
Block a user