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

Add conditional button render props to EditableCard and EditableArrayCard components #574

Open
wants to merge 10 commits into
base: antd3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dist/components/EditableArrayCard.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export interface IEditableArrayCardProps extends IArrayCardProps, ISharedFormPro
defaults?: object;
onCreate: (model: unknown) => Promise<any>;
onDelete?: (model: unknown) => Promise<any>;
disableAdd?: boolean;
disableAddTooltip?: string;
disableDeleteTooltip?: string;
disableDelete?: (model: any) => boolean;
disableEditTooltip?: string;
disableEdit?: (model: any) => boolean;
}
declare class EditableArrayCard extends Component<IEditableArrayCardProps> {
private isAddingNew;
Expand Down
4 changes: 4 additions & 0 deletions dist/components/EditableCard.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { ICardProps } from './Card';
import FormDrawer from './FormDrawer';
import FormModal from './FormModal';
export interface IEditableCardProps extends ICardProps, ISharedFormProps {
disableDeleteTooltip?: string;
disableDelete: boolean;
disableEditTooltip?: string;
disableEdit: boolean;
ModalComponent: new (props: ISharedFormModalProps) => FormModal | FormDrawer;
onDelete?: (model: unknown) => Promise<any>;
}
Expand Down
81 changes: 64 additions & 17 deletions dist/fieldsAnt.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,10 @@ function noopValidator(_rule, _value, callback) {
// Useful for clearing manually-set backend validation errors
callback();
}
function getBtnClassName(action, classNameSuffix, title) {
var prefix = "btn-".concat(action);
return cx(prefix, lodash.isString(title) && "".concat(prefix, "-").concat(lodash.kebabCase(title)), _defineProperty({}, "".concat(prefix, "-").concat(classNameSuffix), !!classNameSuffix));
}

// Takes an API response and converts it to a string to string map
function getFieldErrors(errors) {
Expand Down Expand Up @@ -3618,7 +3622,12 @@ function (_Component) {
value: function buttons() {
return React__default.createElement(ButtonToolbar, {
noSpacing: true
}, this.deleteButton, this.editButton);
}, this.deleteButton, React__default.createElement("div", {
style: {
display: 'inline-block',
width: '10px'
}
}), this.editButton);
}
}, {
key: "render",
Expand All @@ -3644,26 +3653,31 @@ function (_Component) {
key: "deleteButton",
get: function get() {
var _this$props3 = this.props,
classNameSuffix = _this$props3.classNameSuffix,
disableDeleteTooltip = _this$props3.disableDeleteTooltip,
disableDelete = _this$props3.disableDelete,
isGuarded = _this$props3.isGuarded,
title = _this$props3.title,
onDelete = _this$props3.onDelete,
isLoading = _this$props3.isLoading,
classNameSuffix = this.props.classNameSuffix || lodash.kebabCase(title);
onDelete = _this$props3.onDelete,
title = _this$props3.title,
className = getBtnClassName('delete', classNameSuffix, title);

if (!onDelete) {
return;
}

return React__default.createElement(GuardedButton, {
className: "btn-delete btn-delete-".concat(classNameSuffix),
return React__default.createElement(Antd.Tooltip, {
title: disableDelete ? disableDeleteTooltip : ''
}, React__default.createElement("span", null, React__default.createElement(GuardedButton, {
className: className,
confirm: true,
disabled: isLoading || this.isDeleting.isTrue,
disabled: disableDelete || isLoading || this.isDeleting.isTrue,
icon: "delete",
isGuarded: isGuarded,
onClick: this.handleDelete,
size: "small",
type: "danger"
}, "Delete");
}, "Delete")));
}
}, {
key: "editButton",
Expand All @@ -3672,21 +3686,30 @@ function (_Component) {
isLoading = _this$props4.isLoading,
title = _this$props4.title,
isGuarded = _this$props4.isGuarded,
disableEdit = _this$props4.disableEdit,
disableEditTooltip = _this$props4.disableEditTooltip,
classNameSuffix = this.props.classNameSuffix || lodash.kebabCase(title);
return React__default.createElement(GuardedButton, {
return React__default.createElement(Antd.Tooltip, {
title: disableEdit ? disableEditTooltip : ''
}, React__default.createElement("span", null, React__default.createElement(GuardedButton, {
className: "btn-edit btn-edit-".concat(classNameSuffix),
disabled: isLoading || this.isEditing.isTrue || this.isDeleting.isTrue,
disabled: isLoading || this.isEditing.isTrue || this.isDeleting.isTrue || disableEdit,
icon: "edit",
isGuarded: isGuarded,
onClick: this.isEditing.setTrue,
size: "small",
type: "primary"
}, "Edit");
}, "Edit")));
}
}]);

return EditableCard;
}(React.Component), _class3$3.defaultProps = _objectSpread2({}, formPropsDefaults), _temp$9), (_descriptor$4 = _applyDecoratedDescriptor(_class2$g.prototype, "isDeleting", [mobx.observable], {
}(React.Component), _class3$3.defaultProps = _objectSpread2({}, formPropsDefaults, {
disableDeleteTooltip: '',
disableDelete: false,
disableEditTooltip: '',
disableEdit: false
}), _temp$9), (_descriptor$4 = _applyDecoratedDescriptor(_class2$g.prototype, "isDeleting", [mobx.observable], {
configurable: true,
enumerable: true,
writable: true,
Expand Down Expand Up @@ -3776,16 +3799,20 @@ function (_Component) {
title = _this$props2.title,
isLoading = _this$props2.isLoading,
isGuarded = _this$props2.isGuarded,
disableAdd = _this$props2.disableAdd,
disableAddTooltip = _this$props2.disableAddTooltip,
classNameSuffix = this.props.classNameSuffix || lodash.kebabCase(title);
return React__default.createElement(GuardedButton, {
return React__default.createElement(Antd.Tooltip, {
title: disableAdd ? disableAddTooltip : ''
}, React__default.createElement("span", null, React__default.createElement(GuardedButton, {
className: "btn-new btn-new-".concat(classNameSuffix),
disabled: isLoading || this.isAddingNew.isTrue,
disabled: isLoading || this.isAddingNew.isTrue || disableAdd,
icon: "plus",
isGuarded: isGuarded,
onClick: this.isAddingNew.setTrue,
size: "small",
type: "primary"
}, "Add");
}, "Add")));
}
}, {
key: "render",
Expand All @@ -3798,7 +3825,11 @@ function (_Component) {
onDelete = _this$props3.onDelete,
onSave = _this$props3.onSave,
onSuccess = _this$props3.onSuccess,
title = _this$props3.title;
title = _this$props3.title,
disableDeleteTooltip = _this$props3.disableDeleteTooltip,
disableDelete = _this$props3.disableDelete,
disableEditTooltip = _this$props3.disableEditTooltip,
disableEdit = _this$props3.disableEdit;
return React__default.createElement(Antd.Card, {
title: title,
extra: this.renderAddNew(),
Expand All @@ -3820,14 +3851,29 @@ function (_Component) {
onDelete: onDelete,
onSave: onSave,
onSuccess: onSuccess,
disableDeleteTooltip: disableDeleteTooltip,
disableDelete: disableDelete ? disableDelete(model) : false,
disableEditTooltip: disableEditTooltip,
disableEdit: disableEdit ? disableEdit(model) : false,
title: ""
});
}));
}
}]);

return EditableArrayCard;
}(React.Component), _class3$4.defaultProps = _objectSpread2({}, formPropsDefaults), _temp$a), (_descriptor$5 = _applyDecoratedDescriptor(_class2$h.prototype, "isAddingNew", [mobx.observable], {
}(React.Component), _class3$4.defaultProps = _objectSpread2({}, formPropsDefaults, {
disableAdd: false,
disableAddTooltip: '',
disableDeleteTooltip: '',
disableDelete: function disableDelete() {
return false;
},
disableEditTooltip: '',
disableEdit: function disableEdit() {
return false;
}
}), _temp$a), (_descriptor$5 = _applyDecoratedDescriptor(_class2$h.prototype, "isAddingNew", [mobx.observable], {
configurable: true,
enumerable: true,
writable: true,
Expand Down Expand Up @@ -4274,6 +4320,7 @@ exports.filterFieldSets = filterFieldSets;
exports.formPropsDefaults = formPropsDefaults;
exports.formatOptionSelect = formatOptionSelect;
exports.formatRating = formatRating;
exports.getBtnClassName = getBtnClassName;
exports.getDateFormatList = getDateFormatList;
exports.getFieldSetFields = getFieldSetFields;
exports.getFieldSetsFields = getFieldSetsFields;
Expand Down
84 changes: 65 additions & 19 deletions dist/fieldsAnt.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import autoBindMethods from 'class-autobind-decorator';
import cx from 'classnames';
import { Form as Form$1, Col, Select, Icon, Button, Tooltip, Input, Radio, Rate as Rate$1, Checkbox as Checkbox$1, DatePicker, notification, Row, Popconfirm, Divider, Card as Card$1, Drawer, Modal, List, Table as Table$1 } from 'antd';
import { toJS, observable, computed } from 'mobx';
import { get, values, omit, debounce, uniqBy, pick, isObject, isBoolean, isArray, flatten, sortBy, has, set, some, isPlainObject, extend, mapValues, pickBy, noop, isEmpty, kebabCase } from 'lodash';
import { get, values, omit, debounce, uniqBy, pick, isObject, isBoolean, isArray, flatten, sortBy, has, set, isString, kebabCase, some, isPlainObject, extend, mapValues, pickBy, noop, isEmpty } from 'lodash';
import SmartBool from '@mighty-justice/smart-bool';
import { toKey, inferCentury, getNameOrDefault, EMPTY_FIELD, mapBooleanToText, isValidDate, formatDate, formatEmployerIdNumber, formatMoney, formatCommaSeparatedNumber, getPercentValue, formatPercentage, getPercentDisplay, formatPhoneNumber, formatSocialSecurityNumber, parseAndPreserveNewlines, formatWebsite, formatAddressMultiline, varToLabel, getOrDefault, createDisabledContainer, createGuardedContainer, splitName } from '@mighty-justice/utils';
import moment from 'moment';
Expand Down Expand Up @@ -2271,6 +2271,10 @@ function noopValidator(_rule, _value, callback) {
// Useful for clearing manually-set backend validation errors
callback();
}
function getBtnClassName(action, classNameSuffix, title) {
var prefix = "btn-".concat(action);
return cx(prefix, isString(title) && "".concat(prefix, "-").concat(kebabCase(title)), _defineProperty({}, "".concat(prefix, "-").concat(classNameSuffix), !!classNameSuffix));
}

// Takes an API response and converts it to a string to string map
function getFieldErrors(errors) {
Expand Down Expand Up @@ -3611,7 +3615,12 @@ function (_Component) {
value: function buttons() {
return React.createElement(ButtonToolbar, {
noSpacing: true
}, this.deleteButton, this.editButton);
}, this.deleteButton, React.createElement("div", {
style: {
display: 'inline-block',
width: '10px'
}
}), this.editButton);
}
}, {
key: "render",
Expand All @@ -3637,26 +3646,31 @@ function (_Component) {
key: "deleteButton",
get: function get() {
var _this$props3 = this.props,
classNameSuffix = _this$props3.classNameSuffix,
disableDeleteTooltip = _this$props3.disableDeleteTooltip,
disableDelete = _this$props3.disableDelete,
isGuarded = _this$props3.isGuarded,
title = _this$props3.title,
onDelete = _this$props3.onDelete,
isLoading = _this$props3.isLoading,
classNameSuffix = this.props.classNameSuffix || kebabCase(title);
onDelete = _this$props3.onDelete,
title = _this$props3.title,
className = getBtnClassName('delete', classNameSuffix, title);

if (!onDelete) {
return;
}

return React.createElement(GuardedButton, {
className: "btn-delete btn-delete-".concat(classNameSuffix),
return React.createElement(Tooltip, {
title: disableDelete ? disableDeleteTooltip : ''
}, React.createElement("span", null, React.createElement(GuardedButton, {
className: className,
confirm: true,
disabled: isLoading || this.isDeleting.isTrue,
disabled: disableDelete || isLoading || this.isDeleting.isTrue,
icon: "delete",
isGuarded: isGuarded,
onClick: this.handleDelete,
size: "small",
type: "danger"
}, "Delete");
}, "Delete")));
}
}, {
key: "editButton",
Expand All @@ -3665,21 +3679,30 @@ function (_Component) {
isLoading = _this$props4.isLoading,
title = _this$props4.title,
isGuarded = _this$props4.isGuarded,
disableEdit = _this$props4.disableEdit,
disableEditTooltip = _this$props4.disableEditTooltip,
classNameSuffix = this.props.classNameSuffix || kebabCase(title);
return React.createElement(GuardedButton, {
return React.createElement(Tooltip, {
title: disableEdit ? disableEditTooltip : ''
}, React.createElement("span", null, React.createElement(GuardedButton, {
className: "btn-edit btn-edit-".concat(classNameSuffix),
disabled: isLoading || this.isEditing.isTrue || this.isDeleting.isTrue,
disabled: isLoading || this.isEditing.isTrue || this.isDeleting.isTrue || disableEdit,
icon: "edit",
isGuarded: isGuarded,
onClick: this.isEditing.setTrue,
size: "small",
type: "primary"
}, "Edit");
}, "Edit")));
}
}]);

return EditableCard;
}(Component), _class3$3.defaultProps = _objectSpread2({}, formPropsDefaults), _temp$9), (_descriptor$4 = _applyDecoratedDescriptor(_class2$g.prototype, "isDeleting", [observable], {
}(Component), _class3$3.defaultProps = _objectSpread2({}, formPropsDefaults, {
disableDeleteTooltip: '',
disableDelete: false,
disableEditTooltip: '',
disableEdit: false
}), _temp$9), (_descriptor$4 = _applyDecoratedDescriptor(_class2$g.prototype, "isDeleting", [observable], {
configurable: true,
enumerable: true,
writable: true,
Expand Down Expand Up @@ -3769,16 +3792,20 @@ function (_Component) {
title = _this$props2.title,
isLoading = _this$props2.isLoading,
isGuarded = _this$props2.isGuarded,
disableAdd = _this$props2.disableAdd,
disableAddTooltip = _this$props2.disableAddTooltip,
classNameSuffix = this.props.classNameSuffix || kebabCase(title);
return React.createElement(GuardedButton, {
return React.createElement(Tooltip, {
title: disableAdd ? disableAddTooltip : ''
}, React.createElement("span", null, React.createElement(GuardedButton, {
className: "btn-new btn-new-".concat(classNameSuffix),
disabled: isLoading || this.isAddingNew.isTrue,
disabled: isLoading || this.isAddingNew.isTrue || disableAdd,
icon: "plus",
isGuarded: isGuarded,
onClick: this.isAddingNew.setTrue,
size: "small",
type: "primary"
}, "Add");
}, "Add")));
}
}, {
key: "render",
Expand All @@ -3791,7 +3818,11 @@ function (_Component) {
onDelete = _this$props3.onDelete,
onSave = _this$props3.onSave,
onSuccess = _this$props3.onSuccess,
title = _this$props3.title;
title = _this$props3.title,
disableDeleteTooltip = _this$props3.disableDeleteTooltip,
disableDelete = _this$props3.disableDelete,
disableEditTooltip = _this$props3.disableEditTooltip,
disableEdit = _this$props3.disableEdit;
return React.createElement(Card$1, {
title: title,
extra: this.renderAddNew(),
Expand All @@ -3813,14 +3844,29 @@ function (_Component) {
onDelete: onDelete,
onSave: onSave,
onSuccess: onSuccess,
disableDeleteTooltip: disableDeleteTooltip,
disableDelete: disableDelete ? disableDelete(model) : false,
disableEditTooltip: disableEditTooltip,
disableEdit: disableEdit ? disableEdit(model) : false,
title: ""
});
}));
}
}]);

return EditableArrayCard;
}(Component), _class3$4.defaultProps = _objectSpread2({}, formPropsDefaults), _temp$a), (_descriptor$5 = _applyDecoratedDescriptor(_class2$h.prototype, "isAddingNew", [observable], {
}(Component), _class3$4.defaultProps = _objectSpread2({}, formPropsDefaults, {
disableAdd: false,
disableAddTooltip: '',
disableDeleteTooltip: '',
disableDelete: function disableDelete() {
return false;
},
disableEditTooltip: '',
disableEdit: function disableEdit() {
return false;
}
}), _temp$a), (_descriptor$5 = _applyDecoratedDescriptor(_class2$h.prototype, "isAddingNew", [observable], {
configurable: true,
enumerable: true,
writable: true,
Expand Down Expand Up @@ -4215,4 +4261,4 @@ function (_Component) {
return Table;
}(Component), (_applyDecoratedDescriptor(_class2$l.prototype, "columns", [computed], Object.getOwnPropertyDescriptor(_class2$l.prototype, "columns"), _class2$l.prototype), _applyDecoratedDescriptor(_class2$l.prototype, "dataSource", [computed], Object.getOwnPropertyDescriptor(_class2$l.prototype, "dataSource"), _class2$l.prototype)), _class2$l)) || _class$x) || _class$x;

export { ArrayCard, ButtonToolbar, CARD_COL_LABEL, CARD_COL_VALUE, CX_PREFIX_SEARCH_CREATE, Card, CardField, DEFAULT_DEBOUNCE_WAIT, DEFAULT_STATE_OPTION_TYPE, Date, EditableArrayCard, EditableCard, Form, FormCard, FormDrawer, FormField, FormFieldSet, FormItem, FormManager, FormModal, GuardedButton, Hidden, ID_ATTR, Info, Label, NestedFieldSet, ObjectSearch, ObjectSearchCreate, OptionSelect, OptionSelectDisplay, REGEXP_EIN, REGEXP_SSN, RadioGroup, Rate, SummaryCard, TYPES, Table, Value, backendValidation, booleanToForm, falseyToString, fieldSetsToColumns, fillInFieldConfig, fillInFieldSet, fillInFieldSets, filterFieldConfig, filterFieldConfigs, filterFieldSet, filterFieldSets, formPropsDefaults, formatOptionSelect, formatRating, getDateFormatList, getFieldSetFields, getFieldSetsFields, getOptions, getUnsortedOptions, isFieldSetSimple, isPartialFieldSetSimple, mapFieldSetFields, modelFromFieldConfigs, noopValidator, renderLabel, renderValue, setFieldSetFields };
export { ArrayCard, ButtonToolbar, CARD_COL_LABEL, CARD_COL_VALUE, CX_PREFIX_SEARCH_CREATE, Card, CardField, DEFAULT_DEBOUNCE_WAIT, DEFAULT_STATE_OPTION_TYPE, Date, EditableArrayCard, EditableCard, Form, FormCard, FormDrawer, FormField, FormFieldSet, FormItem, FormManager, FormModal, GuardedButton, Hidden, ID_ATTR, Info, Label, NestedFieldSet, ObjectSearch, ObjectSearchCreate, OptionSelect, OptionSelectDisplay, REGEXP_EIN, REGEXP_SSN, RadioGroup, Rate, SummaryCard, TYPES, Table, Value, backendValidation, booleanToForm, falseyToString, fieldSetsToColumns, fillInFieldConfig, fillInFieldSet, fillInFieldSets, filterFieldConfig, filterFieldConfigs, filterFieldSet, filterFieldSets, formPropsDefaults, formatOptionSelect, formatRating, getBtnClassName, getDateFormatList, getFieldSetFields, getFieldSetsFields, getOptions, getUnsortedOptions, isFieldSetSimple, isPartialFieldSetSimple, mapFieldSetFields, modelFromFieldConfigs, noopValidator, renderLabel, renderValue, setFieldSetFields };
Loading