Skip to content

Commit

Permalink
Merge pull request #387 from jayesh-bhoot/feat/allow-template-variabl…
Browse files Browse the repository at this point in the history
…es-in-header-path

allow usage of template-variables in the header-path in a capture-tem…
  • Loading branch information
munen committed Jul 8, 2020
2 parents 7a33b3c + 8b7d7e8 commit 5e391b4
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog.org
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ When there are updates to the changelog, you will be notified and see a 'gift' i



* [2020-07-08 Wed]
** Added
- Allow template-variables in the header-path in a capture template
- Thank you [[https://github.com/jayesh-bhoot][jayesh-bhoot]] for your [[https://github.com/200ok-ch/organice/pull/387/][PR]] 🙏
* [2020-06-14 Sun]
** Added
- Allow capture templates to insert at beginning or end of file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export default ({
for more details.
</li>
</ul>
You can also use <code>%u</code> and <code>%t</code> as part of the header path.
</div>
</div>
);
Expand Down
7 changes: 6 additions & 1 deletion src/components/OrgFile/components/CaptureModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ export default ({ template, onCapture, headers, onClose }) => {
<span>{template.get('description')}</span>
</div>

<div className="capture-modal-header-path">{template.get('headerPaths').join(' > ')}</div>
<div className="capture-modal-header-path">
{template
.get('headerPaths')
.map((hP) => substituteTemplateVariables(hP)[0])
.join(' > ')}
</div>

{targetHeader ? (
<Fragment>
Expand Down
4 changes: 3 additions & 1 deletion src/lib/org_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { formatDistanceToNow } from 'date-fns';

import generateId from './id_generator';
import { attributedStringToRawText } from './export_org';
import substituteTemplateVariables from './capture_template_substitution';

function generateHash(list) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -193,7 +194,8 @@ export const headerWithPath = (headers, headerPath) => {
const firstHeader = headers.find(
(header) =>
parentIdOfHeaderWithId(headers, header.get('id')) === null &&
header.getIn(['titleLine', 'rawTitle']).trim() === headerPath.first().trim()
header.getIn(['titleLine', 'rawTitle']).trim() ===
substituteTemplateVariables(headerPath.first())[0].trim()
);
if (!firstHeader) {
return null;
Expand Down
128 changes: 128 additions & 0 deletions src/lib/org_utils.unit.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import readFixture from '../../test_helpers/index';
import { parseOrg } from './parse_org.js';
import { fromJS } from 'immutable';
import format from 'date-fns/format';

import {
extractAllOrgProperties,
computeAllPropertyNames,
computeAllPropertyValuesFor,
headerWithPath,
} from './org_utils';

describe('Extracting and computing property names and values', () => {
Expand Down Expand Up @@ -36,3 +39,128 @@ describe('Extracting and computing property names and values', () => {
});
});
});

describe('Find the headline at the end of the headline-path', () => {
it('where the headline-path contains template variables as headlines', () => {
// path to be traced: [today] > <today> > test
const today = new Date();
const inactiveTimestampAsHeadline = {
planningItems: [],
logBookEntries: [],
opened: true,
titleLine: {
title: [
{
id: 7,
type: 'timestamp',
firstTimestamp: {
month: format(today, 'MM'),
dayName: format(today, 'eee'),
isActive: false,
day: format(today, 'dd'),
year: format(today, 'yyyy'),
},
secondTimestamp: null,
},
],
rawTitle: `[${format(today, 'yyyy-MM-dd eee')}]`,
tags: [],
},
propertyListItems: [],
rawDescription: '',
nestingLevel: 1,
id: 8,
description: [],
};
const activeTimestampAsHeadline = {
planningItems: [
{
type: 'TIMESTAMP_TITLE',
timestamp: {
month: format(today, 'MM'),
dayName: format(today, 'eee'),
isActive: true,
day: format(today, 'dd'),
year: format(today, 'yyyy'),
},
id: 147,
},
],
logBookEntries: [],
opened: true,
titleLine: {
title: [
{
id: 9,
type: 'timestamp',
firstTimestamp: {
month: format(today, 'MM'),
dayName: format(today, 'eee'),
isActive: true,
day: format(today, 'dd'),
year: format(today, 'yyyy'),
},
secondTimestamp: null,
},
],
rawTitle: `<${format(today, 'yyyy-MM-dd eee')}>`,
tags: [],
},
propertyListItems: [],
rawDescription: '',
nestingLevel: 2,
id: 10,
description: [],
};
const expectedHeadline = {
planningItems: [],
logBookEntries: [],
opened: false,
titleLine: {
title: [
{
type: 'text',
contents: 'test',
},
],
rawTitle: 'test',
tags: [],
},
propertyListItems: [],
rawDescription: '',
nestingLevel: 3,
id: 11,
description: [],
};
const extraSiblingHeadline = {
planningItems: [],
logBookEntries: [],
opened: false,
titleLine: {
title: [
{
type: 'text',
contents: 'testnot',
},
],
rawTitle: 'testnot',
tags: [],
},
propertyListItems: [],
rawDescription: '',
nestingLevel: 3,
id: 200,
description: [],
};

const headers = fromJS([
inactiveTimestampAsHeadline,
activeTimestampAsHeadline,
expectedHeadline,
extraSiblingHeadline,
]);
const headerPath = fromJS(['%u', '%t', 'test']);

expect(headerWithPath(headers, headerPath).toJS()).toStrictEqual(expectedHeadline);
});
});

0 comments on commit 5e391b4

Please sign in to comment.