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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
* Fix instance format filter. Refs UIIN-1423.
* Change label Duplicate MARC bib record to Derive new MARC bib record. Refs UIIN-1436.
* 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.
* Update `data-export` interface to `4.0`. Refs UIIN-1448.
* Update `@folio/react-intl-safe-html`, `@folio/plugin-find-instance`, and `@folio/quick-marc` for compatibility with `@folio/stripes` `v6`.
* Unable to move item to separate holding (same instance) when list of items scrolls down and off the screen. Refs UIIN-1446
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 @@ -347,22 +336,12 @@ 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 { inTransitItemsExportInProgress } = this.state;
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 @@ -474,20 +453,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 @@ -626,7 +592,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 @@ -636,11 +601,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 @@ -658,7 +628,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