Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow usage of template-variables in the header-path in a capture-tem… #387

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});