Skip to content

Commit

Permalink
Fix breadcrumb on listing page and update saved object mapping (#2069)
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chu <[email protected]>
  • Loading branch information
noCharger authored Aug 4, 2022
1 parent 58a3319 commit fec5e3d
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ export function getCreateBreadcrumbs() {
...getListBreadcrumbs(),
{
text: i18n.translate('credentialManagement.credentials.createBreadcrumb', {
defaultMessage: 'Create credentials',
defaultMessage: 'Create Stored Credential',
}),
href: `/create`,
},
];
}

export function getEditBreadcrumbs(credentials: CredentialEditPageItem) {
export function getEditBreadcrumbs(credential: CredentialEditPageItem) {
return [
...getListBreadcrumbs(),
{
text: credentials.title,
href: `/${credentials.id}`,
text: credential.title,
href: `/${credential.id}`,
},
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import { context as contextType } from '../../../../opensearch_dashboards_react/

interface CreateCredentialWizardState {
credentialName: string;
credentialType: string;
authType: string;
credentialMaterialsType: string;
userName: string;
password: string;
dual: boolean;
Expand All @@ -50,7 +51,8 @@ export class CreateCredentialWizard extends React.Component<

this.state = {
credentialName: '',
credentialType: 'username_password_credential',
authType: 'shared',
credentialMaterialsType: 'username_password_credential',
userName: '',
password: '',
dual: true,
Expand Down Expand Up @@ -119,7 +121,7 @@ export class CreateCredentialWizard extends React.Component<
>
<EuiFormRow label="Credential Type">
<EuiSelect
onChange={(e) => this.setState({ credentialType: e.target.value })}
onChange={(e) => this.setState({ credentialMaterialsType: e.target.value })}
options={options}
/>
</EuiFormRow>
Expand Down Expand Up @@ -176,9 +178,9 @@ export class CreateCredentialWizard extends React.Component<
// TODO: Add rendering spanner https://github.com/opensearch-project/OpenSearch-Dashboards/issues/2050
await savedObjects.client.create('credential', {
title: this.state.credentialName,
credentialType: this.state.credentialType,
authType: this.state.authType,
credentialMaterials: {
credentialMaterialsType: this.state.credentialType,
credentialMaterialsType: this.state.credentialMaterialsType,
credentialMaterialsContent: {
userName: this.state.userName,
password: this.state.password,
Expand All @@ -190,7 +192,7 @@ export class CreateCredentialWizard extends React.Component<
const createCredentialFailMsg = (
<FormattedMessage
id="credentialManagement.createCredential.loadCreateCredentialFailMsg"
defaultMessage="The credential saved object creation failed with some errors. Please try it again.'"
defaultMessage="The credential saved object creation failed with some errors. Please configure data_source.enabled and try it again."
/>
);
this.setState((prevState) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
useOpenSearchDashboards,
} from '../../../../opensearch_dashboards_react/public';

import { getListBreadcrumbs } from '../breadcrumbs';
import { CredentialManagementContext } from '../../types';
import { deleteCredentials, getCredentials } from '../utils';
import { CredentialsTableItem } from '../types';
Expand Down Expand Up @@ -66,6 +67,9 @@ export const CredentialsTable = ({ canSave, history }: Props) => {
const [credentials, setCredentials] = React.useState<CredentialsTableItem[]>([]);
const [selectedCredentials, setSelectedCredentials] = React.useState<CredentialsTableItem[]>([]);

const { setBreadcrumbs } = useOpenSearchDashboards<CredentialManagementContext>().services;
setBreadcrumbs(getListBreadcrumbs());

const { savedObjects, uiSettings } = useOpenSearchDashboards<
CredentialManagementContext
>().services;
Expand Down Expand Up @@ -101,7 +105,7 @@ export const CredentialsTable = ({ canSave, history }: Props) => {
sortable: ({ sort }: { sort: string }) => sort,
},
{
field: 'credentialType',
field: 'credentialMaterialsType',
name: 'Credential Type',
truncateText: true,
mobileOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { CredentialEditPageItem } from '../types';

interface EditCredentialState {
credentialName: string;
credentialType: string;
credentialMaterialsType: string;
userName: string;
password: string;
dual: boolean;
Expand All @@ -55,7 +55,7 @@ export class EditCredentialComponent extends React.Component<

this.state = {
credentialName: props.credential.title,
credentialType: props.credential.credentialType,
credentialMaterialsType: props.credential.credentialMaterialsType,
userName: '',
password: '',
dual: true,
Expand Down Expand Up @@ -114,7 +114,7 @@ export class EditCredentialComponent extends React.Component<
>
<EuiFormRow label="Credential Type">
<EuiSelect
onChange={(e) => this.setState({ credentialType: e.target.value })}
onChange={(e) => this.setState({ credentialMaterialsType: e.target.value })}
options={options}
/>
</EuiFormRow>
Expand Down Expand Up @@ -171,9 +171,8 @@ export class EditCredentialComponent extends React.Component<
// TODO: Add rendering spanner https://github.com/opensearch-project/OpenSearch-Dashboards/issues/2050
await savedObjects.client.update('credential', this.props.credential.id, {
title: this.state.credentialName,
credentialType: this.state.credentialType,
credentialMaterials: {
credentialMaterialsType: this.state.credentialType,
credentialMaterialsType: this.state.credentialMaterialsType,
credentialMaterialsContent: {
userName: this.state.userName,
password: this.state.password,
Expand All @@ -185,7 +184,7 @@ export class EditCredentialComponent extends React.Component<
const editCredentialFailMsg = (
<FormattedMessage
id="credentialManagement.editCredential.loadEditCredentialFailMsg"
defaultMessage="The credential saved object edit failed with some errors. Please try it again.'"
defaultMessage="The credential saved object edit failed with some errors. Please configure data_source.enabled and try it again."
/>
);
this.setState((prevState) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const EditCredentialPage: React.FC<RouteComponentProps<{ id: string }>> = ({ ...
const object = {
id: savedObject.id,
title: savedObject.attributes.title,
credentialType: savedObject.attributes.credentialType,
credentialMaterialsType: savedObject.attributes.credentialMaterials.credentialMaterialsType,
};
setCredential(object);
setBreadcrumbs(getEditBreadcrumbs(object));
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/credential_management/public/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
export interface CredentialsTableItem {
id: string;
title: string;
credentialMaterialsType: string;
sort: string;
}

export interface CredentialEditPageItem {
id: string;
title: string;
credentialType: string;
credentialMaterialsType: string;
}
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 @@ -10,19 +10,19 @@ export async function getCredentials(savedObjectsClient: SavedObjectsClientContr
return await (savedObjectsClient
.find({
type: 'credential',
fields: ['id', 'title', 'credentialType'],
fields: ['id', 'title', 'credentialMaterials'],
perPage: 10000,
})
.then((response) =>
response.savedObjects
.map((source) => {
const id = source.id;
const title = source.get('title');
const credentialType = source.get('credentialType');
const credentialMaterialsType = source.get('credentialMaterials').credentialMaterialsType;
return {
id,
title,
credentialType,
credentialMaterialsType,
sort: `${title}`,
};
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Switch, Route } from 'react-router-dom';
import { i18n } from '@osd/i18n';
import { I18nProvider } from '@osd/i18n/react';

import { StartServicesAccessor } from 'src/core/public';
Expand Down Expand Up @@ -38,6 +39,13 @@ export async function mountManagementSection(
setBreadcrumbs: params.setBreadcrumbs,
};

/* Browser - Page Title */
const title = i18n.translate('credentialManagement.objects.credentialsTitle', {
defaultMessage: 'Credentials',
});

chrome.docTitle.change(title);

ReactDOM.render(
<OpenSearchDashboardsContextProvider services={deps}>
<I18nProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const credential: SavedObjectsType = {
namespaceType: 'agnostic',
management: {
defaultSearchField: 'title',
importableAndExportable: true,
// TODO: Support import / export https://github.com/opensearch-project/OpenSearch-Dashboards/issues/1872
importableAndExportable: false,
getTitle(obj) {
return obj.attributes.title;
},
Expand All @@ -28,10 +29,8 @@ export const credential: SavedObjectsType = {
mappings: {
dynamic: false,
properties: {
title: { type: 'text', index: false },
credentialType: { type: 'keyword', index: false },
credentialMaterials: { type: 'object' },
description: { type: 'text', index: false },
title: { type: 'text' },
authType: { type: 'keyword' },
},
},
migrations: {},
Expand Down

0 comments on commit fec5e3d

Please sign in to comment.