Skip to content

Commit ed2863e

Browse files
authored
Task/tup 534 auto get correct data col value (#277)
* test: get correct data-col value (INCOMPLETE) * feat: get correct col names & values (INCOMPLETE) * feat: get correct col names & values (SUCCESS) * chore: clean up new helper getColFromRow * refactor: less chars in hbs, more logic in config * fix: remove cruft change * chore: remove console.log * fix: missing cols breaks getColFromRow * chore: simplify previous fix
1 parent 790f4c9 commit ed2863e

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

fractal.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ engine.handlebars.registerHelper('eq', function(a, b) {
9898
engine.handlebars.registerHelper('has', function(array, item) {
9999
return array.includes(item);
100100
});
101+
engine.handlebars.registerHelper('getColFromRow', function(row, val, cols) {
102+
if ( ! cols ) return '';
103+
104+
const index = Object.entries(row).findIndex(el => el[1] === val);
105+
const col = cols[index];
106+
107+
return col;
108+
});
101109

102110
// Export
103111
module.exports = fractal;

src/lib/_imports/elements/table/table.hbs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@
1818
{{/each}}
1919
{{#each data.rows}}
2020
<tr>
21-
{{#if id}}<td data-col="ID">{{ id }}</td>{{/if}}
22-
{{#if name}}<td data-col="Name">{{ name }}</td>{{/if}}
23-
{{#if name-link}}<td data-col="Name"><a href="#">{{ name-link }}</a></td>{{/if}}
21+
{{#if id}}<td data-col="{{ getColFromRow this id @root.data.cols }}">{{ id }}</td>{{/if}}
22+
{{#if name}}<td data-col="{{ getColFromRow this name @root.data.cols }}">{{ name }}</td>{{/if}}
23+
{{#if name-link}}<td data-col="{{ getColFromRow this name-link @root.data.cols }}"><a href="#">{{ name-link }}</a></td>{{/if}}
2424
{{#if paragraph}}
25-
<td data-col="Summary" title="{{> @text-of-one-paragraph-short }}">
25+
<td data-col="{{ getColFromRow this paragraph @root.data.cols }}" title="{{> @text-of-one-paragraph-short }}">
2626
<p>{{> @text-of-one-paragraph-short }}</p>
2727
</td>
2828
{{/if}}
2929
{{#if sentence}}
30-
<td data-col="Sentence" title="{{> @text-of-one-sentence }}">
30+
<td data-col="{{ getColFromRow this sentence @root.data.cols }}" title="{{> @text-of-one-sentence }}">
3131
<span>{{> @text-of-one-sentence }}</span>
3232
</td>
3333
{{/if}}
34-
{{#if custom-1}}<td data-col="Size">{{{ custom-1 }}}</td>{{/if}}
35-
{{#if custom-2}}<td data-col="">{{{ custom-2 }}}</td>{{/if}}
36-
{{#if custom-3}}<td data-col="">{{{ custom-3 }}}</td>{{/if}}
37-
{{#if time}}<td data-col="Time"><time>{{ time }}</time></td>{{/if}}
34+
{{#if custom-1}}<td data-col="{{ getColFromRow this custom-1 @root.data.cols }}">{{{ custom-1 }}}</td>{{/if}}
35+
{{#if custom-2}}<td data-col="{{ getColFromRow this custom-2 @root.data.cols }}">{{{ custom-2 }}}</td>{{/if}}
36+
{{#if custom-3}}<td data-col="{{ getColFromRow this custom-3 @root.data.cols }}">{{{ custom-3 }}}</td>{{/if}}
37+
{{#if time}}<td data-col="{{ getColFromRow this time @root.data.cols }}"><time>{{ time }}</time></td>{{/if}}
3838
{{#if acts}}
39-
<td data-col="Actions">
39+
<td data-col="{{ getColFromRow this acts @root.data.cols }}">
4040
<ul>
4141
{{#each acts}}
4242
{{#if is-link }}<li><a href="#">{{ text }}</a></li>{{/if}}

0 commit comments

Comments
 (0)