-
Notifications
You must be signed in to change notification settings - Fork 108
feat(communication): add settings listing page #19760
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aottr
wants to merge
1
commit into
project/communication-app
Choose a base branch
from
feat/MANAGER-18774
base: project/communication-app
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
packages/manager/apps/communication/public/translations/settings/Messages_fr_FR.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"description": "Définissez vos règles de diffusion pour choisir quels contacts recevront les communications, en fonction des catégories et priorités que vous sélectionnez.", | ||
"table_column_name": "Nom", | ||
"table_column_status": "Statut", | ||
"add_routing_button": "Créer une règle", | ||
"status_enabled": "Activé", | ||
"status_disabled": "Désactivé", | ||
"actions_menu_label": "Actions", | ||
"table_action_deactivate": "Désactiver", | ||
"add_routing_error_message": "Une erreur est survenue lors de la création de la règle.", | ||
"add_routing_success_message": "La règle a été créée avec succès.", | ||
"edit_routing_error_message": "Une erreur est survenue lors de la modification de la règle.", | ||
"edit_routing_success_message": "La règle a été modifiée avec succès.", | ||
"delete_routing_error_message": "Une erreur est survenue lors de la suppression de la règle.", | ||
"delete_routing_success_message": "La règle a été supprimée avec succès.", | ||
"add_routing_modal_title": "Créer une règle", | ||
"edit_routing_modal_title": "Modifier la règle", | ||
"delete_routing_modal_title": "Supprimer la règle", | ||
"delete_routing_modal_info": "Êtes-vous sûr de vouloir supprimer la règle <strong>{{ routingName }}</strong> ?" | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/manager/apps/communication/src/components/routingStatus/RoutingStatus.component.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { NAMESPACES } from '@ovh-ux/manager-common-translations'; | ||
import { ODS_BADGE_COLOR } from '@ovhcloud/ods-components'; | ||
import { OdsBadge } from '@ovhcloud/ods-components/react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export default function RoutingStatusChip({ active }: { active: boolean }) { | ||
const { t } = useTranslation(NAMESPACES.STATUS); | ||
return ( | ||
<OdsBadge | ||
color={active ? ODS_BADGE_COLOR.success : ODS_BADGE_COLOR.critical} | ||
label={t(active ? 'ok' : 'disabled')} | ||
/> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/manager/apps/communication/src/data/api/notification.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import apiClient from '@ovh-ux/manager-core-api'; | ||
import { NotificationRouting } from '../types/routing.type'; | ||
|
||
export const getNotificationRoutingQueryKey = () => ['/notification/routing']; | ||
export const getNotificationRouting = async (): Promise<NotificationRouting[]> => { | ||
const { data } = await apiClient.v2.get('/notification/routing'); | ||
return data; | ||
}; |
16 changes: 16 additions & 0 deletions
16
...nager/apps/communication/src/data/hooks/useNotificationRouting/useNotificationRouting.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useQuery, UseQueryResult } from '@tanstack/react-query'; | ||
import { ApiError } from '@ovh-ux/manager-core-api'; | ||
import { NotificationRouting } from '@/data/types/routing.type'; | ||
import { | ||
getNotificationRouting, | ||
getNotificationRoutingQueryKey, | ||
} from '@/data/api/routing'; | ||
|
||
export const useNotificationRouting = (): UseQueryResult< | ||
NotificationRouting[], | ||
ApiError | ||
> => | ||
useQuery({ | ||
queryKey: getNotificationRoutingQueryKey(), | ||
queryFn: () => getNotificationRouting(), | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './notification.type'; | ||
export * from './reference.type'; | ||
export * from './routing.type'; | ||
export * from './iam-resource.type'; |
26 changes: 26 additions & 0 deletions
26
packages/manager/apps/communication/src/data/types/routing.type.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { ContactMeanType } from './contact-mean.type'; | ||
|
||
export type NotificationRoutingContactMean = { | ||
id: string; | ||
email: string; | ||
type: ContactMeanType; | ||
}; | ||
|
||
export type NotificationRoutingCondition = { | ||
category: string[]; | ||
priority: string[]; | ||
}; | ||
|
||
export type NotificationRoutingRule = { | ||
continue: boolean; | ||
condition: NotificationRoutingCondition; | ||
contactMeans: NotificationRoutingContactMean[]; | ||
}; | ||
|
||
export type NotificationRouting = { | ||
active: boolean; | ||
createdAt: string; | ||
id: string; | ||
name: string; | ||
rules: NotificationRoutingRule[]; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
packages/manager/apps/communication/src/pages/settings/Settings.page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import { OdsMessage, OdsText } from '@ovhcloud/ods-components/react'; | ||
import { | ||
ActionMenu, | ||
ActionMenuItem, | ||
Datagrid, | ||
DatagridColumn, | ||
DataGridTextCell, | ||
ManagerButton, | ||
Notifications, | ||
useResourcesIcebergV2, | ||
} from '@ovh-ux/manager-react-components'; | ||
import { ODS_BUTTON_VARIANT } from '@ovhcloud/ods-components'; | ||
import { useMemo } from 'react'; | ||
import { Outlet } from 'react-router-dom'; | ||
import { NAMESPACES } from '@ovh-ux/manager-common-translations'; | ||
import { useAuthorization } from '@/hooks'; | ||
import { NotificationRouting } from '@/data/types/routing.type'; | ||
import { useAccountUrn } from '@/data'; | ||
import { getNotificationRoutingQueryKey } from '@/data/api/routing'; | ||
import { | ||
NotificationRoutingActions, | ||
displayActionMenuItem, | ||
} from './settings.constants'; | ||
import RoutingStatusChip from '@/components/routingStatus/RoutingStatus.component'; | ||
|
||
function RoutingActionMenu({ routing }: { routing: NotificationRouting }) { | ||
const { t } = useTranslation(['settings', NAMESPACES.ACTIONS, 'common']); | ||
// const { addSuccess, addError, clearNotifications } = useNotifications(); | ||
const { data: accountUrn } = useAccountUrn(); | ||
|
||
const items = useMemo( | ||
() => | ||
[ | ||
displayActionMenuItem(routing, NotificationRoutingActions.ENABLE) && { | ||
id: 1, | ||
label: t('activate', { ns: NAMESPACES.ACTIONS }), | ||
onClick: () => {}, | ||
iamActions: ['account:apiovh:notification/routing/edit'], | ||
urn: accountUrn, | ||
}, | ||
displayActionMenuItem(routing, NotificationRoutingActions.DISABLE) && { | ||
id: 2, | ||
label: t('table_action_deactivate'), | ||
onClick: () => {}, | ||
iamActions: ['account:apiovh:notification/routing/edit'], | ||
urn: accountUrn, | ||
}, | ||
displayActionMenuItem(routing, NotificationRoutingActions.EDIT) && { | ||
id: 3, | ||
label: t('modify', { ns: NAMESPACES.ACTIONS }), | ||
onClick: () => {}, | ||
iamActions: ['account:apiovh:notification/routing/edit'], | ||
urn: accountUrn, | ||
}, | ||
displayActionMenuItem(routing, NotificationRoutingActions.DELETE) && { | ||
id: 4, | ||
label: t('delete', { ns: NAMESPACES.ACTIONS }), | ||
onClick: () => {}, | ||
iamActions: ['account:apiovh:notification/routing/delete'], | ||
urn: accountUrn, | ||
}, | ||
].filter(Boolean) as ActionMenuItem[], | ||
[t, routing], | ||
); | ||
|
||
return ( | ||
<ActionMenu | ||
id={routing.id} | ||
items={items} | ||
isCompact | ||
variant={ODS_BUTTON_VARIANT.ghost} | ||
aria-label={t('actions_menu_label')} | ||
/> | ||
); | ||
} | ||
|
||
function SettingsPage() { | ||
const { t } = useTranslation(['settings', 'common']); | ||
const { data: accountUrn } = useAccountUrn(); | ||
const { isAuthorized, isLoading: isLoadingAuthorization } = useAuthorization([ | ||
'account:apiovh:notification/routing/get', | ||
]); | ||
|
||
const columns: DatagridColumn<NotificationRouting>[] = useMemo( | ||
() => [ | ||
{ | ||
id: 'name', | ||
label: t('table_column_name'), | ||
isSortable: false, | ||
cell: ({ name }) => ( | ||
<DataGridTextCell className="truncate">{name}</DataGridTextCell> | ||
), | ||
}, | ||
{ | ||
id: 'status', | ||
label: t('table_column_status'), | ||
isSortable: false, | ||
size: 50, | ||
cell: ({ active }) => ( | ||
<DataGridTextCell> | ||
<RoutingStatusChip active={active} /> | ||
</DataGridTextCell> | ||
), | ||
}, | ||
{ | ||
id: 'actions', | ||
label: '', | ||
size: 50, | ||
isSortable: false, | ||
cell: (routing) => ( | ||
<div className="flex flex-row justify-center"> | ||
<RoutingActionMenu routing={routing} /> | ||
</div> | ||
), | ||
} | ||
], | ||
[t], | ||
); | ||
|
||
const { | ||
flattenData, | ||
isLoading: isLoadingRouting, | ||
hasNextPage, | ||
fetchNextPage, | ||
} = useResourcesIcebergV2<NotificationRouting>({ | ||
columns, | ||
route: '/notification/routing', | ||
queryKey: getNotificationRoutingQueryKey(), | ||
enabled: isAuthorized, | ||
}); | ||
|
||
const isLoading = isLoadingRouting || isLoadingAuthorization; | ||
|
||
return ( | ||
<div className="flex flex-col gap-4"> | ||
<OdsText preset="paragraph" className="mb-6"> | ||
{t('description')} | ||
</OdsText> | ||
|
||
{!isLoading && !isAuthorized && ( | ||
<OdsMessage color="warning" isDismissible={false} className="w-full"> | ||
{t('common:iam_display_content_message', { ns: 'common' })} | ||
</OdsMessage> | ||
)} | ||
|
||
<Notifications clearAfterRead /> | ||
|
||
<Datagrid | ||
items={flattenData} | ||
columns={columns} | ||
isLoading={isLoading} | ||
tableLayoutFixed={true} | ||
topbar={ | ||
<ManagerButton | ||
id="add-routing-button" | ||
iamActions={['account:apiovh:notification/routing/create']} | ||
urn={accountUrn} | ||
icon="plus" | ||
label={t('add_routing_button')} | ||
aria-label={t('add_routing_button')} | ||
size="sm" | ||
onClick={() => {}} | ||
/> | ||
} | ||
totalItems={flattenData?.length || 0} | ||
hasNextPage={hasNextPage} | ||
onFetchNextPage={fetchNextPage} | ||
manualSorting={true} | ||
/> | ||
|
||
<Outlet /> | ||
</div> | ||
); | ||
} | ||
|
||
export default SettingsPage; |
7 changes: 0 additions & 7 deletions
7
packages/manager/apps/communication/src/pages/settings/index.tsx
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
packages/manager/apps/communication/src/pages/settings/settings.constants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { NotificationRouting } from '@/data/types/routing.type'; | ||
|
||
export enum NotificationRoutingActions { | ||
EDIT = 'EDIT', | ||
DELETE = 'DELETE', | ||
ENABLE = 'ENABLE', | ||
DISABLE = 'DISABLE', | ||
} | ||
|
||
export const displayActionMenuItem = ( | ||
routing: NotificationRouting, | ||
action: NotificationRoutingActions, | ||
): boolean => { | ||
switch (action) { | ||
case NotificationRoutingActions.EDIT: | ||
case NotificationRoutingActions.DISABLE: | ||
return routing.active; | ||
case NotificationRoutingActions.ENABLE: | ||
return !routing.active; | ||
case NotificationRoutingActions.DELETE: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will we need this line soon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, with the next ticket that's coming :)