Skip to content

Commit

Permalink
fix: send default values from ProfilesModal to the database
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekzyla committed Sep 13, 2022
1 parent c129eb1 commit 4786bba
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
8 changes: 7 additions & 1 deletion frontend/packages/manager/src/components/Conditions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class Conditions extends Component {
field: '',
patterns: null
};
}

this.props.onConditionsCreator(this.state);
}
handleChange = (e, {value}) => {
this.setState({condition: value});
};
Expand Down Expand Up @@ -57,4 +58,9 @@ class Conditions extends Component {
}
}

Conditions.prototype.toString = function conditionToString () {
let result = `\n condition: ${this.state.condition}`;

};

export default Conditions;
4 changes: 3 additions & 1 deletion frontend/packages/manager/src/components/PatternsCreator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class PatternsCreator extends Component {
this.state = {
items,
};

props.onPatternsCreator(this.patterns);
}

handlePatternChange = () => {
var patterns = this.patterns;
this.props.onPatternsCreator(patterns);
this.props.onPatternsCreator(this.patterns);
}

handleItemValue = (index, e) => {
Expand Down
2 changes: 2 additions & 0 deletions frontend/packages/manager/src/components/VarbindsCreator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class VarbindsCreator extends Component {
this.state = {
items,
};

this.props.onVarbindsCreator(this.varBinds);
}

handleItemValueFamily = (index, e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,28 @@ function ProfilePanel() {
return () => { isMounted = false }
}, [setProfiles]);

let mappedPatterns = null;
const profilesPanels = profiles.map((v) => (
<CollapsiblePanel title={v.profileName}>

{ v.frequency && <P>frequency: {v.frequency}</P> }
{ v.conditions && <P>conditions: {v.conditions.toString()}</P> }
{ v.conditions &&
<Table stripeRows>
<Table.Head>
<Table.HeadCell>Condition</Table.HeadCell>
<Table.HeadCell>Field</Table.HeadCell>
<Table.HeadCell>Patterns</Table.HeadCell>
</Table.Head>
<Table.Body>
<Table.Row key={createDOMID()}>
<Table.Cell>{v.conditions.condition}</Table.Cell>
<Table.Cell>{v.conditions.field}</Table.Cell>
<Table.Cell>{v.conditions.patterns && v.conditions.patterns.map(value =>
<P>{value.pattern}</P>)}</Table.Cell>
</Table.Row>
</Table.Body>
</Table>}

{ v.varBinds &&
<Table stripeRows>
<Table.Head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Number from '@splunk/react-ui/Number';
import Text from '@splunk/react-ui/Text';
import VarbindsCreator from "../VarbindsCreator";
import Conditions from "../Conditions";
import PatternsCreator from "../PatternsCreator";
import axios from "axios";


Expand All @@ -14,10 +15,12 @@ function ProfilesModal() {
const modalToggle = useRef(null);
const [open, setOpen] = useState(false);
const [profileName, setProfileName] = useState('');
const [frequency, setFrequency] = useState(0);
const [frequency, setFrequency] = useState(1);
const [varBinds, setVarBinds] = useState(null);
const [conditions, setConditions] = useState(null);

const varBindsRef = useRef(null);

const handleRequestOpen = () => {
setOpen(true);
};
Expand Down Expand Up @@ -54,10 +57,12 @@ function ProfilesModal() {

const handleApply = useCallback(
(e) => {
var profileObj = {profileName: profileName,
frequency: frequency,
varBinds: varBinds,
conditions: conditions}
var profileObj = {
profileName: profileName,
frequency: frequency,
varBinds: varBinds,
conditions: conditions
}
postProfile(profileObj)
setOpen(false);
modalToggle?.current?.focus();},
Expand All @@ -70,17 +75,21 @@ function ProfilesModal() {
<Modal onRequestClose={handleRequestClose} open={open} style={{ width: '600px' }}>
<Modal.Header title="Add new profile" onRequestClose={handleRequestClose} />
<Modal.Body>

<ControlGroup label="Profile name">
<Text value={profileName} onChange={handleProfileName}/>
</ControlGroup>

<ControlGroup label="Frequency of polling" >
<Number value={frequency} onChange={handleFrequency}/>
</ControlGroup>
<Conditions onConditionsCreator={handleConditions}/>
<ControlGroup label="VarBinds">
<VarbindsCreator onVarbindsCreator={handleVarBinds}/>
</ControlGroup>

<Conditions onConditionsCreator={handleConditions}/>

<ControlGroup label="VarBinds">
<VarbindsCreator onVarbindsCreator={handleVarBinds}/>
</ControlGroup>

</Modal.Body>
<Modal.Footer>
<Button appearance="secondary" onClick={handleRequestClose} label="Cancel" />
Expand Down

0 comments on commit 4786bba

Please sign in to comment.