fix: added translation in ViewControls Component

also added in Filter, SortBy & ColumnSettings components
This commit is contained in:
Shariq Ansari 2024-04-15 16:23:43 +05:30
parent e9ad564fdc
commit 97edec317a
4 changed files with 43 additions and 33 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<NestedPopover> <NestedPopover>
<template #target> <template #target>
<Button label="Columns"> <Button :label="__('Columns')">
<template #prefix> <template #prefix>
<ColumnsIcon class="h-4" /> <ColumnsIcon class="h-4" />
</template> </template>

View File

@ -1,7 +1,7 @@
<template> <template>
<NestedPopover> <NestedPopover>
<template #target> <template #target>
<Button label="Filter"> <Button :label="__('Filter')">
<template #prefix><FilterIcon class="h-4" /></template> <template #prefix><FilterIcon class="h-4" /></template>
<template v-if="filters?.size" #suffix> <template v-if="filters?.size" #suffix>
<div <div

View File

@ -1,7 +1,7 @@
<template> <template>
<NestedPopover> <NestedPopover>
<template #target> <template #target>
<Button label="Sort" ref="sortButtonRef"> <Button :label="__('Sort')" ref="sortButtonRef">
<template #prefix><SortIcon class="h-4" /></template> <template #prefix><SortIcon class="h-4" /></template>
<template v-if="sortValues?.size" #suffix> <template v-if="sortValues?.size" #suffix>
<div <div

View File

@ -3,7 +3,7 @@
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<Dropdown :options="viewsDropdownOptions"> <Dropdown :options="viewsDropdownOptions">
<template #default="{ open }"> <template #default="{ open }">
<Button :label="currentView.label"> <Button :label="__(currentView.label)">
<template #prefix> <template #prefix>
<FeatherIcon :name="currentView.icon" class="h-4" /> <FeatherIcon :name="currentView.icon" class="h-4" />
</template> </template>
@ -29,11 +29,11 @@
v-if="viewUpdated && route.query.view && (!view.public || isManager())" v-if="viewUpdated && route.query.view && (!view.public || isManager())"
class="flex items-center gap-2 border-r pr-2" class="flex items-center gap-2 border-r pr-2"
> >
<Button label="Cancel" @click="cancelChanges" /> <Button :label="__('Cancel')" @click="cancelChanges" />
<Button label="Save Changes" @click="saveView" /> <Button :label="__('Save Changes')" @click="saveView" />
</div> </div>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<Button label="Refresh" @click="reload()" :loading="isLoading"> <Button :label="__('Refresh')" @click="reload()" :loading="isLoading">
<template #icon> <template #icon>
<RefreshIcon class="h-4 w-4" /> <RefreshIcon class="h-4 w-4" />
</template> </template>
@ -55,11 +55,11 @@
v-if="!options.hideColumnsButton" v-if="!options.hideColumnsButton"
:options="[ :options="[
{ {
group: 'Options', group: __('Options'),
hideLabel: true, hideLabel: true,
items: [ items: [
{ {
label: 'Export', label: __('Export'),
icon: () => icon: () =>
h(FeatherIcon, { name: 'download', class: 'h-4 w-4' }), h(FeatherIcon, { name: 'download', class: 'h-4 w-4' }),
onClick: () => (showExportDialog = true), onClick: () => (showExportDialog = true),
@ -96,10 +96,10 @@
<Dialog <Dialog
v-model="showExportDialog" v-model="showExportDialog"
:options="{ :options="{
title: 'Export', title: __('Export'),
actions: [ actions: [
{ {
label: 'Download', label: __('Download'),
variant: 'solid', variant: 'solid',
onClick: () => exportRows(), onClick: () => exportRows(),
}, },
@ -109,16 +109,25 @@
<template #body-content> <template #body-content>
<FormControl <FormControl
variant="outline" variant="outline"
label="Export Type" :label="__('Export Type')"
type="select" type="select"
:options="['Excel', 'CSV']" :options="[
{
label: __('Excel'),
value: 'Excel',
},
{
label: __('CSV'),
value: 'CSV',
},
]"
v-model="export_type" v-model="export_type"
placeholder="Select Export Type" :placeholder="__('Excel')"
/> />
<div class="mt-3"> <div class="mt-3">
<FormControl <FormControl
type="checkbox" type="checkbox"
:label="`Export All ${list.data.total_count} Records`" :label="__('Export All {0} Record(s)', [list.data.total_count])"
v-model="export_all" v-model="export_all"
/> />
</div> </div>
@ -321,7 +330,7 @@ async function exportRows() {
const defaultViews = [ const defaultViews = [
{ {
label: props.options?.defaultViewName || 'List View', label: __(props.options?.defaultViewName) || __('List View'),
icon: 'list', icon: 'list',
onClick() { onClick() {
viewUpdated.value = false viewUpdated.value = false
@ -333,7 +342,7 @@ const defaultViews = [
const viewsDropdownOptions = computed(() => { const viewsDropdownOptions = computed(() => {
let _views = [ let _views = [
{ {
group: 'Default Views', group: __('Default Views'),
hideLabel: true, hideLabel: true,
items: defaultViews, items: defaultViews,
}, },
@ -341,6 +350,7 @@ const viewsDropdownOptions = computed(() => {
if (list.value?.data?.views) { if (list.value?.data?.views) {
list.value.data.views.forEach((view) => { list.value.data.views.forEach((view) => {
view.label = __(view.label)
view.icon = view.icon || 'list' view.icon = view.icon || 'list'
view.filters = view.filters =
typeof view.filters == 'string' typeof view.filters == 'string'
@ -359,18 +369,18 @@ const viewsDropdownOptions = computed(() => {
publicViews.length && publicViews.length &&
_views.push({ _views.push({
group: 'Public Views', group: __('Public Views'),
items: publicViews, items: publicViews,
}) })
savedViews.length && savedViews.length &&
_views.push({ _views.push({
group: 'Saved Views', group: __('Saved Views'),
items: savedViews, items: savedViews,
}) })
pinnedViews.length && pinnedViews.length &&
_views.push({ _views.push({
group: 'Pinned Views', group: __('Pinned Views'),
items: pinnedViews, items: pinnedViews,
}) })
} }
@ -489,11 +499,11 @@ function updatePageLength(value, loadMore = false) {
const viewActions = computed(() => { const viewActions = computed(() => {
let actions = [ let actions = [
{ {
group: 'Default Views', group: __('Default Views'),
hideLabel: true, hideLabel: true,
items: [ items: [
{ {
label: 'Duplicate', label: __('Duplicate'),
icon: () => h(DuplicateIcon, { class: 'h-4 w-4' }), icon: () => h(DuplicateIcon, { class: 'h-4 w-4' }),
onClick: () => duplicateView(), onClick: () => duplicateView(),
}, },
@ -503,14 +513,14 @@ const viewActions = computed(() => {
if (route.query.view && (!view.value.public || isManager())) { if (route.query.view && (!view.value.public || isManager())) {
actions[0].items.push({ actions[0].items.push({
label: 'Rename', label: __('Rename'),
icon: () => h(EditIcon, { class: 'h-4 w-4' }), icon: () => h(EditIcon, { class: 'h-4 w-4' }),
onClick: () => renameView(), onClick: () => renameView(),
}) })
if (!view.value.public) { if (!view.value.public) {
actions[0].items.push({ actions[0].items.push({
label: view.value.pinned ? 'Unpin View' : 'Pin View', label: view.value.pinned ? __('Unpin View') : __('Pin View'),
icon: () => icon: () =>
h(view.value.pinned ? UnpinIcon : PinIcon, { class: 'h-4 w-4' }), h(view.value.pinned ? UnpinIcon : PinIcon, { class: 'h-4 w-4' }),
onClick: () => pinView(), onClick: () => pinView(),
@ -519,7 +529,7 @@ const viewActions = computed(() => {
if (isManager()) { if (isManager()) {
actions[0].items.push({ actions[0].items.push({
label: view.value.public ? 'Make Private' : 'Make Public', label: view.value.public ? __('Make Private') : __('Make Public'),
icon: () => icon: () =>
h(FeatherIcon, { h(FeatherIcon, {
name: view.value.public ? 'lock' : 'unlock', name: view.value.public ? 'lock' : 'unlock',
@ -530,20 +540,20 @@ const viewActions = computed(() => {
} }
actions.push({ actions.push({
group: 'Delete View', group: __('Delete View'),
hideLabel: true, hideLabel: true,
items: [ items: [
{ {
label: 'Delete', label: __('Delete'),
icon: 'trash-2', icon: 'trash-2',
onClick: () => onClick: () =>
$dialog({ $dialog({
title: 'Delete View', title: __('Delete View'),
message: 'Are you sure you want to delete this view?', message: __('Are you sure you want to delete this view?'),
variant: 'danger', variant: 'danger',
actions: [ actions: [
{ {
label: 'Delete', label: __('Delete'),
variant: 'solid', variant: 'solid',
theme: 'red', theme: 'red',
onClick: (close) => deleteView(close), onClick: (close) => deleteView(close),
@ -558,15 +568,15 @@ const viewActions = computed(() => {
}) })
function duplicateView() { function duplicateView() {
let label = getView(route.query.view)?.label || 'List View' let label = __(getView(route.query.view)?.label) || __('List View')
view.value.name = '' view.value.name = ''
view.value.label = label + ' (New)' view.value.label = label + __(' (New)')
showViewModal.value = true showViewModal.value = true
} }
function renameView() { function renameView() {
view.value.name = route.query.view view.value.name = route.query.view
view.value.label = getView(route.query.view).label view.value.label = __(getView(route.query.view).label)
showViewModal.value = true showViewModal.value = true
} }