Skip to content

Commit

Permalink
Merge branch 'dev/1.10.2' into enterprise
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinplemelon committed Nov 4, 2024
2 parents acc8b3a + 59879de commit 5201c38
Show file tree
Hide file tree
Showing 16 changed files with 315 additions and 41 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"echarts": "^5.2.1",
"element-plus": "~2.3.0",
"genson-js": "^0.0.8",
"github-markdown-css": "^5.7.0",
"highlight.js": "10.7.3",
"hocon-parser": "^1.0.1",
"js-base64": "^3.7.2",
Expand Down
2 changes: 1 addition & 1 deletion src/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { PostLogin200 } from '@/types/schemas/dashboard.schemas'

//account
export function login(user: { password: string; username: string }): Promise<PostLogin200> {
return http.post('/login', user)
return http.post('/login', user, { keepSpaces: true })
}

export function logout(username: string, backend: 'ldap' | 'local' = 'local') {
Expand Down
9 changes: 9 additions & 0 deletions src/common/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { stringifyObjSafely } from '@emqx/shared-ui-utils'
import _ from 'lodash'
import { API_BASE_URL, REQUEST_TIMEOUT_CODE } from '@/common/constants'
import { BAD_TOKEN, TOKEN_TIME_OUT, NAME_PWD_ERROR } from '@/common/customErrorCode'
import { trimValues } from '@/common/tools'
import i18n from '@/i18n'

NProgress.configure({ showSpinner: false, trickleSpeed: 200 })
Expand All @@ -30,6 +31,14 @@ axios.interceptors.request.use(
config.signal = controller.signal
config.controller = controller
store.commit('ADD_ABORT_CONTROLLER', controller)

if (
!config.keepSpaces &&
['post', 'put'].includes(config.method) &&
typeof config.data === 'object'
) {
config.data = trimValues(config.data)
}
return config
},
(error) => {
Expand Down
36 changes: 30 additions & 6 deletions src/common/tools.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { cloneDeep, escape, get, isFunction, isObject, isUndefined, omit, set } from 'lodash'
import { cloneDeep, escape, get, isFunction, isObject, isUndefined, omit, round, set } from 'lodash'
import moment from 'moment'
import { API_BASE_URL, COPY_SUFFIX } from './constants'
import { ListDataWithPagination } from '@/types/common'
Expand Down Expand Up @@ -400,17 +400,17 @@ const ONE_MB = ONE_KB * 1024
const ONE_GB = ONE_MB * 1024

export const transMemorySizeNumToStr = (byte: number, toFixed?: number): string => {
const getNumPart = (num: number) => (toFixed ? num.toFixed(toFixed) : num)
const getNumPart = (num: number) => (toFixed ? round(num, toFixed) : num)
if (byte < ONE_KB) {
return getNumPart(byte) + 'Byte'
return getNumPart(byte) + ' bytes'
}
if (byte < ONE_MB) {
return getNumPart(byte / ONE_KB) + 'KB'
return getNumPart(byte / ONE_KB) + ' KB'
}
if (byte < ONE_GB) {
return getNumPart(byte / ONE_MB) + 'MB'
return getNumPart(byte / ONE_MB) + ' MB'
}
return getNumPart(byte / ONE_GB) + 'GB'
return getNumPart(byte / ONE_GB) + ' GB'
}

const memoryStrReg = new RegExp(`^(\\d+(\\.\\d+)?)(${usefulMemoryUnit.join('|')})$`)
Expand Down Expand Up @@ -749,6 +749,30 @@ export const accAdd = (arg1: number, arg2: number): number => {
return (adjustedArg1 + adjustedArg2) / multiplier
}

type TrimValuesParam = string | Record<string, any> | Array<TrimValuesParam>
export const trimValues = (obj: TrimValuesParam, omitKeys?: Array<string>) => {
const ret = cloneDeep(obj)
const handle = (val: TrimValuesParam): TrimValuesParam => {
// If the value is from a textarea, don't handle spaces
if (typeof val === 'string' && !/\n/.test(val)) {
return val.trim()
}
if (Array.isArray(val)) {
return val.map((item) => handle(item))
}
if (isObject(val)) {
Object.entries(val).forEach(([key, value]) => {
if (omitKeys?.includes(key)) {
return
}
val[key] = handle(value)
})
}
return val
}
return handle(ret)
}

const getDataFromParams = (params: string): Record<string, string> => {
const str = params
if (URLSearchParams) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/FormItemLabel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<InfoTooltip v-if="desc" v-bind="$attrs">
<template #content>
<template v-if="!descMarked">{{ desc }}</template>
<MarkdownContent v-else :content="desc" />
<MarkdownContent v-else :content="desc" in-tooltip />
</template>
</InfoTooltip>
</template>
Expand Down
15 changes: 14 additions & 1 deletion src/components/MarkdownContent.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<template>
<el-row class="markdown-content" :gutter="gutter">
<el-col :span="showToc ? 18 : 24">
<div class="markdown-content" ref="containerEle"></div>
<div
class="markdown-content"
:class="{ 'markdown-body': !inTooltip }"
ref="containerEle"
></div>
</el-col>
<el-col class="toc-list" v-if="showToc" :span="6">
<div class="toc-title">{{ $t('Base.content') }}</div>
Expand All @@ -14,6 +18,7 @@

<script setup lang="ts">
/* eslint-disable @typescript-eslint/ban-ts-comment */
import 'github-markdown-css/github-markdown.css'
import { ref, defineProps, onMounted, onUnmounted, PropType, watch } from 'vue'
import { marked } from 'marked'
import xss from 'xss'
Expand All @@ -38,6 +43,14 @@ const props = defineProps({
type: Number,
default: 40,
},
/**
* do not use github style in tooltip
*/
inTooltip: {
required: false,
type: Boolean,
default: false,
},
})
const renderer = new marked.Renderer()
Expand Down
32 changes: 29 additions & 3 deletions src/components/Metrics/OverviewMetrics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
</el-row>
</div>
</div>
<slot name="custom-block" :data="currentMetrics"></slot>
<!-- Node Status Table -->
<div class="metric-block" v-if="$slots.table && !isFlowNode">
<div class="block-hd">
Expand Down Expand Up @@ -186,7 +187,7 @@ import { Metrics, MetricsDataWithExtraData, SetItem } from '@/types/common'
import { Close, Refresh } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { get } from 'lodash'
import { computed, defineProps, inject, ref } from 'vue'
import { computed, defineEmits, defineProps, inject, ref } from 'vue'
import TypeMetrics from './TypeMetrics.vue'
type MetricsData = MetricsDataWithExtraData<unknown>
Expand Down Expand Up @@ -224,6 +225,10 @@ const props = defineProps<{
nodeStatusDesc?: string
childrenTitle?: string
}>()
const emit = defineEmits<{
(e: 'metrics-change', totalMetrics: MetricsData): void
(e: 'node-change', node: string, isSelectedCluster: boolean): void
}>()
// Special handling of metric styles under Flow nodes
const isFlowNode = inject('isFlowNode', false)
Expand All @@ -242,7 +247,9 @@ const selectedNode = ref(CLUSTER)
const handleNodeChange = () => {
rateData = getInitRateData()
updateToView()
emit('node-change', selectedNode.value, selectedNode.value === CLUSTER)
}
emit('node-change', selectedNode.value, selectedNode.value === CLUSTER)
const getMetricItemLabel = (key: string) => props.textMap[key]?.label || key
const getMetricItemDesc = (key: string) => props.textMap[key]?.desc || ''
Expand Down Expand Up @@ -352,6 +359,7 @@ const getMetrics = async () => {
try {
metricsData.value = await props.requestMetrics()
updateToView()
emit('metrics-change', metricsData.value)
} catch (error) {
//
}
Expand Down Expand Up @@ -407,8 +415,6 @@ const { syncPolling } = useSyncPolling()
line-height: 32px;
color: var(--color-title-primary);
font-weight: 400;
}
.metric-num {
.unit {
margin-left: 2px;
font-size: 14px;
Expand Down Expand Up @@ -519,6 +525,26 @@ const { syncPolling } = useSyncPolling()
}
}
.num-container {
display: flex;
.metric-num {
margin-right: 8px;
}
}
.num-diff {
color: var(--color-primary);
line-height: 24px;
&.is-red {
color: #469cf7;
}
&.need-plus {
&:before {
content: '+';
margin-right: 2px;
}
}
}
.metric-bar {
.el-card__body {
display: flex;
Expand Down
26 changes: 3 additions & 23 deletions src/components/Metrics/TypeMetricsItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ const oneDetailData = computed<DetailItem>(() => props.data.detail[0])
const diff = ref(0)
watch(
() => props.data.count,
() => props.data,
(newVal, oldVal) => {
if (oldVal !== undefined && newVal !== undefined) {
diff.value = newVal - oldVal
if (oldVal?.count !== undefined && newVal?.count !== undefined) {
diff.value = newVal.count - oldVal.count
}
},
)
Expand Down Expand Up @@ -127,26 +127,6 @@ watch(
margin-right: 6px;
}
.num-container {
display: flex;
.metric-num {
margin-right: 8px;
}
}
.num-diff {
color: var(--color-primary);
line-height: 24px;
&.is-red {
color: #469cf7;
}
&.need-plus {
&:before {
content: '+';
margin-right: 2px;
}
}
}
.detail-trigger {
display: flex;
align-items: center;
Expand Down
2 changes: 1 addition & 1 deletion src/components/ObjectArrayEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</label>
<InfoTooltip v-if="value.description">
<template #content>
<MarkdownContent :content="value.description" />
<MarkdownContent :content="value.description" in-tooltip />
</template>
</InfoTooltip>
</template>
Expand Down
2 changes: 1 addition & 1 deletion src/components/SchemaForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ const SchemaForm = defineComponent({
const tooltipSlots = {
content: () => (
<el-scrollbar max-height="158px">
<MarkdownContent content={desc} gutter={0} />
<MarkdownContent content={desc} gutter={0} inTooltip={true} />
</el-scrollbar>
),
}
Expand Down
Loading

0 comments on commit 5201c38

Please sign in to comment.