Skip to content

Commit d7ee05d

Browse files
Merge pull request #219 from ronlavi2412/contextification
Add project documentation and rewrite README
2 parents 735ba23 + 00e1358 commit d7ee05d

7 files changed

Lines changed: 655 additions & 94 deletions

File tree

.coderabbit.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.yaml
2+
3+
language: en-US
4+
tone_instructions: >
5+
Be concise and direct. Focus on correctness, SDK compatibility, and PatternFly
6+
best practices. This is an OpenShift console dynamic plugin — flag any direct
7+
K8s API calls, missing i18n (must use useNMStateTranslation hook or Trans
8+
component), or incorrect extension registration.
9+
10+
reviews:
11+
request_changes_workflow: false
12+
high_level_summary: true
13+
poem: false
14+
review_status: true
15+
collapse_walkthrough: true
16+
path_instructions:
17+
- path: "src/views/**/manifest.ts"
18+
instructions: >
19+
These files register plugin extensions with the OpenShift console.
20+
Verify that EncodedExtension types match the extension type string,
21+
ExposedModules paths resolve to real files, and nav items include
22+
both admin and virtualization perspectives where appropriate.
23+
- path: "src/console-models/**"
24+
instructions: >
25+
K8s model definitions. Verify apiGroup, apiVersion, kind, and plural
26+
are correct for the CRD. Ensure GroupVersionKind and Ref exports exist
27+
and the model is re-exported from index.ts.
28+
- path: "src/views/**/*.tsx"
29+
instructions: >
30+
React components must use PatternFly 6 components and PF utility classes,
31+
functional components with FC typing, and useNMStateTranslation() for
32+
simple user-visible strings or the Trans component for strings with
33+
embedded HTML. No hardcoded English text in JSX. Each file should contain
34+
only a single component.
35+
- path: "src/utils/components/**/*.tsx"
36+
instructions: >
37+
Shared React components must use PatternFly 6 components and PF utility
38+
classes, functional components with FC typing, and useNMStateTranslation()
39+
for simple user-visible strings or the Trans component for strings with
40+
embedded HTML. No hardcoded English text in JSX. Each file should contain
41+
only a single component.
42+
- path: "src/utils/resources/**"
43+
instructions: >
44+
Resource utilities must use SDK hooks (useK8sWatchResource) and SDK
45+
mutation functions (k8sCreate, k8sPatch, k8sDelete). No direct fetch
46+
calls to the K8s API.
47+
path_filters:
48+
- "!package-lock.json"
49+
- "!locales/**"
50+
- "!src/nmstate-types/crds/**"
51+
- "!dist/**"
52+
- "!node_modules/**"
53+
- "!i18n-scripts/**"
54+
auto_review:
55+
enabled: true
56+
drafts: false
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
description: AI context for nmstate-console-plugin — OpenShift console dynamic plugin for kubernetes-nmstate
3+
globs:
4+
alwaysApply: true
5+
---
6+
7+
# nmstate-console-plugin
8+
9+
OpenShift console dynamic plugin for kubernetes-nmstate. Provides UI views for policies, states, physical networks, and topology visualization.
10+
11+
## Key Context Files
12+
13+
- [AGENTS.md](../../AGENTS.md) — repo structure, key patterns, conventions, review guidelines
14+
- [ARCHITECTURE.md](../../ARCHITECTURE.md) — system design, plugin registration, data flow, dependencies
15+
- [CONTRIBUTING.md](../../CONTRIBUTING.md) — coding standards, linting rules, PR process
16+
17+
## Conventions
18+
19+
- **Components:** functional only, typed with `FC`, use PatternFly 6, default export for pages
20+
- **i18n:** `useNMStateTranslation()` or `Trans` component for all user-visible strings, never hardcode English
21+
- **Imports:** sorted by `eslint-plugin-simple-import-sort` — React → external packages → internal `src/` → `@kubevirt-ui` → `@openshift-console` → `@patternfly` → CSS
22+
- **Path aliases:** `@utils/*`, `@models`, `@images/*`
23+
- **K8s data:** SDK hooks only (`useK8sWatchResource`, `k8sCreate`, `k8sPatch`) — no direct API calls
24+
- **Models:** one file per K8s resource in `src/console-models/`, export `GroupVersionKind` + `Ref`, re-export from `index.ts`
25+
- **Views:** each view has `manifest.ts` with `ExposedModules` + `Extensions`, aggregated in `plugin-manifest.ts`
26+
- **Linting:** ESLint + Prettier, single quotes, trailing commas, 100-char width, `simple-import-sort`
27+
- **Testing:** Jest (`npm test`), Cypress e2e (`npm run cypress`), mock SDK + i18n via `src/__mocks__/`

AGENTS.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# AGENTS.md
2+
3+
AI-specific guidance for working with the nmstate-console-plugin codebase.
4+
5+
## Project Overview
6+
7+
This is an OpenShift console dynamic plugin for kubernetes-nmstate. It provides UI views for managing node network configuration policies, states, physical networks, and topology visualization.
8+
9+
**Stack:** React 18, TypeScript, PatternFly 6, OpenShift Dynamic Plugin SDK, Webpack, i18next
10+
11+
## Repository Structure
12+
13+
```text
14+
src/
15+
├── console-models/ # K8s resource model definitions (K8sModel objects)
16+
├── nmstate-types/ # NMState CRD types and custom models
17+
├── utils/
18+
│ ├── components/ # Shared UI components (Loading, HelpTextIcon, etc.)
19+
│ ├── hooks/ # Shared React hooks (useNMStateTranslation, etc.)
20+
│ ├── flags/ # Feature flag detection (NMState operator presence)
21+
│ ├── resources/ # K8s resource fetching utilities
22+
│ └── telemetry/ # Usage tracking
23+
├── views/
24+
│ ├── policies/ # NodeNetworkConfigurationPolicy CRUD
25+
│ │ ├── manifest.ts # Plugin extension registration
26+
│ │ ├── list/ # List page component
27+
│ │ ├── details/ # Details page component
28+
│ │ ├── new/ # Create/edit form
29+
│ │ ├── actions/ # Action menu items
30+
│ │ └── components/ # Policy-specific UI components
31+
│ ├── states/ # NodeNetworkState list + details
32+
│ ├── physical-networks/ # Physical network overview
33+
│ └── nodenetworkconfiguration/ # Topology visualization (PatternFly Topology)
34+
├── __mocks__/ # Jest mocks for SDK and i18n
35+
└── plugin-manifest.ts # Root plugin metadata and extension aggregation
36+
```
37+
38+
## Key Patterns
39+
40+
### Plugin extension registration
41+
42+
Each view has a `manifest.ts` that exports:
43+
- `{View}ExposedModules` — maps module names to file paths for code splitting
44+
- `{View}Extensions` — array of `EncodedExtension` objects defining console nav items, pages, and templates
45+
46+
These are aggregated in the root `plugin-manifest.ts`.
47+
48+
### K8s resource models
49+
50+
Models live in `src/console-models/` as individual files exporting `K8sModel` objects. Each model defines `apiGroup`, `apiVersion`, `kind`, `plural`, and a `GroupVersionKind` constant. Import models via `@models` path alias.
51+
52+
### Path aliases
53+
54+
Defined in `tsconfig.json`:
55+
- `@images/*``images/*`
56+
- `@utils/*``src/utils/*`
57+
- `@models``src/console-models/index.ts`
58+
59+
### React components & i18n
60+
61+
For coding standards (component rules, PatternFly usage, i18n, linting), see [CONTRIBUTING.md](CONTRIBUTING.md#coding-standards).
62+
63+
Key details for code generation:
64+
- Translation keys use the `plugin__nmstate-console-plugin~` prefix
65+
- In manifest files, use `%plugin__nmstate-console-plugin~Label%` syntax for nav item names
66+
- Shared hooks (used in 2+ components) live in `src/utils/hooks/`; single-use hooks must be co-located with the component that uses them — do not add to shared utils
67+
- One component per file — utility functions, types (aside from props), and constants go in a `utils/` folder within the component's directory
68+
- Prefer PatternFly utility classes (e.g., `pf-v6-u-mt-md`) over custom CSS for spacing and layout
69+
70+
### State management
71+
72+
- No global state library — uses OpenShift SDK's `useK8sWatchResource` for K8s data
73+
- Local component state via React `useState`/`useReducer`
74+
75+
## Conventions
76+
77+
For full coding standards, linting rules, testing, and PR process, see [CONTRIBUTING.md](CONTRIBUTING.md).
78+
79+
### File & directory naming
80+
- React components: `PascalCase.tsx`
81+
- Utilities, hooks, constants: `camelCase.ts`
82+
- Directories for components use PascalCase, directories for hooks use camelCase, all other directories use kebab-case
83+
- Each view directory has a `manifest.ts`, `constants.ts`, and optionally `utils.ts`
84+
85+
### Deployment
86+
- Webpack builds the plugin as a dynamic console remote module
87+
- Deployed via Helm chart (`deployment/nmstate-console-plugin/`) or OpenShift templates (`oc-manifest.yaml`)
88+
- Container images published to `quay.io/nmstate/nmstate-console-plugin`
89+
90+
## Review Guidelines
91+
92+
When reviewing changes to this codebase:
93+
94+
1. **SDK compatibility** — verify that `@openshift-console/dynamic-plugin-sdk` APIs are used correctly; the SDK version must match the target release branch (e.g., `release-4.22` uses SDK 4.22.x)
95+
2. **i18n** — all user-visible strings must use the `useNMStateTranslation` hook or the `Trans` component; never hardcode English text
96+
3. **PatternFly** — use PatternFly components and PF utility classes instead of custom HTML/CSS; follow PatternFly 6 patterns
97+
4. **Type safety**`strict` is `false` in tsconfig, but new code should use explicit types
98+
5. **Model consistency** — new K8s resources need a model in `console-models/`, a manifest entry, and registration in `plugin-manifest.ts`
99+
6. **No direct K8s API calls** — use the OpenShift SDK hooks (`useK8sWatchResource`, `k8sCreate`, `k8sPatch`, etc.)
100+
7. **Component isolation** — one component per file; single-use hooks stay co-located with their component, not in shared `utils/hooks/`
101+
8. **Naming conventions** — new resource utility files should use `selectors.ts` (not `getters.ts`); some older directories still use `getters.ts` but the project is migrating to the `selectors` naming

0 commit comments

Comments
 (0)