Skip to content

Commit

Permalink
feat: add new shortcut methods to ViewHelpers
Browse files Browse the repository at this point in the history
relates to #294
  • Loading branch information
wojtek-krysiak committed Oct 1, 2020
1 parent 5e9308f commit 6915056
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
12 changes: 12 additions & 0 deletions spec/backend/helpers/helper-stub.ts
Expand Up @@ -12,6 +12,12 @@ const expectedResult = {
resourceUrl: 'resourceUrl',
dashboardUrl: 'dashboardUrl',
pageUrl: 'pageUrl',
editUrl: 'editUrl',
showUrl: 'showUrl',
deleteUrl: 'deleteUrl',
newUrl: 'newUrl',
listUrl: 'listUrl',
bulkDeleteUrl: 'bulkDeleteUrl',
}

export default (): ViewHelpers => (
Expand All @@ -31,6 +37,12 @@ export default (): ViewHelpers => (
resourceUrl: sinon.stub().returns(expectedResult.resourceUrl),
dashboardUrl: sinon.stub().returns(expectedResult.dashboardUrl),
pageUrl: sinon.stub().returns(expectedResult.pageUrl),
editUrl: sinon.stub().returns(expectedResult.editUrl),
showUrl: sinon.stub().returns(expectedResult.showUrl),
deleteUrl: sinon.stub().returns(expectedResult.deleteUrl),
newUrl: sinon.stub().returns(expectedResult.newUrl),
listUrl: sinon.stub().returns(expectedResult.listUrl),
bulkDeleteUrl: sinon.stub().returns(expectedResult.bulkDeleteUrl),
}
)

Expand Down
68 changes: 67 additions & 1 deletion src/backend/utils/view-helpers/view-helpers.ts
Expand Up @@ -141,12 +141,78 @@ export class ViewHelpers {
return this.urlBuilder(['pages', pageName])
}

/**
* Returns url for a `edit` action in given Resource. Uses {@link recordActionUrl}
*
* @param {string} resourceId id to the resource
* @param {string} recordId id to the record
* @param {string} [search] optional query string
*/
editUrl(resourceId: string, recordId: string, search?: string): string {
return this.recordActionUrl({ resourceId, recordId, actionName: 'edit', search })
}

/**
* Returns url for a `show` action in given Resource. Uses {@link recordActionUrl}
*
* @param {string} resourceId id to the resource
* @param {string} recordId id to the record
* @param {string} [search] optional query string
*/
showUrl(resourceId: string, recordId: string, search?: string): string {
return this.recordActionUrl({ resourceId, recordId, actionName: 'show', search })
}

/**
* Returns url for a `delete` action in given Resource. Uses {@link recordActionUrl}
*
* @param {string} resourceId id to the resource
* @param {string} recordId id to the record
* @param {string} [search] optional query string
*/
deleteUrl(resourceId: string, recordId: string, search?: string): string {
return this.recordActionUrl({ resourceId, recordId, actionName: 'delete', search })
}


/**
* Returns url for a `new` action in given Resource. Uses {@link resourceActionUrl}
*
* @param {string} resourceId id to the resource
* @param {string} [search] optional query string
*/
newUrl(resourceId: string, search?: string): string {
return this.resourceActionUrl({ resourceId, actionName: 'new', search })
}

/**
* Returns url for a `new` action in given Resource. Uses {@link resourceActionUrl}
*
* @param {string} resourceId id to the resource
* @param {string} [search] optional query string
*/
listUrl(resourceId: string, search?: string): string {
return this.resourceActionUrl({ resourceId, actionName: 'list', search })
}

/**
* Returns url for a `bulkDelete` action in given Resource. Uses {@link bulkActionUrl}
*
* @param {string} resourceId id to the resource
* @param {Array<string>} recordIds separated by comma records
* @param {string} [search] optional query string
*/
bulkDeleteUrl(resourceId: string, recordIds: Array<string>, search?: string): string {
return this.bulkActionUrl({ resourceId, recordIds, actionName: 'bulkDelete', search })
}

/**
* Returns resourceAction url
*
* @param {ResourceActionParams} options
* @param {string} options.resourceId
* @param {string} options.actionName
* @param {string} [options.search] optional query string
*
* @return {string}
*/
Expand Down Expand Up @@ -177,7 +243,7 @@ export class ViewHelpers {
*
* @param {BulkActionParams} options
* @param {string} options.resourceId
* @param {string} [options.recordIds]
* @param {Array<string>} [options.recordIds]
* @param {string} options.actionName
*
* @return {string}
Expand Down

0 comments on commit 6915056

Please sign in to comment.