Skip to content

Commit

Permalink
Merge branch 'STSMACOM-858' of https://github.com/folio-org/stripes-s…
Browse files Browse the repository at this point in the history
…mart-components into STSMACOM-858
  • Loading branch information
OleksandrHladchenko1 committed Oct 7, 2024
2 parents 2d25bc1 + c12e393 commit c5e5b8f
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 171 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* Bump up `actions/upload-artifact@v2` to `actions/upload-artifact@v4`. Refs STSMACOM-854.
* `DateRangeFilter` - add the optional `hideCalendarButton` property to hide the calendar icon button; add error message for invalid YYYY format. Refs STSMACOM-855.
* Display `System` user when there is no `updatedByUserId` field in metadata. Refs STSMACOM-858.
* Fix `<DateRangeFilter>` only shows an error in one of failed inputs. Fixes STSMACOM-857.
* Omit (don't disable) "+ New" button in `<EditableList>` when user lacks permission. Refs STSMACOM-836.
* Avoid deprecated `defaultProps` for functional components. Refs STSMACOM-835.

## [9.1.3](https://github.com/folio-org/stripes-smart-components/tree/v9.1.3) (2024-05-06)
[Full Changelog](https://github.com/folio-org/stripes-smart-components/compare/v9.1.2...v9.1.3)
Expand Down
95 changes: 49 additions & 46 deletions lib/AddressFieldGroup/AddressEdit/AddressEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,63 +53,67 @@ const propTypes = {
visibleFields: PropTypes.arrayOf(PropTypes.string),
};

const defaultProps = {
fieldComponents: {
country: TextField,
addressLine1: TextField,
addressLine2: TextField,
city: TextField,
stateRegion: TextField,
zipCode: TextField,
addressType: {
component: TextField,
validate: validateAddressType,
},
const defaultFieldComponents = {
country: TextField,
addressLine1: TextField,
addressLine2: TextField,
city: TextField,
stateRegion: TextField,
zipCode: TextField,
addressType: {
component: TextField,
validate: validateAddressType,
},
headerComponent: address => (
<Field
label="Primary Address"
name="primaryAddress"
type="checkbox"
id={`PrimaryAddress---${address.id}`}
component={Checkbox}
/>
),
labelMap: {
addressType: <FormattedMessage id="stripes-smart-components.addressEdit.label.addressType" />,
addressLine1: <FormattedMessage id="stripes-smart-components.addressEdit.label.addressLine1" />,
addressLine2: <FormattedMessage id="stripes-smart-components.addressEdit.label.addressLine2" />,
stateRegion: <FormattedMessage id="stripes-smart-components.addressEdit.label.stateRegion" />,
zipCode: <FormattedMessage id="stripes-smart-components.addressEdit.label.zipCode" />,
country: <FormattedMessage id="stripes-smart-components.addressEdit.label.country" />,
city: <FormattedMessage id="stripes-smart-components.addressEdit.label.city" />,
},
visibleFields: [
'country',
'addressLine1',
'addressLine2',
'city',
'stateRegion',
'zipCode',
'addressType',
],
};

const AddressEdit = (props) => {
const defaultHeaderComponent = address => (
<Field
label="Primary Address"
name="primaryAddress"
type="checkbox"
id={`PrimaryAddress---${address.id}`}
component={Checkbox}
/>
);

const defaultLabelMap = {
addressType: <FormattedMessage id="stripes-smart-components.addressEdit.label.addressType" />,
addressLine1: <FormattedMessage id="stripes-smart-components.addressEdit.label.addressLine1" />,
addressLine2: <FormattedMessage id="stripes-smart-components.addressEdit.label.addressLine2" />,
stateRegion: <FormattedMessage id="stripes-smart-components.addressEdit.label.stateRegion" />,
zipCode: <FormattedMessage id="stripes-smart-components.addressEdit.label.zipCode" />,
country: <FormattedMessage id="stripes-smart-components.addressEdit.label.country" />,
city: <FormattedMessage id="stripes-smart-components.addressEdit.label.city" />,
};

const defaultVisibleFields = [
'country',
'addressLine1',
'addressLine2',
'city',
'stateRegion',
'zipCode',
'addressType',
];

const AddressEdit = ({
fieldComponents = defaultFieldComponents,
headerComponent = defaultHeaderComponent,
labelMap = defaultLabelMap,
visibleFields = defaultVisibleFields,
...rest
}) => {
const props = { fieldComponents, headerComponent, labelMap, visibleFields, ...rest };
const {
addressObject,
canDelete,
uiId,
handleSubmit,
handleDelete,
handleCancel,
labelMap,
visibleFields,
headerComponent,
fieldComponents
} = props;

const mergedFieldComponents = Object.assign(defaultProps.fieldComponents, fieldComponents);
const mergedFieldComponents = { ...defaultFieldComponents, ...fieldComponents };
const groupArray = [];
let rowArray = [];

Expand Down Expand Up @@ -182,7 +186,6 @@ const AddressEdit = (props) => {
};

AddressEdit.propTypes = propTypes;
AddressEdit.defaultProps = defaultProps;

export default stripesFinalForm({
navigationCheck: true,
Expand Down
20 changes: 8 additions & 12 deletions lib/AddressFieldGroup/AddressView/AddressView.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ const propTypes = {
visibleFields: PropTypes.arrayOf(PropTypes.string),
};

const defaultProps = {
headerField: 'primaryAddress',
headerFormatter: address => (
function AddressView({
headerField = 'primaryAddress',
headerFormatter = address => (
<FormattedMessage
id={`stripes-smart-components.address.${address.primaryAddress ? 'primary' : 'alternate'}`}
/>
),
headingLevel: 5,
visibleFields: [
headingLevel = 5,
visibleFields = [
'addressType',
'addressLine1',
'addressLine2',
Expand All @@ -35,17 +35,14 @@ const defaultProps = {
'zipCode',
'country',
],
};

function AddressView(props) {
...rest
}) {
const props = { headerField, headerFormatter, headingLevel, visibleFields, ...rest };
const {
addressObject,
canEdit,
handleEdit,
headerFormatter,
headingLevel,
uiId,
visibleFields
} = props;

const defaultLabelMap = {
Expand Down Expand Up @@ -108,6 +105,5 @@ function AddressView(props) {
}

AddressView.propTypes = propTypes;
AddressView.defaultProps = defaultProps;

export default AddressView;
39 changes: 17 additions & 22 deletions lib/ChangeDueDateDialog/LoanList.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ const propTypes = {
})
};

const defaultProps = {
allowSelection: true,
height: 400,
loans: [],
loanSelection: {},
requestCounts: {},
};

const manifest = Object.freeze({
loanPolicies: {
type: 'okapi',
Expand All @@ -44,13 +36,17 @@ const manifest = Object.freeze({
},
});

const LoanList = (props) => {
const {
loanSelection,
onToggleLoanSelection,
requestCounts,
} = props;

const LoanList = ({
alerts,
allowSelection = true,
height = 400,
loans = [],
loanSelection = {},
onToggleBulkLoanSelection,
onToggleLoanSelection,
requestCounts = {},
resources,
}) => {
const { formatMessage } = useIntl();

const visibleColumns = [
Expand All @@ -64,22 +60,22 @@ const LoanList = (props) => {
'loanListLoanPolicy',
];

if (props.allowSelection) visibleColumns.unshift('selected');
if (allowSelection) visibleColumns.unshift('selected');

const rowUpdater = (rowData) => requestCounts[rowData.itemId];

return (
<MultiColumnList
interactive={false}
height={props.height}
contentData={props.loans}
height={height}
contentData={loans}
visibleColumns={visibleColumns}
rowUpdater={rowUpdater}
columnMapping={{
selected: <Checkbox
name="selected-all"
checked={Object.values(loanSelection).includes(false) !== true}
onChange={props.onToggleBulkLoanSelection}
onChange={onToggleBulkLoanSelection}
aria-label={formatMessage({ id: 'stripes-smart-components.cddd.selectAllLoans' })}
/>,
loanListAlertDetails: <FormattedMessage id="stripes-smart-components.cddd.header.alertDetails" />,
Expand All @@ -101,7 +97,7 @@ const LoanList = (props) => {
{ loanName: get(loan, ['item', 'title']) }
)}
/>,
loanListAlertDetails: loan => props.alerts[loan.id] || '',
loanListAlertDetails: loan => alerts[loan.id] || '',
loanListTitle: loan => get(loan, ['item', 'title']),
loanListItemStatus: loan => get(loan, ['item', 'status', 'name']),
loanListCurrentDueDate:
Expand All @@ -110,7 +106,7 @@ const LoanList = (props) => {
loanListBarcode: loan => get(loan, ['item', 'barcode']),
loanListEffectiveCallNumber: loan => getEffectiveCallNumber(loan),
loanListLoanPolicy: loan => {
const policies = get(props, ['resources', 'loanPolicies', 'records', 0, 'loanPolicies'], []);
const policies = get(resources, ['loanPolicies', 'records', 0, 'loanPolicies'], []);
const policy = policies.find(p => p.id === loan.loanPolicyId) || {};
return policy.name;
},
Expand All @@ -128,7 +124,6 @@ const LoanList = (props) => {
);
};

LoanList.defaultProps = defaultProps;
LoanList.propTypes = propTypes;
LoanList.manifest = manifest;

Expand Down
7 changes: 1 addition & 6 deletions lib/ColumnManager/ColumnManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
import useColumnManager from './useColumnManager';
import ColumnManagerMenu from './ColumnManagerMenu';

const ColumnManager = ({ id, columnMapping, children, excludeKeys, persist, visibleColumns: visibleColumnsProp }) => {
const ColumnManager = ({ id, columnMapping = {}, children, excludeKeys = [], persist, visibleColumns: visibleColumnsProp }) => {
const prefixId = `column-manager-${id}`;

const nonToggleableColumns = useRef(excludeKeys).current;
Expand Down Expand Up @@ -45,11 +45,6 @@ const ColumnManager = ({ id, columnMapping, children, excludeKeys, persist, visi
return children(renderProps);
};

ColumnManager.defaultProps = {
columnMapping: {},
excludeKeys: [],
};

ColumnManager.propTypes = {
children: PropTypes.func.isRequired,
columnMapping: PropTypes.object.isRequired,
Expand Down
9 changes: 2 additions & 7 deletions lib/ColumnManager/ColumnManagerMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Checkbox, MenuSection } from '@folio/stripes-components';
const ColumnManagerMenu = ({
prefix,
columnMapping,
visibleColumns,
excludeColumns,
visibleColumns = [],
excludeColumns = [],
toggleColumn,
}) => {
const intl = useIntl();
Expand Down Expand Up @@ -51,9 +51,4 @@ ColumnManagerMenu.propTypes = {
visibleColumns: PropTypes.arrayOf(PropTypes.string),
};

ColumnManagerMenu.defaultProps = {
visibleColumns: [],
excludeColumns: [],
};

export default ColumnManagerMenu;
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ const propTypes = {
viewRoute: PropTypes.string.isRequired,
};

const defaultProps = {
fieldOptionsStats: null,
};

const CustomFieldsForm = ({
submitting,
viewRoute,
Expand All @@ -130,7 +126,7 @@ const CustomFieldsForm = ({
onFormReset,
saveCustomFields,
optionsStatsLoaded,
fieldOptionsStats,
fieldOptionsStats = null,
onOptionDelete,
optionsToDelete,
}) => {
Expand Down Expand Up @@ -383,7 +379,6 @@ const CustomFieldsForm = ({
};

CustomFieldsForm.propTypes = propTypes;
CustomFieldsForm.defaultProps = defaultProps;

export default stripesFinalForm({
navigationCheck: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ const propTypes = {
optionsToAddLeft: PropTypes.number,
};

const defaultProps = {
optionsToAddLeft: null,
};

const AddOptionButton = ({
onClick,
optionsToAddLeft,
optionsToAddLeft = null,
}) => (
<>
{optionsToAddLeft !== null && (
Expand All @@ -42,6 +38,5 @@ const AddOptionButton = ({
);

AddOptionButton.propTypes = propTypes;
AddOptionButton.defaultProps = defaultProps;

export default AddOptionButton;
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,15 @@ const propTypes = {
usedOptions: PropTypes.arrayOf(PropTypes.string),
};

const defaultProps = {
isMultiSelect: false,
maxOptionsNumber: null,
};

const isLabelDuplicated = (label, allLabels) => {
return allLabels.filter(currentLabel => label === currentLabel).length > 1;
};

const OptionsField = ({
fieldNamePrefix,
maxOptionsNumber,
maxOptionsNumber = null,
changeFieldValue,
isMultiSelect,
isMultiSelect = false,
usedOptions,
optionsStatsLoaded,
onOptionDelete,
Expand Down Expand Up @@ -269,6 +264,5 @@ const OptionsField = ({
};

OptionsField.propTypes = propTypes;
OptionsField.defaultProps = defaultProps;

export default OptionsField;
Loading

0 comments on commit c5e5b8f

Please sign in to comment.