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.
Signed-off-by: Lin Wang <wonglam@amazon.com>
- Loading branch information
Showing
18 changed files
with
1,905 additions
and
4 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
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
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
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
53 changes: 53 additions & 0 deletions
53
src/plugins/workspace/public/components/utils/feature.test.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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
isFeatureDependBySelectedFeatures, | ||
getFinalFeatureIdsByDependency, | ||
generateFeatureDependencyMap, | ||
} from './feature'; | ||
|
||
describe('feature utils', () => { | ||
describe('isFeatureDependBySelectedFeatures', () => { | ||
it('should return true', () => { | ||
expect(isFeatureDependBySelectedFeatures('a', ['b'], { b: ['a'] })).toBe(true); | ||
expect(isFeatureDependBySelectedFeatures('a', ['b'], { b: ['a', 'c'] })).toBe(true); | ||
}); | ||
it('should return false', () => { | ||
expect(isFeatureDependBySelectedFeatures('a', ['b'], { b: ['c'] })).toBe(false); | ||
expect(isFeatureDependBySelectedFeatures('a', ['b'], {})).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('getFinalFeatureIdsByDependency', () => { | ||
it('should return consistent feature ids', () => { | ||
expect(getFinalFeatureIdsByDependency(['a'], { a: ['b'] }, ['c', 'd'])).toStrictEqual([ | ||
'c', | ||
'd', | ||
'a', | ||
'b', | ||
]); | ||
expect(getFinalFeatureIdsByDependency(['a'], { a: ['b', 'e'] }, ['c', 'd'])).toStrictEqual([ | ||
'c', | ||
'd', | ||
'a', | ||
'b', | ||
'e', | ||
]); | ||
}); | ||
}); | ||
|
||
it('should generate consistent features dependency map', () => { | ||
expect( | ||
generateFeatureDependencyMap([ | ||
{ id: 'a', dependencies: { b: { type: 'required' }, c: { type: 'optional' } } }, | ||
{ id: 'b', dependencies: { c: { type: 'required' } } }, | ||
]) | ||
).toEqual({ | ||
a: ['b'], | ||
b: ['c'], | ||
}); | ||
}); | ||
}); |
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,60 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { App } from '../../../../../core/public'; | ||
|
||
export const isFeatureDependBySelectedFeatures = ( | ||
featureId: string, | ||
selectedFeatureIds: string[], | ||
featureDependencies: { [key: string]: string[] } | ||
) => | ||
selectedFeatureIds.some((selectedFeatureId) => | ||
(featureDependencies[selectedFeatureId] || []).some((dependencies) => | ||
dependencies.includes(featureId) | ||
) | ||
); | ||
|
||
/** | ||
* | ||
* Generate new feature id list based the old feature id list | ||
* and feature dependencies map. The feature dependency map may | ||
* has duplicate ids with old feature id list. Use set here to | ||
* get the unique feature ids. | ||
* | ||
* @param featureIds a feature id list need to add based old feature id list | ||
* @param featureDependencies a feature dependencies map to get depended feature ids | ||
* @param oldFeatureIds a feature id list that represent current feature id selection states | ||
*/ | ||
export const getFinalFeatureIdsByDependency = ( | ||
featureIds: string[], | ||
featureDependencies: { [key: string]: string[] }, | ||
oldFeatureIds: string[] = [] | ||
) => | ||
Array.from( | ||
new Set([ | ||
...oldFeatureIds, | ||
...featureIds.reduce( | ||
(pValue, featureId) => [...pValue, ...(featureDependencies[featureId] || [])], | ||
featureIds | ||
), | ||
]) | ||
); | ||
|
||
export const generateFeatureDependencyMap = ( | ||
allFeatures: Array<Pick<App, 'id' | 'dependencies'>> | ||
) => | ||
allFeatures.reduce<{ [key: string]: string[] }>( | ||
(pValue, { id, dependencies }) => | ||
dependencies | ||
? { | ||
...pValue, | ||
[id]: [ | ||
...(pValue[id] || []), | ||
...Object.keys(dependencies).filter((key) => dependencies[key].type === 'required'), | ||
], | ||
} | ||
: pValue, | ||
{} | ||
); |
7 changes: 7 additions & 0 deletions
7
src/plugins/workspace/public/components/workspace_creator/index.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,7 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export { WorkspaceCreator } from './workspace_creator'; | ||
export { WorkspacePermissionSetting } from './workspace_permission_setting_panel'; |
106 changes: 106 additions & 0 deletions
106
src/plugins/workspace/public/components/workspace_creator/workspace_bottom_bar.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,106 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
EuiBottomBar, | ||
EuiButton, | ||
EuiButtonEmpty, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiSpacer, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@osd/i18n'; | ||
import React, { useState } from 'react'; | ||
import { ApplicationStart } from 'opensearch-dashboards/public'; | ||
import { WORKSPACE_OP_TYPE_CREATE, WORKSPACE_OP_TYPE_UPDATE } from '../../../common/constants'; | ||
import { WorkspaceCancelModal } from './workspace_cancel_modal'; | ||
|
||
interface WorkspaceBottomBarProps { | ||
formId: string; | ||
opType?: string; | ||
numberOfErrors: number; | ||
application: ApplicationStart; | ||
numberOfUnSavedChanges: number; | ||
} | ||
|
||
export const WorkspaceBottomBar = ({ | ||
formId, | ||
opType, | ||
numberOfErrors, | ||
numberOfUnSavedChanges, | ||
application, | ||
}: WorkspaceBottomBarProps) => { | ||
const [isCancelModalVisible, setIsCancelModalVisible] = useState(false); | ||
const closeCancelModal = () => setIsCancelModalVisible(false); | ||
const showCancelModal = () => setIsCancelModalVisible(true); | ||
|
||
return ( | ||
<div> | ||
<EuiSpacer size="xl" /> | ||
<EuiSpacer size="xl" /> | ||
<EuiBottomBar> | ||
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<EuiFlexGroup gutterSize="s"> | ||
{opType === WORKSPACE_OP_TYPE_UPDATE ? ( | ||
<EuiText textAlign="left"> | ||
{i18n.translate('workspace.form.bottomBar.unsavedChanges', { | ||
defaultMessage: `${numberOfUnSavedChanges} Unsaved change(s)`, | ||
})} | ||
</EuiText> | ||
) : ( | ||
<EuiText textAlign="left"> | ||
{i18n.translate('workspace.form.bottomBar.errors', { | ||
defaultMessage: `${numberOfErrors} Error(s)`, | ||
})} | ||
</EuiText> | ||
)} | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiFlexGroup gutterSize="m"> | ||
<EuiButtonEmpty | ||
color="ghost" | ||
onClick={showCancelModal} | ||
data-test-subj="workspaceForm-bottomBar-cancelButton" | ||
> | ||
{i18n.translate('workspace.form.bottomBar.cancel', { | ||
defaultMessage: 'Cancel', | ||
})} | ||
</EuiButtonEmpty> | ||
<EuiSpacer /> | ||
{opType === WORKSPACE_OP_TYPE_CREATE && ( | ||
<EuiButton | ||
fill | ||
type="submit" | ||
color="primary" | ||
form={formId} | ||
data-test-subj="workspaceForm-bottomBar-createButton" | ||
> | ||
{i18n.translate('workspace.form.bottomBar.createWorkspace', { | ||
defaultMessage: 'Create workspace', | ||
})} | ||
</EuiButton> | ||
)} | ||
{opType === WORKSPACE_OP_TYPE_UPDATE && ( | ||
<EuiButton form={formId} type="submit" fill color="primary"> | ||
{i18n.translate('workspace.form.bottomBar.saveChanges', { | ||
defaultMessage: 'Save changes', | ||
})} | ||
</EuiButton> | ||
)} | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiBottomBar> | ||
<WorkspaceCancelModal | ||
application={application} | ||
visible={isCancelModalVisible} | ||
closeCancelModal={closeCancelModal} | ||
/> | ||
</div> | ||
); | ||
}; |
49 changes: 49 additions & 0 deletions
49
src/plugins/workspace/public/components/workspace_creator/workspace_cancel_modal.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,49 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { i18n } from '@osd/i18n'; | ||
import { EuiConfirmModal } from '@elastic/eui'; | ||
import { ApplicationStart } from 'opensearch-dashboards/public'; | ||
import { WORKSPACE_LIST_APP_ID } from '../../../common/constants'; | ||
|
||
interface WorkspaceCancelModalProps { | ||
visible: boolean; | ||
application: ApplicationStart; | ||
closeCancelModal: () => void; | ||
} | ||
|
||
export const WorkspaceCancelModal = ({ | ||
application, | ||
visible, | ||
closeCancelModal, | ||
}: WorkspaceCancelModalProps) => { | ||
if (!visible) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<EuiConfirmModal | ||
data-test-subj="workspaceForm-cancelModal" | ||
title={i18n.translate('workspace.form.cancelModal.title', { | ||
defaultMessage: 'Discard changes?', | ||
})} | ||
onCancel={closeCancelModal} | ||
onConfirm={() => application?.navigateToApp(WORKSPACE_LIST_APP_ID)} | ||
cancelButtonText={i18n.translate('workspace.form.cancelButtonText.', { | ||
defaultMessage: 'Continue editing', | ||
})} | ||
confirmButtonText={i18n.translate('workspace.form.confirmButtonText.', { | ||
defaultMessage: 'Discard changes', | ||
})} | ||
buttonColor="danger" | ||
defaultFocusedButton="confirm" | ||
> | ||
{i18n.translate('workspace.form.cancelModal.body', { | ||
defaultMessage: 'This will discard all changes. Are you sure?', | ||
})} | ||
</EuiConfirmModal> | ||
); | ||
}; |
Oops, something went wrong.