Skip to content
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

Task/lut migrate #13648

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
62d66aa
task: Migrates CachePicker and CachesContainer
zeeklop Aug 24, 2022
495431f
task: Migrates CachesOverview
zeeklop Aug 25, 2022
e0df15b
task: Removes console.log from test mock method
zeeklop Aug 25, 2022
76428ac
task: Fixes error message on select
zeeklop Aug 25, 2022
f7afa19
Merge branch 'master' of github.com:Graylog2/graylog2-server into tas…
zeeklop Aug 25, 2022
23afafb
task: Fixes bug when deleting last item in the last page
zeeklop Aug 25, 2022
9268d64
task: Adds types to useQuery return
zeeklop Aug 25, 2022
50d854c
task: Changes key to follow ecma convetion
zeeklop Aug 25, 2022
2c485e1
task: Popover only works if overview calls a function
zeeklop Aug 26, 2022
227d0f8
task: Migrates LookupTablesOverview to tsx
zeeklop Aug 26, 2022
2f20a1a
task: Migrates LookupTableCreate
zeeklop Aug 29, 2022
b752bbd
Merge branch 'master' of github.com:Graylog2/graylog2-server into tas…
zeeklop Aug 29, 2022
048b462
task: Migrates DataAdapters plugins to tsx
zeeklop Aug 29, 2022
12a8319
task: Improved styling summary data tables
zeeklop Aug 30, 2022
32b1832
task: Migrates DataAdaptersOverview and Container to tsx
zeeklop Aug 31, 2022
3636a51
task: Updates DataAdapterCreate
zeeklop Aug 31, 2022
d99d8e8
task: starts migration of DataAdapterForm
zeeklop Sep 1, 2022
fe720cf
task: continues migration of DataAdapterForm
zeeklop Sep 1, 2022
22fd090
Merge branch 'master' into task/lut-migrate-to-tsx
zeeklop Sep 20, 2022
797bd36
Merge branch 'master' into task/lut-caches-migrate-to-tsx
zeeklop Sep 20, 2022
2058001
Merge branch 'master' of github.com:Graylog2/graylog2-server into tas…
zeeklop Sep 22, 2022
fdfaeae
task: Updates branch with latests master
zeeklop Sep 22, 2022
414ef2b
Merge branch 'task/lut-migrate-to-tsx' of github.com:Graylog2/graylog…
zeeklop Sep 22, 2022
5bea9c3
Merge branch 'master' of github.com:Graylog2/graylog2-server into tas…
zeeklop Sep 22, 2022
4aaa998
task: Updates branch with master
zeeklop Sep 22, 2022
883e7c3
Merge branch 'task/lut-caches-migrate-to-tsx' of github.com:Graylog2/…
zeeklop Oct 4, 2022
358b49c
Merge branch 'task/lut-migrate-to-tsx' of github.com:Graylog2/graylog…
zeeklop Oct 4, 2022
52070c7
Migrate lookup-tables to tsx
zeeklop Oct 4, 2022
96c1e44
fix: Merge conflicts
zeeklop Oct 4, 2022
7a39c4c
Merge branch 'master' of github.com:Graylog2/graylog2-server into tas…
zeeklop Oct 5, 2022
a98a452
task: Started data adapter form migration
zeeklop Oct 6, 2022
290628d
task: Break point to update project
zeeklop Oct 6, 2022
3e9af17
Merge branch 'master' of github.com:Graylog2/graylog2-server into tas…
zeeklop Oct 6, 2022
905a412
task: Creates new form component
zeeklop Oct 7, 2022
3b761a9
Merge branch 'master' of github.com:Graylog2/graylog2-server into tas…
zeeklop Oct 7, 2022
e6654a4
task: New component to create field sets
zeeklop Oct 10, 2022
3c01e5d
Merge branch 'master' of github.com:Graylog2/graylog2-server into tas…
zeeklop Oct 10, 2022
e1a41e6
task: Fixes validation errors for required fields
zeeklop Oct 10, 2022
5580b52
Merge branch 'master' of github.com:Graylog2/graylog2-server into tas…
zeeklop Oct 10, 2022
560486a
task: removs extra space
zeeklop Oct 10, 2022
4b06276
task: Changes the text used to search for input
zeeklop Oct 10, 2022
5264d40
Merge branch 'master' of github.com:Graylog2/graylog2-server into tas…
zeeklop Oct 11, 2022
c7519e0
task: fixes bugs with error message type
zeeklop Oct 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions graylog2-web-interface/src/components/common/InputDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
import * as React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';

import { HelpBlock } from 'components/bootstrap';
Expand All @@ -30,8 +29,8 @@ const HelpMessage = styled.span<{ hasError: boolean }>(({ theme, hasError }) =>

type Props = {
className?: string,
error?: React.ReactElement,
help?: React.ReactNode,
error?: React.ReactElement | string,
help?: React.ReactNode | string,
};

/**
Expand Down Expand Up @@ -60,18 +59,6 @@ const InputDescription = ({ className, error, help }: Props) => {
);
};

InputDescription.propTypes = {
className: PropTypes.string,
error: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
]),
help: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
]),
};

InputDescription.defaultProps = {
className: undefined,
error: undefined,
Expand Down
66 changes: 20 additions & 46 deletions graylog2-web-interface/src/components/common/PaginatedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
import PropTypes from 'prop-types';
import * as React from 'react';

import IfInteractive from 'views/components/dashboard/IfInteractive';
Expand Down Expand Up @@ -60,38 +59,39 @@ const PaginatedList = ({
useQueryParameter,
}: Props) => {
const { page, setPage, pageSize: queryParamPageSize, setPageSize } = usePaginationQueryParameter(pageSizes);
const currentPage = useQueryParameter ? page : Math.max(activePage, INITIAL_PAGE);
const pageSize = (useQueryParameter && showPageSizeSelect) ? queryParamPageSize : propPageSize;

const numberPages = pageSize > 0 ? Math.ceil(totalItems / pageSize) : 0;
const [{ currentPage, currentPageSize }, setPagination] = React.useState({
currentPage: useQueryParameter ? page : Math.max(activePage, INITIAL_PAGE),
currentPageSize: (useQueryParameter && showPageSizeSelect) ? queryParamPageSize : propPageSize,
});

const numberPages = React.useMemo(() => (
currentPageSize > 0 ? Math.ceil(totalItems / currentPageSize) : 0
), [currentPageSize, totalItems]);

const _onChangePageSize = (event: React.ChangeEvent<HTMLOptionElement>) => {
event.preventDefault();
const newPageSize = Number(event.target.value);

if (useQueryParameter) {
setPageSize(newPageSize);
}

if (onChange) {
onChange(INITIAL_PAGE, newPageSize);
}
setPagination({ currentPage: INITIAL_PAGE, currentPageSize: newPageSize });
if (useQueryParameter) setPageSize(newPageSize);
if (onChange) onChange(INITIAL_PAGE, newPageSize);
};

const _onChangePage = (pageNum: number) => {
if (useQueryParameter) {
setPage(pageNum);
}
const _onChangePage = React.useCallback((pageNum: number) => {
setPagination({ currentPage: pageNum, currentPageSize });
if (useQueryParameter) setPage(pageNum);
if (onChange) onChange(pageNum, currentPageSize);
}, [useQueryParameter, setPage, onChange, currentPageSize]);

if (onChange) {
onChange(pageNum, pageSize);
}
};
React.useEffect(() => {
if (numberPages > 0 && currentPage > numberPages) _onChangePage(numberPages);
}, [currentPage, numberPages, _onChangePage]);

return (
<>
{showPageSizeSelect && (
<PageSizeSelect pageSizes={pageSizes} pageSize={pageSize} onChange={_onChangePageSize} />
<PageSizeSelect pageSizes={pageSizes} pageSize={currentPageSize} onChange={_onChangePageSize} />
)}

{children}
Expand All @@ -109,32 +109,6 @@ const PaginatedList = ({
);
};

PaginatedList.propTypes = {
/** The active page number. If not specified the active page number will be tracked internally. */
activePage: PropTypes.number,
/** React element containing items of the current selected page. */
children: PropTypes.node.isRequired,
/**
* Function that will be called when the page changes.
* It receives the current page and the page size as arguments.
*/
onChange: PropTypes.func,
/** boolean flag to hide first and last page links */
hideFirstAndLastPageLinks: PropTypes.bool,
/** boolean flag to hide previous and next page links */
hidePreviousAndNextPageLinks: PropTypes.bool,
/** Array of different items per page that are allowed. */
pageSizes: PropTypes.arrayOf(PropTypes.number),
/** Number of items per page. */
pageSize: PropTypes.number,
/** Whether to show the page size selector or not. */
showPageSizeSelect: PropTypes.bool,
/** Total amount of items in all pages. */
totalItems: PropTypes.number.isRequired,
/** boolean flag that enables saving and using page and pageSize from query parameters. Enabled by default. */
useQueryParameter: PropTypes.bool,
};

PaginatedList.defaultProps = {
activePage: 1,
className: undefined,
Expand Down
25 changes: 11 additions & 14 deletions graylog2-web-interface/src/components/lookup-tables/Cache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ import useScopePermissions from 'hooks/useScopePermissions';
import type { LookupTableCache } from 'logic/lookup-tables/types';

import type { CachePluginType } from './types';
import {
SummaryContainer,
SummaryRow,
Title,
Value,
} from './caches/SummaryComponents.styled';
import ConfigSummaryDefinitionListWrapper from './ConfigSummaryDefinitionListWrapper';

type Props = {
cache: LookupTableCache,
Expand All @@ -50,16 +45,18 @@ const Cache = ({ cache }: Props) => {

return (
<Row className="content">
<Col md={12}>
<Col md={6}>
<h2>{cache.title} <small>({plugin.displayName})</small></h2>
<SummaryContainer>
<SummaryRow>
<Title>Description:</Title>
<Value>{cache.description || <em>No description.</em>}</Value>
</SummaryRow>
</SummaryContainer>
<ConfigSummaryDefinitionListWrapper>
<dl>
<dt>Description</dt>
<dd>{cache.description || <em>No description.</em>}</dd>
</dl>
</ConfigSummaryDefinitionListWrapper>
<h4>Configuration</h4>
<div>{React.createElement(plugin.summaryComponent, { cache: cache })}</div>
<ConfigSummaryDefinitionListWrapper>
{React.createElement(plugin.summaryComponent, { cache: cache })}
</ConfigSummaryDefinitionListWrapper>
{(!loadingScopePermissions && scopePermissions?.is_mutable) && (
<Button bsStyle="success"
onClick={handleEdit(cache.name)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
import * as React from 'react';
import type { LookupTableCache, validationErrorsType } from 'src/logic/lookup-tables/types';

import type { LookupTableCache, validationErrorsType, LUTTypesType } from 'logic/lookup-tables/types';
import usePluginEntities from 'hooks/usePluginEntities';
import { Row, Col, Input } from 'components/bootstrap';
import { Select } from 'components/common';
import { defaultCompare as naturalSort } from 'logic/DefaultCompare';

import CacheForm from './CacheForm';
import type { CachePluginType } from './types';
Expand All @@ -34,11 +33,11 @@ const INIT_CACHE: LookupTableCache = {
};

type TypesType = { type?: string, lable?: string };
type cacheTypeOptionsType = { value: string, label: string }
type OptionType = { value: string, label: string }

type Props = {
saved: () => void,
types: TypesType[],
types: LUTTypesType,
validate: () => void,
validationErrors: validationErrorsType,
};
Expand All @@ -58,7 +57,12 @@ const CacheCreate = ({ saved, types, validate, validationErrors }: Props) => {
const cacheTypes = React.useMemo(() => (
Object.values(types)
.map((inType: TypesType) => ({ value: inType.type, label: plugins[inType.type].displayName }))
.sort((a: cacheTypeOptionsType, b: cacheTypeOptionsType) => naturalSort(a.label.toLowerCase(), b.label.toLowerCase()))
.sort((a: OptionType, b: OptionType) => {
if (a.label.toLowerCase() > b.label.toLowerCase()) return 1;
if (a.label.toLowerCase() < b.label.toLowerCase()) return -1;

return 0;
})
), [types, plugins]);

const cache = React.useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ const renderedCache = ({
inCache = { ...createLookupTableCache() },
create = false,
withConfig = true,
// eslint-disable-next-line no-console
validate = () => { console.log('validation called'); },
// eslint-disable-next-line no-console
saved = () => { console.log('saved called'); },
validate = () => {},
saved = () => {},
validationErrors = {},
}) => {
const mockCache = {
Expand Down Expand Up @@ -118,7 +116,7 @@ describe('CacheForm', () => {

renderedCache({ scope: 'DEFAULT', inCache: cache, withConfig: false });

const titleInput = screen.queryByLabelText('* Title');
const titleInput = screen.queryByLabelText('Title');
fireEvent.blur(titleInput);
const requiredErrorMessages = await screen.findAllByText('Required');

Expand All @@ -140,7 +138,7 @@ describe('CacheForm', () => {
validationErrors: { name: ['The cache name is already in use.'] },
});

const titleInput = screen.queryByLabelText('* Title');
const titleInput = screen.queryByLabelText('Title');
fireEvent.blur(titleInput);

const dupNameError = await screen.findByText('The cache name is already in use.');
Expand All @@ -164,8 +162,8 @@ describe('CacheForm', () => {
saved: mockSaved,
});

const titleEle = await screen.findByLabelText('* Title');
const nameEle = await screen.findByLabelText('* Name');
const titleEle = await screen.findByLabelText('Title');
const nameEle = await screen.findByLabelText('Name');
const submitButton = await findSubmitButton();

fireEvent.change(titleEle, { target: { value: '' } });
Expand Down Expand Up @@ -193,8 +191,8 @@ describe('CacheForm', () => {
saved: mockSaved,
});

const titleEle = await screen.findByLabelText('* Title');
const nameEle = await screen.findByLabelText('* Name');
const titleEle = await screen.findByLabelText('Title');
const nameEle = await screen.findByLabelText('Name');
const submitButton = await findSubmitButton();

fireEvent.change(titleEle, { target: { value: 'Test title' } });
Expand Down
27 changes: 12 additions & 15 deletions graylog2-web-interface/src/components/lookup-tables/CacheForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import * as React from 'react';
import _ from 'lodash';
import { Formik, Form } from 'formik';
import { PluginStore } from 'graylog-web-plugin/plugin';
import type { LookupTableCache, validationErrorsType } from 'src/logic/lookup-tables/types';

import usePluginEntities from 'hooks/usePluginEntities';
import type { LookupTableCache, validationErrorsType } from 'logic/lookup-tables/types';
import { Col, Row } from 'components/bootstrap';
import { FormikFormGroup, FormSubmit } from 'components/common';
import { LookupTableCachesActions } from 'stores/lookup-tables/LookupTableCachesStore';
Expand Down Expand Up @@ -48,30 +48,28 @@ const INIT_CACHE: LookupTableCache = {
title: '',
description: '',
name: '',
config: {},
config: { type: 'none' },
};

type Props = {
type: string,
saved: () => void,
title: string,
saved: () => void,
create?: boolean,
cache?: LookupTableCache,
validate?: (arg: LookupTableCache) => void,
validationErrors?: validationErrorsType,
};

const CacheForm = ({ type, saved, title, create, cache, validate, validationErrors }: Props) => {
const CacheForm = ({ type, title, saved, create, cache, validate, validationErrors }: Props) => {
const configRef = React.useRef(null);
const [generateName, setGenerateName] = React.useState<boolean>(create);
const { loadingScopePermissions, scopePermissions } = useScopePermissions(cache);

const plugin = React.useMemo(() => {
return PluginStore.exports('lookupTableCaches').find((p) => p.type === type);
}, [type]);

const plugin = usePluginEntities('lookupTableCaches').find((p) => p.type === type);
const pluginName = React.useMemo(() => (plugin.displayName || type), [plugin, type]);
const DocComponent = React.useMemo(() => (plugin.documentationComponent), [plugin]);

const configFieldSet = React.useMemo(() => {
if (plugin) {
return React.createElement(
Expand Down Expand Up @@ -108,7 +106,7 @@ const CacheForm = ({ type, saved, title, create, cache, validate, validationErro
validate(values);
}

if (values.config.type !== 'none') {
if (values.config.type !== 'none' && configRef.current && typeof configRef.current.validate !== 'undefined') {
const confErrors = configRef.current?.validate() || {};
if (!_.isEmpty(confErrors)) errors.config = confErrors;
}
Expand All @@ -121,7 +119,7 @@ const CacheForm = ({ type, saved, title, create, cache, validate, validationErro
? LookupTableCachesActions.create(values)
: LookupTableCachesActions.update(values);

return promise.then(() => saved());
promise.then(() => saved());
};

const onCancel = () => history.push(Routes.SYSTEM.LOOKUPTABLES.CACHES.OVERVIEW);
Expand All @@ -144,7 +142,7 @@ const CacheForm = ({ type, saved, title, create, cache, validate, validationErro
<fieldset>
<FormikFormGroup type="text"
name="title"
label="* Title"
label="Title"
required
help={errors.title ? null : 'A short title for this cache.'}
onChange={handleTitleChange(values, setValues)}
Expand All @@ -159,18 +157,17 @@ const CacheForm = ({ type, saved, title, create, cache, validate, validationErro
wrapperClassName="col-sm-9" />
<FormikFormGroup type="text"
name="name"
label="* Name"
label="Name"
required
error={validationErrors.name ? validationErrors.name[0] : null}
onChange={() => setGenerateName(false)}
help={
(errors.name || validationErrors.name)
? null
: 'The name that is being used to refer to this cache. Must be unique.'
}
}
labelClassName="col-sm-3"
wrapperClassName="col-sm-9" />

</fieldset>
{configFieldSet}
<fieldset>
Expand Down
Loading