Skip to content
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

test(ui): fixes default values not set TCTC-4635 #1602

Merged
merged 9 commits into from
Nov 14, 2022
Prev Previous commit
Next Next commit
refactor(ui): switch TabbedRangeCalendar to defineComponent
Same problem of default value
  • Loading branch information
davinov committed Nov 14, 2022
commit 594ca91a6f338408056260c93d749d6a96bea2c7
Original file line number Diff line number Diff line change
Expand Up @@ -37,78 +37,109 @@ import Tabs from '@/components/Tabs.vue';
import type { CustomDateRange, DateRange } from '@/lib/dates';
import t from '@/lib/internationalization';
import type { LocaleIdentifier } from '@/lib/internationalization';
import { defineComponent, type PropType } from 'vue';

@Component({
export default defineComponent({
name: 'tabbed-range-calendars',

components: {
Tabs,
Calendar,
CustomGranularityCalendar,
},
})
export default class TabbedRangeCalendars extends Vue {
@Prop({ default: () => ({}) })
value!: CustomDateRange;

@Prop({ default: () => ({}) })
bounds!: DateRange;

@Prop({ default: () => ['year', 'quarter', 'month', 'week', 'day'] })
enabledCalendars!: string[];
props: {
value: {
type: Object as PropType<CustomDateRange>,
default: () => ({}),
},

bounds: {
type: Object as PropType<DateRange>,
default: () => ({}),
},

enabledCalendars: {
type: Array as PropType<string[]>,
default: () => ['year', 'quarter', 'month', 'week', 'day'],
},

locale: {
type: String as PropType<LocaleIdentifier>,
},

compactMode: {
type: Boolean as PropType<boolean>,
default: false,
},
},

@Prop({ type: String, required: false })
locale?: LocaleIdentifier;
emits: {
input: (_val: CustomDateRange) => true,
},

@Prop({ default: false })
compactMode!: boolean;
data(): {
selectedTab: string;
} {
return {
selectedTab: this.enabledCalendars[0],
};
},

selectedTab = this.enabledCalendars[0];
computed: {
currentValue: {
get(): CustomDateRange {
return this.value;
},
set(value: CustomDateRange) {
this.$emit('input', value);
},
},

calendarGranularity(): string | undefined {
return this.selectedTab !== 'day' ? this.selectedTab : undefined;
},
},

created() {
this.updateTabForCurrentValue();
}

@Watch('enabledCalendars')
onEnabledCalendarsChange() {
if (
!this.enabledCalendars.includes(this.selectedTab) ||
(this.value.duration && !this.enabledCalendars.includes(this.value.duration))
) {
this.selectedTab = this.enabledCalendars[0];
}
}

@Watch('value')
onValueChange() {
this.updateTabForCurrentValue();
}

get currentValue(): CustomDateRange {
return this.value;
}

set currentValue(value: CustomDateRange) {
this.$emit('input', value);
}
},

get calendarGranularity(): string | undefined {
return this.selectedTab !== 'day' ? this.selectedTab : undefined;
}
methods: {
updateTabForCurrentValue() {
if (this.value.duration && this.enabledCalendars.includes(this.value.duration)) {
this.selectTab(this.value.duration);
}
},

updateTabForCurrentValue() {
if (this.value.duration && this.enabledCalendars.includes(this.value.duration)) {
this.selectTab(this.value.duration);
}
}
selectTab(tab: string) {
this.selectedTab = tab;
},

selectTab(tab: string) {
this.selectedTab = tab;
}
translateTab(tab: string) {
return t(tab.toUpperCase(), this.locale);
},
},

translateTab(tab: string) {
return t(tab.toUpperCase(), this.locale);
}
}
watch: {
enabledCalendars: {
handler: function onEnabledCalendarsChange() {
if (
!this.enabledCalendars.includes(this.selectedTab) ||
(this.value.duration && !this.enabledCalendars.includes(this.value.duration))
) {
this.selectedTab = this.enabledCalendars[0];
}
},
},

value: {
handler: function onValueChange() {
this.updateTabForCurrentValue();
},
},
},
});
</script>

<style scoped lang="scss">
Expand Down