@nocobase/plugin-action-bulk-edit
Version:
Batch edit all records or selected records.
10 lines (9 loc) • 11.9 kB
JavaScript
/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
;(self.webpackChunk_nocobase_plugin_action_bulk_edit_client_v2=self.webpackChunk_nocobase_plugin_action_bulk_edit_client_v2||[]).push([["278"],{269:function(e,t,r){r.r(t),r.d(t,{BulkEditFormItemModel:function(){return k}});var n,o,l=r(155),i=r.n(l),a=r(485),u=r(773),c=r.n(u),f=r(59),s=r(477),p=r(866),y=r(967);function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function b(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var l=[],i=!0,a=!1;try{for(o=o.call(e);!(i=(r=o.next()).done)&&(l.push(r.value),!t||l.length!==t);i=!0);}catch(e){a=!0,n=e}finally{try{i||null==o.return||o.return()}finally{if(a)throw n}}return l}}(e,t)||h(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e,t){if(e){if("string"==typeof e)return d(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return d(e,t)}}function O(){var e,t,r=(e=["\n display: flex;\n > .ant-space-item {\n width: 100%;\n }\n "],t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}})));return O=function(){return r},r}var v=function(e){var t,r,n=(0,y.H6)().t,o=e.formItemModel,a=e.onChange,u=e.field,c=function(e,t){if(null==e)return{};var r,n,o,l={};if("u">typeof Reflect&&Reflect.ownKeys){for(o=0,r=Reflect.ownKeys(Object(e));o<r.length;o++)n=r[o],!(t.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(e,n)&&(l[n]=e[n]);return l}if(l=function(e,t){if(null==e)return{};var r,n,o={},l=Object.getOwnPropertyNames(e);for(n=0;n<l.length;n++)r=l[n],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r]);return o}(e,t),Object.getOwnPropertySymbols)for(o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)n=r[o],!(t.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(e,n)&&(l[n]=e[n]);return l}(e,["formItemModel","onChange","field"]),v=m((0,l.useState)(p.f.RemainsTheSame),2),g=v[0],j=v[1],w=m((0,l.useState)(null),2),S=w[0],P=w[1],_=o.context.blockModel.form,x=m((0,l.useState)(function(){var e;return(null==o||null==(e=o.props)?void 0:e.rules)||[]}),1)[0];(0,l.useEffect)(function(){if(g===p.f.ChangedTo){var e=x.filter(function(e){return!e.required}),t=[{required:!0,message:o.context.t("The field value is required")}].concat(function(e){if(Array.isArray(e))return d(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||h(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}());null==o||o.setProps({required:!0,rules:t})}else null==o||o.setProps({required:!1,rules:[]})},[o,x,g]);var E=function(e){var t,r,n,o,l=null!=(t=null!=(r=null==e||null==(n=e.target)?void 0:n.value)?r:null==e||null==(o=e.target)?void 0:o.checked)?t:e;P(l),null==a||a(l)},I=i().cloneElement(u,(t=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){b(e,t,r[t])})}return e}({},c),r=r={onChange:E},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}),t));return i().createElement(f.Space,{className:(0,s.css)(O()),direction:"vertical"},i().createElement(f.Select,{defaultValue:g,value:g,onChange:function(e){j(e);var t,r,n,l=(t=b({},e,S),p.f.Clear in t?null:p.f.ChangedTo in t?t[p.f.ChangedTo]:p.f.RemainsTheSame in t?void 0:void 0);_.setFieldValue(o.props.name,l),e===p.f.ChangedTo&&"CheckboxFieldModel"===(null==o||null==(n=o.subModels)||null==(r=n.field)?void 0:r.use)&&setTimeout(function(){E(!1)})},disabled:e.aclDisabled},i().createElement(f.Select.Option,{value:p.f.RemainsTheSame},n("Remains the same")),i().createElement(f.Select.Option,{value:p.f.ChangedTo},n("Changed to")),i().createElement(f.Select.Option,{value:p.f.Clear},n("Clear"))),[p.f.ChangedTo,p.f.AddAttach].includes(g)&&I)},g=r(694);function j(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function w(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function S(e){return(S=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function P(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}function _(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}),e}function x(e,t){if(null==e)return{};var r,n,o,l={};if("u">typeof Reflect&&Reflect.ownKeys){for(o=0,r=Reflect.ownKeys(Object(e));o<r.length;o++)n=r[o],!(t.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(e,n)&&(l[n]=e[n]);return l}if(l=function(e,t){if(null==e)return{};var r,n,o={},l=Object.getOwnPropertyNames(e);for(n=0;n<l.length;n++)r=l[n],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r]);return o}(e,t),Object.getOwnPropertySymbols)for(o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)n=r[o],!(t.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(e,n)&&(l[n]=e[n]);return l}function E(e,t){return(E=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function I(e){return function(e){if(Array.isArray(e))return j(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||C(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function C(e,t){if(e){if("string"==typeof e)return j(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return j(e,t)}}function A(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(A=function(){return!!e})()}var k=function(e){var t,r;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function n(){var e,t;if(!(this instanceof n))throw TypeError("Cannot call a class as a function");return e=n,t=arguments,e=S(e),function(e,t){var r;if(t&&("object"==((r=t)&&"u">typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,A()?Reflect.construct(e,t||[],S(this).constructor):e.apply(this,t))}return n.prototype=Object.create(e&&e.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),e&&E(n,e),t=[{key:"renderItem",value:function(){var e,t,r=this,n=this.subModels.field,o=this.context.fieldIndex,l=this.context.fieldKey,a=(null==(t=this.parent)?void 0:t.context.fieldPathArray)||[],u=null!=o?((e=n.createFork({},"".concat(l))).context.defineProperty("fieldIndex",{get:function(){return o}}),e.context.defineProperty("fieldKey",{get:function(){return l}}),r.context.currentObject&&e.context.defineProperty("currentObject",{get:function(){return r.context.currentObject}}),r.context.pattern&&e.context.defineProperty("pattern",{get:function(){return r.context.pattern}}),e):n,f=this.context.pattern?_(P({},this.props),{pattern:this.context.pattern}):this.props,s=function(e,t){if(!(null==t?void 0:t.length))return e;var r,n=function(e){if(Array.isArray(e))return e}(r=t[t.length-1].split(":"))||function(e){var t,r,n=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o=[],l=!0,i=!1;try{for(n=n.call(e);!(l=(t=n.next()).done)&&(o.push(t.value),2!==o.length);l=!0);}catch(e){i=!0,r=e}finally{try{l||null==n.return||n.return()}finally{if(i)throw r}}return o}}(r)||C(r,2)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),o=n[0],l=Number(n[1]),i=e.indexOf(o);return -1===i?e:[l].concat(I(e.slice(i+1)))}(this.props.name,o);this.context.defineProperty("fieldPathArray",{value:I(a).concat(I(c().castArray(s)))});var p=this.context.currentObject||this.context.record;return i().createElement(g.FormItem,_(P({},f),{name:s,validateFirst:!0,disabled:this.props.disabled||!c().isEmpty(p)&&!p.__is_new__&&this.props.aclDisabled||!c().isEmpty(p)&&p.__is_new__&&this.props.aclCreateDisabled}),i().createElement(v,{formItemModel:this,field:i().createElement(g.FieldModelRenderer,{model:u,name:s})}))}}],r=[{key:"defineChildren",value:function(e){var t=e.collection.getFields();return(a.FormItemModel.defineChildren(e)||[]).filter(function(e){var r,n=t.find(function(t){return t.name===e.key});return(null==n?void 0:n.interface)&&!(null==n||null==(r=n.uiSchema)?void 0:r["x-read-pretty"])&&"snapshot"!==n.interface&&"sequence"!==n.type}).map(function(e){return _(P({},e),{createModelOptions:function(){return _(P({},e.createModelOptions()),{use:"BulkEditFormItemModel"})}})})}}],t&&w(n.prototype,t),r&&w(n,r),n}(a.FormItemModel);k.define({label:(0,g.tExpr)("Display fields")});var T=null==(o=a.FormItemModel.globalFlowRegistry)||null==(n=o.getFlow)?void 0:n.call(o,"editItemSettings");if(T){var M=T.serialize();M.key;var R=M.steps,F=x(M,["key","steps"]),D=R||{},q=(D.initialValue,D.required,D.validation,D.pattern,x(D,["initialValue","required","validation","pattern"]));(null==q?void 0:q.model)&&(q.model=_(P({},q.model),{use:"bulkEditFieldComponent"})),k.registerFlow(_(P({key:"editItemSettings"},F),{steps:q}))}},967:function(e,t,r){r.d(t,{CU:function(){return o},H6:function(){return i},vV:function(){return l}});var n=r(953),o="action-bulk-edit";function l(e){var t,r,n,l,i=null==(n=globalThis)||null==(r=n.window)?void 0:r.__nocobase_i18n__;return null!=(t=null==i||null==(l=i.t)?void 0:l.call(i,e,{ns:o}))?t:e}function i(){return(0,n.useTranslation)(o,{nsMode:"fallback"})}},866:function(e,t,r){r.d(t,{f:function(){return o}});var n,o=((n={})[n.RemainsTheSame=1]="RemainsTheSame",n[n.ChangedTo=2]="ChangedTo",n[n.Clear=3]="Clear",n[n.AddAttach=4]="AddAttach",n)}}]);