dsql-admin/dsql-app/.local_dist/static/chunks/5160-e9f06aec35447872.js
Benjamin Toby 3ffd2d6777 Updates
2024-12-05 08:03:33 +01:00

1 line
19 KiB
JavaScript

"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5160],{35160:(e,l,a)=>{a.d(l,{A:()=>o});var t=a(74848),n=a(96540),i=a(66051),s=a(39007),d=a(2543),r=a.n(d);function o(e){var l,d,o;let{targetField:u,fieldIndex:c,tableFields:m,setTableFields:x,refreshFieldsListRef:h,setActiveEdit:p,database:f,currentTable:v,user:g}=e,N=(null==u?void 0:u.dataType)?u.dataType.replace(/\d|\(|\)/g,""):null,j=(null==u?void 0:u.dataType)?u.dataType.replace(/[^\d]/g,""):"200",y=a(43431),b=n.useRef(r().cloneDeep(u)),T=n.useRef(),[w,_]=n.useState(u),[F,V]=n.useState(null==u?void 0:u.fieldName),[C,I]=n.useState(N),[S,A]=n.useState(j),[E,k]=n.useState("Varchar is simply letters and numbers within the range 0 - 255"),[D,K]=n.useState((null==u?void 0:u.richText)&&!(null==u?void 0:u.encrypted)?"Yes":"No"),R=!!(null==C?void 0:C.match(/uuid/i));return(0,t.jsx)("div",{className:"w-full -mt-3 bg-white dark:bg-slate-800 flex-wrap",ref:T,children:(0,t.jsxs)("form",{className:"flex flex-col xl:flex-row items-start gap-4 w-full justify-between border border-solid p-4 border-slate-200 dark:border-slate-600 rounded rounded-t-none focus:shadow-lg shadow-slate-700 dark:shadow-black relative flex-wrap",onSubmit:e=>{var l,a;e.preventDefault(),x(e=>(e[c]=w,e)),h.current(e=>e+1),null===(a=e.target.closest(".table-field-wrapper"))||void 0===a||null===(l=a.querySelector(".edit-table-field-section"))||void 0===l||l.classList.toggle("hidden")},children:[(0,t.jsxs)("div",{className:"gap-4 flex-wrap w-full md:w-auto flex-col xl:flex-row items-stretch",children:[(0,t.jsxs)("div",{className:"flex flex-col items-start gap-0.5",children:[(0,t.jsx)("label",{htmlFor:"new_field_name",children:"Field Name"}),(0,t.jsx)("input",{type:"text",name:"new_field_name",id:"new_field_name",placeholder:"Eg. post_title",onInput:async e=>{let l=e.target;l.value=l.value.toLowerCase().replace(/ /g,"_"),_(e=>(e.fieldName=l.value,e.updatedField=!0,e.originName||(e.originName=F),e))},required:!0,defaultValue:F})]}),(0,t.jsxs)("div",{className:"flex flex-col items-start gap-4 xl:gap-0.5",children:[(0,t.jsxs)("div",{className:"flex-wrap xl:flex-nowrap w-full md:w-auto",children:[(0,t.jsx)("label",{htmlFor:"new_field_data_type",children:"Data Type"}),(0,t.jsxs)("div",{className:"dropdown-wrapper reversed text-sm items-start",children:[(0,t.jsx)("span",{className:"px-2 bg-slate-200 dark:bg-slate-700 rounded-full hover:bg-slate-100 dark:hover:bg-slate-600 hidden xl:flex",children:"Info"}),(0,t.jsx)("div",{className:"dropdown mt-0 xl:-mt-2",children:(0,t.jsx)("span",{children:E})})]})]}),(0,t.jsxs)("div",{className:"w-auto",children:[(0,t.jsx)("select",{name:"new_field_data_type",id:"new_field_data_type",className:"w-full xl-w-auto",onChange:e=>{let l=e.target;I(l.value),l.childNodes.forEach(e=>{e.value===l.value&&e.dataset.desc&&k(e.dataset.desc),e.value===l.value&&e.dataset.literal?(w.defaultValueLiteral=e.dataset.literal,w.nullValue=!1):delete w.defaultValueLiteral}),u.dataType=l.value+(l.value.match(/VARCHAR/)?"(".concat(S||200,")"):"")},defaultValue:C||void 0,children:y.map((e,l)=>e.name.match(/VARCHAR/)?(0,t.jsx)("option",{value:e.name,"data-desc":e.description,children:e.title+"("+(S||200)+")"},l+1):(0,t.jsx)("option",{value:e.name,"data-desc":e.description,"data-literal":e.valueLiteral||void 0,children:e.title},l+1))}),(null==C?void 0:C.match(/VARCHAR/))&&(0,t.jsx)("input",{type:"number",defaultValue:S||200,className:"px-2",style:{maxWidth:"60px"},max:255,min:5,onChange:e=>{A(e.target.value),u.dataType=C+"(".concat(e.target.value,")")}})]})]}),(null==C?void 0:C.match(/text/i))&&(0,t.jsx)(n.Fragment,{children:(0,t.jsx)(s.A,{targetField:u})}),!(null===(l=u.dataType)||void 0===l?void 0:l.match(/text/i))&&!R&&(0,t.jsxs)("div",{className:"flex flex-col items-start gap-0.5",style:{minWidth:"70px"},children:[(0,t.jsx)("label",{htmlFor:"new_field_required",children:"Required?"}),(0,t.jsxs)("select",{name:"new_field_required",id:"new_field_required",className:"px-2",defaultValue:(null==u?void 0:u.notNullValue)?"Yes":"No",onChange:e=>{console.log(u),"Yes"===e.target.value?u.notNullValue=!0:(u.notNullValue=!1,delete u.notNullValue)},children:[(0,t.jsx)("option",{value:"No",children:"No"}),(0,t.jsx)("option",{value:"Yes",children:"Yes"})]})]}),!R&&(0,t.jsxs)("div",{className:"flex flex-col items-start gap-0.5",children:[(0,t.jsx)("label",{htmlFor:"new_field_default_value",children:(null==w?void 0:null===(d=w.dataType)||void 0===d?void 0:d.match(/text$/i))?"Can't Set Default for text values":"Default Value (optional)"}),(0,t.jsx)("input",{type:"text",name:"new_field_default_value",id:"new_field_default_value",className:(null==w?void 0:null===(o=w.dataType)||void 0===o?void 0:o.match(/text$/i))?"pointer-events-none opacity-50":"",placeholder:"Default Value",defaultValue:(null==w?void 0:w.defaultValue)?w.defaultValue:(null==w?void 0:w.nullValue)?"NULL":"",onInput:e=>{var l;let a=e.target;null!==(l=w.dataType)&&void 0!==l&&l.match(/text$/i)||_(e=>(a.value.match(/./)?delete e.notNullValue:(delete e.defaultValue,delete e.nullValue),a.value.match(/^null$/i)?(delete e.defaultValue,e.nullValue=!0):a.value.match(/./)&&(delete e.nullValue,e.defaultValue=a.value),e))}})]}),!R&&(0,t.jsx)(i.A,{database:f,setFieldData:_,setTableFields:x,tableFields:m,targetField:u,user:g,currentTable:v,fieldIndex:c})]}),(0,t.jsxs)("div",{className:"secondary mt-auto flex-wrap w-full xl:w-auto",children:[(0,t.jsx)("button",{type:"submit",className:"secondary mt-auto py-3 w-full md:w-auto grow",children:"Save Updates"}),(0,t.jsx)("div",{className:"button outlined gray mt-auto py-2.5 w-full md:w-auto justify-center grow",onClick:e=>{b.current&&(u=r().cloneDeep(b.current)),x(e=>{let l=r().cloneDeep(e);return c&&b.current&&(l[c]=r().cloneDeep(b.current)),l}),p&&p(!1)},children:"Cancel"})]})]})})}},66051:(e,l,a)=>{a.d(l,{A:()=>f});var t=a(74848),n=a(96540),i=a(25414),s=a(76897);function d(e){let{targetField:l}=e;if(!(null==l?void 0:l.richText))return null;let[a,d]=n.useState(l.cssFiles||[]),r=n.useRef(null);return n.useEffect(()=>{l.cssFiles=a},[a]),(0,t.jsxs)("div",{className:"flex flex-col items-start gap-2 w-full my-4",style:{minWidth:"70px"},children:[(0,t.jsx)("span",{className:"label text-xs text-slate-500",children:"Add CSS"}),a.map((e,l)=>(0,t.jsxs)("div",{className:"relative border border-solid border-slate-300 text-xs px-2 py-1 rounded-full",children:[(0,t.jsx)("span",{children:e}),(0,t.jsx)(s.A,{size:20,onClick:()=>{d(l=>l.filter(l=>l!==e))},className:"cursor-pointer hover:opacity-60 "})]},l+1)),(0,t.jsxs)("div",{className:"row w-full",children:[(0,t.jsx)(i.A,{name:"css-file",placeholder:"CSS file URL",elementRef:r}),(0,t.jsx)("button",{className:"secondary outlined",onClick:()=>{var e;let l=null===(e=r.current)||void 0===e?void 0:e.value;(null==l?void 0:l.match(/./))&&d(e=>[...new Set([...e,l])])},children:"Add"})]}),(0,t.jsx)("span",{className:"text-sm text-slate-600",children:"Add CSS files to your Rich Text field"})]})}function r(e){let{targetField:l,setFieldData:a}=e;return(0,t.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",style:{minWidth:"70px"},children:[(0,t.jsx)("label",{htmlFor:"encryption_field",children:"Encrypt?"}),(0,t.jsxs)("select",{name:"encryption_field",id:"encryption_field",className:"px-2",defaultValue:(null==l?void 0:l.encrypted)?"Yes":"No",onChange:e=>{a&&a(l=>(e.target.value.match(/yes/i)?l.encrypted=!0:(l.encrypted=!1,delete l.encrypted),l))},children:[(0,t.jsx)("option",{value:"No",children:"No"}),(0,t.jsx)("option",{value:"Yes",children:"Yes"})]})]})}var o=a(94996);function u(e){let{targetField:l,setFieldData:a}=e;return null}function c(e){let{targetField:l}=e;return(0,t.jsxs)("div",{className:"flex flex-col items-start gap-2 w-full",style:{minWidth:"70px"},children:[(0,t.jsx)("label",{htmlFor:"encryption_field",children:"Pattern"}),(0,t.jsx)("span",{className:"text-sm text-slate-500",children:'This describes a pattern that must be matched for this field to be valid. If you add a pattern and make a db entry that doesn\'t match, the entry will be "NULL" or an empty string or the default value.'}),(0,t.jsx)("input",{type:"text",placeholder:"Regex Pattern. Eg: '\\\\.[a-z]+'",onInput:e=>{var a;let t=e.target;(null==t?void 0:null===(a=t.value)||void 0===a?void 0:a.length)>0?l.pattern=t.value:delete l.pattern},defaultValue:null==l?void 0:l.pattern}),(0,t.jsx)("input",{type:"text",placeholder:"Regex Pattern Flags. Eg: igm",onInput:e=>{var a;let t=e.target;(null==t?void 0:null===(a=t.value)||void 0===a?void 0:a.length)>0?l.patternFlags=t.value:delete l.patternFlags},defaultValue:null==l?void 0:l.patternFlags})]})}var m=a(2543),x=a.n(m),h=a(44500);function p(e){let{targetField:l,setFieldData:a}=e;return(0,t.jsxs)("div",{className:"flex flex-col items-start gap-0.5 w-full",style:{minWidth:"70px"},children:[(0,t.jsx)("label",{htmlFor:"unique_field",children:"Unique Field?"}),(0,t.jsxs)("select",{name:"unique_field",id:"unique_field",className:"px-2",defaultValue:(null==l?void 0:l.unique)?"Yes":"No",onChange:e=>{a&&a(l=>(e.target.value.match(/yes/i)?l.unique=!0:(l.unique=!1,delete l.unique),l))},children:[(0,t.jsx)("option",{value:"No",children:"No"}),(0,t.jsx)("option",{value:"Yes",children:"Yes"})]})]})}function f(e){let{targetField:l,currentTable:a,database:i,tableFields:s,setTableFields:m,setFieldData:f,user:v,fieldIndex:g}=e,[N,j]=n.useState(!1),y=n.useRef(x().cloneDeep(l));return n.useEffect(()=>{},[]),(0,t.jsxs)(n.Fragment,{children:[(0,t.jsx)("span",{className:"button outlined gray mt-5 w-full xl:w-auto",onClick:()=>{j(!0)},children:"More"}),(0,t.jsx)(h.A,{open:N,onClose:()=>{y.current&&(l=x().cloneDeep(y.current)),j(!1)},maxWidth:"600px",children:(0,t.jsxs)("div",{className:"m-auto flex flex-col max-w-xl w-full max-h-[90vh] overflow-y-auto",children:[(0,t.jsx)("div",{className:"w-full justify-between",children:(0,t.jsx)("span",{className:"text-xl",children:"More Options"})}),(0,t.jsx)(d,{targetField:l}),(0,t.jsx)(p,{targetField:l,setFieldData:f}),(0,t.jsx)(r,{targetField:l,setFieldData:f}),a&&(0,t.jsx)(o.A,{targetField:l,setFieldData:f,database:i,tableFields:s,setTableFields:m,currentTable:a,user:v}),(0,t.jsx)(u,{targetField:l,setFieldData:f}),(0,t.jsx)(c,{targetField:l}),(0,t.jsx)("button",{className:"w-full outlined more-padding",onClick:()=>{j(!1)},children:"Done"})]})})]})}},94996:(e,l,a)=>{a.d(l,{A:()=>d});var t=a(74848),n=a(96540),i=a(23698),s=a(620);function d(e){var l,a;let{targetField:d,setFieldData:r,tableFields:o,setTableFields:u,database:c,currentTable:m,user:x,setActiveEdit:h,activeClonedTable:p}=e,[f,v]=n.useState(null!=d&&!!d.foreignKey),[g,N]=n.useState(null),[j,y]=n.useState(null),[b,T]=n.useState(null),[w,_]=n.useState(null),[F,V]=n.useState(!1);return n.useEffect(()=>{(f||(null==d?void 0:d.foreignKey))&&(0,i.A)("/api/getUserSchemaData").then(e=>{if(e.success)try{let a=e.schemaData.filter(e=>e.dbFullName===c.db_full_name),t=m?a[0].tables.filter(e=>e.tableName!==m.tableName):a[0].tables;if(N(t),null==d?void 0:d.foreignKey){var l;let e=t.filter(e=>{var l;return e.tableName===(null==d?void 0:null===(l=d.foreignKey)||void 0===l?void 0:l.destinationTableName)});y(e[0]),(null===(l=e[0])||void 0===l?void 0:l.fields)&&T(e[0].fields)}}catch(e){(0,i.A)("/api/admin/clientError",{method:"post",body:{component:"ForeignKey/fetch-error-getUserSchemaData/lines-65-77",message:e.message,user:x}})}})},[f]),(0,t.jsxs)("div",{className:"flex flex-col items-start gap-2 w-full mt-2 relative",style:{minWidth:"70px"},children:[F&&(0,t.jsx)(s.A,{}),(0,t.jsxs)("label",{htmlFor:"foreign_key_field",className:"flex flex-wrap items-center gap-2 mt-2",children:[(0,t.jsx)("span",{children:"Foreign Key?"}),(0,t.jsxs)("div",{className:"dropdown-wrapper reversed text-sm items-start",children:[(0,t.jsx)("span",{className:"px-2 bg-slate-200 rounded-full hover:bg-slate-100 hidden xl:flex text-slate-600",children:"Info"}),(0,t.jsx)("div",{className:"dropdown mt-0 xl:-mt-2",children:(0,t.jsx)("span",{children:"Foriegn key links the current table to another table"})})]})]}),(0,t.jsxs)("select",{name:"foreign_key_field",id:"foreign_key_field",className:"px-2",defaultValue:(null==d?void 0:d.foreignKey)?"Yes":"No",onChange:e=>{e.target.value.match(/yes/i)?(v(!0),r&&r(e=>(e.foreignKey={foreignKeyName:void 0,destinationTableName:void 0,destinationTableColumnName:void 0,cascadeDelete:!0},e))):(v(!1),r&&r(e=>(delete e.foreignKey,e)))},children:[(0,t.jsx)("option",{value:"No",children:"No"}),(0,t.jsx)("option",{value:"Yes",children:"Yes"})]}),f&&g&&(0,t.jsx)(n.Fragment,{children:(0,t.jsxs)("select",{name:"foreign_key_destination_table_name",id:"foreign_key_destination_table_name",className:"px-2",defaultValue:(null==d?void 0:null===(l=d.foreignKey)||void 0===l?void 0:l.destinationTableName)?d.foreignKey.destinationTableName:void 0,onChange:e=>{var l;let a=e.target;if(null===(l=e.target.value)||void 0===l?void 0:l.match(/--/)){r?r(e=>{let l=e.foreignKey;return l&&(l.destinationTableName=void 0),e}):a.dataset.destinationTableName=void 0;return}let t=g.filter(l=>l.tableName===e.target.value)[0];y(t),(null==t?void 0:t.fields)&&T(t.fields),r?r(l=>{let a=l.foreignKey;return a&&(a.destinationTableName=e.target.value),l}):e.target.dataset.destinationTableName=e.target.value},children:[(0,t.jsx)("option",{value:"--",children:"--Select Table--"}),g.map((e,l)=>(0,t.jsx)("option",{value:e.tableName,children:e.tableFullName},l+1))]})}),j&&b&&(0,t.jsxs)(n.Fragment,{children:[(0,t.jsxs)("select",{name:"foreign_key_destination_table_column_name",id:"foreign_key_destination_table_column_name",className:"px-2",defaultValue:(null==d?void 0:null===(a=d.foreignKey)||void 0===a?void 0:a.destinationTableColumnName)?d.foreignKey.destinationTableColumnName:void 0,onChange:e=>{try{var l;let a=b.filter(l=>l.fieldName===e.target.value)[0];if(_(a),null===(l=e.target.value)||void 0===l?void 0:l.match(/--/)){r&&r(e=>{let l=e.foreignKey;return l&&(l.destinationTableColumnName=void 0),e});return}let t="dsql_".concat(c.user_id,"_").concat(c.db_slug,"_").concat(Date.now());r?r(e=>{e.dataType=a.dataType;let l=e.foreignKey;return l&&(l.destinationTableColumnName=a.fieldName,l.destinationTableColumnType=a.dataType,l.foreignKeyName=t),e}):(e.target.dataset.dataType=a.dataType,e.target.dataset.destinationTableColumnName=a.fieldName,e.target.dataset.foreignKeyName=t)}catch(e){(0,i.A)("/api/admin/clientError",{method:"post",body:{component:"ForeignKey/lines-232-264",message:e.message,user:x}})}},children:[(0,t.jsx)("option",{value:"--",children:"--Select Column--"}),b.map((e,l)=>(0,t.jsx)("option",{value:e.fieldName,children:e.fieldName},l+1))]}),p&&w&&(0,t.jsx)("button",{className:"secondary w-full",onClick:e=>{var l,a;V(!0),(0,i.A)("/api/updateClonedTableForeignKeys",{method:"post",body:{tableData:m,database:c.db_full_name,dbSlug:c.db_slug,delegated:null!==(a=window.location)&&void 0!==a&&null!==(l=a.search)&&void 0!==l&&!!l.match(/delegated=true/i)}},!0).then(e=>{e.success?window.alert("Foreign Key Added Successfully!"):window.alert("Update Failed, Please Try again."),setTimeout(()=>{h&&h(!1)},1e3)})},children:"Add Foreign Key"})]}),p&&(0,t.jsx)("button",{className:"light-gray w-full",onClick:e=>{delete d.foreignKey,h&&h(!1)},children:"Cancel"})]})}},39007:(e,l,a)=>{a.d(l,{A:()=>n});var t=a(74848);function n(e){let{targetField:l}=e;return(0,t.jsxs)("div",{className:"flex flex-col items-start gap-0.5",style:{minWidth:"70px"},children:[(0,t.jsx)("label",{htmlFor:"rich_text_option",children:"Text Type"}),(0,t.jsxs)("select",{name:"rich_text_option",id:"rich_text_option",className:"px-2",onChange:e=>{switch(delete l.json,delete l.richText,delete l.yaml,delete l.html,delete l.javascript,delete l.shell,e.target.value){case"plain":break;case"rte":l.richText=!0;break;case"json":l.json=!0;break;case"yaml":l.yaml=!0;break;case"html":l.html=!0;break;case"css":l.css=!0;break;case"javascript":l.javascript=!0;break;case"shell":l.shell=!0}},defaultValue:l.richText?"rte":l.json?"json":l.yaml?"yaml":l.html?"html":l.javascript?"javascript":l.shell?"shell":l.css?"css":"plain",children:[(0,t.jsx)("option",{value:"plain",children:"Plain Text"}),(0,t.jsx)("option",{value:"rte",children:"Rich Text"}),(0,t.jsx)("option",{value:"json",children:"JSON"}),(0,t.jsx)("option",{value:"yaml",children:"YAML"}),(0,t.jsx)("option",{value:"html",children:"HTML"}),(0,t.jsx)("option",{value:"css",children:"CSS"}),(0,t.jsx)("option",{value:"javascript",children:"Javascript"}),(0,t.jsx)("option",{value:"shell",children:"Shell"})]})]})}a(96540)},44500:(e,l,a)=>{a.d(l,{A:()=>d});var t=a(74848),n=a(96540),i=a(5338),s=a(76897);function d(e){let{children:l,open:a,setOpen:s,onClose:d,maxWidth:o}=e;return n.useEffect(()=>{if(a){let e=document.createElement("div");e.className="modal-wrapper",(0,i.createRoot)(e).render((0,t.jsx)(r,{onClose:d,maxWidth:o,children:l})),document.body.appendChild(e)}else document.querySelectorAll(".modal-wrapper").forEach(e=>{var l;null===(l=e.parentElement)||void 0===l||l.removeChild(e)})},[a]),(0,t.jsx)(t.Fragment,{})}function r(e){let{children:l,onClose:a,maxWidth:i,open:d}=e,r=n.useRef();return(0,t.jsxs)(n.Fragment,{children:[(0,t.jsx)("div",{className:"modal-cancel",onClick:e=>{o({modalEl:e.target.closest(".modal-wrapper"),closeFn:a})}}),(0,t.jsxs)("div",{className:"modal-content",style:{maxWidth:i||void 0},ref:r,children:[l," ",(0,t.jsx)("button",{className:"ghost modal-cancel-button",onClick:e=>{o({modalEl:e.target.closest(".modal-wrapper"),closeFn:a})},children:(0,t.jsx)(s.A,{})})]})]})}function o(e){var l;let{modalEl:a,closeFn:t}=e;t&&t(),null===(l=a.parentElement)||void 0===l||l.removeChild(a)}},43431:e=>{e.exports=JSON.parse('[{"title":"VARCHAR","name":"VARCHAR","value":"0-255","argument":true,"description":"Varchar is simply letters and numbers within the range 0 - 255","maxValue":255},{"title":"TINYINT","name":"TINYINT","value":"0-100","description":"TINYINT means Integers: 0 to 100","maxValue":127},{"title":"SMALLINT","name":"SMALLINT","value":"0-255","description":"SMALLINT means Integers: 0 to 240933","maxValue":32767},{"title":"MEDIUMINT","name":"MEDIUMINT","value":"0-255","description":"MEDIUMINT means Integers: 0 to 1245568545560","maxValue":8388607},{"title":"INT","name":"INT","value":"0-255","description":"INT means Integers: 0 to 12560","maxValue":2147483647},{"title":"BIGINT","name":"BIGINT","value":"0-255","description":"BIGINT means Integers: 0 to 1245569056767568545560","maxValue":2e+63},{"title":"TINYTEXT","name":"TINYTEXT","value":"0-255","description":"Text with 255 max characters","maxValue":127},{"title":"TEXT","name":"TEXT","value":"0-100","description":"MEDIUMTEXT is just text with max length 16,777,215","maxValue":127},{"title":"MEDIUMTEXT","name":"MEDIUMTEXT","value":"0-255","description":"MEDIUMTEXT is just text with max length 16,777,215","maxValue":127},{"title":"LONGTEXT","name":"LONGTEXT","value":"0-255","description":"LONGTEXT is just text with max length 4,294,967,295","maxValue":127},{"title":"UUID","name":"UUID","valueLiteral":"UUID()","description":"A Unique ID"}]')}}]);