Skip to content

Commit

Permalink
feat: integrate with workspace create API (opensearch-project#13)
Browse files Browse the repository at this point in the history
* feat: integrate with workspace create API

Signed-off-by: Lin Wang <wonglam@amazon.com>

* feat: update to i18n text for toast

Signed-off-by: Lin Wang <wonglam@amazon.com>

---------

Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam authored and ruanyl committed Aug 3, 2023
1 parent a21d0c2 commit e9b5c3b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,48 @@

import React, { useCallback } from 'react';
import { EuiPage, EuiPageBody, EuiPageHeader, EuiPageContent } from '@elastic/eui';
import { i18n } from '@osd/i18n';

import { useOpenSearchDashboards } from '../../../../../plugins/opensearch_dashboards_react/public';

import { WorkspaceForm } from './workspace_form';
import { WorkspaceForm, WorkspaceFormData } from './workspace_form';

export const WorkspaceCreator = () => {
const {
services: { application },
services: { application, workspaces, notifications },
} = useOpenSearchDashboards();

const handleWorkspaceFormSubmit = useCallback(() => {}, []);
const handleWorkspaceFormSubmit = useCallback(
async (data: WorkspaceFormData) => {
let result;
try {
result = await workspaces?.client.create(data);
} catch (error) {
notifications?.toasts.addDanger({
title: i18n.translate('workspace.create.failed', {
defaultMessage: 'Failed to create workspace',
}),
text: error instanceof Error ? error.message : JSON.stringify(error),
});
return;
}
if (result?.success) {
notifications?.toasts.addSuccess({
title: i18n.translate('workspace.create.success', {
defaultMessage: 'Create workspace successfully',
}),
});
return;
}
notifications?.toasts.addDanger({
title: i18n.translate('workspace.create.failed', {
defaultMessage: 'Failed to create workspace',
}),
text: result?.error,
});
},
[notifications?.toasts, workspaces?.client]
);

return (
<EuiPage paddingSize="none">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface WorkspaceFeatureGroup {
features: WorkspaceFeature[];
}

interface WorkspaceFormData {
export interface WorkspaceFormData {
name: string;
description?: string;
features: string[];
Expand Down

0 comments on commit e9b5c3b

Please sign in to comment.