Commit f8f84ee6 authored by Matija Obreza's avatar Matija Obreza

Merge branch 'ui-part-for-server-447' into 'master'

Reindexing ES using JSON filter

See merge request genesys-pgr/genesys-ui!335
parents 2f82be8e 2ee3f006
......@@ -849,6 +849,19 @@
}
}
},
"cluster": {
"admin": {
"p": {
"elastic": {
"title": "ElasticSearch Administration",
"jsonFilterLabel": "JSON filter",
"reindexBtn": "Reindex",
"invalidFilterError": "Invalid filter",
"startedReindex": "Reindexing by filter has started"
}
}
}
},
"cms": {
"admin": {
"c": {
......
// actions
import { showSnackbar } from 'actions/snackbar';
import {createPureApiCaller} from 'actions/ApiCall';
// service
import AdminService from 'service/genesys/AdminService';
// Wrapped API calls
const apiReindexElasticFiltered = createPureApiCaller(AdminService.reindexElasticFiltered);
export const reindexElasticFiltered = (filter: string) => (dispatch) => {
return dispatch(apiReindexElasticFiltered(filter))
.then(() => {
dispatch(showSnackbar('cluster.admin.p.elastic.startedReindex'));
});
};
export const ELASTICSEARCH_JSON_FILTER_FORM = 'Form/cluster/admin/ELASTICSEARCH_JSON_FILTER_FORM';
import Loadable from 'utilities/CustomReactLoadable';
const adminRoutes = [
{
path: '/elastic',
component: Loadable({ loader: () => import(/* webpackMode:"lazy", webpackChunkName: "cms" */'cluster/ui/admin/ElasticSearchPage') }),
exact: true,
extraProps: {
title: 'cluster.admin.p.elastic.title',
},
},
];
export { adminRoutes as clusterAdminRoutes };
{
"admin": {
"p": {
"elastic": {
"title": "ElasticSearch Administration",
"jsonFilterLabel": "JSON filter",
"reindexBtn": "Reindex",
"invalidFilterError": "Invalid filter",
"startedReindex": "Reindexing by filter has started"
}
}
}
}
\ No newline at end of file
import * as React from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import { translate } from 'react-i18next';
// UI
import PageLayout from 'ui/layout/PageLayout';
import JsonFiltersForm from '../c/JsonFiltersForm';
import PageTitle from 'ui/common/PageTitle';
// actions
import {reindexElasticFiltered} from 'cluster/actions/admin';
interface IElasticSearchPageProps {
t: any;
i18n: any;
pageTitle: string;
reindexElasticFiltered: (filter: string) => Promise<boolean>;
}
class ElasticSearchPage extends React.Component<IElasticSearchPageProps> {
public state = {
errorMsg: null,
};
private handleSubmit = (values) => {
const { reindexElasticFiltered } = this.props;
reindexElasticFiltered(values.jsonFilter)
.catch(() => {
this.setState({errorMsg: 'cluster.admin.p.elastic.invalidFilterError'});
});
}
public render() {
const { t, pageTitle} = this.props;
const jsonFilter = `{"institute":{"code":["NGA039"]}}`;
return (
<PageLayout withFooter>
<div className="p-20">
<PageTitle title={ t(pageTitle) }/>
<h1>{ t('cluster.admin.p.elastic.title') }</h1>
<JsonFiltersForm t={ t } initialValues={ { jsonFilter } } onSubmit={ this.handleSubmit } errorMsg={ this.state.errorMsg }/>
</div>
</PageLayout>
);
}
}
const mapStateToProps = (state, ownProps) => ({
pageTitle: ownProps.route.extraProps.title,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
reindexElasticFiltered,
}, dispatch);
export default translate()(connect(mapStateToProps, mapDispatchToProps)(ElasticSearchPage));
import * as React from 'react';
import { translate } from 'react-i18next';
import { withStyles } from '@material-ui/core/styles';
import { Field, reduxForm } from 'redux-form';
import Button from '@material-ui/core/Button';
import { TextField } from 'ui/common/text-field/index';
import Validators from 'utilities/Validators';
import {ELASTICSEARCH_JSON_FILTER_FORM} from 'cluster/constants';
const styleSheet = (theme) => ({
/*tslint:disable*/
root: {
display: 'flex',
alignItems: 'center',
minWidth: '400px',
height: '65px',
'& > div': {
minWidth: '400px',
width: 'auto !important' as 'auto !important',
[theme.breakpoints.down('xs')]: {
minWidth: '250px',
},
},
'& > button': {
width: 'auto' as 'auto',
marginLeft: '1rem',
},
},
/*tslint:enable*/
});
class JsonFiltersForm extends React.Component<any, void> {
public constructor(props: any) {
super(props);
}
public render() {
const { t, errorMsg, handleSubmit, submitting, invalid, classes } = this.props;
return (
<div>
<form onSubmit={ handleSubmit } className={ classes.root }>
<Field name="jsonFilter"
component={ TextField }
type="text"
label={ t(`cluster.admin.p.elastic.jsonFilterLabel`) }
validate={ [ Validators.required ] }
/>
<Button variant="contained" type="submit" style={ { marginRight: '1rem', marginTop: '1rem' } } disabled={ submitting || invalid }>
{ t('cluster.admin.p.elastic.reindexBtn') }
</Button>
</form>
{ errorMsg && <div style={ { color: 'red' } }>{ t(errorMsg) }</div> }
</div>
);
}
}
export default translate()(reduxForm({
form: ELASTICSEARCH_JSON_FILTER_FORM,
enableReinitialize: true,
})(withStyles(styleSheet)<any>(JsonFiltersForm)));
import * as UrlTemplate from 'url-template';
import * as QueryString from 'query-string';
import { axiosBackend } from 'utilities/requestUtils';
const URL_CLEANUP_ACL = `/api/v1/admin/cleanup-acl`;
const URL_REINDEX_ELASTIC_FILTERED = `/api/v1/admin/elastic/reindex`;
const URL_REINDEX_ELASTIC_CONTENT = UrlTemplate.parse(`/api/v1/admin/elastic/reindex/{type}`);
const URL_ENSURE_DATASET_FOLDERS = `/api/v1/admin/ensure-dataset-folders`;
const URL_ENSURE_INSTITUTE_FOLDERS = `/api/v1/admin/ensure-inst-folders`;
const URL_ENSURE_THUMBNAILS = `/api/v1/admin/ensure-thumbnails`;
const URL_UPDATE_GLIS = `/api/v1/admin/update-glis`;
/*
* Defined in Swagger as 'admin'
*/
class AdminService {
/**
* cleanupAcl at /api/v1/admin/cleanup-acl
*
*/
public static cleanupAcl(xhrConfig?): Promise<boolean> {
const apiUrl = URL_CLEANUP_ACL;
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
...xhrConfig,
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as boolean);
}
/**
* reindexElasticFiltered at /api/v1/admin/elastic/reindex
*
* @param filter filter
*/
public static reindexElasticFiltered(filter: string, xhrConfig?): Promise<boolean> {
const qs = QueryString.stringify({
filter: filter || undefined,
}, {});
const apiUrl = URL_REINDEX_ELASTIC_FILTERED + (qs ? `?${qs}` : '');
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
...xhrConfig,
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as boolean);
}
/**
* reindexElasticContent at /api/v1/admin/elastic/reindex/{type}
*
* @param type type
*/
public static reindexElasticContent(type: string, xhrConfig?): Promise<boolean> {
const apiUrl = URL_REINDEX_ELASTIC_CONTENT.expand({ type });
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
...xhrConfig,
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as boolean);
}
/**
* ensureDatasetFolders at /api/v1/admin/ensure-dataset-folders
*
*/
public static ensureDatasetFolders(xhrConfig?): Promise<boolean> {
const apiUrl = URL_ENSURE_DATASET_FOLDERS;
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
...xhrConfig,
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as boolean);
}
/**
* ensureInstituteFolders at /api/v1/admin/ensure-inst-folders
*
*/
public static ensureInstituteFolders(xhrConfig?): Promise<boolean> {
const apiUrl = URL_ENSURE_INSTITUTE_FOLDERS;
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
...xhrConfig,
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as boolean);
}
/**
* ensureThumbnails at /api/v1/admin/ensure-thumbnails
*
*/
public static ensureThumbnails(xhrConfig?): Promise<boolean> {
const apiUrl = URL_ENSURE_THUMBNAILS;
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
...xhrConfig,
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as boolean);
}
/**
* updateGLIS at /api/v1/admin/update-glis
*
* @param from from
*/
public static updateGLIS(from: string, xhrConfig?): Promise<boolean> {
const qs = QueryString.stringify({
from: from || undefined,
}, {});
const apiUrl = URL_UPDATE_GLIS + (qs ? `?${qs}` : '');
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
...xhrConfig,
url: apiUrl,
method: 'POST',
...content,
}).then(({ data }) => data as boolean);
}
}
export default AdminService;
......@@ -29,6 +29,8 @@ import {instituteDashboardRoutes, institutePublicRoutes} from 'institutes/routes
import {requestPublicRoutes, requestsAdminRoutes} from 'requests/routes';
// CMS
import {cmsPublicRoutes, cmsAdminRoutes} from 'cms/routes';
// Cluster
import {clusterAdminRoutes} from 'cluster/routes';
// Datasets
......@@ -100,6 +102,7 @@ const routes = [
...partnerAdminRoutes,
...vocabularyAdminRoutes,
...cmsAdminRoutes,
...clusterAdminRoutes,
{
path: '/',
component: AdminDashboardPage,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment