@checkstack/ui 0.0.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +104 -0
- package/package.json +1 -1
- package/src/components/{PermissionDenied.tsx → AccessDenied.tsx} +2 -5
- package/src/components/AccessGate.tsx +97 -0
- package/src/components/Button.tsx +5 -1
- package/src/components/DynamicForm/DynamicForm.tsx +3 -1
- package/src/components/NavItem.tsx +16 -8
- package/src/components/PageLayout.tsx +4 -4
- package/src/index.ts +2 -2
- package/src/components/PermissionGate.tsx +0 -97
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,109 @@
|
|
|
1
1
|
# @checkstack/ui
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9faec1f: # Unified AccessRule Terminology Refactoring
|
|
8
|
+
|
|
9
|
+
This release completes a comprehensive terminology refactoring from "permission" to "accessRule" across the entire codebase, establishing a consistent and modern access control vocabulary.
|
|
10
|
+
|
|
11
|
+
## Changes
|
|
12
|
+
|
|
13
|
+
### Core Infrastructure (`@checkstack/common`)
|
|
14
|
+
|
|
15
|
+
- Introduced `AccessRule` interface as the primary access control type
|
|
16
|
+
- Added `accessPair()` helper for creating read/manage access rule pairs
|
|
17
|
+
- Added `access()` builder for individual access rules
|
|
18
|
+
- Replaced `Permission` type with `AccessRule` throughout
|
|
19
|
+
|
|
20
|
+
### API Changes
|
|
21
|
+
|
|
22
|
+
- `env.registerPermissions()` → `env.registerAccessRules()`
|
|
23
|
+
- `meta.permissions` → `meta.access` in RPC contracts
|
|
24
|
+
- `usePermission()` → `useAccess()` in frontend hooks
|
|
25
|
+
- Route `permission:` field → `accessRule:` field
|
|
26
|
+
|
|
27
|
+
### UI Changes
|
|
28
|
+
|
|
29
|
+
- "Roles & Permissions" tab → "Roles & Access Rules"
|
|
30
|
+
- "You don't have permission..." → "You don't have access..."
|
|
31
|
+
- All permission-related UI text updated
|
|
32
|
+
|
|
33
|
+
### Documentation & Templates
|
|
34
|
+
|
|
35
|
+
- Updated 18 documentation files with AccessRule terminology
|
|
36
|
+
- Updated 7 scaffolding templates with `accessPair()` pattern
|
|
37
|
+
- All code examples use new AccessRule API
|
|
38
|
+
|
|
39
|
+
## Migration Guide
|
|
40
|
+
|
|
41
|
+
### Backend Plugins
|
|
42
|
+
|
|
43
|
+
```diff
|
|
44
|
+
- import { permissionList } from "./permissions";
|
|
45
|
+
- env.registerPermissions(permissionList);
|
|
46
|
+
+ import { accessRules } from "./access";
|
|
47
|
+
+ env.registerAccessRules(accessRules);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### RPC Contracts
|
|
51
|
+
|
|
52
|
+
```diff
|
|
53
|
+
- .meta({ userType: "user", permissions: [permissions.read.id] })
|
|
54
|
+
+ .meta({ userType: "user", access: [access.read] })
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Frontend Hooks
|
|
58
|
+
|
|
59
|
+
```diff
|
|
60
|
+
- const canRead = accessApi.usePermission(permissions.read.id);
|
|
61
|
+
+ const canRead = accessApi.useAccess(access.read);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Routes
|
|
65
|
+
|
|
66
|
+
```diff
|
|
67
|
+
- permission: permissions.entityRead.id,
|
|
68
|
+
+ accessRule: access.read,
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Patch Changes
|
|
72
|
+
|
|
73
|
+
- Updated dependencies [9faec1f]
|
|
74
|
+
- Updated dependencies [f533141]
|
|
75
|
+
- @checkstack/common@0.2.0
|
|
76
|
+
- @checkstack/frontend-api@0.1.0
|
|
77
|
+
|
|
78
|
+
## 0.1.0
|
|
79
|
+
|
|
80
|
+
### Minor Changes
|
|
81
|
+
|
|
82
|
+
- 8e43507: # Button component defaults to type="button"
|
|
83
|
+
|
|
84
|
+
The `Button` component now defaults to `type="button"` instead of the HTML default `type="submit"`. This prevents accidental form submissions when buttons are placed inside forms but aren't intended to submit.
|
|
85
|
+
|
|
86
|
+
## Changes
|
|
87
|
+
|
|
88
|
+
- Default `type` prop is now `"button"` instead of the HTML implicit `"submit"`
|
|
89
|
+
- Form submission buttons must now explicitly set `type="submit"`
|
|
90
|
+
|
|
91
|
+
## Migration
|
|
92
|
+
|
|
93
|
+
No migration needed if your submit buttons already have `type="submit"` explicitly set (recommended practice). If you have buttons that should submit forms but don't have an explicit type, add `type="submit"`:
|
|
94
|
+
|
|
95
|
+
```diff
|
|
96
|
+
- <Button onClick={handleSubmit}>Submit</Button>
|
|
97
|
+
+ <Button type="submit">Submit</Button>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Patch Changes
|
|
101
|
+
|
|
102
|
+
- 97c5a6b: Fixed DOM clobbering issue in DynamicForm by prefixing field IDs with 'field-'. Previously, schema fields with names matching native DOM properties (like 'nodeName', 'tagName', 'innerHTML') could shadow those properties, causing floating-ui and React to crash during DOM traversal.
|
|
103
|
+
- Updated dependencies [8e43507]
|
|
104
|
+
- @checkstack/common@0.1.0
|
|
105
|
+
- @checkstack/frontend-api@0.0.4
|
|
106
|
+
|
|
3
107
|
## 0.0.4
|
|
4
108
|
|
|
5
109
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -3,13 +3,10 @@ import { ShieldAlert } from "lucide-react";
|
|
|
3
3
|
import { Card, CardHeader, CardTitle, CardContent } from "./Card";
|
|
4
4
|
import { cn } from "../utils";
|
|
5
5
|
|
|
6
|
-
export const
|
|
6
|
+
export const AccessDenied: React.FC<{
|
|
7
7
|
message?: string;
|
|
8
8
|
className?: string;
|
|
9
|
-
}> = ({
|
|
10
|
-
message = "You do not have permission to view this page.",
|
|
11
|
-
className,
|
|
12
|
-
}) => {
|
|
9
|
+
}> = ({ message = "You do not have access to this page.", className }) => {
|
|
13
10
|
return (
|
|
14
11
|
<div
|
|
15
12
|
className={cn(
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AccessDenied } from "./AccessDenied";
|
|
3
|
+
import { LoadingSpinner } from "./LoadingSpinner";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Props for the AccessGate component.
|
|
7
|
+
*/
|
|
8
|
+
export interface AccessGateProps {
|
|
9
|
+
/**
|
|
10
|
+
* The access rule ID to check for access.
|
|
11
|
+
*/
|
|
12
|
+
accessRuleId: string;
|
|
13
|
+
/**
|
|
14
|
+
* Content to render when access is granted.
|
|
15
|
+
*/
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* Custom fallback to render when access is denied.
|
|
19
|
+
* If not provided and showDenied is false, renders nothing.
|
|
20
|
+
*/
|
|
21
|
+
fallback?: React.ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* If true, shows a AccessDenied component when access is denied.
|
|
24
|
+
* Useful for entire page sections. Overridden by fallback if provided.
|
|
25
|
+
*/
|
|
26
|
+
showDenied?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Custom message to show in the AccessDenied component.
|
|
29
|
+
*/
|
|
30
|
+
deniedMessage?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Hook to check access. Must be provided by the consumer.
|
|
33
|
+
* This allows the component to be used without depending on auth-frontend directly.
|
|
34
|
+
*/
|
|
35
|
+
useAccess: (accessRuleId: string) => { loading: boolean; allowed: boolean };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Conditionally renders children based on whether the user has a required access rule.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Hide content if access denied
|
|
43
|
+
* <AccessGate accessRuleId="catalog.manage" useAccess={accessApi.useAccess}>
|
|
44
|
+
* <ManageButton />
|
|
45
|
+
* </AccessGate>
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // Show access denied message
|
|
49
|
+
* <AccessGate
|
|
50
|
+
* accessRuleId="catalog.read"
|
|
51
|
+
* useAccess={accessApi.useAccess}
|
|
52
|
+
* showDenied
|
|
53
|
+
* deniedMessage="You don't have access to view the catalog."
|
|
54
|
+
* >
|
|
55
|
+
* <CatalogList />
|
|
56
|
+
* </AccessGate>
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // Custom fallback
|
|
60
|
+
* <AccessGate
|
|
61
|
+
* accessRuleId="admin.manage"
|
|
62
|
+
* useAccess={accessApi.useAccess}
|
|
63
|
+
* fallback={<p>Admin access required</p>}
|
|
64
|
+
* >
|
|
65
|
+
* <AdminPanel />
|
|
66
|
+
* </AccessGate>
|
|
67
|
+
*/
|
|
68
|
+
export const AccessGate: React.FC<AccessGateProps> = ({
|
|
69
|
+
accessRuleId,
|
|
70
|
+
children,
|
|
71
|
+
fallback,
|
|
72
|
+
showDenied = false,
|
|
73
|
+
deniedMessage,
|
|
74
|
+
useAccess,
|
|
75
|
+
}) => {
|
|
76
|
+
const { loading, allowed } = useAccess(accessRuleId);
|
|
77
|
+
|
|
78
|
+
if (loading) {
|
|
79
|
+
return <LoadingSpinner size="sm" />;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!allowed) {
|
|
83
|
+
if (fallback) {
|
|
84
|
+
return <>{fallback}</>;
|
|
85
|
+
}
|
|
86
|
+
if (showDenied) {
|
|
87
|
+
return (
|
|
88
|
+
<AccessDenied
|
|
89
|
+
message={deniedMessage ?? `You don't have access: ${accessRuleId}`}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
return <></>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return <>{children}</>;
|
|
97
|
+
};
|
|
@@ -39,12 +39,16 @@ export interface ButtonProps
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
42
|
-
(
|
|
42
|
+
(
|
|
43
|
+
{ className, variant, size, asChild = false, type = "button", ...props },
|
|
44
|
+
ref
|
|
45
|
+
) => {
|
|
43
46
|
const Comp = asChild ? Slot : "button";
|
|
44
47
|
return (
|
|
45
48
|
<Comp
|
|
46
49
|
className={cn(buttonVariants({ variant, size, className }))}
|
|
47
50
|
ref={ref}
|
|
51
|
+
type={asChild ? undefined : type}
|
|
48
52
|
{...props}
|
|
49
53
|
/>
|
|
50
54
|
);
|
|
@@ -109,7 +109,9 @@ export const DynamicForm: React.FC<DynamicFormProps> = ({
|
|
|
109
109
|
return (
|
|
110
110
|
<FormField
|
|
111
111
|
key={key}
|
|
112
|
-
|
|
112
|
+
// Prefix with 'field-' to prevent DOM clobbering when field names
|
|
113
|
+
// match native DOM properties (e.g., nodeName, tagName, innerHTML)
|
|
114
|
+
id={`field-${key}`}
|
|
113
115
|
label={label}
|
|
114
116
|
propSchema={propSchema}
|
|
115
117
|
value={value[key]}
|
|
@@ -2,13 +2,15 @@ import React, { useState, useRef, useEffect } from "react";
|
|
|
2
2
|
import { NavLink } from "react-router-dom";
|
|
3
3
|
import { ChevronDown } from "lucide-react";
|
|
4
4
|
import { cn } from "../utils";
|
|
5
|
-
import { useApi,
|
|
5
|
+
import { useApi, accessApiRef } from "@checkstack/frontend-api";
|
|
6
|
+
import type { AccessRule } from "@checkstack/common";
|
|
6
7
|
|
|
7
8
|
export interface NavItemProps {
|
|
8
9
|
to?: string;
|
|
9
10
|
label: string;
|
|
10
11
|
icon?: React.ReactNode;
|
|
11
|
-
|
|
12
|
+
/** Access rule to check - if not provided, always shows */
|
|
13
|
+
accessRule?: AccessRule;
|
|
12
14
|
children?: React.ReactNode;
|
|
13
15
|
className?: string;
|
|
14
16
|
}
|
|
@@ -17,7 +19,7 @@ export const NavItem: React.FC<NavItemProps> = ({
|
|
|
17
19
|
to,
|
|
18
20
|
label,
|
|
19
21
|
icon,
|
|
20
|
-
|
|
22
|
+
accessRule,
|
|
21
23
|
children,
|
|
22
24
|
className,
|
|
23
25
|
}) => {
|
|
@@ -25,11 +27,17 @@ export const NavItem: React.FC<NavItemProps> = ({
|
|
|
25
27
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
26
28
|
|
|
27
29
|
// Always call hooks at top level
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
30
|
+
const accessApi = useApi(accessApiRef);
|
|
31
|
+
|
|
32
|
+
// Create a dummy access rule for when accessRule is undefined
|
|
33
|
+
const dummyRule: AccessRule = {
|
|
34
|
+
id: "",
|
|
35
|
+
resource: "",
|
|
36
|
+
level: "read",
|
|
37
|
+
description: "",
|
|
38
|
+
};
|
|
39
|
+
const { allowed, loading } = accessApi.useAccess(accessRule ?? dummyRule);
|
|
40
|
+
const hasAccess = accessRule ? allowed : true;
|
|
33
41
|
|
|
34
42
|
// Handle click outside for dropdown
|
|
35
43
|
useEffect(() => {
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
PageHeader,
|
|
5
5
|
PageContent,
|
|
6
6
|
LoadingSpinner,
|
|
7
|
-
|
|
7
|
+
AccessDenied,
|
|
8
8
|
} from "..";
|
|
9
9
|
|
|
10
10
|
interface PageLayoutProps {
|
|
@@ -39,7 +39,7 @@ export const PageLayout: React.FC<PageLayoutProps> = ({
|
|
|
39
39
|
}) => {
|
|
40
40
|
// If loading is explicitly true, show loading state
|
|
41
41
|
// If loading is undefined and allowed is false, also show loading state
|
|
42
|
-
// (this prevents "Access Denied" flash when
|
|
42
|
+
// (this prevents "Access Denied" flash when access rules are still being fetched)
|
|
43
43
|
const isLoading =
|
|
44
44
|
loading === true || (loading === undefined && allowed === false);
|
|
45
45
|
|
|
@@ -56,13 +56,13 @@ export const PageLayout: React.FC<PageLayoutProps> = ({
|
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
// Only show
|
|
59
|
+
// Only show access denied when loading is explicitly false and allowed is false
|
|
60
60
|
if (allowed === false) {
|
|
61
61
|
return (
|
|
62
62
|
<Page>
|
|
63
63
|
<PageHeader title={title} subtitle={subtitle} actions={actions} />
|
|
64
64
|
<PageContent>
|
|
65
|
-
<
|
|
65
|
+
<AccessDenied />
|
|
66
66
|
</PageContent>
|
|
67
67
|
</Page>
|
|
68
68
|
);
|
package/src/index.ts
CHANGED
|
@@ -3,8 +3,8 @@ export * from "./components/Input";
|
|
|
3
3
|
export * from "./components/Card";
|
|
4
4
|
export * from "./components/Label";
|
|
5
5
|
export * from "./components/NavItem";
|
|
6
|
-
export * from "./components/
|
|
7
|
-
export * from "./components/
|
|
6
|
+
export * from "./components/AccessDenied";
|
|
7
|
+
export * from "./components/AccessGate";
|
|
8
8
|
export * from "./components/SectionHeader";
|
|
9
9
|
export * from "./components/StatusCard";
|
|
10
10
|
export * from "./components/EmptyState";
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { PermissionDenied } from "./PermissionDenied";
|
|
3
|
-
import { LoadingSpinner } from "./LoadingSpinner";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Props for the PermissionGate component.
|
|
7
|
-
*/
|
|
8
|
-
export interface PermissionGateProps {
|
|
9
|
-
/**
|
|
10
|
-
* The permission ID to check for access.
|
|
11
|
-
*/
|
|
12
|
-
permission: string;
|
|
13
|
-
/**
|
|
14
|
-
* Content to render when permission is granted.
|
|
15
|
-
*/
|
|
16
|
-
children: React.ReactNode;
|
|
17
|
-
/**
|
|
18
|
-
* Custom fallback to render when permission is denied.
|
|
19
|
-
* If not provided and showDenied is false, renders nothing.
|
|
20
|
-
*/
|
|
21
|
-
fallback?: React.ReactNode;
|
|
22
|
-
/**
|
|
23
|
-
* If true, shows a PermissionDenied component when access is denied.
|
|
24
|
-
* Useful for entire page sections. Overridden by fallback if provided.
|
|
25
|
-
*/
|
|
26
|
-
showDenied?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Custom message to show in the PermissionDenied component.
|
|
29
|
-
*/
|
|
30
|
-
deniedMessage?: string;
|
|
31
|
-
/**
|
|
32
|
-
* Hook to check permissions. Must be provided by the consumer.
|
|
33
|
-
* This allows the component to be used without depending on auth-frontend directly.
|
|
34
|
-
*/
|
|
35
|
-
usePermission: (permission: string) => { loading: boolean; allowed: boolean };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Conditionally renders children based on whether the user has a required permission.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* // Hide content if permission denied
|
|
43
|
-
* <PermissionGate permission="catalog.manage" usePermission={permissionApi.usePermission}>
|
|
44
|
-
* <ManageButton />
|
|
45
|
-
* </PermissionGate>
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* // Show permission denied message
|
|
49
|
-
* <PermissionGate
|
|
50
|
-
* permission="catalog.read"
|
|
51
|
-
* usePermission={permissionApi.usePermission}
|
|
52
|
-
* showDenied
|
|
53
|
-
* deniedMessage="You don't have access to view the catalog."
|
|
54
|
-
* >
|
|
55
|
-
* <CatalogList />
|
|
56
|
-
* </PermissionGate>
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* // Custom fallback
|
|
60
|
-
* <PermissionGate
|
|
61
|
-
* permission="admin.manage"
|
|
62
|
-
* usePermission={permissionApi.usePermission}
|
|
63
|
-
* fallback={<p>Admin access required</p>}
|
|
64
|
-
* >
|
|
65
|
-
* <AdminPanel />
|
|
66
|
-
* </PermissionGate>
|
|
67
|
-
*/
|
|
68
|
-
export const PermissionGate: React.FC<PermissionGateProps> = ({
|
|
69
|
-
permission,
|
|
70
|
-
children,
|
|
71
|
-
fallback,
|
|
72
|
-
showDenied = false,
|
|
73
|
-
deniedMessage,
|
|
74
|
-
usePermission,
|
|
75
|
-
}) => {
|
|
76
|
-
const { loading, allowed } = usePermission(permission);
|
|
77
|
-
|
|
78
|
-
if (loading) {
|
|
79
|
-
return <LoadingSpinner size="sm" />;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (!allowed) {
|
|
83
|
-
if (fallback) {
|
|
84
|
-
return <>{fallback}</>;
|
|
85
|
-
}
|
|
86
|
-
if (showDenied) {
|
|
87
|
-
return (
|
|
88
|
-
<PermissionDenied
|
|
89
|
-
message={deniedMessage ?? `You don't have permission: ${permission}`}
|
|
90
|
-
/>
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
return <></>;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return <>{children}</>;
|
|
97
|
-
};
|