Skip to content

Commit

Permalink
Merge pull request opensearch-project#8 from ajygupta/point-in-time
Browse files Browse the repository at this point in the history
Point in time
  • Loading branch information
bharath-techie authored May 19, 2023
2 parents 71a90dd + 4b20cad commit a651368
Show file tree
Hide file tree
Showing 13 changed files with 1,865 additions and 1,372 deletions.
2 changes: 1 addition & 1 deletion packages/osd-opensearch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"osd:watch": "../../scripts/use_node scripts/build --watch"
},
"dependencies": {
"@opensearch-project/opensearch": "^2.1.0",
"@opensearch-project/opensearch": "^2.2.0",
"@osd/dev-utils": "1.0.0",
"abort-controller": "^3.0.0",
"chalk": "^4.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';

export function getListBreadcrumbs() {
return [
{
text: i18n.translate('pitManagement.listBreadcrumb', {
defaultMessage: 'Point in time',
}),
href: `/`,
},
];
}
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';

export function getListBreadcrumbs() {
return [
{
text: i18n.translate('pitManagement.listBreadcrumb', {
defaultMessage: 'Point in time',
}),
href: `/`,
},
];
}

export function getEditBreadcrumbs() {
return [
...getListBreadcrumbs(),
{
text: i18n.translate('dataSourcesManagement.dataSources.createBreadcrumb', {
defaultMessage: 'Edit',
}),
href: `/edit`,
},
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useEffect, useState } from 'react';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import { useEffectOnce, useMount } from 'react-use';
import { i18n } from '@osd/i18n';
import {
EuiBottomBar,
EuiButton,
EuiButtonEmpty,
EuiCheckbox,
EuiDescribedFormGroup,
EuiFieldNumber,
EuiFieldText,
EuiFlexGroup,
EuiFlexItem,
EuiForm,
EuiFormRow,
EuiPageContent,
EuiPageHeader,
EuiPageHeaderSection,
EuiSpacer,
EuiTitle,
} from '@elastic/eui';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import { PointInTimeAttributes, PointInTimeManagementContext } from '../../types';
import { getEditBreadcrumbs } from '../breadcrumbs';
import { EditPitForm } from './edit_pit_form';
import {
findById,
findPointInTimeSavedObject,
updatePointInTimeById,
updatePointInTimeKeepAlive,
} from '../utils';
import { ToastMessageItem } from '../../../../data_source_management/public/types';
import { getServices, Services } from '../../services';

const defaultPitSavedObject: PointInTimeAttributes = {
pit_id: '',
creation_time: 0,
id: '',
keepAlive: 0,
name: '',
addtime: 0,
delete_on_expiry: false,
};

export const PITEdit: React.FunctionComponent<RouteComponentProps<{ id: string }>> = (
props: RouteComponentProps<{ id: string }>
) => {
const {
setBreadcrumbs,
savedObjects,
notifications: { toasts },
http,
} = useOpenSearchDashboards<PointInTimeManagementContext>().services;
const PitID: string = props.match.params.id;
const [pitSavedObject, setPitSavedObject] = useState<PointInTimeAttributes>(
defaultPitSavedObject
);
const [isLoading, setIsLoading] = useState(false);
const [newProp, setNewProp] = useState(false);
const services: Services = getServices(http);
useEffectOnce(() => {
console.log(PitID);
setBreadcrumbs(getEditBreadcrumbs());
setIsLoading(true);
(async function () {
await fetchPitSavedObject();
})();
});

const fetchPitSavedObject = async () => {
const tempPitSavedObject = await findById(savedObjects.client, PitID);
setNewProp(true);
const pointInTimeAttributes: PointInTimeAttributes = {
creation_time: tempPitSavedObject.attributes.creation_time,
name: tempPitSavedObject.attributes.name,
keepAlive: tempPitSavedObject.attributes.keepAlive,
pit_id: tempPitSavedObject.attributes.pit_id,
id: tempPitSavedObject.id,
addtime: 0,
delete_on_expiry: tempPitSavedObject.attributes.delete_on_expiry,
};
console.log('This is teh attributes');
console.log(pointInTimeAttributes);
setPitSavedObject(pointInTimeAttributes);
setIsLoading(false);
};

const handleSubmit = async (attributes: PointInTimeAttributes) => {
console.log('These are the attributes', attributes);
const new_keep_alive_proposal = attributes.addtime.toString() + 'm';
console.log(attributes.pit_id, new_keep_alive_proposal);
await services.addPitTime(attributes.pit_id, new_keep_alive_proposal);
await updatePointInTimeById(savedObjects.client, attributes.id, attributes);
};

const handleDisplayToastMessage = ({ id, defaultMessage, success }: ToastMessageItem) => {
if (success) {
toasts.addSuccess(i18n.translate(id, { defaultMessage }));
} else {
toasts.addWarning(i18n.translate(id, { defaultMessage }));
}
};

return (
<>
{!isLoading ? (
<EditPitForm
existingPointInTime={pitSavedObject}
newProp={newProp}
handleSubmit={handleSubmit}
displayToastMessage={handleDisplayToastMessage}
/>
) : null}
</>
);
};

export const PITEditWithRouter = withRouter(PITEdit);
Loading

0 comments on commit a651368

Please sign in to comment.