Skip to content

Commit

Permalink
Task/tup 534 auto get correct data col value (#277)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
wesleyboar authored Nov 30, 2023
1 parent 790f4c9 commit ed2863e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 8 additions & 0 deletions fractal.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ engine.handlebars.registerHelper('eq', function(a, b) {
engine.handlebars.registerHelper('has', function(array, item) {
return array.includes(item);
});
engine.handlebars.registerHelper('getColFromRow', function(row, val, cols) {
if ( ! cols ) return '';

const index = Object.entries(row).findIndex(el => el[1] === val);
const col = cols[index];

return col;
});

// Export
module.exports = fractal;
20 changes: 10 additions & 10 deletions src/lib/_imports/elements/table/table.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@
{{/each}}
{{#each data.rows}}
<tr>
{{#if id}}<td data-col="ID">{{ id }}</td>{{/if}}
{{#if name}}<td data-col="Name">{{ name }}</td>{{/if}}
{{#if name-link}}<td data-col="Name"><a href="#">{{ name-link }}</a></td>{{/if}}
{{#if id}}<td data-col="{{ getColFromRow this id @root.data.cols }}">{{ id }}</td>{{/if}}
{{#if name}}<td data-col="{{ getColFromRow this name @root.data.cols }}">{{ name }}</td>{{/if}}
{{#if name-link}}<td data-col="{{ getColFromRow this name-link @root.data.cols }}"><a href="#">{{ name-link }}</a></td>{{/if}}
{{#if paragraph}}
<td data-col="Summary" title="{{> @text-of-one-paragraph-short }}">
<td data-col="{{ getColFromRow this paragraph @root.data.cols }}" title="{{> @text-of-one-paragraph-short }}">
<p>{{> @text-of-one-paragraph-short }}</p>
</td>
{{/if}}
{{#if sentence}}
<td data-col="Sentence" title="{{> @text-of-one-sentence }}">
<td data-col="{{ getColFromRow this sentence @root.data.cols }}" title="{{> @text-of-one-sentence }}">
<span>{{> @text-of-one-sentence }}</span>
</td>
{{/if}}
{{#if custom-1}}<td data-col="Size">{{{ custom-1 }}}</td>{{/if}}
{{#if custom-2}}<td data-col="">{{{ custom-2 }}}</td>{{/if}}
{{#if custom-3}}<td data-col="">{{{ custom-3 }}}</td>{{/if}}
{{#if time}}<td data-col="Time"><time>{{ time }}</time></td>{{/if}}
{{#if custom-1}}<td data-col="{{ getColFromRow this custom-1 @root.data.cols }}">{{{ custom-1 }}}</td>{{/if}}
{{#if custom-2}}<td data-col="{{ getColFromRow this custom-2 @root.data.cols }}">{{{ custom-2 }}}</td>{{/if}}
{{#if custom-3}}<td data-col="{{ getColFromRow this custom-3 @root.data.cols }}">{{{ custom-3 }}}</td>{{/if}}
{{#if time}}<td data-col="{{ getColFromRow this time @root.data.cols }}"><time>{{ time }}</time></td>{{/if}}
{{#if acts}}
<td data-col="Actions">
<td data-col="{{ getColFromRow this acts @root.data.cols }}">
<ul>
{{#each acts}}
{{#if is-link }}<li><a href="#">{{ text }}</a></li>{{/if}}
Expand Down

0 comments on commit ed2863e

Please sign in to comment.