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

STSMACOM-468: Enabled <ColumnManager> in the results list #1339

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
* Add a warning icon for instance/holdings/item marked as Suppressed from discovery. Refs UIIN-1380.
* Fix nature of content filter. Fixes UIIN-1441.
* Add a warning icon for instance marked as Staff suppressed. Refs UIIN-1381.

* Enabled `<ColumnManager>` in the results list. Refs STSMACOM-468.
## [5.0.1](https://github.com/folio-org/ui-inventory/tree/v5.0.1) (2020-10-15)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v5.0.0...v5.0.1)

Expand Down
45 changes: 7 additions & 38 deletions src/components/InstancesList/InstancesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const RESULT_COUNT_INCREMENT = 30;
const TOGGLEABLE_COLUMNS = ['contributors', 'publishers', 'relation'];
const NON_TOGGLEABLE_COLUMNS = ['select', 'title'];
const ALL_COLUMNS = [...NON_TOGGLEABLE_COLUMNS, ...TOGGLEABLE_COLUMNS];
const VISIBLE_COLUMNS_STORAGE_KEY = 'inventory-visible-columns';

class InstancesList extends React.Component {
static defaultProps = {
Expand Down Expand Up @@ -123,20 +122,10 @@ class InstancesList extends React.Component {
showErrorModal: false,
selectedRows: {},
isSelectedRecordsModalOpened: false,
visibleColumns: this.getInitialToggableColumns(),
isImportRecordModalOpened: false,
};
}

getInitialToggableColumns = () => {
return getItem(VISIBLE_COLUMNS_STORAGE_KEY) || TOGGLEABLE_COLUMNS;
}

getVisibleColumns = () => {
const visibleColumns = new Set([...this.state.visibleColumns, ...NON_TOGGLEABLE_COLUMNS]);
return ALL_COLUMNS.filter(key => visibleColumns.has(key));
}

onFilterChangeHandler = ({ name, values }) => {
const {
data: { query },
Expand Down Expand Up @@ -341,21 +330,11 @@ class InstancesList extends React.Component {
);
}

handleToggleColumn = ({ target: { value: key } }) => {
this.setState(({ visibleColumns }) => ({
visibleColumns: visibleColumns.includes(key) ? visibleColumns.filter(k => key !== k) : [...visibleColumns, key]
}), () => {
setItem(VISIBLE_COLUMNS_STORAGE_KEY, this.state.visibleColumns);
});
}

getActionMenu = ({ onToggle }) => {
getActionMenu = ({ onToggle, renderColumnsMenu }) => {
const { parentResources, intl } = this.props;
const selectedRowsCount = size(this.state.selectedRows);
const isInstancesListEmpty = isEmpty(get(parentResources, ['records', 'records'], []));
const isQuickExportLimitExceeded = selectedRowsCount > QUICK_EXPORT_LIMIT;
const visibleColumns = this.getVisibleColumns();
const columnMapping = this.getColumnMapping();

const buildOnClickHandler = onClickHandler => {
return () => {
Expand Down Expand Up @@ -457,20 +436,7 @@ class InstancesList extends React.Component {
isDisabled: !selectedRowsCount,
})}
</MenuSection>
<MenuSection label={intl.formatMessage({ id: 'ui-inventory.showColumns' })} id="columns-menu-section">
{TOGGLEABLE_COLUMNS.map(key => (
<Checkbox
key={key}
name={key}
data-testid={key}
label={columnMapping[key]}
id={`inventory-search-column-checkbox-${key}`}
checked={visibleColumns.includes(key)}
value={key}
onChange={this.handleToggleColumn}
/>
))}
</MenuSection>
{renderColumnsMenu}
</>
);
};
Expand Down Expand Up @@ -609,7 +575,6 @@ class InstancesList extends React.Component {
'contributors': r => formatters.contributorsFormatter(r, data.contributorTypes),
};

const visibleColumns = this.getVisibleColumns();
const columnMapping = this.getColumnMapping();

const formattedSearchableIndexes = searchableIndexes.map(index => {
Expand All @@ -619,11 +584,16 @@ class InstancesList extends React.Component {
return { ...index, label };
});

const columnManagerProps = {
excludeKeys: ['select', 'title']
};

return (
<>
<div data-test-inventory-instances>
<SearchAndSort
actionMenu={this.getActionMenu}
columnManagerProps={columnManagerProps}
packageInfo={packageInfo}
objectName="inventory"
maxSortKeys={1}
Expand All @@ -641,7 +611,6 @@ class InstancesList extends React.Component {
previouslyHeld: false,
source: 'FOLIO',
}}
visibleColumns={visibleColumns}
columnMapping={columnMapping}
columnWidths={{
select: '30px',
Expand Down
2 changes: 1 addition & 1 deletion src/components/InstancesList/InstancesList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('InstancesRoute', () => {

describe('hiding contributors column', () => {
beforeEach(() => {
userEvent.click(screen.getByTestId('contributors'));
userEvent.click(document.querySelector('[data-test-column-manager-checkbox="contributors"]'));
});

it('should hide contributors column', () => {
Expand Down