Skip to content

Commit

Permalink
Fix CM navigation (#16)
Browse files Browse the repository at this point in the history
Fix CM navigation
  • Loading branch information
noCharger authored Jul 19, 2022
1 parent c49b18b commit db8c74e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class CreateCredentialWizard extends React.Component<
};
}

// TODO: Fix header component error
renderHeader() {
const { docLinks } = this.state;

Expand Down Expand Up @@ -155,7 +156,7 @@ export class CreateCredentialWizard extends React.Component<
<EuiFilePicker />
</EuiFormRow> */}
</EuiDescribedFormGroup>
<EuiButton type="submit" fill onClick={this.createCredential}>
<EuiButton fill onClick={this.createCredential}>
Save
</EuiButton>
</EuiForm>
Expand Down Expand Up @@ -190,23 +191,20 @@ export class CreateCredentialWizard extends React.Component<
const { http } = this.context.services;
try {
// TODO: Refactor it by registering client wrapper factory
await http
.post('/api/credential_management/create', {
body: JSON.stringify({
credential_name: this.state.credentialName,
credential_type: this.state.credentialType,
username_password_credential_materials: {
user_name: this.state.userName,
password: this.state.password,
},
}),
})
.then((res) => {
// TODO: Fix routing
this.props.history.push('');
console.log(res);
});
// TODO: Add rendering spanner
await http.post('/api/credential_management/create', {
body: JSON.stringify({
credential_name: this.state.credentialName,
credential_type: this.state.credentialType,
username_password_credential_materials: {
user_name: this.state.userName,
password: this.state.password,
},
}),
});
this.props.history.push('');
} catch (e) {
// TODO: Add Toast
console.log(e);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,15 @@ export const CredentialsTable = ({ canSave, history }: Props) => {
);
};

const onClickDelete = () => {
Promise.resolve(deleteCredentials(savedObjects.client, selectedCredentials)).then(function () {
setSelectedCredentials([]);
// TODO: Fix routing
history.push('');
});
const onClickDelete = async () => {
await deleteCredentials(savedObjects.client, selectedCredentials);
// TODO: Add status bar + fetch from source + refresh list
const fetchedCredentials: CredentialsTableItem[] = await getCredentials(
savedObjects.client,
uiSettings.get('defaultIndex')
);
setCredentials(fetchedCredentials);
setSelectedCredentials([]);
};

const deleteButton = renderDeleteButton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import { DocLinksStart } from 'src/core/public';
import { getCreateBreadcrumbs } from '../breadcrumbs';
import { CredentialManagmentContextValue } from '../../types';
// TODO: Add Header
// import { Header } from './components/header';
import { context as contextType } from '../../../../opensearch_dashboards_react/public';
import { Credential } from '../../../common';
Expand Down Expand Up @@ -146,7 +147,7 @@ export class EditCredentialComponent extends React.Component<
<EuiFilePicker />
</EuiFormRow> */}
</EuiDescribedFormGroup>
<EuiButton type="submit" fill onClick={this.updateCredential}>
<EuiButton fill onClick={this.updateCredential}>
Update
</EuiButton>
</EuiForm>
Expand Down Expand Up @@ -180,25 +181,21 @@ export class EditCredentialComponent extends React.Component<
updateCredential = async () => {
const { http } = this.context.services;
try {
console.warn(this.props.credential.id);
// TODO: Refactor it by registering client wrapper factory
await http
.put(`/api/credential_management/${this.props.credential.id}`, {
body: JSON.stringify({
credential_name: this.state.credentialName,
credential_type: this.state.credentialType,
username_password_credential_materials: {
user_name: this.state.userName,
password: this.state.password,
},
}),
})
.then((res) => {
// TODO: Fix routing
this.props.history.push('');
console.log(res);
});
// TODO: Add rendering spanner
await http.put(`/api/credential_management/${this.props.credential.id}`, {
body: JSON.stringify({
credential_name: this.state.credentialName,
credential_type: this.state.credentialType,
username_password_credential_materials: {
user_name: this.state.userName,
password: this.state.password,
},
}),
});
this.props.history.push('');
} catch (e) {
// TODO: Add Toast
console.log(e);
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/credential_management/public/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function deleteCredentials(
selectedCredentials: CredentialsTableItem[]
) {
// TODO: Refactor it
selectedCredentials.forEach(function (selectedCredential) {
savedObjectsClient.delete('credential', selectedCredential.id);
});
for (const credential of selectedCredentials) {
await savedObjectsClient.delete('credential', credential.id);
}
}

0 comments on commit db8c74e

Please sign in to comment.