Skip to content

Commit 4e1a07b

Browse files
Merge branch 'main' into disable-dryrun
2 parents 72b946f + fef6dbd commit 4e1a07b

File tree

12 files changed

+212
-149
lines changed

12 files changed

+212
-149
lines changed

.github/workflows/pr-preview.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
### WARNING -- this file was generated by generate-workflows
3+
name: pr-preview
4+
on: pull_request_target
5+
jobs:
6+
build-upload:
7+
runs-on: ubuntu-latest
8+
env:
9+
SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }}
10+
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
11+
GH_PR_TOKEN: ${{ secrets.GH_PR_TOKEN }}
12+
GH_PR_NUM: ${{ github.event.number }}
13+
steps:
14+
- uses: actions/checkout@v4
15+
# Yes, we really want to checkout the PR
16+
- run: |
17+
git fetch origin pull/$GH_PR_NUM/head:tmp
18+
git checkout tmp
19+
20+
- run: |
21+
git rev-parse origin/main
22+
git rev-parse HEAD
23+
git rev-parse origin/main..HEAD
24+
git log origin/main..HEAD --format="%b"
25+
26+
# Yes, we really want to checkout the PR
27+
# Injected by generate-workflows.js
28+
- uses: actions/setup-node@v4
29+
with:
30+
node-version: '20'
31+
- uses: actions/cache@v4
32+
id: npm-cache
33+
name: Load npm deps from cache
34+
with:
35+
path: '**/node_modules'
36+
key: ${{ runner.os }}-npm-14-${{ secrets.CACHE_VERSION }}-${{ hashFiles('package-lock.json') }}
37+
- run: npm install --frozen-lockfile --legacy-peer-deps
38+
if: steps.yarn-cache.outputs.cache-hit != 'true'
39+
- run: npm run build
40+
name: Build component groups
41+
- uses: actions/cache@v4
42+
id: docs-cache
43+
name: Load webpack cache
44+
with:
45+
path: '.cache'
46+
key: ${{ runner.os }}-v4-${{ hashFiles('yarn.lock') }}
47+
- run: npm run build:docs
48+
name: Build docs
49+
- run: node .github/upload-preview.js packages/module/public
50+
name: Upload docs
51+
if: always()
52+
- run: npx puppeteer browsers install chrome
53+
name: Install Chrome for Puppeteer
54+
- run: npm run serve:docs & npm run test:a11y
55+
name: a11y tests
56+
- run: node .github/upload-preview.js packages/module/coverage
57+
name: Upload a11y report
58+
if: always()

README.md

Lines changed: 77 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
# Widgetized Dashboard
22

3-
A generic, reusable PatternFly component library providing a customizable widget-based dashboard with drag-and-drop functionality. This library was created by lifting and adapting code from the [RedHatInsights/widget-layout](https://github.com/RedHatInsights/widget-layout) repository, removing console-specific dependencies to make it suitable for any PatternFly application.
3+
A generic, reusable PatternFly component library providing a customizable widget-based dashboard with drag-and-drop functionality.
44

5-
## Features
5+
## Prerequisites
66

7-
- **Drag-and-Drop Grid Layout**: Powered by `react-grid-layout` with responsive breakpoints
8-
- **Widget Drawer**: Easy widget selection and management
9-
- **Lock/Unlock Widgets**: Prevent accidental changes to widget positions and sizes
10-
- **Resize Widgets**: Adjust widget dimensions with corner handles
11-
- **Responsive Design**: Automatic layout adjustments for xl, lg, md, and sm breakpoints
12-
- **Customizable**: Fully configurable widgets with custom icons, titles, and content
13-
- **TypeScript Support**: Full type definitions included
14-
- **No External Dependencies**: Self-contained state management (no Jotai, Redux, or other state libraries required)
7+
- Node.js 18 or higher
8+
- Yarn 4.10.3 or higher (recommended) or npm
9+
- React 18 (peer dependency)
10+
- React DOM 18 (peer dependency)
1511

1612
## Installation
1713

@@ -27,10 +23,10 @@ npm install @patternfly/widgetized-dashboard
2723

2824
### Peer Dependencies
2925

30-
Make sure you have the required peer dependencies installed:
26+
This library requires React 18+ and React DOM 18+ as peer dependencies. Make sure these are installed in your project:
3127

3228
```bash
33-
yarn add react react-dom react-router-dom @patternfly/react-core @patternfly/react-icons
29+
yarn add react@^18 react-dom@^18
3430
```
3531

3632
## Quick Start
@@ -85,7 +81,12 @@ function App() {
8581
## Documentation
8682

8783
- [Getting Started Guide](./packages/module/patternfly-docs/content/examples/basic.md)
88-
- [API Reference](./packages/module/patternfly-docs/content/design-guidelines/design-guidelines.md)
84+
85+
## Examples
86+
87+
- [Basic Example](./packages/module/patternfly-docs/content/examples/BasicExample.tsx) - Complete dashboard with drawer
88+
- [Locked Layout Example](./packages/module/patternfly-docs/content/examples/LockedLayoutExample.tsx) - Dashboard with locked widgets
89+
- [Without Drawer Example](./packages/module/patternfly-docs/content/examples/WithoutDrawerExample.tsx) - Grid layout without widget drawer
8990

9091
## Key Components
9192

@@ -105,40 +106,81 @@ The widget selection drawer (can be used standalone with GridLayout).
105106

106107
Individual widget tile wrapper with actions menu (used internally by GridLayout).
107108

108-
## Differences from widget-layout
109+
## Development
109110

110-
This library is based on [RedHatInsights/widget-layout](https://github.com/RedHatInsights/widget-layout) but has been adapted to be a generic, reusable PatternFly component:
111+
### Setup
111112

112-
### Removed
113-
- ❌ Scalprum federated module loading
114-
- ❌ Chrome Services API calls for template persistence
115-
- ❌ Console-specific authentication (useCurrentUser)
116-
- ❌ Console-specific analytics (useChrome)
117-
- ❌ Jotai state management atoms
118-
- ❌ Console-specific icons and branding
113+
1. Clone the repository:
114+
```bash
115+
git clone https://github.com/patternfly/widgetized-dashboard.git
116+
cd widgetized-dashboard
117+
```
119118

120-
### Added
121-
- ✅ Generic widget rendering via `renderWidget` prop
122-
- ✅ Prop-based template management (bring your own state management)
123-
- ✅ Optional analytics callback
124-
- ✅ Standalone component usage (no external state required)
125-
- ✅ Full TypeScript support
126-
- ✅ Simplified API without console dependencies
119+
2. Install dependencies:
120+
```bash
121+
yarn install
122+
```
127123

128-
## Browser Support
124+
3. Start the development server:
125+
```bash
126+
yarn start
127+
```
128+
This will build the library and start the documentation site at http://localhost:8003
129129

130-
Modern browsers (Chrome, Firefox, Safari, Edge) with ES6 support.
130+
### Building for Production
131131

132-
## License
132+
```bash
133+
yarn build
134+
```
133135

134-
MIT
136+
### Testing and Linting
137+
138+
- Run unit tests: `yarn test`
139+
- Run linter: `yarn lint`
140+
- Lint JavaScript: `yarn lint:js`
141+
- Lint Markdown: `yarn lint:md`
142+
143+
### Accessibility Testing
144+
145+
1. Build the docs: `yarn build:docs`
146+
2. Serve the docs: `yarn serve:docs`
147+
3. In a new terminal window, run: `yarn test:a11y`
148+
4. View the generated report: `yarn serve:a11y`
135149

136150
## Contributing
137151

152+
We welcome contributions! Please follow the guidelines below when contributing to this project.
153+
154+
### Component Guidelines
155+
156+
- Follow PatternFly naming conventions
157+
- Include TypeScript definitions for all components and props
158+
- Write unit tests using React Testing Library
159+
- Add documentation examples in `packages/module/patternfly-docs/content/examples/`
160+
- Follow the existing code style and linting rules
161+
- Ensure all tests pass before submitting a pull request
162+
163+
### Pull Request Process
164+
165+
1. Fork the repository
166+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
167+
3. Make your changes with appropriate tests
168+
4. Run `yarn lint` and `yarn test` to ensure code quality
169+
5. Commit your changes (`git commit -m 'Add some amazing feature'`)
170+
6. Push to the branch (`git push origin feature/amazing-feature`)
171+
7. Open a pull request
172+
138173
### AI-assisted development guidelines
139174

140175
Please reference [PatternFly's AI-assisted development guidelines](https://github.com/patternfly/.github/blob/main/CONTRIBUTING.md) if you'd like to contribute code generated using AI.
141176

142-
## Credits
177+
## License
178+
179+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
180+
181+
## Repository
182+
183+
- **Issues**: [GitHub Issues](https://github.com/patternfly/widgetized-dashboard/issues)
184+
- **Source**: [GitHub Repository](https://github.com/patternfly/widgetized-dashboard)
185+
143186

144-
This library is based on the [RedHatInsights/widget-layout](https://github.com/RedHatInsights/widget-layout) repository, adapted to be a generic PatternFly component.

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ module.exports = {
1313
moduleNameMapper: {
1414
'\\.(css|less)$': '<rootDir>/styleMock.js'
1515
},
16-
testEnvironment: 'jsdom'
16+
testEnvironment: 'jsdom',
17+
setupFilesAfterEnv: ['<rootDir>/jest.setup.js']
1718
};

jest.setup.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Mock ResizeObserver for tests
2+
global.ResizeObserver = class ResizeObserver {
3+
constructor(callback) {
4+
this.callback = callback;
5+
}
6+
observe() {
7+
// Mock observe method
8+
}
9+
unobserve() {
10+
// Mock unobserve method
11+
}
12+
disconnect() {
13+
// Mock disconnect method
14+
}
15+
};
16+

packages/module/patternfly-docs/content/examples/basic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The WidgetLayout component provides a complete drag-and-drop dashboard experienc
2525

2626
### Interactive example
2727

28-
```js file="./BasicExample.tsx"
28+
```js file="./BasicExample.tsx" isFullscreen
2929
3030
```
3131

packages/module/release.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
branches: [{ name: 'main', channel: 'prerelease' }],
2+
branches: [{ name: 'main', channel: 'prerelease', prerelease: 'prerelease' }, 'do-not-delete'],
33
analyzeCommits: {
44
preset: 'angular'
55
},
@@ -9,6 +9,6 @@ module.exports = {
99
'@semantic-release/github',
1010
'@semantic-release/npm'
1111
],
12-
tagFormat: 'v${version}',
12+
tagFormat: 'prerelease-v${version}',
1313
dryRun: false
1414
};

packages/module/src/WidgetLayout/GridLayout.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,24 +257,25 @@ const GridLayout = ({
257257
onLayoutChange={onLayoutChange}
258258
>
259259
{activeLayout
260-
.map(({ widgetType, title, ...rest }, index) => {
260+
.map((layoutItem, index) => {
261+
const { widgetType } = layoutItem;
261262
const widget = widgetMapping[widgetType];
262263
if (!widget) {
263264
return null;
264265
}
265266
const config = widgetMapping[widgetType]?.config;
266267
return (
267-
<div key={rest.i} data-grid={rest} tabIndex={index} className={`widget-columns-${rest.w} widget-rows-${rest.h}`}>
268+
<div key={layoutItem.i} data-grid={layoutItem} tabIndex={index} className={`widget-columns-${layoutItem.w} widget-rows-${layoutItem.h}`}>
268269
<GridTile
269270
isDragging={isDragging}
270271
setIsDragging={setIsDragging}
271272
widgetType={widgetType}
272-
widgetConfig={{ ...rest, colWidth: layoutWidth / columns[layoutVariant], config }}
273+
widgetConfig={{ ...layoutItem, colWidth: layoutWidth / columns[layoutVariant], config }}
273274
setWidgetAttribute={setWidgetAttribute}
274275
removeWidget={removeWidget}
275276
analytics={analytics}
276277
>
277-
{widget.renderWidget(rest.i)}
278+
{widget.renderWidget(layoutItem.i)}
278279
</GridTile>
279280
</div>
280281
);

0 commit comments

Comments
 (0)