feat: Article table component (#5018)

This commit is contained in:
Muhsin Keloth 2022-07-18 10:47:15 +05:30 committed by GitHub
parent bba3475083
commit 21a8b79aa5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 202 additions and 26 deletions

View file

@ -1,29 +1,30 @@
<template> <template>
<tbody> <tr>
<tr> <td>
<td> <div class="row--article-block">
<div class="row--article-block"> <div class="article-block">
<div class="article-block"> <h6 class="sub-block-title text-truncate">
<h6 class="sub-block-title text-truncate"> <router-link class="article-name" :to="articlePath">
<router-link class="article-name"> {{ title }} </router-link> {{ title }}
</h6> </router-link>
<div class="author"> </h6>
<span class="by">{{ $t('HELP_CENTER.TABLE.COLUMNS.BY') }}</span> <div class="author">
<span class="name">{{ articleAuthorName }}</span> <span class="by">{{ $t('HELP_CENTER.TABLE.COLUMNS.BY') }}</span>
</div> <span class="name">{{ articleAuthorName }}</span>
</div> </div>
</div> </div>
</td> </div>
<td>{{ category }}</td> </td>
<td>{{ readCount }}</td> <td>{{ category }}</td>
<td> <td>{{ readCount }}</td>
<Label :title="status" color-scheme="success" /> <td>
</td> <Label :title="status" :color-scheme="labelColor" />
<td>{{ lastUpdatedAt }}</td> </td>
</tr> <td>{{ lastUpdatedAt }}</td>
</tbody> </tr>
</template> </template>
<script> <script>
import { frontendURL } from 'dashboard/helper/URLHelper';
import Label from 'dashboard/components/ui/Label'; import Label from 'dashboard/components/ui/Label';
import timeMixin from 'dashboard/mixins/time'; import timeMixin from 'dashboard/mixins/time';
export default { export default {
@ -31,6 +32,7 @@ export default {
Label, Label,
}, },
mixins: [timeMixin], mixins: [timeMixin],
props: { props: {
title: { title: {
type: String, type: String,
@ -52,13 +54,14 @@ export default {
status: { status: {
type: String, type: String,
default: 'draft', default: 'draft',
values: ['archived', 'draft', 'archived'], values: ['archived', 'draft', 'published'],
}, },
updatedAt: { updatedAt: {
type: Number, type: Number,
default: 0, default: 0,
}, },
}, },
computed: { computed: {
lastUpdatedAt() { lastUpdatedAt() {
return this.dynamicTime(this.updatedAt); return this.dynamicTime(this.updatedAt);
@ -66,19 +69,29 @@ export default {
articleAuthorName() { articleAuthorName() {
return this.author.name; return this.author.name;
}, },
labelColor() {
switch (this.status) {
case 'archived':
return 'secondary';
case 'draft':
return 'warning';
default:
return 'success';
}
},
articlePath() {
return frontendURL(`accounts/${this.accountId}/hc/articles/${this.id}`);
},
}, },
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
tbody {
width: 100%;
display: table;
}
td { td {
font-weight: var(--font-weight-normal); font-weight: var(--font-weight-normal);
color: var(--s-700); color: var(--s-700);
font-size: var(--font-size-mini); font-size: var(--font-size-mini);
padding-left: 0;
} }
.row--article-block { .row--article-block {
align-items: center; align-items: center;

View file

@ -0,0 +1,72 @@
import ArticleTableComponent from './ArticleTable.vue';
import { action } from '@storybook/addon-actions';
export default {
title: 'Components/Help Center',
component: ArticleTableComponent,
argTypes: {
articles: {
defaultValue: [],
control: {
type: 'array',
},
},
articleCount: {
defaultValue: 10,
control: {
type: 'number',
},
},
currentPage: {
defaultValue: 1,
control: {
type: 'number',
},
},
},
};
const Template = (args, { argTypes }) => ({
props: Object.keys(argTypes),
components: { ArticleTableComponent },
template:
'<article-table-component @onPageChange="onPageChange" v-bind="$props" ></article-table-component>',
});
export const ArticleTable = Template.bind({});
ArticleTable.args = {
articles: [
{
title: 'Setup your account',
author: {
name: 'John Doe',
},
readCount: 13,
category: 'Getting started',
status: 'published',
updatedAt: 1657255863,
},
{
title: 'Docker Configuration',
author: {
name: 'Sam Manuel',
},
readCount: 13,
category: 'Engineering',
status: 'draft',
updatedAt: 1656658046,
},
{
title: 'Campaigns',
author: {
name: 'Sam Manuel',
},
readCount: 28,
category: 'Engineering',
status: 'archived',
updatedAt: 1657590446,
},
],
articleCount: 10,
currentPage: 1,
onPageChange: action('onPageChange'),
};

View file

@ -0,0 +1,84 @@
<template>
<div class="article-container">
<table>
<thead>
<tr>
<th scope="col">{{ $t('HELP_CENTER.TABLE.HEADERS.TITLE') }}</th>
<th scope="col">{{ $t('HELP_CENTER.TABLE.HEADERS.CATEGORY') }}</th>
<th scope="col">{{ $t('HELP_CENTER.TABLE.HEADERS.READ_COUNT') }}</th>
<th scope="col">{{ $t('HELP_CENTER.TABLE.HEADERS.STATUS') }}</th>
<th scope="col">{{ $t('HELP_CENTER.TABLE.HEADERS.LAST_EDITED') }}</th>
</tr>
</thead>
<tr>
<td colspan="100%" class="horizontal-line" />
</tr>
<tbody>
<ArticleItem
v-for="article in articles"
:key="article.id"
:title="article.title"
:author="article.author"
:category="article.category"
:read-count="article.readCount"
:status="article.status"
:updated-at="article.updatedAt"
/>
</tbody>
</table>
<table-footer
:on-page-change="onPageChange"
:current-page="Number(currentPage)"
:total-count="articleCount"
/>
</div>
</template>
<script>
import ArticleItem from './ArticleItem.vue';
import TableFooter from 'dashboard/components/widgets/TableFooter';
export default {
components: {
ArticleItem,
TableFooter,
},
props: {
articles: {
type: Array,
default: () => {},
},
articleCount: {
type: Number,
default: 0,
},
currentPage: {
type: Number,
default: 1,
},
},
methods: {
onPageChange() {
this.$emit('onPageChange');
},
},
};
</script>
<style lang="scss" scoped>
.article-container {
width: 100%;
table thead th {
font-weight: var(--font-weight-bold);
text-transform: capitalize;
color: var(--s-700);
font-size: var(--font-size-small);
padding-left: 0;
}
.horizontal-line {
border-bottom: 1px solid var(--color-border);
}
.footer {
padding: 0;
}
}
</style>

View file

@ -16,6 +16,13 @@
"SAVED": "Draft saved" "SAVED": "Draft saved"
}, },
"TABLE": { "TABLE": {
"HEADERS": {
"TITLE": "Title",
"CATEGORY": "Category",
"READ_COUNT": "Read count",
"STATUS": "Status",
"LAST_EDITED": "Last edited"
},
"COLUMNS": { "COLUMNS": {
"BY": "by" "BY": "by"
} }