Skip to content
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
71 changes: 30 additions & 41 deletions packages/react-core/src/demos/Card/Card.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import swaggerIcon from './camel-swagger-java_200x150.png';
import azureIcon from './FuseConnector_Icons_AzureServices.png';
import restIcon from './FuseConnector_Icons_REST.png';
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
import { data } from './CardData.jsx';

## Demos

Expand Down Expand Up @@ -84,6 +85,7 @@ import sparkIcon from './camel-spark_200x150.png';
import swaggerIcon from './camel-swagger-java_200x150.png';
import azureIcon from './FuseConnector_Icons_AzureServices.png';
import restIcon from './FuseConnector_Icons_REST.png';
import { data } from './CardData.jsx';

class CardViewBasic extends React.Component {
constructor(props) {
Expand All @@ -93,7 +95,7 @@ class CardViewBasic extends React.Component {
filters: {
products: []
},
res: [],
cardData: data,
isChecked: false,
selectedItems: [],
areAllSelected: false,
Expand Down Expand Up @@ -134,7 +136,8 @@ class CardViewBasic extends React.Component {
});
};

this.onCardKebabDropdownToggle = (key) => {
this.onCardKebabDropdownToggle = (key, event) => {
event?.stopPropagation();
this.setState((prevState) => ({
[key]: !prevState[key]
}));
Expand All @@ -149,7 +152,7 @@ class CardViewBasic extends React.Component {
this.deleteItem = (item) => (event) => {
const filter = (getter) => (val) => getter(val) !== item.id;
this.setState({
res: this.state.res.filter(filter(({ id }) => id)),
cardData: this.state.cardData.filter(filter(({ id }) => id)),
selectedItems: this.state.selectedItems.filter(filter((id) => id))
});
};
Expand All @@ -162,7 +165,8 @@ class CardViewBasic extends React.Component {

this.onPerPageSelect = (_event, perPage) => {
this.setState({
perPage
perPage,
page: 1
});
};

Expand Down Expand Up @@ -264,7 +268,7 @@ class CardViewBasic extends React.Component {

splitCheckboxSelectAll(e) {
const { checked } = e.target;
const { isChecked, res } = this.state;
const { isChecked, cardData } = this.state;
let collection = [];

if (checked) {
Expand Down Expand Up @@ -329,41 +333,29 @@ class CardViewBasic extends React.Component {
}

getAllItems() {
const { res } = this.state;
const { cardData } = this.state;
const collection = [];
for (const items of res) {
for (const items of cardData) {
collection.push(items.id);
}

return collection;
}

updateSelected() {
const { res, selectedItems } = this.state;
let rows = res.map((post) => {
const { cardData, selectedItems } = this.state;
let rows = cardData.map((post) => {
post.selected = selectedItems.includes(post.id);
return post;
});

this.setState({
res: rows
cardData: rows
});
}

fetch(page, perPage) {
fetch(`https://my-json-server.typicode.com/jenny-s51/cardviewdata/posts?_page=${page}&_limit=${perPage}`)
.then((resp) => resp.json())
.then((resp) => this.setState({ res: resp, perPage, page }))
.then(() => this.updateSelected())
.catch((err) => this.setState({ error: err }));
}

componentDidMount() {
this.fetch(this.state.page, this.state.perPage);
}

renderPagination() {
const { page, perPage, totalItemCount } = this.state;
const { page, perPage, totalItemCount, cardData } = this.state;

const defaultPerPageOptions = [
{
Expand All @@ -386,20 +378,16 @@ class CardViewBasic extends React.Component {
page={page}
perPage={perPage}
perPageOptions={defaultPerPageOptions}
onSetPage={(_evt, value) => {
this.fetch(value, perPage);
}}
onPerPageSelect={(_evt, value) => {
this.fetch(1, value);
}}
onSetPage={this.onSetPage}
onPerPageSelect={this.onPerPageSelect}
variant="top"
isCompact
/>
);
}

buildSelectDropdown() {
const { splitButtonDropdownIsOpen, selectedItems, areAllSelected } = this.state;
const { splitButtonDropdownIsOpen, selectedItems, areAllSelected, filters, cardData } = this.state;
const numSelected = selectedItems.length;
const allSelected = areAllSelected;
const anySelected = numSelected > 0;
Expand Down Expand Up @@ -508,7 +496,7 @@ class CardViewBasic extends React.Component {
splitButtonDropdownIsOpen,
activeItem,
filters,
res,
cardData,
checked,
selectedItems,
areAllSelected,
Expand Down Expand Up @@ -576,13 +564,6 @@ class CardViewBasic extends React.Component {
</React.Fragment>
);

const filtered =
filters.products.length > 0
? res.filter((card) => {
return filters.products.length === 0 || filters.products.includes(card.name);
})
: res;

const icons = {
pfIcon,
activeMQIcon,
Expand All @@ -595,6 +576,13 @@ class CardViewBasic extends React.Component {
restIcon,
swaggerIcon
};

const filtered =
filters.products.length > 0
? data.filter((card) => {
return filters.products.length === 0 || filters.products.includes(card.name);
})
: cardData.slice((page - 1) * perPage, perPage === 1 ? page * perPage : page * perPage - 1);

return (
<React.Fragment>
Expand Down Expand Up @@ -630,6 +618,7 @@ class CardViewBasic extends React.Component {
<Card
hasSelectableInput
isCompact
isSelectableRaised
key={product.name}
id={product.name.replace(/ /g, '-')}
onKeyDown={(e) => this.onKeyDown(e, product.id)}
Expand All @@ -642,14 +631,14 @@ class CardViewBasic extends React.Component {
actions: (
<>
<Dropdown
isOpen={this.state[key]}
isOpen={this.state[key] ?? false}
onOpenChange={(isOpen) => this.setState({ [key]: isOpen })}
toggle={(toggleRef) => (
toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle
ref={toggleRef}
aria-label={`${product.name} actions`}
variant="plain"
onClick={() => this.onCardKebabDropdownToggle(key)}
onClick={(e) => this.onCardKebabDropdownToggle(key, e)}
isExpanded={this.state[key]}
>
<EllipsisVIcon />
Expand Down
62 changes: 62 additions & 0 deletions packages/react-core/src/demos/Card/CardData.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
export const data = [
{
"id": 0,
"name": "PatternFly",
"description": "PatternFly is a community project that promotes design commonality and improves user experience.",
"icon": "pfIcon"
},
{
"id": 1,
"name": "ActiveMQ",
"description": "The ActiveMQ component allows messages to be sent to a JMS Queue or Topic; or messages to be consumed from a JMS Queue or Topic using Apache ActiveMQ.",
"icon": "activeMQIcon"
},
{
"id": 2,
"name": "Apache Spark",
"description": "This documentation page covers the Apache Spark component for the Apache Camel.",
"icon": "sparkIcon"
},
{
"id": 3,
"name": "Avro",
"description": "This component provides a dataformat for avro, which allows serialization and deserialization of messages using Apache Avro’s binary dataformat. Moreover, it provides support for Apache Avro’s rpc, by providing producers and consumers endpoint for using avro over netty or http.",
"icon": "avroIcon"
},
{
"id": 4,
"name": "Azure Services",
"description": "The Camel Components for Windows Azure Services provide connectivity to Azure services from Camel.",
"icon": "azureIcon"
},
{
"id": 5,
"name": "Crypto",
"description": "For providing flexible endpoints to sign and verify exchanges using the Signature Service of the Java Cryptographic Extension.",
"icon": "saxonIcon"
},
{
"id": 6,
"name": "DropBox",
"description": "The dropbox component allows you to treat Dropbox remote folders as a producer or consumer of messages.",
"icon": "dropBoxIcon"
},
{
"id": 7,
"name": "JBoss Data Grid",
"description": "Read or write to a fully-supported distributed cache and data grid for faster integration services.",
"icon": "infinispanIcon"
},
{
"id": 8,
"name": "REST",
"description": "The rest component allows to define REST endpoints (consumer) using the Rest DSL and plugin to other Camel components as the REST transport. From Camel 2.18 onwards the rest component can also be used as a client (producer) to call REST services.",
"icon": "restIcon"
},
{
"id": 9,
"name": "SWAGGER",
"description": "Expose REST services and their APIs using Swagger specification.",
"icon": "swaggerIcon"
}
]
30 changes: 10 additions & 20 deletions packages/react-core/src/demos/PrimaryDetail.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import swaggerIcon from './Card/camel-swagger-java_200x150.png';
import azureIcon from './Card/FuseConnector_Icons_AzureServices.png';
import restIcon from './Card/FuseConnector_Icons_REST.png';
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
import { data } from '@patternfly/react-core/src/demos/Card/CardData.jsx';

## Demos

Expand Down Expand Up @@ -1009,6 +1010,7 @@ import swaggerIcon from './camel-swagger-java_200x150.png';
import azureIcon from './FuseConnector_Icons_AzureServices.png';
import restIcon from './FuseConnector_Icons_REST.png';
import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon';
import { data } from '@patternfly/react-core/src/demos/Card/CardData.jsx';

class PrimaryDetailCardView extends React.Component {
constructor(props) {
Expand All @@ -1027,7 +1029,7 @@ class PrimaryDetailCardView extends React.Component {
filters: {
products: []
},
res: [],
cardData: data,
isUpperToolbarDropdownOpen: false,
isUpperToolbarKebabDropdownOpen: false,
isLowerToolbarDropdownOpen: false,
Expand Down Expand Up @@ -1253,9 +1255,9 @@ class PrimaryDetailCardView extends React.Component {
this.deleteItem = (event, item) => {
event.stopPropagation();
const filter = (getter) => (val) => getter(val) !== item.id;
const filteredCards = this.state.res.filter(filter(({ id }) => id));
const filteredCards = this.state.cardData.filter(filter(({ id }) => id));
this.setState({
res: filteredCards,
cardData: filteredCards,
selectedItems: this.state.selectedItems.filter(filter((id) => id)),
totalItemCount: this.state.totalItemCount - 1,
isDrawerExpanded: false,
Expand Down Expand Up @@ -1287,27 +1289,15 @@ class PrimaryDetailCardView extends React.Component {
}

getAllItems() {
const { res } = this.state;
const { cardData } = this.state;
const collection = [];
for (const items of res) {
for (const items of cardData) {
collection.push(items.id);
}

return collection;
}

fetch(page, perPage) {
fetch(`https://my-json-server.typicode.com/jenny-s51/cardviewdata/posts?_page=${page}&_limit=${perPage}`)
.then((resp) => resp.json())
.then((resp) => this.setState({ res: resp, perPage, page }))
.then(() => this.updateSelected())
.catch((err) => this.setState({ error: err }));
}

componentDidMount() {
this.fetch(this.state.page, this.state.perPage);
}

buildSelectDropdown() {
const { splitButtonDropdownIsOpen, selectedItems, areAllSelected } = this.state;
const numSelected = selectedItems.length;
Expand Down Expand Up @@ -1362,7 +1352,7 @@ class PrimaryDetailCardView extends React.Component {
}

render() {
const { isDrawerExpanded, isChecked, selectedItems, activeCard, isLowerToolbarKebabDropdownOpen, filters, res } =
const { isDrawerExpanded, isChecked, selectedItems, activeCard, isLowerToolbarKebabDropdownOpen, filters, cardData } =
this.state;

const toolbarKebabDropdownItems = (
Expand Down Expand Up @@ -1428,8 +1418,8 @@ class PrimaryDetailCardView extends React.Component {

const filtered =
filters.products.length > 0
? res.filter((card) => filters.products.length === 0 || filters.products.includes(card.name))
: res;
? cardData.filter((card) => filters.products.length === 0 || filters.products.includes(card.name))
: cardData;

const icons = {
pfIcon,
Expand Down