forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opensearch-project#8 from ajygupta/point-in-time
Point in time
- Loading branch information
Showing
13 changed files
with
1,865 additions
and
1,372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 29 additions & 17 deletions
46
src/plugins/point_in_time_management/public/components/breadcrumbs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`, | ||
}, | ||
]; | ||
} |
124 changes: 124 additions & 0 deletions
124
src/plugins/point_in_time_management/public/components/pit_edit/edit_page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.