Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[workspace]Fix/UI of assets table #8519

Merged
merged 11 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8519.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Adds badge when there are more than one workspaces and updates the icon ([#8519](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8519))
1 change: 1 addition & 0 deletions src/core/server/ui_settings/saved_objects/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const uiSettingsType: SavedObjectsType = {
},
},
management: {
icon: 'gear',
importableAndExportable: true,
getInAppUrl() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const dataSource: SavedObjectsType = {
namespaceType: 'agnostic',
hidden: false,
management: {
icon: 'apps', // todo: pending ux #2034
icon: 'database',
defaultSearchField: 'title',
importableAndExportable: true,
getTitle(obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export class Table extends PureComponent<TableProps, TableState> {
items,
totalItemCount,
isSearching,
columnRegistry,
filters,
selectionConfig: selection,
onDelete,
Expand All @@ -186,8 +187,6 @@ export class Table extends PureComponent<TableProps, TableState> {
onShowRelationships,
basePath,
actionRegistry,
columnRegistry,
namespaceRegistry,
dateFormat,
availableWorkspaces,
currentWorkspaceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,6 @@ describe('SavedObjectsTable', () => {
{ force: true }
);
expect(component.state('selectedSavedObjects').length).toBe(0);
expect(notifications.toasts.addDanger).not.toHaveBeenCalled();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to remove this assertion?

Copy link
Contributor Author

@Qxisylolo Qxisylolo Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting the error, I think it is an accidental delete. already reverted.

expect(component.state('isDeleting')).toBe(false);
expect(component.state('isShowingDeleteConfirmModal')).toBe(false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ import { DataPublicPluginStart } from '../../../../../plugins/data/public';
import { DuplicateObject } from '../types';
import { formatWorkspaceIdParams } from '../../utils';
import { NavigationPublicPluginStart } from '../../../../navigation/public';
import { WorkspaceObject } from '../../../../workspaces/public';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this import been removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting the error already reverted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems it should import from core now:

import { WorkspaceObject } from '../../../../../core/public';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is correct, sorry I haven't made a double check. already updated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, I guess the export location was changed in another PR, thanks for fixing this.


interface ExportAllOption {
id: string;
Expand Down Expand Up @@ -1174,7 +1173,6 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
searchThreshold: 1,
});
}

return (
<EuiPageContent horizontalPosition="center" paddingSize={useUpdatedUX ? 'm' : undefined}>
{this.renderFlyout()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import React from 'react';
import { coreMock } from '../../../../../core/public/mocks';
import { render } from '@testing-library/react';
import { render, fireEvent } from '@testing-library/react';
import { WorkspaceColumn } from './workspace_column';

describe('workspace column in saved objects page', () => {
Expand All @@ -21,27 +21,77 @@ describe('workspace column in saved objects page', () => {
];
coreSetup.workspaces.workspaceList$.next(workspaceList);

it('should show workspace name correctly', () => {
it('should show workspace name badge correctly', async () => {
const workspaces = ['ws-1', 'ws-2'];
const { container } = render(<WorkspaceColumn coreSetup={coreSetup} workspaces={workspaces} />);
const { findByTestId, findByText, container } = render(
<WorkspaceColumn coreSetup={coreSetup} workspaces={workspaces} />
);
const badge = await findByTestId('workspace-column-more-workspaces-badge');
expect(badge).toBeInTheDocument();
fireEvent.click(badge);
expect(await findByTestId('workspace-column-popover')).toBeInTheDocument();
expect(await findByText('foo')).toBeInTheDocument();
expect(await findByText('bar')).toBeInTheDocument();
expect(container).toMatchInlineSnapshot(`
<div>
<div
class="euiText euiText--medium"
class="euiText euiText--small"
>
foo | bar
foo
</div>

<span
class="euiBadge euiBadge--hollow euiBadge--iconRight"
>
<span
class="euiBadge__content"
>
<button
aria-label="Open workspaces popover"
class="euiBadge__childButton"
data-test-subj="workspace-column-more-workspaces-badge"
title="+ 1 more"
>
+
1
more
</button>
<button
aria-label="Open workspaces popover"
class="euiBadge__iconButton"
title="Open workspaces popover"
type="button"
>
<span
class="euiBadge__icon"
color="inherit"
data-euiicon-type="popout"
/>
</button>
</span>
</span>
<div
class="euiPopover euiPopover--anchorRightCenter euiPopover-isOpen"
data-test-subj="workspace-column-popover"
>
<div
class="euiPopover__anchor"
/>
</div>
</div>
`);
});

it('show empty when no workspace', () => {
it('show when no workspace', () => {
const { container } = render(<WorkspaceColumn coreSetup={coreSetup} />);

expect(container).toMatchInlineSnapshot(`
<div>
<div
class="euiText euiText--medium"
/>
class="euiText euiText--small"
>
</div>
</div>
`);
});
Expand All @@ -51,7 +101,7 @@ describe('workspace column in saved objects page', () => {
expect(container).toMatchInlineSnapshot(`
<div>
<div
class="euiText euiText--medium"
class="euiText euiText--small"
/>
</div>
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { EuiText } from '@elastic/eui';
import React, { useState } from 'react';
import { EuiText, EuiBadge, EuiPopover } from '@elastic/eui';
import useObservable from 'react-use/lib/useObservable';
import { i18n } from '@osd/i18n';
import { WorkspaceAttribute, CoreSetup } from '../../../../../core/public';
Expand All @@ -17,16 +17,65 @@

export function WorkspaceColumn({ coreSetup, workspaces }: WorkspaceColumnProps) {
const workspaceList = useObservable(coreSetup.workspaces.workspaceList$);

const [showBadgePopover, setShowBadgePopover] = useState(false);
const wsLookUp = workspaceList?.reduce((map, ws) => {
return map.set(ws.id, ws.name);
}, new Map<string, string>());

const workspaceNames = workspaces?.map((wsId) => wsLookUp?.get(wsId)).join(' | ');
const workspaceNames = workspaces?.map((wsId) => wsLookUp?.get(wsId)).filter((ws) => ws);

return <EuiText>{workspaceNames}</EuiText>;
}
const toggleBadgePopover = () => {
setShowBadgePopover(!showBadgePopover);
};

const closeBadgePopover = () => {
setShowBadgePopover(false);

Check warning on line 32 in src/plugins/workspace/public/components/workspace_column/workspace_column.tsx

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/public/components/workspace_column/workspace_column.tsx#L32

Added line #L32 was not covered by tests
};

if (workspaceNames) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (workspaceNames) {
if (workspaceNames?.length) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for comment, updated

const displayedWorkspaces = workspaceNames.slice(0, 1);
const remainingWorkspacesCount = workspaceNames.length - 1;
return (
<>
<EuiText size="s">{displayedWorkspaces}</EuiText>
{remainingWorkspacesCount > 0 && (
<>
&nbsp;&nbsp;
<EuiBadge
color="hollow"
iconType="popout"
iconSide="right"
onClick={toggleBadgePopover}
iconOnClick={toggleBadgePopover}
iconOnClickAriaLabel="Open workspaces popover"
onClickAriaLabel="Open workspaces popover"
data-test-subj="workspace-column-more-workspaces-badge"
>
+ {remainingWorkspacesCount} more
</EuiBadge>
{showBadgePopover && (
<EuiPopover
isOpen={showBadgePopover}
closePopover={closeBadgePopover}
anchorPosition="rightCenter"
panelPaddingSize="s"
data-test-subj="workspace-column-popover"
>
{workspaceNames.slice(1).map((ws) => (
<EuiText key={ws} size="xs">
{ws}
</EuiText>
))}
</EuiPopover>
)}
</>
)}
</>
);
} else {
return <EuiText size="s">&mdash;</EuiText>;
}
}
export function getWorkspaceColumn(
coreSetup: CoreSetup
): SavedObjectsManagementColumn<WorkspaceAttribute | undefined> {
Expand Down
Loading