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

fix: get start section cards not aligned #7624

Merged
Show file tree
Hide file tree
Changes from all 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/7624.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- [contentManagement] display cards by specifying a column size or display all cards in one row ([#7624](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7624))
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@

import React from 'react';
import ReactDOM from 'react-dom';
import { Container, ContainerInput, EmbeddableStart } from '../../../../embeddable/public';
import { Container, EmbeddableStart } from '../../../../embeddable/public';
import { CardList } from './card_list';
import { CardContainerInput } from './types';

export const CARD_CONTAINER = 'CARD_CONTAINER';

export type CardContainerInput = ContainerInput<{
description: string;
onClick?: () => void;
getIcon?: () => React.ReactElement;
getFooter?: () => React.ReactElement;
}>;

export class CardContainer extends Container<{}, CardContainerInput> {
public readonly type = CARD_CONTAINER;
private node?: HTMLElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export const CARD_EMBEDDABLE = 'card_embeddable';
export type CardEmbeddableInput = EmbeddableInput & {
description: string;
onClick?: () => void;
getIcon: () => React.ReactElement;
getFooter: () => React.ReactElement;
getIcon?: () => React.ReactElement;
getFooter?: () => React.ReactElement;
};

export class CardEmbeddable extends Embeddable<CardEmbeddableInput> {
Expand All @@ -37,8 +37,8 @@ export class CardEmbeddable extends Embeddable<CardEmbeddableInput> {
description={this.input.description}
display="plain"
onClick={this.input.onClick}
icon={this.input?.getIcon()}
footer={this.input?.getFooter()}
icon={this.input?.getIcon?.()}
footer={this.input?.getFooter?.()}
/>,
node
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import React from 'react';
import { EuiFlexGrid, EuiFlexItem } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';

import {
IContainer,
Expand All @@ -13,10 +13,11 @@ import {
ContainerOutput,
EmbeddableStart,
} from '../../../../embeddable/public';
import { CardContainerInput } from './types';

interface Props {
embeddable: IContainer;
input: ContainerInput;
input: CardContainerInput;
embeddableServices: EmbeddableStart;
}

Expand All @@ -29,10 +30,12 @@ const CardListInner = ({ embeddable, input, embeddableServices }: Props) => {
</EuiFlexItem>
);
});

// TODO: we should perhaps display the cards in multiple rows when the actual number of cards exceed the column size
return (
<EuiFlexGrid gutterSize="s" columns={4}>
{cards}
</EuiFlexGrid>
<EuiFlexGroup gutterSize="s">
{input.columns ? cards.slice(0, input.columns) : cards}
</EuiFlexGroup>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { ContainerInput } from '../../../../embeddable/public';

export interface CardExplicitInput {
title: string;
description: string;
onClick?: () => void;
getIcon?: () => React.ReactElement;
getFooter?: () => React.ReactElement;
}

export type CardContainerInput = ContainerInput<CardExplicitInput> & { columns?: number };
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { Content, Section } from '../services';
import { ViewMode } from '../../../embeddable/public';
import { DashboardContainerInput, SavedObjectDashboard } from '../../../dashboard/public';
import { CUSTOM_CONTENT_EMBEDDABLE } from './custom_content_embeddable';
import { CardContainerInput } from './card_container/card_container';
import { CARD_EMBEDDABLE } from './card_container/card_embeddable';
import { CardContainerInput } from './card_container/types';

const DASHBOARD_GRID_COLUMN_COUNT = 48;

Expand All @@ -30,6 +30,7 @@ export const createCardInput = (
title: section.title ?? '',
hidePanelTitles: true,
viewMode: ViewMode.VIEW,
columns: section.columns,
panels,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type Section =
id: string;
order: number;
title?: string;
columns?: number;
};

export type Content =
Expand Down
Loading