Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

filter groups at the render level, rather than the data fetching level#19115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ const meta = {
},
],
user: MockUserOwner,
permissions: {viewDeploymentConfig: true },
permissions: {createTemplates: true, createUser: true },
},
decorators: [withGlobalSnackbar, withAuthProvider, withDashboardProvider],
} satisfies Meta<typeof NotificationsPage>;
Expand DownExpand Up@@ -74,13 +74,19 @@ export const ToggleNotification: Story = {

export const NonAdmin: Story = {
parameters: {
permissions: {viewDeploymentConfig: false },
permissions: {createTemplates: false, createUser: false },
},
};

export constTemplateCreator: Story = {
export constTemplateAdmin: Story = {
parameters: {
permissions: { viewDeploymentConfig: false, createTemplates: true },
permissions: { createTemplates: true, createUser: false },
},
};

export const UserAdmin: Story = {
parameters: {
permissions: { createTemplates: false, createUser: true },
},
};

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,6 +28,7 @@ import {
methodIcons,
methodLabels,
} from "modules/notifications/utils";
import type { Permissions } from "modules/permissions";
import { type FC, Fragment } from "react";
import { useEffect } from "react";
import { Helmet } from "react-helmet-async";
Expand All@@ -46,22 +47,7 @@ const NotificationsPage: FC = () => {
},
{
...systemNotificationTemplates(),
select: (data: NotificationTemplate[]) => {
const groups = selectTemplatesByGroup(data);

let displayedGroups: Record<string, NotificationTemplate[]> = {
// Members only have access to the "Workspace Notifications" group.
"Workspace Events": groups["Workspace Events"],
};

if (permissions.viewDeploymentConfig) {
displayedGroups = groups;
} else if (permissions.createTemplates) {
displayedGroups["Template Events"] = groups["Template Events"];
}

return displayedGroups;
},
select: (data: NotificationTemplate[]) => selectTemplatesByGroup(data),
},
notificationDispatchMethods(),
],
Expand DownExpand Up@@ -110,6 +96,10 @@ const NotificationsPage: FC = () => {
{ready ? (
<Stack spacing={4}>
{Object.entries(templatesByGroup.data).map(([group, templates]) => {
if (!canSeeNotificationGroup(group, permissions)) {
return null;
}

const allDisabled = templates.some((tpl) => {
return notificationIsDisabled(disabledPreferences.data, tpl);
});
Expand DownExpand Up@@ -218,6 +208,22 @@ const NotificationsPage: FC = () => {

export default NotificationsPage;

function canSeeNotificationGroup(
group: string,
permissions: Permissions,
): boolean {
switch (group) {
case "Workspace Events":
return true;
case "Template Events":
return permissions.createTemplates;
case "User Events":
return permissions.createUser;
default:
return false;
}
}

function notificationIsDisabled(
disabledPreferences: Record<string, boolean>,
tmpl: NotificationTemplate,
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp