Skip to content

Commit

Permalink
adjsut list on single mode
Browse files Browse the repository at this point in the history
  • Loading branch information
usavkov-epam committed Dec 6, 2023
1 parent 880002c commit 3d3fbc5
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 37 deletions.
52 changes: 38 additions & 14 deletions lib/FindLocation/FindLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,56 @@ import { FindLocationFilters } from './FindLocationFilters';

export const FindLocation = (props) => {
const {
columnMapping,
idPrefix,
isMultiSelect,
modalLabel,
onRecordsSelect,
resultsPaneTitle,
sortableColumns,
visibleColumns,
...rest
} = props;

const [selectedLocations, setSelectedLocations] = useState();
const [selectedLocations, setSelectedLocations] = useState({});

const columnMapping = useMemo(() => ({
...COLUMN_MAPPING,
...(
isMultiSelect
? { [COLUMN_NAMES.isAssigned]: <FormattedMessage id="stripes-acq-components.find-location.results.column.assignment" /> }

Check failure on line 32 in lib/FindLocation/FindLocation.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Expected indentation of 8 spaces but found 6
: {}

Check failure on line 33 in lib/FindLocation/FindLocation.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Expected indentation of 8 spaces but found 6
)

Check failure on line 34 in lib/FindLocation/FindLocation.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Missing trailing comma
}), [isMultiSelect]);

const visibleColumns = useMemo(() => ([
...VISIBLE_COLUMNS,
...(isMultiSelect ? [COLUMN_NAMES.isAssigned] : []),
]), [isMultiSelect]);

const resultsFormatter = useMemo(() => ({
[COLUMN_NAMES.name]: ({ name }) => name,
// TODO: refine
// TODO: add formatters for the rest of colls
[COLUMN_NAMES.code]: ({ code }) => code,
[COLUMN_NAMES.isActive]: ({ isActive }) => (

Check failure on line 46 in lib/FindLocation/FindLocation.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'isActive' is missing in props validation
<FormattedMessage id={`stripes-acq-components.find-location.results.column.status.${ isActive ? 'active': 'inactive'}`} />

Check failure on line 47 in lib/FindLocation/FindLocation.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Unexpected space(s) after '${'

Check failure on line 47 in lib/FindLocation/FindLocation.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Operator ':' must be spaced
),
[COLUMN_NAMES.isAssigned]: ({ id }) => id,
}), []);
[COLUMN_NAMES.isAssigned]: ({ id }) => (

Check failure on line 49 in lib/FindLocation/FindLocation.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

'id' is missing in props validation
<FormattedMessage id={`stripes-acq-components.filter.assignment.${ selectedLocations[id] ? 'assigned': 'unassigned'}`} />

Check failure on line 50 in lib/FindLocation/FindLocation.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Unexpected space(s) after '${'
),
}), [selectedLocations]);

const { locations, isLoading } = useLocationsRecords();

const renderFilters = useCallback((activeFilters, applyFilters) => (
<FindLocationFilters
activeFilters={activeFilters}
applyFilters={applyFilters}
isMultiSelect={isMultiSelect}
/>
), []);
), [isMultiSelect]);

const refreshRecords = useCallback((data) => {
console.log('refresh', data)

Check warning on line 65 in lib/FindLocation/FindLocation.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

Unexpected console statement
}, []);

return (
<FindRecords
Expand All @@ -55,29 +75,33 @@ export const FindLocation = (props) => {
columnMapping={columnMapping}
resultsFormatter={resultsFormatter}
records={locations}
totalCount={0}
refreshRecords={console.log}
totalCount={locations.length}
refreshRecords={refreshRecords}
isMultiSelect={isMultiSelect}
isLoading={isLoading}
selectRecords={console.log}
selectRecords={onRecordsSelect}
onSelectedChange={setSelectedLocations}
stickyFirstColumn
stickyFirstColumn={isMultiSelect}
renderFilters={renderFilters}
{...rest}
/>
);
};

FindLocation.propTypes = {

idPrefix: PropTypes.string,
isMultiSelect: PropTypes.bool,
modalLabel: PropTypes.oneOf([PropTypes.element, PropTypes.string]),
onRecordsSelect: PropTypes.func.isRequired,
resultsPaneTitle: PropTypes.oneOf([PropTypes.element, PropTypes.string]),
sortableColumns: PropTypes.arrayOf(PropTypes.string),
visibleColumns: PropTypes.arrayOf(PropTypes.string),
};

FindLocation.defaultProps = {
columnMapping: COLUMN_MAPPING,
idPrefix: 'FindLocation-',
isMultiSelect: false,
modalLabel: <FormattedMessage id="stripes-acq-components.find-location.modal.label" />,
resultsPaneTitle: <FormattedMessage id="stripes-acq-components.find-location.results.heading" />,
sortableColumns: SORTABLE_COLUMNS,
visibleColumns: VISIBLE_COLUMNS,
};
43 changes: 29 additions & 14 deletions lib/FindLocation/FindLocationFilters/FindLocationFilters.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import PropTypes from 'prop-types';
import { useCallback, useMemo } from 'react';
import { useCallback } from 'react';

import { AccordionSet } from '@folio/stripes/components';

import { AcqCheckboxFilter } from '../../AcqCheckboxFilter';
import { FILTERS } from '../configs';
import { LibrariesFilter } from './LibrariesFilter';
import { InstitutionsFilter } from './InstitutionsFilter';
import {
ASSIGNED_FILTER_OPTIONS,
FILTERS,
} from '../configs';
import { CampusesFilter } from './CampusesFilter';
import { InstitutionsFilter } from './InstitutionsFilter';
import { LibrariesFilter } from './LibrariesFilter';

export const FindLocationFilters = ({
activeFilters,
applyFilters,
disabled,
isMultiSelect,
}) => {
const adaptedApplyFilters = useCallback(({ name, values }) => applyFilters(name, values), [applyFilters]);

Expand All @@ -27,26 +31,36 @@ export const FindLocationFilters = ({
options={[]}
/>

<LibrariesFilter
id={FILTERS.libraries}
activeFilters={activeFilters[FILTERS.libraries]}
name={FILTERS.libraries}
<CampusesFilter
id={FILTERS.campuses}
activeFilters={activeFilters[FILTERS.campuses]}
name={FILTERS.campuses}
onChange={adaptedApplyFilters}
disabled={disabled}
options={[]}
/>

<CampusesFilter
id={FILTERS.campuses}
activeFilters={activeFilters[FILTERS.campuses]}
name={FILTERS.campuses}
<LibrariesFilter
id={FILTERS.libraries}
activeFilters={activeFilters[FILTERS.libraries]}
name={FILTERS.libraries}
onChange={adaptedApplyFilters}
disabled={disabled}
options={[]}
/>

{/* <AcqCheckboxFilter
/> */}
{isMultiSelect && (
<AcqCheckboxFilter
closedByDefault={false}
id={FILTERS.isAssigned}
activeFilters={activeFilters[FILTERS.isAssigned]}
labelId="stripes-acq-components.find-location.results.column.assignment"
name={FILTERS.isAssigned}
onChange={adaptedApplyFilters}
disabled={disabled}
options={ASSIGNED_FILTER_OPTIONS}
/>
)}
</AccordionSet>
);
}
Expand All @@ -55,4 +69,5 @@ FindLocationFilters.propTypes = {
activeFilters: PropTypes.object.isRequired,
applyFilters: PropTypes.func.isRequired,
disabled: PropTypes.bool,
isMultiSelect: PropTypes.bool,
};
43 changes: 35 additions & 8 deletions lib/FindLocation/configs.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,53 @@
import { FormattedMessage } from "react-intl";
import { FormattedMessage } from 'react-intl';

export const COLUMN_NAMES = {
name: 'name',
// TODO: refine
code: 'code',
institution: 'institution',
campus: 'campus',
library: 'library',
isActive: 'isActive',
isAssigned: 'isAssigned',
};

export const COLUMN_MAPPING = {
[COLUMN_NAMES.name]: <FormattedMessage id="stripes-acq-components.find-location.results.column.name" />,
// TODO: refine
[COLUMN_NAMES.code]: <FormattedMessage id="code" />,
[COLUMN_NAMES.code]: <FormattedMessage id="stripes-acq-components.find-location.results.column.code" />,
[COLUMN_NAMES.institution]: <FormattedMessage id="stripes-acq-components.find-location.results.column.institution" />,
[COLUMN_NAMES.campus]: <FormattedMessage id="stripes-acq-components.find-location.results.column.campus" />,
[COLUMN_NAMES.library]: <FormattedMessage id="stripes-acq-components.find-location.results.column.library" />,
[COLUMN_NAMES.isActive]: <FormattedMessage id="stripes-acq-components.find-location.results.column.status" />,
[COLUMN_NAMES.isAssigned]: <FormattedMessage id="stripes-acq-components.find-location.results.column.assignment" />,
};

export const VISIBLE_COLUMNS = Object.values(COLUMN_NAMES);
export const SORTABLE_COLUMNS = Object.values(COLUMN_NAMES);
export const VISIBLE_COLUMNS = [
COLUMN_NAMES.name,
COLUMN_NAMES.code,
COLUMN_NAMES.institution,
COLUMN_NAMES.campus,
COLUMN_NAMES.library,
COLUMN_NAMES.isActive,
];

export const SORTABLE_COLUMNS = [
COLUMN_NAMES.name,
COLUMN_NAMES.code,
COLUMN_NAMES.isActive,
];

export const FILTERS = {
institutions: 'institutions',
libraries: 'libraries',
campuses: 'campuses',
libraries: 'libraries',
isAssigned: 'isAssigned',
};

export const ASSIGNED_FILTER_OPTIONS = [
{
value: true,
label: <FormattedMessage id="stripes-acq-components.filter.assignment.assigned" />,
},
{
value: false,
label: <FormattedMessage id="stripes-acq-components.filter.assignment.unassigned" />,
},
];
2 changes: 1 addition & 1 deletion lib/FindRecords/FindRecordsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ FindRecordsModal.propTypes = {

FindRecordsModal.defaultProps = {
columnMapping: {},
columnWidths: {},
columnWidths: { isChecked: '34px' },
resultsFormatter: {},
isMultiSelect: false,
resetData: noop,
Expand Down
6 changes: 6 additions & 0 deletions translations/stripes-acq-components/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"filter.campus": "Campus",
"filter.institution": "Institution",
"filter.library": "Library",
"filter.assignment.assigned": "Assigned",
"filter.assignment.unassigned": "Unassigned",

"holdings.deleteModal.heading": "Delete Holdings",
"holdings.deleteModal.message": "This piece is connected to records in inventory. After this edit there will be no other pieces OR items connected to the related Holdings record(s). After making this change would you like FOLIO to delete the Holdings record(s)?",
Expand Down Expand Up @@ -203,6 +205,10 @@

"find-location.modal.label": "Select locations",
"find-location.results.column.assignment": "Location assignment status",
"find-location.results.column.campus": "Campus",
"find-location.results.column.code": "Code",
"find-location.results.column.institution": "Institution",
"find-location.results.column.library": "Library",
"find-location.results.column.name": "Name",
"find-location.results.column.status": "Location status",
"find-location.results.column.status.active": "Active",
Expand Down

0 comments on commit 3d3fbc5

Please sign in to comment.