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
Fixes #26753 - react-router foundation #3 #6741
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
class ReactController < ApplicationController | ||
layout 'layouts/react_application' | ||
end | ||
|
||
def index | ||
render 'react/index' | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`URI query and stringify tests should return stringified params: stringify params 1`] = `"?page=1&per_page=21"`; | ||
|
||
exports[`URI query and stringify tests should return stringified params: stringify params w/search 1`] = `"?page=1&per_page=21&search=search"`; | ||
|
||
exports[`URI query and stringify tests should test params functions: getPage 1`] = `1`; | ||
|
||
exports[`URI query and stringify tests should test params functions: getParams 1`] = ` | ||
Object { | ||
"page": 1, | ||
"perPage": 25, | ||
"searchQuery": "some-search", | ||
} | ||
`; | ||
|
||
exports[`URI query and stringify tests should test params functions: getPerPage 1`] = `25`; | ||
|
||
exports[`URI query and stringify tests should test params functions: getSearchQuery 1`] = `"some-search"`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import URI from 'urijs'; | ||
|
||
/** | ||
* Build a url from given controller, action and id | ||
* @param {String} controller - the controller | ||
|
@@ -13,3 +15,57 @@ export const urlBuilder = (controller, action, id = undefined) => | |
*/ | ||
export const urlWithSearch = (base, searchQuery) => | ||
`/${base}?search=${searchQuery}`; | ||
|
||
/** | ||
* Get updated URI | ||
*/ | ||
export const getURI = () => new URI(window.location.href); | ||
|
||
/** | ||
* Get updated page param | ||
*/ | ||
export const getURIpage = () => Number(getURI().query(true).page) || 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test? |
||
/** | ||
* Get updated perPage param | ||
*/ | ||
export const getURIperPage = () => Number(getURI().query(true).per_page); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test? |
||
/** | ||
* Get updated searchQuery param | ||
*/ | ||
export const getURIsearch = () => getURI().query(true).search || ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test? |
||
|
||
/** | ||
* Get updated URI params | ||
*/ | ||
export const getParams = () => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test? |
||
page: getURIpage(), | ||
perPage: getURIperPage(), | ||
searchQuery: getURIsearch(), | ||
}); | ||
|
||
/** | ||
* Get updated Stringified params | ||
*/ | ||
export const stringifyParams = ({ | ||
page = 1, | ||
perPage = 25, | ||
searchQuery = '', | ||
}) => { | ||
const uri = getURI(); | ||
if (searchQuery !== '') | ||
uri.search({ page, per_page: perPage, search: searchQuery }); | ||
else uri.search({ page, per_page: perPage }); | ||
return uri.search(); | ||
}; | ||
|
||
/** | ||
* change current query and trigger navigation | ||
* @param {URI} uri - URI object | ||
* @param {Object} newQuery - Query Object | ||
* @param {Function} navigateTo - navigate func | ||
*/ | ||
export const changeQuery = (newQuery, navigateTo, uri = getURI()) => { | ||
uri.setQuery(newQuery); | ||
if (navigateTo) navigateTo(uri.toString()); | ||
else window.Turbolinks.visit(uri.toString()); | ||
}; |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused, why is this needed?
Do we need special permission to see react pages or it should just be allowed to everyone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these changes are needed for a rake test to pass (permissions_test, seed_test)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They shouldn't be. We don't add permissions just so tests pass when they don't make sense from a user standpoint. opened https://projects.theforeman.org/issues/27333 to remove this.