Skip to content

Commit

Permalink
[EuiDataGrid] use schema sorting labels instead of placeholder value (#…
Browse files Browse the repository at this point in the history
…4199)

* Modified datagrid column actions to use schema sorting labels instead of placeholder text

* snapshot updates

* changelog
  • Loading branch information
chandlerprall authored Oct 30, 2020
1 parent 9826570 commit c067b3c
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Bug fixes**

- Fixed issue with `labelDisplay` not being passed to `EuiSuggestItem` ([#4180](https://github.com/elastic/eui/pull/4180))
- Fixed copy in `EuiDataGrid`'s header menu's sort actions ([#4199](https://github.com/elastic/eui/pull/4199))

## [`30.1.1`](https://github.com/elastic/eui/tree/v30.1.1)

Expand Down
176 changes: 152 additions & 24 deletions src/components/datagrid/__snapshots__/data_grid.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,16 @@ exports[`EuiDataGrid render column actions renders various column actions config
key="title-1"
label={
<EuiI18n
default="Sort schema asc"
token="euiColumnActions.sortAsc"
default="Sort {schemaLabel}"
token="euiColumnActions.sort"
values={
Object {
"schemaLabel": <EuiI18n
default="A-Z"
token="euiColumnSortingDraggable.defaultSortAsc"
/>,
}
}
/>
}
onClick={[Function]}
Expand Down Expand Up @@ -253,13 +261,37 @@ exports[`EuiDataGrid render column actions renders various column actions config
</EuiIcon>
<span
className="euiListGroupItem__label"
title="Sort schema asc"
title="Sort A-Z"
>
<EuiI18n
default="Sort schema asc"
token="euiColumnActions.sortAsc"
default="Sort {schemaLabel}"
token="euiColumnActions.sort"
values={
Object {
"schemaLabel": <EuiI18n
default="A-Z"
token="euiColumnSortingDraggable.defaultSortAsc"
/>,
}
}
>
Sort schema asc
<Component
schemaLabel={
<EuiI18n
default="A-Z"
token="euiColumnSortingDraggable.defaultSortAsc"
/>
}
>
Sort
<EuiI18n
default="A-Z"
key="1"
token="euiColumnSortingDraggable.defaultSortAsc"
>
A-Z
</EuiI18n>
</Component>
</EuiI18n>
</span>
</button>
Expand All @@ -273,8 +305,16 @@ exports[`EuiDataGrid render column actions renders various column actions config
key="title-2"
label={
<EuiI18n
default="Sort schema desc"
token="euiColumnActions.sortDesc"
default="Sort {schemaLabel}"
token="euiColumnActions.sort"
values={
Object {
"schemaLabel": <EuiI18n
default="Z-A"
token="euiColumnSortingDraggable.defaultSortDesc"
/>,
}
}
/>
}
onClick={[Function]}
Expand Down Expand Up @@ -302,13 +342,37 @@ exports[`EuiDataGrid render column actions renders various column actions config
</EuiIcon>
<span
className="euiListGroupItem__label"
title="Sort schema desc"
title="Sort Z-A"
>
<EuiI18n
default="Sort schema desc"
token="euiColumnActions.sortDesc"
default="Sort {schemaLabel}"
token="euiColumnActions.sort"
values={
Object {
"schemaLabel": <EuiI18n
default="Z-A"
token="euiColumnSortingDraggable.defaultSortDesc"
/>,
}
}
>
Sort schema desc
<Component
schemaLabel={
<EuiI18n
default="Z-A"
token="euiColumnSortingDraggable.defaultSortDesc"
/>
}
>
Sort
<EuiI18n
default="Z-A"
key="1"
token="euiColumnSortingDraggable.defaultSortDesc"
>
Z-A
</EuiI18n>
</Component>
</EuiI18n>
</span>
</button>
Expand Down Expand Up @@ -459,8 +523,16 @@ exports[`EuiDataGrid render column actions renders various column actions config
key="title-0"
label={
<EuiI18n
default="Sort schema asc"
token="euiColumnActions.sortAsc"
default="Sort {schemaLabel}"
token="euiColumnActions.sort"
values={
Object {
"schemaLabel": <EuiI18n
default="A-Z"
token="euiColumnSortingDraggable.defaultSortAsc"
/>,
}
}
/>
}
onClick={[Function]}
Expand Down Expand Up @@ -488,13 +560,37 @@ exports[`EuiDataGrid render column actions renders various column actions config
</EuiIcon>
<span
className="euiListGroupItem__label"
title="Sort schema asc"
title="Sort A-Z"
>
<EuiI18n
default="Sort schema asc"
token="euiColumnActions.sortAsc"
default="Sort {schemaLabel}"
token="euiColumnActions.sort"
values={
Object {
"schemaLabel": <EuiI18n
default="A-Z"
token="euiColumnSortingDraggable.defaultSortAsc"
/>,
}
}
>
Sort schema asc
<Component
schemaLabel={
<EuiI18n
default="A-Z"
token="euiColumnSortingDraggable.defaultSortAsc"
/>
}
>
Sort
<EuiI18n
default="A-Z"
key="1"
token="euiColumnSortingDraggable.defaultSortAsc"
>
A-Z
</EuiI18n>
</Component>
</EuiI18n>
</span>
</button>
Expand All @@ -508,8 +604,16 @@ exports[`EuiDataGrid render column actions renders various column actions config
key="title-1"
label={
<EuiI18n
default="Sort schema desc"
token="euiColumnActions.sortDesc"
default="Sort {schemaLabel}"
token="euiColumnActions.sort"
values={
Object {
"schemaLabel": <EuiI18n
default="Z-A"
token="euiColumnSortingDraggable.defaultSortDesc"
/>,
}
}
/>
}
onClick={[Function]}
Expand Down Expand Up @@ -537,13 +641,37 @@ exports[`EuiDataGrid render column actions renders various column actions config
</EuiIcon>
<span
className="euiListGroupItem__label"
title="Sort schema desc"
title="Sort Z-A"
>
<EuiI18n
default="Sort schema desc"
token="euiColumnActions.sortDesc"
default="Sort {schemaLabel}"
token="euiColumnActions.sort"
values={
Object {
"schemaLabel": <EuiI18n
default="Z-A"
token="euiColumnSortingDraggable.defaultSortDesc"
/>,
}
}
>
Sort schema desc
<Component
schemaLabel={
<EuiI18n
default="Z-A"
token="euiColumnSortingDraggable.defaultSortDesc"
/>
}
>
Sort
<EuiI18n
default="Z-A"
key="1"
token="euiColumnSortingDraggable.defaultSortDesc"
>
Z-A
</EuiI18n>
</Component>
</EuiI18n>
</span>
</button>
Expand Down
33 changes: 31 additions & 2 deletions src/components/datagrid/column_actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,21 @@ import React from 'react';
import { EuiDataGridColumn, EuiDataGridSorting } from './data_grid_types';
import { EuiI18n } from '../i18n';
import { EuiListGroupItemProps } from '../list_group';
import {
EuiDataGridSchema,
EuiDataGridSchemaDetector,
getDetailsForSchema,
} from './data_grid_schema';
import {
defaultSortAscLabel,
defaultSortDescLabel,
} from './column_sorting_draggable';

export function getColumnActions(
column: EuiDataGridColumn,
columns: EuiDataGridColumn[],
schema: EuiDataGridSchema,
schemaDetectors: EuiDataGridSchemaDetector[],
setVisibleColumns: (columnId: string[]) => void,
setIsPopoverOpen: (value: boolean) => void,
sorting: EuiDataGridSorting | undefined,
Expand Down Expand Up @@ -118,10 +129,21 @@ export function getColumnActions(
}
}

const schemaDetails =
schema.hasOwnProperty(column.id) && schema[column.id].columnType != null
? getDetailsForSchema(schemaDetectors, schema[column.id].columnType)
: null;
if (column.actions?.showSortAsc !== false && sorting) {
const label = schemaDetails
? schemaDetails.sortTextAsc
: defaultSortAscLabel;
const option = {
label: (
<EuiI18n token="euiColumnActions.sortAsc" default="Sort schema asc" />
<EuiI18n
token="euiColumnActions.sort"
default="Sort {schemaLabel}"
values={{ schemaLabel: label }}
/>
),
onClick: onClickSortAsc,
isDisabled: column.isSortable === false,
Expand All @@ -141,9 +163,16 @@ export function getColumnActions(
}

if (column.actions?.showSortDesc !== false && sorting) {
const label = schemaDetails
? schemaDetails.sortTextDesc
: defaultSortDescLabel;
const option = {
label: (
<EuiI18n token="euiColumnActions.sortDesc" default="Sort schema desc" />
<EuiI18n
token="euiColumnActions.sort"
default="Sort {schemaLabel}"
values={{ schemaLabel: label }}
/>
),
onClick: onClickSortDesc,
isDisabled: column.isSortable === false,
Expand Down
22 changes: 9 additions & 13 deletions src/components/datagrid/column_sorting_draggable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export interface EuiDataGridColumnSortingDraggableProps {
display: string;
}

export const defaultSortAscLabel = (
<EuiI18n token="euiColumnSortingDraggable.defaultSortAsc" default="A-Z" />
);
export const defaultSortDescLabel = (
<EuiI18n token="euiColumnSortingDraggable.defaultSortDesc" default="Z-A" />
);

export const EuiDataGridColumnSortingDraggable: FunctionComponent<EuiDataGridColumnSortingDraggableProps> = ({
id,
display,
Expand All @@ -62,21 +69,10 @@ export const EuiDataGridColumnSortingDraggable: FunctionComponent<EuiDataGridCol
: null;

const textSortAsc =
schemaDetails != null ? (
schemaDetails.sortTextAsc
) : (
<EuiI18n token="euiColumnSortingDraggable.defaultSortAsc" default="A-Z" />
);
schemaDetails != null ? schemaDetails.sortTextAsc : defaultSortAscLabel;

const textSortDesc =
schemaDetails != null ? (
schemaDetails.sortTextDesc
) : (
<EuiI18n
token="euiColumnSortingDraggable.defaultSortDesc"
default="Z-A"
/>
);
schemaDetails != null ? schemaDetails.sortTextDesc : defaultSortDescLabel;

const toggleOptions = [
{
Expand Down
1 change: 1 addition & 0 deletions src/components/datagrid/data_grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ export const EuiDataGrid: FunctionComponent<EuiDataGridProps> = (props) => {
setVisibleColumns={setVisibleColumns}
switchColumnPos={switchColumnPos}
schema={mergedSchema}
schemaDetectors={allSchemaDetectors}
sorting={sorting}
headerIsInteractive={
headerIsInteractive
Expand Down
3 changes: 3 additions & 0 deletions src/components/datagrid/data_grid_header_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const EuiDataGridHeaderCell: FunctionComponent<EuiDataGridHeaderCellProps
columns,
columnWidths,
schema,
schemaDetectors,
defaultColumnWidth,
setColumnWidth,
setVisibleColumns,
Expand Down Expand Up @@ -274,6 +275,8 @@ export const EuiDataGridHeaderCell: FunctionComponent<EuiDataGridHeaderCellProps
const columnActions = getColumnActions(
column,
columns,
schema,
schemaDetectors,
setVisibleColumns,
setIsPopoverOpen,
sorting,
Expand Down
Loading

0 comments on commit c067b3c

Please sign in to comment.