From 7728c17ab9880aa758beef83dbe1db5e5381dc86 Mon Sep 17 00:00:00 2001 From: shubham4443 Date: Sat, 30 Jan 2021 22:53:59 +0530 Subject: [PATCH 1/5] WIP: disabling eventing, truncate event logs and remove allow, deny and authenticated rule from eventing filters --- src/components/eventing/EventingConfigure.jsx | 129 ++++++++++++++---- .../configure-rule/ConfigureRule.jsx | 7 +- src/constants.js | 2 +- src/pages/eventing/EventingSettings.jsx | 13 ++ src/services/eventing.js | 40 ++++++ 5 files changed, 159 insertions(+), 32 deletions(-) diff --git a/src/components/eventing/EventingConfigure.jsx b/src/components/eventing/EventingConfigure.jsx index 3ab4fb96..e2582a50 100644 --- a/src/components/eventing/EventingConfigure.jsx +++ b/src/components/eventing/EventingConfigure.jsx @@ -1,42 +1,111 @@ -import React from 'react' -import { AutoComplete, Button, Form, Checkbox } from 'antd'; +import React, { useState } from 'react' +import { AutoComplete, Button, Form, Checkbox, Select, Input, DatePicker } from 'antd'; import ConditionalFormBlock from "../conditional-form-block/ConditionalFormBlock"; import FormItemLabel from "../form-item-label/FormItemLabel"; +import { useSelector } from 'react-redux'; +import { getTrackedCollections } from '../../operations/database'; +const { Option } = AutoComplete; -const EventingConfigure = ({ initialValues, handleSubmit, dbList, loading }) => { +const EventingConfigure = ({ initialValues, handleSubmit, dbList, loading, onDeleteEventingLogs }) => { + const [form] = Form.useForm() - const [form] = Form.useForm() - const handleSubmitClick = e => { - form.validateFields().then(values => { - handleSubmit(values) - }) - } + const [value, setValue] = useState(""); + const [selectedDbs, setSelectedDbs] = useState([]); + const trackedCollections = useSelector(state => { + const allTrackedCollections = selectedDbs.reduce((prev, curr) => [...prev, ...getTrackedCollections(state, curr)], []) + return [...new Set(allTrackedCollections)] + }) - if (!loading) { - form.setFieldsValue(initialValues) - } + const handleSearch = value => setValue(value); + const handleSelectDatabases = values => setSelectedDbs(values) - return ( -
- - - Enable eventing module + const handleTruncateEventLogs = () => { + form.validateFields(["truncateSince"]).then(values => { + values.truncateSince = values.truncateSince.unix() + + onDeleteEventingLogs(values.truncateSince) + }) + } + const handleSubmitClick = e => { + form.validateFields(["dbAlias", "db", "col"]).then(values => { + values = Object.assign({}, initialValues, values) + + if (values.enabled) { + values.dbTablesInclusionMap = {} + if (!values.db) { + values.dbTablesInclusionMap["*"] = "*"; + } + else { + values.db.forEach(item => { + if (item == values.dbAlias) { + values.dbTablesInclusionMap[item] = values.col ? values.col : "*"; + return; + } + values.dbTablesInclusionMap[item] = values.col ? [] : "*"; + }) + } + } + + delete values["db"] + delete values["col"] + // handleSubmit(values) + console.log(values) + }) + } + + if (!loading) { + form.setFieldsValue(initialValues) + } + + return ( + + + + Enable eventing module - - form.getFieldValue("enabled")}> - - - ({ value: db }))} /> - - - - - - - ) +
+ form.getFieldValue("enabled")}> + + + + + + + + ) } export default EventingConfigure; \ No newline at end of file diff --git a/src/components/security-rules/configure-rule/ConfigureRule.jsx b/src/components/security-rules/configure-rule/ConfigureRule.jsx index a2974b73..a6f8c77c 100644 --- a/src/components/security-rules/configure-rule/ConfigureRule.jsx +++ b/src/components/security-rules/configure-rule/ConfigureRule.jsx @@ -339,7 +339,12 @@ const ConfigureRule = (props) => { - { - dbList.map(db => ()) - } - - - - - - + + {(fields, { add, remove }) => { + return ( +
+ {fields.map((field) => ( + + + + + + + + + remove(field.name)} style={{ fontSize: 20, cursor: "pointer" }} /> + + + ))} + +
+ ) + }} +