Skip to content

Commit

Permalink
add proptypes for components
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro-Melnyshyn committed Dec 12, 2024
1 parent 4e8a21e commit 7737953
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 37 deletions.
25 changes: 12 additions & 13 deletions src/settings/CallNumberBrowseSettings/CallNumberBrowseSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { ControlledVocab } from '@folio/stripes/smart-components';
import {
InfoPopover,
List,
LoadingPane,
} from '@folio/stripes/components';
import {
Expand All @@ -19,9 +18,10 @@ import {
useUserTenantPermissions,
} from '@folio/stripes/core';

import { CallNumberTypeList } from './CallNumberTypeList';
import { CallNumberTypeField } from './CallNumberTypeField';
import { useCallNumberTypesQuery } from '../../hooks';
import { CALL_NUMBER_BROWSE_COLUMNS } from './constants';
import getFieldComponents from './getFieldComponents';

const CallNumberBrowseSettings = () => {
const stripes = useStripes();
Expand Down Expand Up @@ -82,15 +82,6 @@ const CallNumberBrowseSettings = () => {
[CALL_NUMBER_BROWSE_COLUMNS.TYPE_IDS]: item[CALL_NUMBER_BROWSE_COLUMNS.TYPE_IDS].map(type => type.id),
}), []);

const renderCallNumberTypes = (types = []) => (
<List
items={types}
itemFormatter={type => <li>{type?.label}</li>}
listStyle="bullets"
marginBottom0
/>
);

if (!hasRequiredPermissions) {
return null;
}
Expand All @@ -115,15 +106,23 @@ const CallNumberBrowseSettings = () => {
columnMapping={columnMapping}
hiddenFields={[CALL_NUMBER_BROWSE_COLUMNS.SHELVING_ALGORITHM, 'lastUpdated', 'numberOfObjects']}
formatter={{
[CALL_NUMBER_BROWSE_COLUMNS.TYPE_IDS]: ({ typeIds }) => renderCallNumberTypes(typeIds),
[CALL_NUMBER_BROWSE_COLUMNS.TYPE_IDS]: CallNumberTypeList,
}}
readOnlyFields={[CALL_NUMBER_BROWSE_COLUMNS.NAME]}
nameKey="name"
formType="final-form"
id="call-number-browse"
preUpdateHook={formatItemForSaving}
editable
fieldComponents={getFieldComponents(fieldLabels, callNumberTypeOptions)}
fieldComponents={{
[CALL_NUMBER_BROWSE_COLUMNS.TYPE_IDS]: (callNumberTypeProps) => (
<CallNumberTypeField
{...callNumberTypeProps}
fieldLabels={fieldLabels}
callNumberTypeOptions={callNumberTypeOptions}
/>
),
}}
canCreate={false}
parseRow={formatRowData}
actionSuppressor={{
Expand Down
40 changes: 40 additions & 0 deletions src/settings/CallNumberBrowseSettings/CallNumberTypeField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import PropTypes from 'prop-types';

import { Field } from 'react-final-form';

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

export const CallNumberTypeField = ({
fieldProps,
name,
rowIndex,
fieldIndex,
fieldLabels,
callNumberTypeOptions,
}) => {
return (
<Field
{...fieldProps}
component={MultiSelection}
aria-label={`${fieldLabels[name]} ${rowIndex}`}
placeholder={fieldLabels[name]}
marginBottom0
renderToOverlay
valueFormatter={({ option }) => option.label}
dataOptions={callNumberTypeOptions}
autoFocus={fieldIndex === 0}
/>
);
};

CallNumberTypeField.propTypes = {
fieldProps: PropTypes.object.isRequired,
name: PropTypes.string.isRequired,
rowIndex: PropTypes.number.isRequired,
fieldIndex: PropTypes.number.isRequired,
fieldLabels: PropTypes.object.isRequired,
callNumberTypeOptions: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string,
label: PropTypes.string.isRequired,
})),
};
20 changes: 20 additions & 0 deletions src/settings/CallNumberBrowseSettings/CallNumberTypeList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import PropTypes from 'prop-types';

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

export const CallNumberTypeList = ({ typeIds = [] }) => {
return (
<List
items={typeIds}
itemFormatter={type => <li>{type?.label}</li>}
listStyle="bullets"
marginBottom0
/>
);
};

CallNumberTypeList.propTypes = {
typeIds: PropTypes.arrayOf(PropTypes.shape({
label: PropTypes.string.isRequired,
})),
};
24 changes: 0 additions & 24 deletions src/settings/CallNumberBrowseSettings/getFieldComponents.js

This file was deleted.

0 comments on commit 7737953

Please sign in to comment.