Skip to content

Commit

Permalink
feat: Add support for viewing templates and channels in notification …
Browse files Browse the repository at this point in the history
…settings
  • Loading branch information
tikazyq committed Jul 24, 2024
1 parent 5acbd90 commit 045b6b9
Show file tree
Hide file tree
Showing 20 changed files with 438 additions and 154 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script setup lang="ts">
import { useStore } from 'vuex';
import useNotificationSetting from '@/components/core/notification/setting/useNotificationSetting';
import { translate } from '@/utils';
import { allTemplates, translate } from '@/utils';
import { ref } from 'vue';
import ClNotificationSettingTriggerSelect from '@/components/core/notification/setting/NotificationSettingTriggerSelect.vue';
defineProps<{
readonly?: boolean;
Expand All @@ -11,9 +13,29 @@ defineProps<{
const t = translate;
// store
const ns: ListStoreNamespace = 'notificationSetting';
const store = useStore();
const { form, formRef, isSelectiveForm } = useNotificationSetting(store);
const { form, formRef, isSelectiveForm, activeDialogKey } =
useNotificationSetting(store);
const templateKey = ref();
const onTemplateChange = () => {
const template = allTemplates.find(t => t.key === templateKey.value);
if (!template) return;
const { name, description, title, template_markdown, template_rich_text } =
template;
store.commit(`${ns}/setForm`, {
...form.value,
...template,
name: t(name as string),
description: t(description as string),
title: t(title as string),
template_markdown: template_markdown && t(template_markdown as string),
template_rich_text: template_rich_text && t(template_rich_text as string),
});
};
defineOptions({ name: 'ClNotificationSettingForm' });
</script>

Expand All @@ -37,6 +59,7 @@ defineOptions({ name: 'ClNotificationSettingForm' });
>
<cl-switch v-model="form.enabled" />
</cl-form-item>

<cl-form-item
:span="4"
:label="t('views.notification.settings.form.description')"
Expand All @@ -48,7 +71,32 @@ defineOptions({ name: 'ClNotificationSettingForm' });
:placeholder="t('views.notification.settings.form.description')"
/>
</cl-form-item>

<template v-if="activeDialogKey === 'create'">
<cl-form-item
:span="2"
:offset="2"
:label="t('views.notification.settings.form.trigger')"
>
<cl-notification-setting-trigger-select v-model="form.trigger" />
</cl-form-item>

<cl-form-item
:span="2"
:offset="2"
:label="t('views.notification.settings.templates.label')"
>
<el-select v-model="templateKey" @change="onTemplateChange" clearable>
<el-option
v-for="op in allTemplates"
:key="op.key"
:value="op.key"
:label="
t(`components.notification.setting.templates.${op.key}.label`)
"
/>
</el-select>
</cl-form-item>
</template>
</cl-form>
</template>

<style scoped></style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<script setup lang="tsx">
import { computed } from 'vue';
import { getTriggerOptions } from '@/utils';
const trigger = defineModel<NotificationTrigger>();
const emit = defineEmits<{
(e: 'trigger-change', value: NotificationTrigger): void;
}>();
const getTriggerTarget = (
trigger?: NotificationTrigger
): NotificationTriggerTarget | undefined => {
if (trigger?.startsWith('task')) {
return 'task';
} else if (trigger?.startsWith('node')) {
return 'node';
} else {
return;
}
};
const triggerOptions = computed<SelectOption<string>[]>(() =>
getTriggerOptions()
);
const getTriggerTargetIcon = (value: NotificationTrigger) => {
const target = getTriggerTarget(value);
switch (target) {
case 'task':
return ['fa', 'tasks'];
case 'node':
return ['fa', 'server'];
}
};
const getTriggerIcon = (value: NotificationTrigger) => {
return triggerOptions.value
.flatMap(o => o.children)
.find(o => o?.value === value)?.icon;
};
defineOptions({ name: 'ClNotificationSettingTriggerSelect' });
</script>

<template>
<el-tree-select
popper-class="notification-trigger-select"
v-model="trigger"
:data="triggerOptions"
accordion
@change="(val: NotificationTrigger) => emit('trigger-change', val)"
>
<template #label="{ value, label }">
<span style="margin-right: 5px">
<cl-icon :icon="getTriggerTargetIcon(value)" />
</span>
<span style="margin-right: 5px">
<cl-icon :icon="getTriggerIcon(value)" />
</span>
<span style="margin-right: 5px">
{{ label }}
</span>
</template>
<template #default="{ data }">
<cl-icon :icon="data.icon" />
<span style="margin-left: 5px">{{ data.label }}</span>
</template>
</el-tree-select>
</template>

<style>
.notification-trigger-select .el-tree-node__content {
height: 36px;
}
</style>
53 changes: 28 additions & 25 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import NotificationChannelForm from './core/notification/channel/NotificationCha
import useNotificationChannel from './core/notification/channel/useNotificationChannel';
import CreateEditNotificationSettingDialog from './core/notification/setting/CreateEditNotificationSettingDialog.vue';
import NotificationSettingForm from './core/notification/setting/NotificationSettingForm.vue';
import NotificationSettingTriggerSelect from './core/notification/setting/NotificationSettingTriggerSelect.vue';
import useNotificationSetting from './core/notification/setting/useNotificationSetting';
import CreateEditProjectDialog from './core/project/CreateEditProjectDialog.vue';
import ProjectForm from './core/project/ProjectForm.vue';
Expand Down Expand Up @@ -73,10 +74,10 @@ import Chart from './ui/chart/Chart.vue';
import Metric from './ui/chart/Metric.vue';
import ContextMenu from './ui/context-menu/ContextMenu.vue';
import ContextMenuList from './ui/context-menu/ContextMenuList.vue';
import * as date from './ui/date/date';
import DateRangePicker from './ui/date/DateRangePicker.vue';
import DateTimeRangePicker from './ui/date/DateTimeRangePicker.vue';
import RangePicker from './ui/date/RangePicker.vue';
import * as date from './ui/date/date';
import ConfirmDialog from './ui/dialog/ConfirmDialog.vue';
import CreateEditDialog from './ui/dialog/CreateEditDialog.vue';
import Dialog from './ui/dialog/Dialog.vue';
Expand All @@ -90,7 +91,6 @@ import FileActions from './ui/file/FileActions.vue';
import FileDiff from './ui/file/FileDiff.vue';
import FileEditor from './ui/file/FileEditor.vue';
import FileEditorCreateWithAiDialog from './ui/file/FileEditorCreateWithAiDialog.vue';
import * as fileEditorDropZone from './ui/file/fileEditorDropZone';
import FileEditorNavMenu from './ui/file/FileEditorNavMenu.vue';
import FileEditorNavMenuContextMenu from './ui/file/FileEditorNavMenuContextMenu.vue';
import FileEditorNavTabs from './ui/file/FileEditorNavTabs.vue';
Expand All @@ -100,21 +100,23 @@ import FileEditorSettingsDialog from './ui/file/FileEditorSettingsDialog.vue';
import FileTab from './ui/file/FileTab.vue';
import FileUpload from './ui/file/FileUpload.vue';
import UploadFilesDialog from './ui/file/UploadFilesDialog.vue';
import * as filter from './ui/filter/filter';
import * as fileEditorDropZone from './ui/file/fileEditorDropZone';
import FilterCondition from './ui/filter/FilterCondition.vue';
import FilterConditionList from './ui/filter/FilterConditionList.vue';
import FilterInput from './ui/filter/FilterInput.vue';
import FilterSelect from './ui/filter/FilterSelect.vue';
import * as filter from './ui/filter/filter';
import Form from './ui/form/Form.vue';
import FormItem from './ui/form/FormItem.vue';
import * as formTable from './ui/form/formTable';
import FormTableField from './ui/form/FormTableField.vue';
import * as formTable from './ui/form/formTable';
import useForm from './ui/form/useForm';
import AtomMaterialIcon from './ui/icon/AtomMaterialIcon.vue';
import * as icon from './ui/icon/icon';
import Icon from './ui/icon/Icon.vue';
import MenuItemIcon from './ui/icon/MenuItemIcon.vue';
import * as icon from './ui/icon/icon';
import InputList from './ui/input/InputList.vue';
import LexicalEditor from './ui/lexical/LexicalEditor.vue';
import BlockOptionsDropdownList from './ui/lexical/components/BlockOptionsDropdownList.vue';
import DropdownButton from './ui/lexical/components/DropdownButton.vue';
import FloatLinkEditor from './ui/lexical/components/FloatLinkEditor.vue';
Expand All @@ -130,7 +132,6 @@ import useLexicalList from './ui/lexical/composables/useLexicalList';
import useLexicalMounted from './ui/lexical/composables/useLexicalMounted';
import useRichTextSetup from './ui/lexical/composables/useRichTextSetup';
import useVariableSetup from './ui/lexical/composables/useVariableSetup';
import LexicalEditor from './ui/lexical/LexicalEditor.vue';
import * as ImageNode from './ui/lexical/nodes/ImageNode';
import * as VariableNode from './ui/lexical/nodes/VariableNode';
import LexicalAutoFocusPlugin from './ui/lexical/plugins/LexicalAutoFocusPlugin.vue';
Expand All @@ -149,6 +150,7 @@ import * as autoLink from './ui/lexical/utils/autoLink';
import * as getSelectedNode from './ui/lexical/utils/getSelectedNode';
import * as markdownTransformers from './ui/lexical/utils/markdownTransformers';
import * as node from './ui/lexical/utils/node';
import * as theme from './ui/lexical/utils/theme';
import DetailTabList from './ui/list/DetailTabList.vue';
import MarkdownEditor from './ui/markdown/MarkdownEditor.vue';
import MarkdownEditorToolbar from './ui/markdown/MarkdownEditorToolbar.vue';
Expand All @@ -166,12 +168,6 @@ import NavSidebarTree from './ui/nav/NavSidebarTree.vue';
import NavTabs from './ui/nav/NavTabs.vue';
import Switch from './ui/switch/Switch.vue';
import ActionTab from './ui/tab/ActionTab.vue';
import * as action from './ui/table/action';
import * as column from './ui/table/column';
import * as data from './ui/table/data';
import * as header from './ui/table/header';
import * as pagination from './ui/table/pagination';
import * as store from './ui/table/store';
import Table from './ui/table/Table.vue';
import TableActions from './ui/table/TableActions.vue';
import TableCell from './ui/table/TableCell.vue';
Expand All @@ -181,6 +177,12 @@ import TableHeaderAction from './ui/table/TableHeaderAction.vue';
import TableHeaderDialog from './ui/table/TableHeaderDialog.vue';
import TableHeaderDialogFilter from './ui/table/TableHeaderDialogFilter.vue';
import TableHeaderDialogSort from './ui/table/TableHeaderDialogSort.vue';
import * as action from './ui/table/action';
import * as column from './ui/table/column';
import * as data from './ui/table/data';
import * as header from './ui/table/header';
import * as pagination from './ui/table/pagination';
import * as store from './ui/table/store';
import CheckTag from './ui/tag/CheckTag.vue';
import CheckTagGroup from './ui/tag/CheckTagGroup.vue';
import LinkTag from './ui/tag/LinkTag.vue';
Expand Down Expand Up @@ -226,6 +228,7 @@ export {
useNotificationChannel as useNotificationChannel,
CreateEditNotificationSettingDialog as ClCreateEditNotificationSettingDialog,
NotificationSettingForm as ClNotificationSettingForm,
NotificationSettingTriggerSelect as ClNotificationSettingTriggerSelect,
useNotificationSetting as useNotificationSetting,
CreateEditProjectDialog as ClCreateEditProjectDialog,
ProjectForm as ClProjectForm,
Expand Down Expand Up @@ -266,10 +269,10 @@ export {
Metric as ClMetric,
ContextMenu as ClContextMenu,
ContextMenuList as ClContextMenuList,
date as date,
DateRangePicker as ClDateRangePicker,
DateTimeRangePicker as ClDateTimeRangePicker,
RangePicker as ClRangePicker,
date as date,
ConfirmDialog as ClConfirmDialog,
CreateEditDialog as ClCreateEditDialog,
Dialog as ClDialog,
Expand All @@ -283,7 +286,6 @@ export {
FileDiff as ClFileDiff,
FileEditor as ClFileEditor,
FileEditorCreateWithAiDialog as ClFileEditorCreateWithAiDialog,
fileEditorDropZone as fileEditorDropZone,
FileEditorNavMenu as ClFileEditorNavMenu,
FileEditorNavMenuContextMenu as ClFileEditorNavMenuContextMenu,
FileEditorNavTabs as ClFileEditorNavTabs,
Expand All @@ -293,21 +295,23 @@ export {
FileTab as ClFileTab,
FileUpload as ClFileUpload,
UploadFilesDialog as ClUploadFilesDialog,
filter as filter,
fileEditorDropZone as fileEditorDropZone,
FilterCondition as ClFilterCondition,
FilterConditionList as ClFilterConditionList,
FilterInput as ClFilterInput,
FilterSelect as ClFilterSelect,
filter as filter,
Form as ClForm,
FormItem as ClFormItem,
formTable as formTable,
FormTableField as ClFormTableField,
formTable as formTable,
useForm as useForm,
AtomMaterialIcon as ClAtomMaterialIcon,
icon as icon,
Icon as ClIcon,
MenuItemIcon as ClMenuItemIcon,
icon as icon,
InputList as ClInputList,
LexicalEditor as ClLexicalEditor,
BlockOptionsDropdownList as ClBlockOptionsDropdownList,
DropdownButton as ClDropdownButton,
FloatLinkEditor as ClFloatLinkEditor,
Expand All @@ -323,7 +327,6 @@ export {
useLexicalMounted as useLexicalMounted,
useRichTextSetup as useRichTextSetup,
useVariableSetup as useVariableSetup,
LexicalEditor as ClLexicalEditor,
ImageNode as ImageNode,
VariableNode as VariableNode,
LexicalAutoFocusPlugin as ClLexicalAutoFocusPlugin,
Expand All @@ -342,6 +345,7 @@ export {
getSelectedNode as getSelectedNode,
markdownTransformers as markdownTransformers,
node as node,
theme as theme,
DetailTabList as ClDetailTabList,
MarkdownEditor as ClMarkdownEditor,
MarkdownEditorToolbar as ClMarkdownEditorToolbar,
Expand All @@ -359,13 +363,6 @@ export {
NavTabs as ClNavTabs,
Switch as ClSwitch,
ActionTab as ClActionTab,
Tab as ClTab,
action as action,
column as column,
data as data,
header as header,
pagination as pagination,
store as store,
Table as ClTable,
TableActions as ClTableActions,
TableCell as ClTableCell,
Expand All @@ -375,6 +372,12 @@ export {
TableHeaderDialog as ClTableHeaderDialog,
TableHeaderDialogFilter as ClTableHeaderDialogFilter,
TableHeaderDialogSort as ClTableHeaderDialogSort,
action as action,
column as column,
data as data,
header as header,
pagination as pagination,
store as store,
CheckTag as ClCheckTag,
CheckTagGroup as ClCheckTagGroup,
LinkTag as ClLinkTag,
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/lang/en/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const common: LCommon = {
unlink: 'Unlink',
goto: 'Go To',
selectAll: 'Select All',
viewTemplate: 'View Template',
viewChannels: 'View Channels',
},
messageBox: {
confirm: {
Expand Down
Loading

0 comments on commit 045b6b9

Please sign in to comment.