Skip to content
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
1 change: 1 addition & 0 deletions src/CONST/SENTRY_LABEL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ const SENTRY_LABEL = {
COLUMN_MENU_SORT_DESCENDING: 'Search-ColumnMenu-SortDescending',
COLUMN_MENU_HIDE_COLUMN: 'Search-ColumnMenu-HideColumn',
COLUMN_MENU_EDIT_COLUMNS: 'Search-ColumnMenu-EditColumns',
COLUMN_MENU_RESET_COLUMN_SIZES: 'Search-ColumnMenu-ResetColumnSizes',
UNREPORTED_EXPENSE_LIST_ITEM: 'Search-UnreportedExpenseListItem',
WORKSPACE_SELECTOR_SELECT_ALL: 'Search-WorkspaceSelectorSelectAll',
STATIC_LIST_ITEM: 'Search-StaticListItem',
Expand Down
17 changes: 15 additions & 2 deletions src/components/Search/SearchColumnMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/** A Spend table heading that opens its column's menu when pressed: sorting, and hiding and editing the columns. */
/** A Spend table heading that opens its column's menu when pressed: sorting, hiding and editing the columns, and resetting their sizes. */
import Icon from '@components/Icon';
import * as PopoverMenu from '@components/PopoverMenu/v2';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import {useColumnResizeController} from '@components/Table/columnResize/ColumnResizeContext';
import RESIZE_HANDLE_COLUMN_OVERLAP from '@components/Table/columnResize/resizeHandleColumnOverlap';

import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
Expand Down Expand Up @@ -136,7 +137,8 @@ function SearchColumnMenu({hidableColumns, hideColumn}: SearchColumnMenuProps) {
const {columnName, sorting} = useSortableColumn();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const icons = useMemoizedLazyExpensifyIcons(['ArrowUpLong', 'ArrowDownLong', 'Checkmark', 'Columns', 'EyeDisabled']);
const icons = useMemoizedLazyExpensifyIcons(['ArrowUpLong', 'ArrowDownLong', 'Checkmark', 'Columns', 'EyeDisabled', 'RotateLeft']);
const resetColumnWidths = useColumnResizeController()?.resetColumnWidths;

// `success` colors the checkmark of the active order, and would color the arrow beside it too. The arrow keeps its usual colors.
const getSortIconFill = (isHovered: boolean) => StyleUtils.getIconFillColor({buttonState: getButtonState({isActive: isHovered}), isMenuIcon: true, isPane: true});
Expand Down Expand Up @@ -188,6 +190,17 @@ function SearchColumnMenu({hidableColumns, hideColumn}: SearchColumnMenuProps) {
onSelect={() => Navigation.navigate(ROUTES.SEARCH_COLUMNS)}
sentryLabel={CONST.SENTRY_LABEL.SEARCH.COLUMN_MENU_EDIT_COLUMNS}
/>
{!!resetColumnWidths && (
Comment thread
war-in marked this conversation as resolved.
Resolved
<>
<PopoverMenu.Separator />
<PopoverMenu.Item
text={translate('search.columnMenu.resetColumnSizes')}
icon={icons.RotateLeft}
onSelect={resetColumnWidths}
sentryLabel={CONST.SENTRY_LABEL.SEARCH.COLUMN_MENU_RESET_COLUMN_SIZES}
/>
</>
)}
</PopoverMenu.Content>
</PopoverMenu.Root>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/Search/SearchListViewLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function SearchListViewLayoutContent({
columnResizingID,
...resizableLayout,
columnGap: variables.searchTableColumnGap,
hasStoredColumnWidths: !!storedTableColumnWidths,
});

const resizableColumnWidths: Partial<Record<SearchColumnType, number>> = {};
Expand Down
1 change: 1 addition & 0 deletions src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ function TableContent<DataType extends TableData, ColumnKey extends string = str
getStoredTableColumnWidths,
getTargetColumnWidth,
columnGap: styles.gap3.gap,
hasStoredColumnWidths: !!storedTableColumnWidths,
});

const tableMethods: TableMethods<ColumnKey, FilterKey> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function useColumnResize({
getStoredTableColumnWidths,
getTargetColumnWidth,
columnGap,
hasStoredColumnWidths,
}: UseColumnResizeParams): ColumnResizeController | undefined {
const styles = useThemeStyles();
const dragRef = useRef<Drag | null>(null);
Expand Down Expand Up @@ -243,7 +244,9 @@ function useColumnResize({
};
};

return {setScopeElement, getHandleProps, hasHandle};
const resetColumnWidths = hasStoredColumnWidths ? () => setTableColumnWidths(columnResizingID, null) : undefined;

return {setScopeElement, getHandleProps, hasHandle, resetColumnWidths};
}

export default useColumnResize;
6 changes: 6 additions & 0 deletions src/components/Table/columnResize/useColumnResize/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type UseColumnResizeParams = {

/** Gap between columns, which handles span. */
columnGap: number;

/** Whether a layout is saved under `columnResizingID`, so there are widths to reset. */
hasStoredColumnWidths: boolean;
};

type ColumnResizeHandleDOMProps = React.ComponentPropsWithRef<'div'>;
Expand All @@ -44,6 +47,9 @@ type ColumnResizeController = {

/** Whether the column has a resize handle. */
hasHandle: (columnKey: string) => boolean;

/** Drops the saved layout, so every column sizes from its content again. `undefined` while no column has been resized. */
resetColumnWidths: (() => void) | undefined;
};

export type {ColumnResizeController, ColumnResizeHandleDOMProps, UseColumnResizeParams};
1 change: 1 addition & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10922,6 +10922,7 @@ Fügen Sie weitere Ausgabelimits hinzu, um den Cashflow Ihres Unternehmens zu sc
sortAscending: 'Aufsteigend sortieren',
sortDescending: 'Absteigend sortieren',
hideColumn: 'Spalte ausblenden',
resetColumnSizes: 'Spaltenbreiten zurücksetzen',
},
groupColumns: 'Spalten gruppieren',
expenseColumns: 'Spalten für Ausgaben',
Expand Down
1 change: 1 addition & 0 deletions src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11137,6 +11137,7 @@ ${reportName}`,
sortAscending: 'Αύξουσα ταξινόμηση',
sortDescending: 'Φθίνουσα ταξινόμηση',
hideColumn: 'Απόκρυψη στήλης',
resetColumnSizes: 'Επαναφορά πλάτους στηλών',
},
groupColumns: 'Ομαδοποίηση στηλών',
expenseColumns: 'Στήλες εξόδων',
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11235,6 +11235,7 @@ const translations = {
sortAscending: 'Sort ascending',
sortDescending: 'Sort descending',
hideColumn: 'Hide column',
resetColumnSizes: 'Reset column sizes',
},
groupColumns: 'Group columns',
expenseColumns: 'Expense Columns',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10847,6 +10847,7 @@ ${reportName}`,
sortAscending: 'Ordenar ascendente',
sortDescending: 'Ordenar descendente',
hideColumn: 'Ocultar columna',
resetColumnSizes: 'Restablecer el ancho de las columnas',
},
groupColumns: 'Columnas de grupo',
expenseColumns: 'Columnas de gastos',
Expand Down
1 change: 1 addition & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10956,6 +10956,7 @@ Ajoutez davantage de règles de dépenses pour protéger la trésorerie de l’e
sortAscending: 'Trier par ordre croissant',
sortDescending: 'Trier par ordre décroissant',
hideColumn: 'Masquer la colonne',
resetColumnSizes: 'Réinitialiser la largeur des colonnes',
},
groupColumns: 'Regrouper les colonnes',
expenseColumns: 'Colonnes de dépenses',
Expand Down
1 change: 1 addition & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10872,6 +10872,7 @@ Aggiungi altre regole di spesa per proteggere il flusso di cassa aziendale.`,
sortAscending: 'Ordina in modo crescente',
sortDescending: 'Ordina in modo decrescente',
hideColumn: 'Nascondi colonna',
resetColumnSizes: 'Reimposta larghezza colonne',
},
groupColumns: 'Raggruppa colonne',
expenseColumns: 'Colonne spese',
Expand Down
1 change: 1 addition & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10693,6 +10693,7 @@ ${reportName}`,
sortAscending: '昇順で並べ替え',
sortDescending: '降順で並べ替え',
hideColumn: '列を非表示',
resetColumnSizes: '列幅をリセット',
},
groupColumns: '列をグループ化',
expenseColumns: '経費列',
Expand Down
1 change: 1 addition & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10842,6 +10842,7 @@ er bestedingsregels toe om de kasstroom van het bedrijf te beschermen.`,
sortAscending: 'Oplopend sorteren',
sortDescending: 'Aflopend sorteren',
hideColumn: 'Kolom verbergen',
resetColumnSizes: 'Kolombreedtes opnieuw instellen',
},
groupColumns: 'Kolommen groeperen',
expenseColumns: 'Onkostencolommen',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10870,6 +10870,7 @@ Dodaj więcej zasad wydatków, żeby chronić płynność finansową firmy.`,
sortAscending: 'Sortuj rosnąco',
sortDescending: 'Sortuj malejąco',
hideColumn: 'Ukryj kolumnę',
resetColumnSizes: 'Resetuj szerokość kolumn',
},
groupColumns: 'Grupuj kolumny',
expenseColumns: 'Kolumny wydatków',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10849,6 +10849,7 @@ Adicione mais regras de gasto para proteger o fluxo de caixa da empresa.`,
sortAscending: 'Classificar em ordem crescente',
sortDescending: 'Classificar em ordem decrescente',
hideColumn: 'Ocultar coluna',
resetColumnSizes: 'Redefinir largura das colunas',
},
groupColumns: 'Agrupar colunas',
expenseColumns: 'Colunas de despesas',
Expand Down
1 change: 1 addition & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10406,6 +10406,7 @@ ${reportName}`,
sortAscending: '升序排序',
sortDescending: '降序排序',
hideColumn: '隐藏列',
resetColumnSizes: '重置列宽',
},
groupColumns: '分组列',
expenseColumns: '报销列',
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/components/Table/useColumnResizeTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function renderColumnResize(params?: Partial<UseColumnResizeParams>) {
getStoredTableColumnWidths,
getTargetColumnWidth,
columnGap: 12,
hasStoredColumnWidths: false,
...params,
};
const hook = renderHook((props: UseColumnResizeParams) => useColumnResize(props), {initialProps});
Expand Down Expand Up @@ -186,6 +187,7 @@ describe('useColumnResize', () => {
resolvedColumnWidths,
getStoredTableColumnWidths,
columnGap: 12,
hasStoredColumnWidths: false,
};

// When the hook runs
Expand All @@ -204,6 +206,7 @@ describe('useColumnResize', () => {
resolvedColumnWidths: {},
getStoredTableColumnWidths,
columnGap: 12,
hasStoredColumnWidths: false,
};

// When the hook runs
Expand All @@ -215,6 +218,27 @@ describe('useColumnResize', () => {
expect(result.current?.getHandleProps(NAME_COLUMN_KEY)).toBeUndefined();
});

it('offers no reset while no column has been resized', () => {
// Given a resizable table with no saved layout
const {result} = renderColumnResize({hasStoredColumnWidths: false});

// Then there is nothing to reset, so menus leave the reset item out
expect(result.current?.resetColumnWidths).toBeUndefined();
});

it('drops the saved layout when the columns are reset', () => {
// Given a resizable table with a saved layout
const {result} = renderColumnResize({hasStoredColumnWidths: true});

// When its columns are reset
act(() => {
result.current?.resetColumnWidths?.();
});

// Then the table's layout is cleared, so every column sizes from its content again
expect(setTableColumnWidths).toHaveBeenCalledWith(COLUMN_RESIZING_ID, null);
});

it('paints a drag onto the scope and stores the dragged column on release', () => {
// Given a 200px column with two 200px columns after it, the first of which absorbs its resize
const {handleElement, getHandleProps, readWidth} = renderColumnResize();
Expand Down
Loading