-
Notifications
You must be signed in to change notification settings - Fork 1.1k
add Inputs notifications for failed, setup and stopped state and improve input creation #24283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
3a49999
9e4d9bb
ae8b6e3
33995e9
56f667b
5f38cca
ef34ea8
ca80962
1b0200d
19bf1bd
1070476
133d711
5a853a8
9ee0543
41cc33a
a1558b3
9719cf4
dd9cc82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* | ||
| * Copyright (C) 2020 Graylog, Inc. | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the Server Side Public License, version 1, | ||
| * as published by MongoDB, Inc. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Server Side Public License for more details. | ||
| * | ||
| * You should have received a copy of the Server Side Public License | ||
| * along with this program. If not, see | ||
| * <http://www.mongodb.com/licensing/server-side-public-license>. | ||
| */ | ||
| import * as React from 'react'; | ||
| import { useEffect, useMemo } from 'react'; | ||
| import styled, { css } from 'styled-components'; | ||
|
|
||
| import { Alert, Row, Col } from 'components/bootstrap'; | ||
| import useInputsStates from 'hooks/useInputsStates'; | ||
| import type { InputStates, InputState } from 'hooks/useInputsStates'; | ||
| import { useStore } from 'stores/connect'; | ||
| import { InputsStore, InputsActions } from 'stores/inputs/InputsStore'; | ||
|
|
||
| const INPUT_STATES = { | ||
| FAILED: 'FAILED', | ||
| FAILING: 'FAILING', | ||
| SETUP: 'SETUP', | ||
| } as const; | ||
| const StyledAlert = styled(Alert)( | ||
| ({ theme }) => css` | ||
| margin-top: 10px; | ||
|
|
||
| i { | ||
| color: ${theme.colors.gray[10]}; | ||
| } | ||
|
|
||
| form { | ||
| margin-bottom: 0; | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| const hasInputInState = (inputStates: InputStates, targetStates: InputState | Array<InputState>) => { | ||
| const statesToCheck = Array.isArray(targetStates) ? targetStates : [targetStates]; | ||
|
|
||
| for (const nodeStates of Object.values(inputStates)) { | ||
| for (const inputState of Object.values(nodeStates)) { | ||
| if (statesToCheck.includes(inputState.state)) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| }; | ||
|
|
||
| const InputsNotifications = () => { | ||
| const { data: inputStates, isLoading } = useInputsStates(); | ||
| const inputs = useStore(InputsStore, (state) => state.inputs); | ||
|
|
||
| useEffect(() => { | ||
| InputsActions.list(); | ||
| }, []); | ||
|
|
||
| const notifications = useMemo(() => { | ||
| if (isLoading || !inputs || !inputStates) return null; | ||
|
|
||
| return { | ||
| hasStoppedInputs: inputs.some((input) => !inputStates[input.id]), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it more accurate to name it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Input in stopped stated are not sent by the backend this means missing are stopped ones. |
||
| hasFailedInputs: hasInputInState(inputStates, [INPUT_STATES.FAILED, INPUT_STATES.FAILING]), | ||
| hasSetupInputs: hasInputInState(inputStates, INPUT_STATES.SETUP), | ||
| }; | ||
| }, [inputs, inputStates, isLoading]); | ||
|
|
||
| const { hasStoppedInputs, hasFailedInputs, hasSetupInputs } = notifications; | ||
|
|
||
| if (!hasStoppedInputs && !hasFailedInputs && !hasSetupInputs) { | ||
| return null; | ||
| }; | ||
|
|
||
| return ( | ||
| <Row className="content"> | ||
| <Col md={12}> | ||
| {hasFailedInputs && ( | ||
| <StyledAlert bsStyle="danger" title="Some inputs are in failed state."> | ||
| One or more inputs are currently failed state. Failed or failing inputs will not receive traffic until | ||
|
||
| fixed. | ||
| </StyledAlert> | ||
| )} | ||
| {hasSetupInputs && ( | ||
| <StyledAlert bsStyle="warning" title="Some inputs are in setup mode."> | ||
| One or more inputs are currently in setup mode. Inputs will not receive traffic until started. | ||
| </StyledAlert> | ||
| )} | ||
| {hasStoppedInputs && ( | ||
| <StyledAlert bsStyle="warning" title="Some inputs are stopped."> | ||
| One or more inputs are currently stopped. Stopped Inputs will not receive traffic until started. | ||
| </StyledAlert> | ||
| )} | ||
| </Col> | ||
| </Row> | ||
| ); | ||
| }; | ||
|
|
||
| export default InputsNotifications; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ type InputsActionsType = { | |
| list: () => Promise<{ inputs: Array<Input>; total: number }>; | ||
| get: (id: string) => Promise<Input>; | ||
| getOptional: (id: string, showError: boolean) => Promise<Input>; | ||
| create: (input: ConfiguredInput) => Promise<void>; | ||
| create: (input: ConfiguredInput) => Promise<{ id: string }>; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we also need to change the create fetch promise return, to make sure it is not a void and it is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The backend return the id on the create fetch Promise since we are returning the promise we can be sure that if it resolve it will have the id |
||
| delete: (input: Input) => Promise<void>; | ||
| update: (id: string, input: ConfiguredInput) => Promise<void>; | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
selectedInputwill always be undefined afterresetFields()no ?