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

Restyle Add column description to table viz #4832

Closed
Closed
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
10 changes: 5 additions & 5 deletions client/app/visualizations/table/Editor/ColumnEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ export default function ColumnEditor({ column, onChange }) {
<Input
data-test={`Table.Column.${column.name}.Title`}
defaultValue={column.title}
onChange={event => handleChangeDebounced({ title: event.target.value })}
onChange={(event) => handleChangeDebounced({ title: event.target.value })}
/>
</Grid.Col>
<Grid.Col span={8}>
<TextAlignmentSelect
data-test={`Table.Column.${column.name}.TextAlignment`}
defaultValue={column.alignContent}
onChange={event => handleChange({ alignContent: event.target.value })}
onChange={(event) => handleChange({ alignContent: event.target.value })}
/>
</Grid.Col>
</Grid.Row>
Expand All @@ -41,7 +41,7 @@ export default function ColumnEditor({ column, onChange }) {
<Checkbox
data-test={`Table.Column.${column.name}.UseForSearch`}
defaultChecked={column.allowSearch}
onChange={event => handleChange({ allowSearch: event.target.checked })}>
onChange={(event) => handleChange({ allowSearch: event.target.checked })}>
Use for search
</Checkbox>
</Section>
Expand All @@ -50,7 +50,7 @@ export default function ColumnEditor({ column, onChange }) {
<Input
label="Description"
defaultValue={column.description}
onChange={event => handleChangeDebounced({ description: event.target.value })}
onChange={(event) => handleChangeDebounced({ description: event.target.value })}
/>
</Section>

Expand All @@ -60,7 +60,7 @@ export default function ColumnEditor({ column, onChange }) {
data-test={`Table.Column.${column.name}.DisplayAs`}
className="w-100"
defaultValue={column.displayAs}
onChange={displayAs => handleChange({ displayAs })}>
onChange={(displayAs) => handleChange({ displayAs })}>
{map(ColumnTypes, ({ friendlyName }, key) => (
<Select.Option key={key} data-test={`Table.Column.${column.name}.DisplayAs.${key}`}>
{friendlyName}
Expand Down
20 changes: 8 additions & 12 deletions client/app/visualizations/table/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ function nextOrderByDirection(direction) {
}

function toggleOrderBy(columnName, orderBy = [], multiColumnSort = false) {
const index = findIndex(orderBy, i => i.name === columnName);
const index = findIndex(orderBy, (i) => i.name === columnName);
const item = { name: columnName, direction: "ascend" };
if (index >= 0) {
item.direction = nextOrderByDirection(orderBy[index].direction);
}

if (multiColumnSort) {
if (!item.direction) {
return filter(orderBy, i => i.name !== columnName);
return filter(orderBy, (i) => i.name !== columnName);
}
if (index >= 0) {
orderBy[index] = item;
Expand All @@ -52,7 +52,7 @@ export function prepareColumns(columns, searchInput, orderBy, onOrderByChange) {
const isMultiColumnSort = orderBy.length > 1;
const orderByInfo = getOrderByInfo(orderBy);

let tableColumns = map(columns, column => {
let tableColumns = map(columns, (column) => {
const isAscend = orderByInfo[column.name] && orderByInfo[column.name].direction === "ascend";
const isDescend = orderByInfo[column.name] && orderByInfo[column.name].direction === "descend";

Expand Down Expand Up @@ -96,7 +96,7 @@ export function prepareColumns(columns, searchInput, orderBy, onOrderByChange) {
className: cx("ant-table-column-has-actions ant-table-column-has-sorters", {
"table-visualization-column-is-sorted": isAscend || isDescend,
}),
onClick: event => onOrderByChange(toggleOrderBy(column.name, orderBy, event.shiftKey)),
onClick: (event) => onOrderByChange(toggleOrderBy(column.name, orderBy, event.shiftKey)),
}),
};

Expand Down Expand Up @@ -151,20 +151,16 @@ export function initRows(rows) {
export function filterRows(rows, searchTerm, searchColumns) {
if (searchTerm !== "" && searchColumns.length > 0) {
searchTerm = searchTerm.toUpperCase();
const matchFields = map(searchColumns, column => {
const matchFields = map(searchColumns, (column) => {
const initColumn = ColumnTypes[column.displayAs];
const { prepareData } = initColumn(column);
return row => {
return (row) => {
const { text } = prepareData(row);
return (
toString(text)
.toUpperCase()
.indexOf(searchTerm) >= 0
);
return toString(text).toUpperCase().indexOf(searchTerm) >= 0;
};
});

return filter(rows, row => some(matchFields, match => match(row.record)));
return filter(rows, (row) => some(matchFields, (match) => match(row.record)));
}
return rows;
}
Expand Down