Skip to content

Commit 1383999

Browse files
committed
fix: OU-1195 coderabbit suggestions
1 parent 5c841af commit 1383999

6 files changed

Lines changed: 27 additions & 29 deletions

File tree

web/locales/en/plugin__monitoring-plugin.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,11 @@
170170
"Dashboard name": "Dashboard name",
171171
"Renaming...": "Renaming...",
172172
"Rename": "Rename",
173+
"Duplicate Dashboard": "Duplicate Dashboard",
173174
"Loading...": "Loading...",
174175
"Failed to load project permissions. Please refresh the page and try again.": "Failed to load project permissions. Please refresh the page and try again.",
175176
"Select namespace": "Select namespace",
177+
"No namespace found for \"{{filter}}\"": "No namespace found for \"{{filter}}\"",
176178
"Duplicate": "Duplicate",
177179
"this dashboard": "this dashboard",
178180
"Permanently delete dashboard?": "Permanently delete dashboard?",
@@ -197,7 +199,7 @@
197199
"Rename dashboard": "Rename dashboard",
198200
"Duplicate dashboard": "Duplicate dashboard",
199201
"Delete dashboard": "Delete dashboard",
200-
"You don't have permissions to dashboard actions": "You don't have permissions to dashboard actions",
202+
"You don't have permissions for dashboard actions": "You don't have permissions for dashboard actions",
201203
"Dashboard": "Dashboard",
202204
"Project": "Project",
203205
"Created on": "Created on",

web/src/components/dashboards/perses/dashboard-action-modals.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ export const DuplicateActionModal = ({ dashboard, isOpen, onClose }: ActionModal
304304
ouiaId="DuplicateModal"
305305
aria-labelledby="duplicate-modal"
306306
>
307-
<ModalHeader title="Duplicate Dashboard" labelId="duplicate-modal-title" />
307+
<ModalHeader title={t('Duplicate Dashboard')} labelId="duplicate-modal-title" />
308308
{permissionsLoading ? (
309309
<ModalBody style={{ textAlign: 'center', padding: '2rem' }}>
310310
{t('Loading...')} <Spinner aria-label="Duplicate Dashboard Modal Loading" />
@@ -373,10 +373,11 @@ export const DuplicateActionModal = ({ dashboard, isOpen, onClose }: ActionModal
373373
initialOptions={projectOptions}
374374
placeholder={t('Select namespace')}
375375
noOptionsFoundMessage={(filter) =>
376-
t(`No namespace found for "${filter}"`)
376+
t('No namespace found for "{{filter}}"', { filter })
377377
}
378378
onClearSelection={() => {
379379
setSelectedProject(null);
380+
form.setValue('projectName', '');
380381
}}
381382
onSelect={onProjectSelect}
382383
isCreatable={false}

web/src/components/dashboards/perses/dashboard-create-dialog.tsx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export const DashboardCreateDialog: React.FunctionComponent = () => {
145145
if (isModalOpen) {
146146
setDashboardName('');
147147
setFormErrors({});
148+
setSelectedProject(null);
148149
}
149150
};
150151

@@ -156,29 +157,25 @@ export const DashboardCreateDialog: React.FunctionComponent = () => {
156157
setSelectedProject(selection);
157158
};
158159

159-
const CreateBtn = () => {
160-
return (
161-
<Button
162-
variant="primary"
163-
onClick={handleModalToggle}
164-
isDisabled={disabled}
165-
data-test={persesDashboardDataTestIDs.createDashboardButtonToolbar}
166-
>
167-
{permissionsLoading ? t('Loading...') : t('Create')}
168-
</Button>
169-
);
170-
};
160+
const createBtn = (
161+
<Button
162+
variant="primary"
163+
onClick={handleModalToggle}
164+
isDisabled={disabled}
165+
data-test={persesDashboardDataTestIDs.createDashboardButtonToolbar}
166+
>
167+
{permissionsLoading ? t('Loading...') : t('Create')}
168+
</Button>
169+
);
171170

172171
return (
173172
<>
174173
{disabled ? (
175174
<Tooltip content={t("You don't have permissions to create dashboards")}>
176-
<span style={{ cursor: 'not-allowed' }}>
177-
<CreateBtn />
178-
</span>
175+
<span style={{ cursor: 'not-allowed' }}> {createBtn}</span>
179176
</Tooltip>
180177
) : (
181-
<CreateBtn />
178+
createBtn
182179
)}
183180
<Modal
184181
variant={ModalVariant.small}

web/src/components/dashboards/perses/dashboard-list.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const DashboardActionsCell = React.memo(
8181

8282
if (disabled || loading) {
8383
return (
84-
<Tooltip content={t("You don't have permissions to dashboard actions")}>
84+
<Tooltip content={t("You don't have permissions for dashboard actions")}>
8585
<div>
8686
<ActionsColumn items={emptyActions} isDisabled={true} />
8787
</div>
@@ -293,7 +293,7 @@ const DashboardsTable: React.FunctionComponent<DashboardsTableProps> = ({
293293
const emptyRowActions = useMemo(
294294
() => [
295295
{
296-
title: t("You don't have permissions to dashboard actions"),
296+
title: t("You don't have permissions for dashboard actions"),
297297
onClick: () => {},
298298
},
299299
],

web/src/components/dashboards/perses/hooks/useEditableProjects.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const getEditableProjects = (
3333
persesUserPermissions: PersesUserPermissions,
3434
allAvailableProjects: string[],
3535
): string[] => {
36-
const editableProjectNames: string[] = [];
36+
const editableProjectNames = new Set<string>();
3737
Object.entries(persesUserPermissions).forEach(([projectName, permissions]) => {
3838
const hasDashboardPermissions = permissions.some((permission) => {
3939
const allActions = permission.actions.includes('*');
@@ -47,16 +47,14 @@ const getEditableProjects = (
4747
});
4848

4949
if (hasDashboardPermissions) {
50-
// Handle wildcard permissions to all projects
5150
if (projectName === '*') {
52-
editableProjectNames.push(...allAvailableProjects);
53-
} else if (projectName !== '*') {
54-
// Handle specific project permissions
55-
editableProjectNames.push(projectName);
51+
allAvailableProjects.forEach((p) => editableProjectNames.add(p));
52+
} else {
53+
editableProjectNames.add(projectName);
5654
}
5755
}
5856
});
59-
return editableProjectNames;
57+
return Array.from(editableProjectNames);
6058
};
6159

6260
export const useEditableProjects = () => {

web/src/components/dashboards/perses/perses-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const fetchPersesProjects = (): Promise<ProjectResource[]> => {
2828
};
2929

3030
export interface PersesPermission {
31-
scopes: string;
31+
scopes: string[];
3232
actions: string[];
3333
}
3434

0 commit comments

Comments
 (0)