debian-mirror-gitlab/app/assets/javascripts/behaviors/components/json_table.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
1.4 KiB
Vue
Raw Normal View History

2022-08-27 11:52:29 +05:30
<script>
import { GlTable, GlFormInput } from '@gitlab/ui';
import { __ } from '~/locale';
export default {
components: {
GlTable,
GlFormInput,
},
props: {
fields: {
type: Array,
required: true,
},
items: {
type: Array,
required: true,
},
hasFilter: {
type: Boolean,
required: false,
default: false,
},
caption: {
type: String,
required: false,
default: __('Generated with JSON data'),
},
},
data() {
return {
filterInput: '',
};
},
computed: {
cleanedFields() {
return this.fields.map((field) => {
if (typeof field === 'string') {
return field;
}
return {
key: field.key,
label: field.label,
sortable: field.sortable || false,
2023-07-09 08:55:56 +05:30
class: field.class || [],
2022-08-27 11:52:29 +05:30
};
});
},
},
};
</script>
<template>
<div class="gl-display-inline-block">
<gl-form-input
v-if="hasFilter"
v-model="filterInput"
:placeholder="__('Type to search')"
class="gl-mb-2!"
/>
<gl-table
:fields="cleanedFields"
:items="items"
:filter="filterInput"
show-empty
class="gl-mt-0!"
>
<template v-if="caption" #table-caption>
<small>{{ caption }}</small>
</template>
</gl-table>
</div>
</template>