Skip to content

Commit

Permalink
Merge pull request #77 from open-contracting/feature/ui-previews
Browse files Browse the repository at this point in the history
feat: ui for previews
  • Loading branch information
olehchepak committed Apr 13, 2021
2 parents 6fda881 + 847896a commit e04eaf6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
31 changes: 27 additions & 4 deletions frontend/src/components/App/AppTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
</thead>
<tbody>
<tr v-for="(row, rowIndex) in data" :key="rowIndex">
<td v-for="(col, colIndex) in row" :key="colIndex">{{ col }}</td>
<td
v-for="(col, colIndex) in row"
:class="{ highlighted: highlightedCols.includes(colIndex) }"
:key="colIndex"
>
{{ col }}
</td>
</tr>
</tbody>
</template>
Expand Down Expand Up @@ -55,14 +61,28 @@ export default {
type: Boolean,
default: false,
},
additionalColumns: {
type: Array,
required: true,
},
},
computed: {
highlightedCols() {
return this.headers.reduce((acc, header, idx) => {
if (this.additionalColumns.includes(header)) {
acc.push(idx);
}
return acc;
}, []);
},
},
};
</script>

<style scoped lang="scss">
.app-table {
&__name {
}
max-width: 100%;
::v-deep table {
border-collapse: collapse !important;
Expand All @@ -75,9 +95,12 @@ export default {
color: map-get($colors, 'darkest') !important;
}
th {
max-width: 100px;
min-width: 100px;
background-color: #facd91;
}
td.highlighted {
background-color: #b6bafd;
}
}
}
</style>
13 changes: 10 additions & 3 deletions frontend/src/components/CustomizeTables/CustomizeTablesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
:data="table.data"
:include="table.include"
:allow-actions="idx !== 0"
:additional-columns="additionalColumns"
@remove="changeIncludeStatus(table, false)"
@restore="changeIncludeStatus(table, true)"
/>
Expand Down Expand Up @@ -139,6 +140,10 @@ export default {
return res;
},
additionalColumns() {
return this.additionalInfo.available_data?.columns?.additional || [];
},
availableData() {
const res = [];
const availableColumns = this.additionalInfo.available_data?.columns?.available;
Expand All @@ -150,8 +155,8 @@ export default {
);
res.push(this.$gettextInterpolate(translated, { n: availableColumns }));
}
const additionalColumns = this.additionalInfo.available_data?.additional;
if (additionalColumns) {
const additionalColumns = this.additionalInfo.available_data?.columns?.additional;
if (additionalColumns?.length) {
let translated = this.$ngettext(
'There is %{ n } column with additional data not part of OCDS',
'There are %{ n } columns with additional data not part of OCDS',
Expand Down Expand Up @@ -206,7 +211,9 @@ export default {
);
this.tables = await Promise.all(
data.map(async (preview) => {
const parsed = await Papa.parse(data[0].preview);
const parsed = await Papa.parse(data[0].preview, {
skipEmptyLines: true,
});
return {
id: preview.id,
name: preview.name,
Expand Down
17 changes: 17 additions & 0 deletions frontend/tests/unit/components/App/AppTable.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { mount } from '@vue/test-utils';
import AppTable from '@/components/App/AppTable';

describe('AppTable.vue', () => {
test("'highlightedCols' returns indexes of additional columns", () => {
const wrapper = mount(AppTable, {
propsData: {
name: 'Test',
headers: ['h1', 'h2', 'h3', 'h4', 'h5'],
data: [['d1', 'd2', 'd3', 'd4', 'd5']],
additionalColumns: ['h2', 'h3'],
},
});

expect(wrapper.vm.highlightedCols).toStrictEqual([1, 2]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('CustomizeTablesTable.vue', () => {
name: 'documents',
},
});
expect(wrapper.vm.availableData.length).toBe(2);
expect(wrapper.vm.availableData.length).toBe(0);
expect(wrapper.vm.arrays.length).toBe(0);
});

Expand Down

0 comments on commit e04eaf6

Please sign in to comment.