Skip to content

Commit

Permalink
Merge pull request #730 from folio-org/UIU-1492-custom-fields-permiss…
Browse files Browse the repository at this point in the history
…ions

UIU-1492 Custom fields: Create UI permissions for Settings > Users > Custom Fields CRUD
  • Loading branch information
BogdanDenis authored Mar 6, 2020
2 parents 70e832b + c385e38 commit c3439ef
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Escape quotes and backslashes in the values inserted into CQL queries. Refs UIIN-589.
* Display `effective call number prefix`, `call number`, `call number suffix`, `enumeration`, `chronology`, `volume` in loans contexts. Refs UIU-1391.
* Handle (i.e., reject) 'declared lost' items in `<ChangeDueDateDialog>`. Refs UIU-1207.
* Create UI permissions for Custom Fields .Refs UIU-1492

## [2.12.0](https://github.com/folio-org/stripes-smart-components/tree/v2.12.0) (2019-12-04)
[Full Changelog](https://github.com/folio-org/stripes-smart-components/compare/v2.11.0...v2.12.0)
Expand Down
2 changes: 1 addition & 1 deletion lib/ChangeDueDateDialog/ChangeDueDateDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class ChangeDueDateDialog extends React.Component {
'stripes-smart-components.cddd.itemHasBeenRecalled'
);
}
if (loan.item.status.name === 'Declared lost') {
if (loan.item?.status?.name === 'Declared lost') {
newAlerts[loan.id] = this.renderAlert(
css.warn,
'exclamation-circle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ const propTypes = {
]).isRequired,
})).isRequired,
onSubmit: PropTypes.func.isRequired,
permissions: PropTypes.shape({
canDelete: PropTypes.bool,
canEdit: PropTypes.bool,
canView: PropTypes.bool,
}).isRequired,
redirectToView: PropTypes.func.isRequired,
sectionTitle: PropTypes.string.isRequired,
submitSucceed: PropTypes.bool.isRequired,
Expand All @@ -81,6 +86,7 @@ const CustomFieldsForm = ({
sectionTitle,
entityType,
onSubmit,
permissions,
}) => {
const getInitialAccordionsState = () => initialValues.reduce((state, cf) => ({
...state,
Expand Down Expand Up @@ -309,6 +315,7 @@ const CustomFieldsForm = ({
isEditMode
onChange={onFieldUpdate(cf.id)}
fieldData={{ ...values }}
permissions={permissions}
/>
);
})}
Expand Down Expand Up @@ -364,6 +371,7 @@ const CustomFieldsForm = ({
<>
<Paneset>
<Pane
id="edit-custom-fields-pane"
paneTitle={<FormattedMessage id="stripes-smart-components.customFields.editCustomFields" />}
firstMenu={firstMenu}
footer={renderPaneFooter()}
Expand Down
21 changes: 16 additions & 5 deletions lib/CustomFields/components/FieldAccordion/FieldAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const propTypes = {
id: PropTypes.string.isRequired,
isEditMode: PropTypes.bool,
onChange: PropTypes.func,
permissions: PropTypes.shape({
canDelete: PropTypes.bool,
canEdit: PropTypes.bool,
canView: PropTypes.bool,
}).isRequired,
separator: PropTypes.bool,
};

Expand All @@ -50,6 +55,7 @@ const FieldAccordion = (props) => {
},
fieldData,
onChange,
permissions,
} = props;

const accordionLabel = (
Expand All @@ -63,10 +69,15 @@ const FieldAccordion = (props) => {
);

const renderHeaderButtons = () => (
<IconButton
icon="trash"
onClick={deleteCustomField}
/>
permissions.canDelete
? (
<IconButton
icon="trash"
onClick={deleteCustomField}
data-test-custom-field-delete-button
/>
)
: null
);

const AccordionContent = isEditMode
Expand All @@ -87,7 +98,7 @@ const FieldAccordion = (props) => {
displayWhenOpen={isEditMode && renderHeaderButtons()}
displayWhenClosed={isEditMode && renderHeaderButtons()}
separator={separator}
closedByDefault
closedByDefault={!isEditMode}
>
<AccordionContent {...contentProps} />
</Accordion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const propTypes = {
token: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
}).isRequired,
permissions: PropTypes.shape({
canDelete: PropTypes.bool,
canEdit: PropTypes.bool,
canView: PropTypes.bool,
}).isRequired,
redirectToView: PropTypes.func.isRequired,
};

Expand All @@ -44,6 +49,7 @@ const EditCustomFieldsSettings = ({
redirectToView,
backendModuleName,
intl,
permissions,
}) => {
const {
customFields,
Expand Down Expand Up @@ -135,16 +141,21 @@ const EditCustomFieldsSettings = ({
<>
{customFieldsLoaded && sectionTitleLoaded
? (
<CustomFieldsForm
entityType={entityType}
initialValues={getInitialValues()}
redirectToView={redirectToView}
onSubmit={saveCustomFields}
submitting={submitting}
submitSucceed={submitFinished}
fetchUsageStatistics={fetchUsageStatistics}
sectionTitle={sectionTitle.value || defaultSectionTitle}
/>
permissions.canEdit
? (
<CustomFieldsForm
entityType={entityType}
initialValues={getInitialValues()}
redirectToView={redirectToView}
onSubmit={saveCustomFields}
submitting={submitting}
submitSucceed={submitFinished}
fetchUsageStatistics={fetchUsageStatistics}
sectionTitle={sectionTitle.value || defaultSectionTitle}
permissions={permissions}
/>
)
: null
)
: (
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ const propTypes = {
token: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
}).isRequired,
permissions: PropTypes.shape({
canDelete: PropTypes.bool,
canEdit: PropTypes.bool,
canView: PropTypes.bool,
}).isRequired,
redirectToEdit: PropTypes.func.isRequired,
};

const ViewCustomFieldsSettings = ({ redirectToEdit, okapi, backendModuleId, entityType, backendModuleName }) => {
const ViewCustomFieldsSettings = ({ redirectToEdit, okapi, backendModuleId, entityType, backendModuleName, permissions }) => {
const {
customFields,
customFieldsLoaded,
Expand All @@ -61,14 +66,18 @@ const ViewCustomFieldsSettings = ({ redirectToEdit, okapi, backendModuleId, enti
const customFieldsExist = customFieldsLoaded && !isEmpty(customFields);

const renderLastMenu = () => (
<Button
buttonStyle="primary"
marginBottom0
onClick={redirectToEdit}
data-test-custom-fields-edit-button
>
<FormattedMessage id="stripes-smart-components.customFields.edit" />
</Button>
permissions.canEdit
? (
<Button
buttonStyle="primary"
marginBottom0
onClick={redirectToEdit}
data-test-custom-fields-edit-button
>
<FormattedMessage id="stripes-smart-components.customFields.edit" />
</Button>
)
: null
);

const renderSectionTitle = () => (
Expand All @@ -93,6 +102,7 @@ const ViewCustomFieldsSettings = ({ redirectToEdit, okapi, backendModuleId, enti
id={id}
key={id}
fieldData={{ ...fieldData }}
permissions={permissions}
/>
);
})}
Expand All @@ -104,6 +114,7 @@ const ViewCustomFieldsSettings = ({ redirectToEdit, okapi, backendModuleId, enti
{customFieldsLoaded && sectionTitleLoaded
? (
<Pane
id="custom-fields-pane"
paneTitle={<FormattedMessage id="stripes-smart-components.customFields.editCustomFields" />}
lastMenu={renderLastMenu()}
defaultWidth="fill"
Expand Down

0 comments on commit c3439ef

Please sign in to comment.