Components / agent
PermissionMatrix builder
A grid of subjects against actions.
A builder is RenderOnce. Construct and mount it in one expression.
use gpui_kit::agent::PermissionMatrix;
Reviewed in permission-matrix.
Construct
new(ident: impl Into<Ident>) -> Self
Options
Chain onto the value.
action(action: PermissionAction) -> Self
actions(actions: impl IntoIterator<Item = PermissionAction>) -> Self
subject(subject: PermissionSubject) -> Self
subjects(subjects: impl IntoIterator<Item = PermissionSubject>) -> Self
on_change(handler: impl Fn(PermissionChange, &mut Window, &mut App) + 'static) -> Self
Example · permission-matrix
fn permission_matrix(_window: &mut Window, cx: &mut App) -> AnyElement {
let theme = cx.theme().clone();
let actions = [
PermissionAction::new("read", "Read files"),
PermissionAction::new("write", "Write files"),
PermissionAction::new("network", "Reach the network"),
];
let subjects = [
PermissionSubject::new("workspace", "This workspace")
.cell("read", PermissionEntry::new(PermissionState::Allowed))
.cell("write", PermissionEntry::new(PermissionState::Ask))
.cell(
"network",
PermissionEntry::inherited(PermissionState::Denied, "the organisation policy"),
),
PermissionSubject::new("scratch", "The scratch directory")
.cell(
"read",
PermissionEntry::inherited(PermissionState::Allowed, "this workspace"),
)
.cell("write", PermissionEntry::new(PermissionState::Allowed))
.cell(
"network",
PermissionEntry::inherited(PermissionState::Denied, "the organisation policy"),
),
// A calculator has no files to read, which is not the same as being
// refused them.
PermissionSubject::new("calculator", "The calculator tool")
.cell("network", PermissionEntry::new(PermissionState::Denied)),
];
stack(&theme)
.w(px(720.0))
.child(
PermissionMatrix::new("scene.permission.editable")
.actions(actions.clone())
.subjects(subjects.clone())
.on_change(|_change, _window, _cx| {}),
)
.child(
Divider::new()
.id("scene.permission.rule.read-only")
.label("The same permissions, shown rather than offered"),
)
.child(
PermissionMatrix::new("scene.permission.read-only")
.actions(actions)
.subjects(subjects),
)
.into_any_element()
}