Skip to content

Commit 492e90e

Browse files
committed
feature(FR-1471): migrate the GitHub/GitLab importing feature to React
1 parent d6ecc7a commit 492e90e

33 files changed

+661
-8
lines changed

packages/backend.ai-ui/src/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ export { default as useErrorMessageResolver } from './useErrorMessageResolver';
3737
export { default as useViewer } from './useViewer';
3838
export type { ErrorResponse } from './useErrorMessageResolver';
3939
export type { ESMClientErrorResponse } from './useErrorMessageResolver';
40+
export { default as useGetAvailableFolderName } from './useGetAvailableFolderName';
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { useGetAvailableFolderNameQuery } from '../__generated__/useGetAvailableFolderNameQuery.graphql';
2+
import { generateRandomString } from '../helper';
3+
import { fetchQuery, graphql, useRelayEnvironment } from 'react-relay';
4+
5+
export const useGetAvailableFolderName = () => {
6+
'use memo';
7+
const relayEnv = useRelayEnvironment();
8+
return async (seedName: string) => {
9+
// Limit folder name length to 64 characters
10+
const targetName = seedName.substring(0, 64);
11+
const count = await fetchQuery<useGetAvailableFolderNameQuery>(
12+
relayEnv,
13+
graphql`
14+
query useGetAvailableFolderNameQuery($filter: String!) {
15+
vfolder_nodes(filter: $filter, permission: "read_attribute") {
16+
edges {
17+
node {
18+
name
19+
status
20+
}
21+
}
22+
count
23+
}
24+
}
25+
`,
26+
{
27+
filter: `(name == "${targetName}") & (status != "delete-complete")`,
28+
},
29+
)
30+
.toPromise()
31+
.then((data) => data?.vfolder_nodes?.count)
32+
.catch(() => 0);
33+
34+
const hash = generateRandomString(5);
35+
console.log(targetName, count);
36+
return count === 0 ? targetName : `${targetName.substring(0, 58)}_${hash}`;
37+
};
38+
};
39+
40+
export default useGetAvailableFolderName;

react-data.instructions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
가---
2+
applyTo: "react/data/**/*"
3+
---
4+
5+
- Use `react/data` for deterministic fixtures only. Keep JSON/TS files lightweight, versioned, and aligned with Backend.AI API schemas.
6+
- Annotate sample payloads with comments or README links where appropriate, and avoid embedding secrets or production identifiers.
7+
- Update dependent tests or demos when fixture structure changes and validate serialization via TypeScript definitions.

react-instructions.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copilot React Review Instruction
2+
3+
## Purpose
4+
This document outlines the review guidelines Copilot should follow when evaluating changes under the `/react` directory. The React SPA powers the latest Backend.AI Web UI features and ships web component wrappers that integrate with the legacy Lit-based shell.
5+
6+
## Review Focus Areas
7+
- **Structure & Patterns**
8+
- New components must be loaded via `React.lazy`, rendered inside `DefaultProviders`, and registered with `reactToWebComponent` using the `backend-ai-react-*` naming convention in `customElements.define`.
9+
- When slotting Lit web components into React wrappers, ensure the README-documented `<slot>` pattern is respected.
10+
- **Data & State Management**
11+
- GraphQL updates require matching Relay compiler artifacts. Confirm `pnpm run relay` output is committed whenever fragments or queries change.
12+
- For TanStack Query, Jotai, and custom hooks, verify cache keys/atom names are stable and avoid unnecessary re-renders.
13+
- Backend.AI client access should go through provided hooks such as `useSuspendedBackendaiClient`.
14+
- **Styling & Theme**
15+
- Disallow direct CSS imports. Prefer inline styles, CSS-in-JS, or `?raw` string imports injected via `<style>` tags.
16+
- Ant Design v5 theme tokens and `resources/theme.json` must be respected to prevent leaking global styles.
17+
- **Static Assets**
18+
- Images/fonts should live under `/resources` and be referenced by path—avoid bundling assets via import statements.
19+
- **Internationalization**
20+
- Wrap new user-facing strings with `react-i18next` utilities and provide translation keys in `resources/i18n/*.json`.
21+
- **Validation & Quality**
22+
- Maintain strict TypeScript typing with minimal `any` usage and honor ESLint rules (`import/no-duplicates`, unused vars suppression via `_` prefix, etc.).
23+
- Update Jest specs (`react/__test__`) or Storybook stories when behavior changes warrant it.
24+
- Ensure asynchronous flows supply loading and error UI consistent with `Suspense`/`ErrorBoundary` patterns.
25+
- **Build & Dependencies**
26+
- New dependencies belong in `react/package.json` using `workspace:*` or appropriate semver ranges.
27+
- Changes to CRACO or build setup must pass `pnpm run build:only`.
28+
- **Accessibility & UX**
29+
- Confirm ARIA attributes, keyboard navigation, and focus handling meet accessibility expectations.
30+
31+
## Review Checklist
32+
1. Style: `pnpm --filter react lint` passes without violations.
33+
2. Format: `pnpm --filter react format` (or `format-fix`) succeeds.
34+
3. Types/Relay: Run `pnpm run relay` and, if needed, `pnpm dlx tsc`.
35+
4. Tests: Execute `pnpm --filter react test` or other relevant suites.
36+
5. Build: For major UI updates, run `pnpm run build:react-only` to verify bundling.
37+
6. Resources: Confirm i18n JSON, theme files, static paths, and docs are updated when required.
38+
39+
## Reference Commands
40+
- Dev server: `pnpm run server:d`
41+
- Lint: `pnpm --filter react lint`
42+
- Format: `pnpm --filter react format`
43+
- Test: `pnpm --filter react test`
44+
- Relay compile: `pnpm run relay`
45+
- Storybook: `pnpm --filter react storybook`
46+
47+
Copilot should recommend fixes whenever changes fail to meet these standards.

react-patches.instructions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
applyTo: "react/patches/**/*"
3+
---
4+
5+
- Each patch must be generated with `pnpm exec patch-package` and accompanied by a note in the PR explaining why upstream cannot be updated. Keep patches minimal and scoped to the issue at hand.
6+
- Preserve existing headers added by patch-package and ensure the target dependency version matches `package.json`. Update or remove patches when bumping dependencies.
7+
- Verify patched packages still satisfy lint/build steps (`pnpm --filter react lint`, `pnpm run build:react-only`).

react-public.instructions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
applyTo: "react/public/**/*"
3+
---
4+
5+
- Static assets served from `react/public` should be optimized (SVG preferred, no unused bitmap variants) and referenced via absolute paths; avoid importing them into bundles.
6+
- Keep `index.html` adjustments minimal and compatible with CRACO overrides—ensure injected scripts honor CSP and do not reintroduce deprecated polyfills.
7+
- Update cache-busting or manifest references alongside `resources/` when assets move, and document any new public endpoints in relevant README sections.

react-src.instructions.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
applyTo: "react/src/**/*.{ts,tsx}"
2+
---
3+
4+
- **React 19 & Compiler Alignment**
5+
- Keep components pure and side-effect free during render so React Compiler can optimize them; lift expensive calculations outside component bodies or wrap them with `useMemo` only when referential stability is required (e.g. Ant Design props, Relay variables).
6+
- Use stable hook signatures (`useSuspenseQuery`, TanStack Query hooks, Jotai atoms) and avoid conditional hooks. Prefer `useEffectEvent` or event handlers defined outside `useEffect` bodies to prevent stale closures.
7+
- Compose async flows with `Suspense`/`ErrorBoundary`, `useTransition`, and `useDeferredValue` where appropriate; when using the experimental `use` helper, gate it behind feature flags that match Backend.AI server capabilities.
8+
- **Component Structure**
9+
- Lazy load new pages/components via `React.lazy` and wrap them with `DefaultProviders` before calling `reactToWebComponent`. Follow the `backend-ai-react-*` naming convention in `customElements.define` and expose slots consistent with existing wrappers.
10+
- Co-locate derived hooks and helper functions next to their components; hoist shared logic into `packages/backend.ai-ui` or dedicated hooks to prevent duplication.
11+
- **Data & State**
12+
- Keep Relay fragments colocated and run `pnpm run relay` whenever schema fragments change. Commit generated artifacts and ensure query variables remain serializable.
13+
- For TanStack Query / Jotai, define cache keys/atoms in stable modules and document invalidation rules. Prefer optimistic updates + `queryClient.invalidateQueries` rather than manual state mutation.
14+
- **Styling & Assets**
15+
- Honor Ant Design v5 token usage (`resources/theme.json`) and shadow DOM isolation. Do not import `.css`/`.less` into components; inject styles via inline props, CSS-in-JS, or `?raw` string resources.
16+
- Reference images/fonts through `/resources` paths to keep CRA bundles lean. Run accessibility checks for new UI (ARIA labels, keyboard focus, reduced motion support).
17+
- **Internationalization & Quality**
18+
- Wrap user-visible copy with `react-i18next` helpers and update corresponding entries in `resources/i18n/*.json`.
19+
- Maintain strict TypeScript typing; avoid `any`, prefer discriminated unions for API responses, and extend shared types in `@backend.ai-ui` where possible. Update Storybook stories/Jest specs when behavior shifts.

react-storybook.instructions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
applyTo: "react/.storybook/**/*"
3+
---
4+
5+
- Keep Storybook configuration aligned with Ant Design v5 and React 19 baseline; ensure global decorators wrap stories with `DefaultProviders` and theming tokens.
6+
- When adjusting preview parameters or webpack/craco overrides, verify compatibility with Relay mock environment and CSS-in-JS injection patterns.
7+
- Document any new addons or manager customizations in README/CHANGELOG and confirm `pnpm --filter react storybook` runs without warnings.

react-tests.instructions.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
applyTo: "react/__test__/**/*"
3+
---
4+
5+
- Mirror production behavior by using React Testing Library and Jest with `NODE_OPTIONS='--no-deprecation'`. Prefer user-centric queries and avoid brittle selectors.
6+
- Provide coverage for new hooks or components under test, mocking Backend.AI clients via existing helpers. Keep Relay environment mocks updated and regenerate snapshots responsibly.
7+
- Localize expectations: assert translated output via i18n keys rather than hardcoded strings. Ensure loading/error states align with `Suspense` and `ErrorBoundary` flows.
8+
- Run `pnpm --filter react test` after changes and include any new fixtures or mock data alongside tests.

0 commit comments

Comments
 (0)