Skip to content

Commit

Permalink
Edit for local PITs
Browse files Browse the repository at this point in the history
Signed-off-by: Arpit Bandejiya <abandeji@amazon.com>
  • Loading branch information
Arpit-Bandejiya committed May 19, 2023
1 parent 4336d03 commit 085a2ad
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { PointInTimeAttributes, PointInTimeManagementContext } from '../../types
import { getEditBreadcrumbs } from '../breadcrumbs';
import { EditPitForm } from './edit_pit_form';
import {
createPit,
findById,
findPointInTimeSavedObject,
updatePointInTimeById,
Expand All @@ -46,6 +47,7 @@ const defaultPitSavedObject: PointInTimeAttributes = {
name: '',
addtime: 0,
delete_on_expiry: false,
isSavedObject: true,
};

export const PITEdit = (
Expand All @@ -60,6 +62,7 @@ export const PITEdit = (
const PitID: string = props.match.params.id;
const pit = props.location && props.location.state;
console.log(pit);
console.log(props.location.state);
debugger;
const [pitSavedObject, setPitSavedObject] = useState<PointInTimeAttributes>(
defaultPitSavedObject
Expand All @@ -77,29 +80,60 @@ export const PITEdit = (
});

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);
if(pit.isSavedObject) {
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,
isSavedObject: true,
};
console.log('This is teh attributes');
console.log(pointInTimeAttributes);
setPitSavedObject(pointInTimeAttributes);
setIsLoading(false);
} else {
const pointInTimeAttributes: PointInTimeAttributes = {
creation_time: pit.creation_time,
name: '',
keepAlive: pit.keep_alive,
pit_id: pit.pit_id,
addtime: 0,
delete_on_expiry: false,
isSavedObject: false,
};
console.log("For a local PIT these are the variables");
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);
if(attributes.isSavedObject){
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);
props.history.push('/');
} else {
console.log(attributes);
console.log("This is not saved object");
// TODO:: Need to call the create PIT ID here.
await createPit(
['opensearch_dashboards_sample_data_ecommerce'],
'opensearch_dashboards_sample_data_ecommerce', indexPatterns, dataSource, data,
http, keepAlive, makedashboardschecked, pitName, savedObjects, deletepitchecked)
props.history.push('/');
}

};

const handleDisplayToastMessage = ({ id, defaultMessage, success }: ToastMessageItem) => {
Expand All @@ -112,7 +146,7 @@ export const PITEdit = (

return (
<>
{!isLoading ? (
{pitSavedObject.creation_time !== 0 ? (
<EditPitForm
existingPointInTime={pitSavedObject}
newProp={newProp}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface EditPitState {
AddTimeHr: any;
AddTimeMin: any;
addTime: any;
isSavedObject: any;
}

export class EditPitForm extends React.Component<EditPitProps, EditPitState> {
Expand All @@ -61,13 +62,14 @@ export class EditPitForm extends React.Component<EditPitProps, EditPitState> {
AddTimeHr: 0,
AddTimeMin: 0,
addTime: 0,
isSavedObject: true,
};
}

componentDidMount() {
this.setFormValuesForEditMode();
console.log('These are the props in mount');
console.log(this.props);
console.log('here',this.props);
}

resetFormValues = () => {
Expand All @@ -77,13 +79,14 @@ export class EditPitForm extends React.Component<EditPitProps, EditPitState> {

setFormValuesForEditMode() {
if (this.props.existingPointInTime) {
const { keepAlive, name, pit_id, id, addtime } = this.props.existingPointInTime;
const { keepAlive, name, pit_id, id, addtime, isSavedObject } = this.props.existingPointInTime;
this.setState({
keepAlive,
name,
pit_id,
id,
addtime,
isSavedObject,
});
}
}
Expand All @@ -103,6 +106,7 @@ export class EditPitForm extends React.Component<EditPitProps, EditPitState> {

onClickUpdatePit = async () => {
if (this.isFormValid()) {
console.log(this.state, "State");
const formValues: PointInTimeAttributes = {
name: this.state.name,
keepAlive: this.state.keepAlive,
Expand All @@ -111,6 +115,7 @@ export class EditPitForm extends React.Component<EditPitProps, EditPitState> {
pit_id: this.state.pit_id,
addtime: this.state.addTime,
delete_on_expiry: this.state.checked,
isSavedObject: this.state.isSavedObject,
};
this.setState({ isLoading: true });

Expand Down Expand Up @@ -229,6 +234,78 @@ export class EditPitForm extends React.Component<EditPitProps, EditPitState> {
);
};

configurationForm = (isSavedObject: boolean) => {
return isSavedObject ? (
<EuiForm
component="form"
onChange={() => this.onChangeFormValues()}
data-test-subj="pit-edit-2"
>
<EuiDescribedFormGroup
title={<h3>PIT name</h3>}
description={<p>Choose a name for a PIT that is available in OpenSearch Dashboards.</p>}
>
<EuiFormRow
label="PIT name"
helpText="Specify a unique and descriptive name that is easy to recognize."
>
<EuiFieldText name="pit-name" onChange={this.onChangePitName} />
</EuiFormRow>
</EuiDescribedFormGroup>
<EuiDescribedFormGroup
title={<h3>Post-expiration actions</h3>}
description={
<p>
PIT data is lost once it expires you have the option to keep the PIT metadata after
after expiration. expiration. expiration. expiration. expiration. You can also choose
to keep the Dashboard Object expiration. This object will be converted to an Index
Pattern and Pattern and it will reference data.
</p>
}
>
<EuiFormRow>
<>
<EuiCheckbox
id="pit-id"
label="Delete this PIT at expiration"
checked={this.state.checked}
onChange={this.onChangeDeleteObject}
/>
<EuiCheckbox
id="pit-id"
label="Delete dependent saved objects at PIT expiration"
onChange={(e) => this.onChange(e)}
disabled={true}
/>
</>
</EuiFormRow>
</EuiDescribedFormGroup>
</EuiForm>
) : (
<EuiForm
component="form"
onChange={() => this.onChangeFormValues()}
data-test-subj="pit-edit-2"
>
<EuiDescribedFormGroup
title={<h3>Dashboard availability</h3>}
description={
<p>To use this PIT in OpenSearch Dashboards, make it available to Dashboards.</p>
}
>
<EuiFormRow>
<>
<EuiCheckbox
id="pit-id"
label="Make available in Dashboards"
onChange={(e) => this.onChange(e)}
/>
</>
</EuiFormRow>
</EuiDescribedFormGroup>
</EuiForm>
);
};
render() {
return (
<>
Expand Down Expand Up @@ -292,55 +369,9 @@ export class EditPitForm extends React.Component<EditPitProps, EditPitState> {
</EuiPageHeaderSection>
</EuiPageHeader>
<EuiSpacer />
<EuiForm
component="form"
onChange={() => this.onChangeFormValues()}
data-test-subj="pit-edit-2"
>
<EuiDescribedFormGroup
title={<h3>PIT name</h3>}
description={
<p>Choose a name for a PIT that is available in OpenSearch Dashboards.</p>
}
>
<EuiFormRow
label="PIT name"
helpText="Specify a unique and descriptive name that is easy to recognize."
>
<EuiFieldText name="pit-name" onChange={this.onChangePitName} />
</EuiFormRow>
</EuiDescribedFormGroup>
<EuiDescribedFormGroup
title={<h3>Post-expiration actions</h3>}
description={
<p>
PIT data is lost once it expires you have the option to keep the PIT metadata
after after expiration. expiration. expiration. expiration. expiration. You can
also choose to keep the Dashboard Object expiration. This object will be converted
to an Index Pattern and Pattern and it will reference data.
</p>
}
>
<EuiFormRow>
<>
<EuiCheckbox
id="pit-id"
label="Delete this PIT at expiration"
checked={this.state.checked}
onChange={this.onChangeDeleteObject}
/>
<EuiCheckbox
id="pit-id"
label="Delete dependent saved objects at PIT expiration"
onChange={(e) => this.onChange(e)}
disabled={true}
/>
</>
</EuiFormRow>
</EuiDescribedFormGroup>
</EuiForm>
{this.state.showUpdateOptions ? this.renderBottomBar() : null}
{this.state.isSavedObject ? this.configurationForm(this.state.isSavedObject) : this.configurationForm(this.state.isSavedObject)}
</EuiPageContent>
{this.state.showUpdateOptions ? this.renderBottomBar() : null}
</>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/point_in_time_management/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface PointInTimeAttributes extends SavedObjectAttributes {
id?: string;
addtime: number;
delete_on_expiry: boolean;
isSavedObject?: boolean;
}

export interface ToastMessageItem {
Expand Down

0 comments on commit 085a2ad

Please sign in to comment.