Skip to content

Commit

Permalink
React version of angular license view
Browse files Browse the repository at this point in the history
  • Loading branch information
matschaffer committed Sep 7, 2021
1 parent 07f4985 commit f4c61b2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 5 deletions.
7 changes: 2 additions & 5 deletions x-pack/plugins/monitoring/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ReactDOM from 'react-dom';
import { Route, Switch, Redirect, Router } from 'react-router-dom';
import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public';
import { LoadingPage } from './pages/loading_page';
import { LicensePage } from './pages/license_page';
import { ClusterOverview } from './pages/cluster/overview_page';
import { MonitoringStartPluginDependencies } from '../types';
import { GlobalStateProvider } from './global_state_context';
Expand Down Expand Up @@ -53,7 +54,7 @@ const MonitoringApp: React.FC<{
<Route path="/loading" component={LoadingPage} />
<RouteInit
path="/license"
component={License}
component={LicensePage}
codePaths={['all']}
fetchAllClusters={false}
/>
Expand Down Expand Up @@ -91,7 +92,3 @@ const NoData: React.FC<{}> = () => {
const Home: React.FC<{}> = () => {
return <div>Home page (Cluster listing)</div>;
};

const License: React.FC<{}> = () => {
return <div>License page</div>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { useContext } from 'react';
import { i18n } from '@kbn/i18n';
import { PageTemplate } from './page_template';
import { PageLoading, License } from '../../components';
import { GlobalStateContext } from '../global_state_context';
import { useClusters } from '../hooks/use_clusters';
import { CODE_PATH_ALL } from '../../../common/constants';
import { formatDateTimeLocal } from '../../../common/formatting';
import { Legacy } from '../../legacy_shims';

const CODE_PATHS = [CODE_PATH_ALL];

export const LicensePage: React.FC<{}> = () => {
const title = i18n.translate('xpack.monitoring.license.licenseRouteTitle', {
defaultMessage: 'License',
});

const state = useContext(GlobalStateContext);
const { clusters, loaded } = useClusters(state.cluster_uuid, state.ccs, CODE_PATHS);

// TODO how do we get timezone from here?
// const timezone = injector.get('config').get('dateFormat:tz');
const timezone = null;

if (loaded) {
const cluster = clusters[0];
const isPrimaryCluster = cluster.isPrimary;
const license = cluster.license;
let expiryDate = license?.expiry_date_in_millis;

if (expiryDate !== undefined) {
// TODO pretty sure type definition is wrong, timezone should probably be string or null
expiryDate = formatDateTimeLocal(expiryDate, false, timezone);
}

const isExpired = Date.now() > expiryDate;

const basePath = Legacy.shims.getBasePath();
// TODO /license_management/common/constants has no BASE_PATH, just hard code for now
// this.uploadLicensePath = basePath + '/app/kibana#' + MANAGEMENT_BASE_PATH + 'upload_license';
const uploadLicensePath = basePath + '/app/management/stack/license_management/upload_license';

// TODO check expired case

// TODO breadcrumbs should include the current cluster. Probably something that needs to happen in PageTemplate
return (
<PageTemplate title={title} pageTitle="">
<License
isPrimaryCluster={isPrimaryCluster}
status={license.status}
type={license.type}
isExpired={isExpired}
expiryDate={expiryDate}
uploadLicensePath={uploadLicensePath}
/>
</PageTemplate>
);
} else {
return (
<PageTemplate title={title} pageTitle={title}>
<PageLoading />
</PageTemplate>
);
}
};
1 change: 1 addition & 0 deletions x-pack/plugins/monitoring/public/components/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*/

export const PageLoading: FunctionComponent<Props>;
export const License: FunctionComponent<Props>;

0 comments on commit f4c61b2

Please sign in to comment.