# Pull Request Template ## Description This PR adds new eslint rules to the code base. **Error rules** | Rule name | Type | Files updated | | ----------------- | --- | - | | `vue/block-order` | error | ✅ | | `vue/component-name-in-template-casing` | error | ✅ | | `vue/component-options-name-casing` | error | ✅ | | `vue/custom-event-name-casing` | error | ✅ | | `vue/define-emits-declaration` | error | ✅ | | `vue/no-unused-properties` | error | ✅ | | `vue/define-macros-order` | error | ✅ | | `vue/define-props-declaration` | error | ✅ | | `vue/match-component-import-name` | error | ✅ | | `vue/next-tick-style` | error | ✅ | | `vue/no-bare-strings-in-template` | error | ✅ | | `vue/no-empty-component-block` | error | ✅ | | `vue/no-multiple-objects-in-class` | error | ✅ | | `vue/no-required-prop-with-default` | error | ✅ | | `vue/no-static-inline-styles` | error | ✅ | | `vue/no-template-target-blank` | error | ✅ | | `vue/no-this-in-before-route-enter` | error | ✅ | | `vue/no-undef-components` | error | ✅ | | `vue/no-unused-emit-declarations` | error | ✅ | | `vue/no-unused-refs` | error | ✅ | | `vue/no-use-v-else-with-v-for` | error | ✅ | | `vue/no-useless-v-bind` | error | ✅ | | `vue/no-v-text` | error | ✅ | | `vue/padding-line-between-blocks` | error | ✅ | | ~`vue/prefer-prop-type-boolean-first`~ | ~error~ | ❌ (removed this rule, cause a bug in displaying custom attributes) | | `vue/prefer-separate-static-class` | error | ✅ | | `vue/prefer-true-attribute-shorthand` | error | ✅ | | `vue/require-explicit-slots` | error | ✅ | | `vue/require-macro-variable-name` | error | ✅ | **Warn rules** | Rule name | Type | Files updated | | ---- | ------------- | ------------- | | `vue/no-root-v-if` | warn | ❎ | Fixes https://linear.app/chatwoot/issue/CW-3492/vue-eslint-rules ## Type of change - [x] New feature (non-breaking change which adds functionality) ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Fayaz Ahmed <fayazara@gmail.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Shivam Mishra <scm.mymail@gmail.com> Co-authored-by: Pranav <pranav@chatwoot.com>
155 lines
3.6 KiB
Vue
155 lines
3.6 KiB
Vue
<script>
|
|
import { evaluateSLAStatus } from '@chatwoot/utils';
|
|
import SLAPopoverCard from './SLAPopoverCard.vue';
|
|
|
|
const REFRESH_INTERVAL = 60000;
|
|
|
|
export default {
|
|
components: {
|
|
SLAPopoverCard,
|
|
},
|
|
props: {
|
|
chat: {
|
|
type: Object,
|
|
default: () => ({}),
|
|
},
|
|
showExtendedInfo: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
timer: null,
|
|
showSlaPopover: false,
|
|
slaStatus: {
|
|
threshold: null,
|
|
isSlaMissed: false,
|
|
type: null,
|
|
icon: null,
|
|
},
|
|
};
|
|
},
|
|
computed: {
|
|
slaPolicyId() {
|
|
return this.chat?.sla_policy_id;
|
|
},
|
|
appliedSLA() {
|
|
return this.chat?.applied_sla;
|
|
},
|
|
slaEvents() {
|
|
return this.chat?.sla_events;
|
|
},
|
|
hasSlaThreshold() {
|
|
return this.slaStatus?.threshold;
|
|
},
|
|
isSlaMissed() {
|
|
return this.slaStatus?.isSlaMissed;
|
|
},
|
|
slaTextStyles() {
|
|
return this.isSlaMissed
|
|
? 'text-red-400 dark:text-red-300'
|
|
: 'text-yellow-600 dark:text-yellow-500';
|
|
},
|
|
slaStatusText() {
|
|
const upperCaseType = this.slaStatus?.type?.toUpperCase(); // FRT, NRT, or RT
|
|
const statusKey = this.isSlaMissed ? 'MISSED' : 'DUE';
|
|
|
|
return this.$t(`CONVERSATION.HEADER.SLA_STATUS.${upperCaseType}`, {
|
|
status: this.$t(`CONVERSATION.HEADER.SLA_STATUS.${statusKey}`),
|
|
});
|
|
},
|
|
showSlaPopoverCard() {
|
|
return (
|
|
this.showExtendedInfo && this.showSlaPopover && this.slaEvents.length
|
|
);
|
|
},
|
|
},
|
|
watch: {
|
|
chat() {
|
|
this.updateSlaStatus();
|
|
},
|
|
},
|
|
mounted() {
|
|
this.updateSlaStatus();
|
|
this.createTimer();
|
|
},
|
|
beforeDestroy() {
|
|
if (this.timer) {
|
|
clearTimeout(this.timer);
|
|
}
|
|
},
|
|
methods: {
|
|
createTimer() {
|
|
this.timer = setTimeout(() => {
|
|
this.updateSlaStatus();
|
|
this.createTimer();
|
|
}, REFRESH_INTERVAL);
|
|
},
|
|
updateSlaStatus() {
|
|
this.slaStatus = evaluateSLAStatus({
|
|
appliedSla: this.appliedSLA,
|
|
chat: this.chat,
|
|
});
|
|
},
|
|
openSlaPopover() {
|
|
if (!this.showExtendedInfo) return;
|
|
this.showSlaPopover = true;
|
|
},
|
|
closeSlaPopover() {
|
|
this.showSlaPopover = false;
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
v-if="hasSlaThreshold"
|
|
class="relative flex items-center border cursor-pointer min-w-fit border-slate-100 dark:border-slate-700"
|
|
:class="showExtendedInfo ? 'h-[26px] rounded-lg' : 'rounded h-5'"
|
|
>
|
|
<div
|
|
v-on-clickaway="closeSlaPopover"
|
|
class="flex items-center w-full truncate"
|
|
:class="showExtendedInfo ? 'px-1.5' : 'px-2 gap-1'"
|
|
@mouseover="openSlaPopover()"
|
|
>
|
|
<div
|
|
class="flex items-center gap-1"
|
|
:class="
|
|
showExtendedInfo &&
|
|
'ltr:pr-1.5 rtl:pl-1.5 ltr:border-r rtl:border-l border-solid border-slate-100 dark:border-slate-700'
|
|
"
|
|
>
|
|
<fluent-icon
|
|
size="14"
|
|
:icon="slaStatus.icon"
|
|
type="outline"
|
|
:icon-lib="isSlaMissed ? 'lucide' : 'fluent'"
|
|
class="flex-shrink-0"
|
|
:class="slaTextStyles"
|
|
/>
|
|
<span
|
|
v-if="showExtendedInfo"
|
|
class="text-xs font-medium"
|
|
:class="slaTextStyles"
|
|
>
|
|
{{ slaStatusText }}
|
|
</span>
|
|
</div>
|
|
<span
|
|
class="text-xs font-medium"
|
|
:class="[slaTextStyles, showExtendedInfo && 'ltr:pl-1.5 rtl:pr-1.5']"
|
|
>
|
|
{{ slaStatus.threshold }}
|
|
</span>
|
|
</div>
|
|
<SLAPopoverCard
|
|
v-if="showSlaPopoverCard"
|
|
:sla-missed-events="slaEvents"
|
|
class="right-0 top-7"
|
|
/>
|
|
</div>
|
|
</template>
|