({value, onChange, controlProps})
| 27 | })); |
| 28 | |
| 29 | export default function Privilege({value, onChange, controlProps}) { |
| 30 | // All available privileges in the PostgreSQL database server for |
| 31 | // generating the label for the specific Control |
| 32 | const LABELS = { |
| 33 | 'C': 'CREATE', |
| 34 | 'T': 'TEMPORARY', |
| 35 | 'c': 'CONNECT', |
| 36 | 'a': 'INSERT', |
| 37 | 'r': 'SELECT', |
| 38 | 'R': 'READ', |
| 39 | 'W': 'WRITE', |
| 40 | 'w': 'UPDATE', |
| 41 | 'd': 'DELETE', |
| 42 | 'D': 'TRUNCATE', |
| 43 | 'x': 'REFERENCES', |
| 44 | 't': 'TRIGGER', |
| 45 | 'U': 'USAGE', |
| 46 | 'X': 'EXECUTE', |
| 47 | 'm': 'MAINTAIN', |
| 48 | }; |
| 49 | let all = false; |
| 50 | let allWithGrant = false; |
| 51 | |
| 52 | let textValue = ''; |
| 53 | for(const v of value||[]) { |
| 54 | if(v.privilege) { |
| 55 | textValue += v.privilege_type; |
| 56 | if(v.with_grant) { |
| 57 | textValue += '*'; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | const checkboxId = _.uniqueId(); |
| 63 | /* Calculate the real display value by merging all supported privs with incoming value */ |
| 64 | const realVal = (controlProps?.supportedPrivs || []).map((priv)=>{ |
| 65 | let inValue = _.find(value, (v)=>v.privilege_type===priv) || { |
| 66 | privilege: false, with_grant: false, |
| 67 | }; |
| 68 | return { |
| 69 | privilege_type: priv, |
| 70 | privilege: Boolean(inValue.privilege), |
| 71 | with_grant: Boolean(inValue.with_grant), |
| 72 | }; |
| 73 | }); |
| 74 | |
| 75 | const onCheckAll = (e, forWithGrant)=>{ |
| 76 | let newValue = []; |
| 77 | /* Push all the privs or ignore if unchecked and return empty */ |
| 78 | realVal.forEach((v)=>{ |
| 79 | if(forWithGrant) { |
| 80 | newValue.push({ |
| 81 | ...v, |
| 82 | privilege: true, |
| 83 | with_grant: e.target.checked, |
| 84 | }); |
| 85 | } else if(e.target.checked) { |
| 86 | newValue.push({ |
nothing calls this directly
no test coverage detected