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

Add Refresh ability on the Gallery & Toolbar #784

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions client/src/containers/AssetAdmin/AssetAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class AssetAdmin extends Component {
this.handleOpenFolder = this.handleOpenFolder.bind(this);
this.handleSort = this.handleSort.bind(this);
this.handleSetPage = this.handleSetPage.bind(this);
this.handleRefreshPage = this.handleRefreshPage.bind(this);
this.createEndpoint = this.createEndpoint.bind(this);
this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
this.handleFolderIcon = this.handleFolderIcon.bind(this);
Expand Down Expand Up @@ -186,10 +187,10 @@ class AssetAdmin extends Component {
* @param {number} [fileId]
* @param {object|null} [query]
*/
handleBrowse(folderId, fileId, query) {
handleBrowse(folderId, fileId, query, forceRefresh = false) {
if (typeof this.props.onBrowse === 'function') {
// for Higher-order component with a router handler
this.props.onBrowse(folderId, fileId, query);
this.props.onBrowse(folderId, fileId, query, CONSTANTS.ACTIONS.EDIT_FILE, forceRefresh);
}
if (folderId !== this.getFolderId()) {
this.props.actions.gallery.deselectFiles();
Expand All @@ -209,6 +210,18 @@ class AssetAdmin extends Component {
);
}

/**
* Passes `true` for `forceReload` so it forces a new request from server
*/
handleRefreshPage() {
this.handleBrowse(
this.getFolderId(),
this.props.fileId,
Object.assign({}, this.props.query),
true
);
}

/**
* Reset to new search results page
*
Expand Down Expand Up @@ -604,6 +617,7 @@ class AssetAdmin extends Component {
onSort={this.handleSort}
onSetPage={this.handleSetPage}
onViewChange={this.handleViewChange}
refreshPage={this.handleRefreshPage}
sort={sort}
sectionConfig={config}
loading={this.props.loading}
Expand Down
17 changes: 13 additions & 4 deletions client/src/containers/AssetAdmin/stateRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,26 @@ class AssetAdminStateRouter extends Component {
* @param {object} query
* @param {string} action
*/
handleBrowse(folderId, fileId, query = {}, action = CONSTANTS.ACTIONS.EDIT_FILE) {
handleBrowse(
folderId,
fileId,
query = {},
action = CONSTANTS.ACTIONS.EDIT_FILE,
forceReload = false
) {
if (action && Object.values(CONSTANTS.ACTIONS).indexOf(action) === -1) {
throw new Error(`Invalid action provided: ${action}`);
}

this.setState({
const newState = {
folderId,
fileId,
query,
action,
});
};
if (forceReload) {
newState.query.cacheBuster = Math.random();
}
this.setState(newState);
}

render() {
Expand Down
2 changes: 1 addition & 1 deletion client/src/containers/AssetAdmin/tests/AssetAdmin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ describe('AssetAdmin', () => {
props.onBrowse = jest.genMockFunction();
component = ReactTestUtils.renderIntoDocument(<AssetAdmin {...props} />);
return component.handleDelete([id]).then(() => {
expect(props.onBrowse).toBeCalledWith(0, null, { ...props.query, view: 'tile' });
expect(props.onBrowse).toBeCalledWith(0, null, { ...props.query, view: 'tile' }, 'edit', false);
});
});
});
Expand Down
2 changes: 2 additions & 0 deletions client/src/containers/Gallery/Gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ class Gallery extends Component {
onCreateFolder,
onOpenFolder,
onViewChange,
refreshPage,
} = this.props;

const props = {
Expand All @@ -714,6 +715,7 @@ class Gallery extends Component {
onCreateFolder,
onOpenFolder,
onViewChange,
refreshPage,
view,
sort,
folder,
Expand Down
4 changes: 3 additions & 1 deletion client/src/state/files/readFilesQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { hasFilters } from 'components/Search/Search';

// GraphQL Query
const query = gql`
query ReadFiles($limit:Int!, $offset:Int!, $rootFilter: FileFilterInput,
query ReadFiles($limit:Int!, $offset:Int!, $rootFilter: FileFilterInput,
$childrenFilter: FileFilterInput, $sortBy:[ChildrenSortInputType]
) {
readFiles(filter: $rootFilter) {
Expand Down Expand Up @@ -77,12 +77,14 @@ const config = {
// - Display a folder with its direct children and filters (a "search" in the current folder)
const [sortField, sortDir] = params.sort ? params.sort.split(',') : ['', ''];
const limit = params.limit || sectionConfig.limit;
const cacheBuster = params.cacheBuster || null;
return {
variables: {
rootFilter,
childrenFilter,
limit,
offset: ((params.page || 1) - 1) * limit,
cacheBuster,
sortBy: (sortField && sortDir)
? [{ field: sortField, direction: sortDir.toUpperCase() }]
: undefined,
Expand Down