code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
onClick = (evt) => { // If it's the currently active navigation item and we're not on the item view, // clear the query params on click if (isActive && !this.props.itemId) { evt.preventDefault(); this.props.dispatch( setActiveList(this.props.currentList, this.props.currentListKey) ); } }
The secondary navigation links to inidvidual lists of a section
onClick
javascript
keystonejs/keystone-classic
admin/client/App/components/Navigation/Secondary/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Secondary/index.js
MIT
render () { if (!this.state.navIsVisible) return null; return ( <nav className="secondary-navbar"> <Container clearFloatingChildren> {this.renderNavigation(this.props.lists)} </Container> </nav> ); }
The secondary navigation links to inidvidual lists of a section
render
javascript
keystonejs/keystone-classic
admin/client/App/components/Navigation/Secondary/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Secondary/index.js
MIT
render () { return ( <li className={this.props.className} data-list-path={this.props.path}> <Link to={this.props.href} onClick={this.props.onClick} title={this.props.title} tabIndex="-1" > {this.props.children} </Link> </li> ); }
A navigation item of the secondary navigation
render
javascript
keystonejs/keystone-classic
admin/client/App/components/Navigation/Secondary/NavItem.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/components/Navigation/Secondary/NavItem.js
MIT
function filtersParser (filters, currentList) { if (typeof filters === 'string') { try { filters = JSON.parse(filters); } catch (e) { console.warn('Invalid filters provided', filters); filters = void 0; } } if (!filters) return []; const assembledFilters = filters.map(filter => { const path = filter.path; const value = Object.assign({}, filter); delete value.path; return createFilterObject(path, value, currentList.fields); }); filters = assembledFilters.filter(filter => filter); return filters; }
Returns an array of expanded filter objects, given (a string representation | an array of filters) and a currentList object. @param { String|Array } Either a string representation of an array of filter objects, or an array of filter objects. @param { Object } the current instantiation of the List prototype used for the <List/> scene @return { Array } of { Objects } as an expanded representation of the filters passed in.
filtersParser
javascript
keystonejs/keystone-classic
admin/client/App/parsers/filters.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/parsers/filters.js
MIT
function filterParser ({ path, value }, activeFilters, currentList) { if (!activeFilters || !isArray(activeFilters)) { throw new Error('activeFilters must be an array'); } if (!currentList) { throw new Error('No currentList selected'); } if (!isObject(currentList) || isArray(currentList)) { throw new Error('currentList is expected to be an { Object }', currentList); } let filter = activeFilters.filter(i => i.field.path === path)[0]; if (filter) { filter.value = value; } else { filter = createFilterObject(path, value, currentList.fields); if (!filter) { return void 0; } } return filter; }
Returns an array of expanded filter objects, given (a string representation | an array of filters) and a currentList object. @param { Object } Filter object containing the following key value pairs {path} and {value}. @param { Array } of { Objects } an array of the currently active filters. @param { Object } the current instantiation of the List prototype used for the <List/> scene @return { Object } an expanded representation of the passed in filter { Object }.
filterParser
javascript
keystonejs/keystone-classic
admin/client/App/parsers/filters.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/parsers/filters.js
MIT
function createFilterObject (path, value, currentListFields) { if (!currentListFields || !isPlainObject(currentListFields)) { console.warn('currentListFields must be a plain object', currentListFields); return; } const field = currentListFields[path]; if (!field) { console.warn('Invalid Filter path specified:', path); return; } return { field, value, }; }
Returns a filter object given a path, a value, and the fields within an instance of the List prototype. @param { String } filter path @param { Object } of filter values. @param { Object } of fields from the current instance of the List prototype. @return { Object } a filter comprised of the:filters.js - corresponding field value within the current List, - and the passed in value { Object }.
createFilterObject
javascript
keystonejs/keystone-classic
admin/client/App/parsers/filters.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/parsers/filters.js
MIT
function columnsParser (columns, currentList) { if (!currentList) { throw new Error('No currentList selected'); } if (!columns || columns.length === 0) { return currentList.expandColumns(currentList.defaultColumns); } return currentList.expandColumns(columns); }
Returns an array of expanded columns object, given a list of columns and currentList object. @param { String } columns, a string representation of a list of columns. @param { Object } the current instantiation of the List prototype used for the <List/> scene @return { Array } of { Objects } as an expanded representation of the column values passed in.
columnsParser
javascript
keystonejs/keystone-classic
admin/client/App/parsers/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/parsers/index.js
MIT
function sortParser (path, currentList) { if (!currentList) { throw new Error('No currentList selected'); } if (!path) return currentList.expandSort(currentList.defaultSort); return currentList.expandSort(path); }
Returns an expanded sort object, given a sort path and currentList object. @param { String } path, a string representation of a list of columns. @param { Object } the current instantiation of the List prototype used for the <List/> scene @return { Object } an expanded representation of the sort path passed in.
sortParser
javascript
keystonejs/keystone-classic
admin/client/App/parsers/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/parsers/index.js
MIT
function * debouncedSearch () { const searchString = yield select((state) => state.active.search); if (searchString) { yield delay(500); } yield call(updateParams); }
Debounce the search loading new items by 500ms
debouncedSearch
javascript
keystonejs/keystone-classic
admin/client/App/sagas/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/sagas/index.js
MIT
function * setActiveColumnsSaga () { while (true) { const { columns } = yield take(actions.SELECT_ACTIVE_COLUMNS); const { currentList } = yield select(state => state.lists); const newColumns = yield call(columnsParser, columns, currentList); yield put({ type: actions.SET_ACTIVE_COLUMNS, columns: newColumns }); } }
Debounce the search loading new items by 500ms
setActiveColumnsSaga
javascript
keystonejs/keystone-classic
admin/client/App/sagas/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/sagas/index.js
MIT
function * setActiveSortSaga () { while (true) { const { path } = yield take(actions.SELECT_ACTIVE_SORT); const { currentList } = yield select(state => state.lists); const sort = yield call(sortParser, path, currentList); yield put({ type: actions.SET_ACTIVE_SORT, sort }); } }
Debounce the search loading new items by 500ms
setActiveSortSaga
javascript
keystonejs/keystone-classic
admin/client/App/sagas/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/sagas/index.js
MIT
function * setActiveFilterSaga () { while (true) { const { filter } = yield take(actions.SELECT_FILTER); const { currentList } = yield select(state => state.lists); const activeFilters = yield select(state => state.active.filters); const updatedFilter = yield call(filterParser, filter, activeFilters, currentList); yield put({ type: actions.ADD_FILTER, filter: updatedFilter }); } }
Debounce the search loading new items by 500ms
setActiveFilterSaga
javascript
keystonejs/keystone-classic
admin/client/App/sagas/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/sagas/index.js
MIT
function * rootSaga () { yield fork(takeLatest, actions.SET_ACTIVE_SEARCH, debouncedSearch); yield fork(takeLatest, actions.SET_ACTIVE_LIST, evalQueryParams); // If one of the other active properties changes, update the query params and load the new items yield fork(setActiveSortSaga); yield fork(setActiveColumnsSaga); yield fork(setActiveFilterSaga); yield fork(takeLatest, [ actions.QUERY_HAS_CHANGED, actions.ADD_FILTER, actions.SET_ACTIVE_COLUMNS, actions.SET_ACTIVE_SORT, actions.SET_CURRENT_PAGE, actions.CLEAR_FILTER, actions.CLEAR_ALL_FILTERS, ], updateParams); }
Debounce the search loading new items by 500ms
rootSaga
javascript
keystonejs/keystone-classic
admin/client/App/sagas/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/sagas/index.js
MIT
function * updateParams () { // Select all the things const activeState = yield select((state) => state.active); const currentList = yield select((state) => state.lists.currentList); const location = yield select((state) => state.routing.locationBeforeTransitions); const { index } = yield select((state) => state.lists.page); // Get the data into the right format, set the defaults let sort = createSortQueryParams(activeState.sort.rawInput, currentList.defaultSort); let page = createPageQueryParams(index, 1); let columns = stringifyColumns(activeState.columns, currentList.defaultColumnPaths); let search = activeState.search; let filters = parametizeFilters(activeState.filters); const newParams = updateQueryParams({ page, columns, sort, search, filters, }, location); // TODO: Starting or clearing a search pushes a new history state, but updating // the current search replaces it for nicer history navigation support yield put({ type: actions.REPLACE_CACHED_QUERY, cachedQuery: newParams }); yield * urlUpdate(newParams, activeState.cachedQuery, location.pathname); yield put(loadItems()); }
Update the query params based on the current state
updateParams
javascript
keystonejs/keystone-classic
admin/client/App/sagas/queryParamsSagas.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/sagas/queryParamsSagas.js
MIT
function * evalQueryParams () { const { pathname, query } = yield select(state => state.routing.locationBeforeTransitions); const { cachedQuery } = yield select(state => state.active); const { currentList } = yield select(state => state.lists); if (pathname !== `${Keystone.adminPath}/${currentList.id}`) return; if (isEqual(query, cachedQuery)) { yield put({ type: actions.QUERY_HAS_NOT_CHANGED }); yield put(loadItems()); } else { const parsedQuery = yield call(parseQueryParams, query, currentList); yield put({ type: actions.QUERY_HAS_CHANGED, parsedQuery }); } }
Update the query params based on the current state
evalQueryParams
javascript
keystonejs/keystone-classic
admin/client/App/sagas/queryParamsSagas.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/sagas/queryParamsSagas.js
MIT
function parseQueryParams (query, currentList) { const columns = columnsParser(query.columns, currentList); const sort = sortParser(query.sort, currentList); const filters = filtersParser(query.filters, currentList); const currentPage = query.page || 1; const search = query.search || ''; return { columns, sort, filters, currentPage, search, }; }
Update the query params based on the current state
parseQueryParams
javascript
keystonejs/keystone-classic
admin/client/App/sagas/queryParamsSagas.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/sagas/queryParamsSagas.js
MIT
function loadCounts () { return (dispatch) => { dispatch({ type: LOAD_COUNTS, }); xhr({ url: `${Keystone.adminPath}/api/counts`, }, (err, resp, body) => { if (err) { dispatch(countsLoadingError(err)); return; } try { body = JSON.parse(body); if (body.counts) { dispatch(countsLoaded(body.counts)); } } catch (e) { console.log('Error parsing results json:', e, body); dispatch(countsLoadingError(e)); return; } }); }; }
Load the counts of all lists
loadCounts
javascript
keystonejs/keystone-classic
admin/client/App/screens/Home/actions.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Home/actions.js
MIT
function countsLoaded (counts) { return { type: COUNTS_LOADING_SUCCESS, counts, }; }
Dispatched when the counts were loaded @param {Object} counts The counts object as returned by the API
countsLoaded
javascript
keystonejs/keystone-classic
admin/client/App/screens/Home/actions.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Home/actions.js
MIT
function countsLoadingError (error) { return (dispatch, getState) => { dispatch({ type: COUNTS_LOADING_ERROR, error, }); setTimeout(() => { dispatch(loadCounts()); }, NETWORK_ERROR_RETRY_DELAY); }; }
Dispatched when unsuccessfully trying to load the counts, will redispatch loadCounts after NETWORK_ERROR_RETRY_DELAY until we get counts back @param {object} error The error
countsLoadingError
javascript
keystonejs/keystone-classic
admin/client/App/screens/Home/actions.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Home/actions.js
MIT
getInitialState () { return { modalIsOpen: true, }; }
The Home view is the view one sees at /keystone. It shows a list of all lists, grouped by their section.
getInitialState
javascript
keystonejs/keystone-classic
admin/client/App/screens/Home/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Home/index.js
MIT
getSpinner () { if (this.props.counts && Object.keys(this.props.counts).length === 0 && (this.props.error || this.props.loading)) { return ( <Spinner /> ); } return null; }
The Home view is the view one sees at /keystone. It shows a list of all lists, grouped by their section.
getSpinner
javascript
keystonejs/keystone-classic
admin/client/App/screens/Home/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Home/index.js
MIT
render () { const spinner = this.getSpinner(); return ( <Container data-screen-id="home"> <div className="dashboard-header"> <div className="dashboard-heading">{Keystone.brand}</div> </div> <div className="dashboard-groups"> {(this.props.error) && ( <AlertMessages alerts={{ error: { error: "There is a problem with the network, we're trying to reconnect...", } }} /> )} {/* Render flat nav */} {Keystone.nav.flat ? ( <Lists counts={this.props.counts} lists={Keystone.lists} spinner={spinner} /> ) : ( <div> {/* Render nav with sections */} {Keystone.nav.sections.map((navSection) => { return ( <Section key={navSection.key} id={navSection.key} label={navSection.label}> <Lists counts={this.props.counts} lists={navSection.lists} spinner={spinner} /> </Section> ); })} {/* Render orphaned lists */} {Keystone.orphanedLists.length ? ( <Section label="Other" icon="octicon-database"> <Lists counts={this.props.counts} lists={Keystone.orphanedLists} spinner={spinner} /> </Section> ) : null} </div> )} </div> </Container> ); }
The Home view is the view one sees at /keystone. It shows a list of all lists, grouped by their section.
render
javascript
keystonejs/keystone-classic
admin/client/App/screens/Home/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Home/index.js
MIT
render () { var opts = { 'data-list-path': this.props.path, }; return ( <div className="dashboard-group__list" {...opts}> <span className="dashboard-group__list-inner"> <Link to={this.props.href} className="dashboard-group__list-tile"> <div className="dashboard-group__list-label">{this.props.label}</div> <div className="dashboard-group__list-count">{this.props.spinner || this.props.count}</div> </Link> {/* If we want to create a new list, we append ?create, which opens the create form on the new page! */} {(!this.props.hideCreateButton) && ( <Link to={this.props.href + '?create'} className="dashboard-group__list-create octicon octicon-plus" title="Create" tabIndex="-1" /> )} </span> </div> ); }
Displays information about a list and lets you create a new one.
render
javascript
keystonejs/keystone-classic
admin/client/App/screens/Home/components/ListTile.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Home/components/ListTile.js
MIT
function getRelatedIconClass (string) { const icons = [ { icon: 'book', sections: ['books', 'posts', 'blog', 'blog-posts', 'stories', 'news-stories', 'content'] }, { icon: 'briefcase', sections: ['businesses', 'companies', 'listings', 'organizations', 'partners'] }, { icon: 'calendar', sections: ['events', 'dates'] }, { icon: 'clock', sections: ['classes', 'hours', 'times'] }, { icon: 'file-media', sections: ['gallery', 'galleries', 'images', 'photos', 'pictures'] }, { icon: 'file-text', sections: ['attachments', 'docs', 'documents', 'files'] }, { icon: 'location', sections: ['locations', 'markers', 'places'] }, { icon: 'mail', sections: ['emails', 'enquiries'] }, { icon: 'megaphone', sections: ['broadcasts', 'jobs', 'talks'] }, { icon: 'organization', sections: ['contacts', 'customers', 'groups', 'members', 'people', 'speakers', 'teams', 'users'] }, { icon: 'package', sections: ['boxes', 'items', 'packages', 'parcels'] }, { icon: 'tag', sections: ['tags'] }, ]; const classes = icons .filter(obj => obj.sections.indexOf(string) !== -1) .map(obj => `octicon octicon-${obj.icon}`); if (!classes.length) { classes.push('octicon octicon-primitive-dot'); } return classes.join(' '); }
Gets a related icon for a string, returned as a classname to be applied to a span. If no related icon is found, returns a classname for a dot icon @param [String] string @return [String] The classname of the icon
getRelatedIconClass
javascript
keystonejs/keystone-classic
admin/client/App/screens/Home/utils/getRelatedIconClass.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Home/utils/getRelatedIconClass.js
MIT
function selectItem (itemId) { return { type: SELECT_ITEM, id: itemId, }; }
Select an item @param {String} itemId The item ID
selectItem
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/actions.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/actions.js
MIT
function loadItemData () { return (dispatch, getState) => { // Hold on to the id of the item we currently want to load. // Dispatch this reference to our redux store to hold on to as a 'loadingRef'. const currentItemID = getState().item.id; dispatch({ type: LOAD_DATA, }); const state = getState(); const list = state.lists.currentList; // const itemID = state.item.id; // Load a specific item with the utils/List.js helper list.loadItem(state.item.id, { drilldown: true }, (err, itemData) => { // Once this async request has fired this callback, check that // the item id referenced by thisLoadRef is the same id // referenced by loadingRef in the redux store. // If it is, then this is the latest request, and it is safe to resolve it normally. // If it is not the same id however, // this means that this request is NOT the latest fired request, // and so we'll bail out of it early. if (getState().item.id !== currentItemID) return; if (err || !itemData) { dispatch(dataLoadingError(err)); } else { dispatch(dataLoaded(itemData)); } }); }; }
Load the item data of the current item
loadItemData
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/actions.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/actions.js
MIT
function loadRelationshipItemData ({ columns, refList, relationship, relatedItemId }) { return (dispatch, getState) => { refList.loadItems({ columns: columns, filters: [{ field: refList.fields[relationship.refPath], value: { value: relatedItemId }, }], }, (err, items) => { // // TODO: indicate pagination & link to main list view // this.setState({ items }); dispatch(relationshipDataLoaded(relationship.path, items)); }); }; }
Load the item data of the current item
loadRelationshipItemData
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/actions.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/actions.js
MIT
function dataLoaded (data) { return { type: DATA_LOADING_SUCCESS, loadingRef: null, data, }; }
Called when data of the current item is loaded @param {Object} data The item data
dataLoaded
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/actions.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/actions.js
MIT
function relationshipDataLoaded (path, data) { return { type: LOAD_RELATIONSHIP_DATA, relationshipPath: path, data, }; }
Called when data of the current item is loaded @param {Object} data The item data
relationshipDataLoaded
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/actions.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/actions.js
MIT
function dataLoadingError (err) { return { type: DATA_LOADING_ERROR, loadingRef: null, error: err, }; }
Called when there was an error during the loading of the current item data, will retry loading the data ever NETWORK_ERROR_RETRY_DELAY milliseconds @param {Object} error The error
dataLoadingError
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/actions.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/actions.js
MIT
function deleteItem (id, router) { return (dispatch, getState) => { const state = getState(); const list = state.lists.currentList; list.deleteItem(id, (err) => { // If a router is passed, redirect to the current list path, // otherwise stay where we are if (router) { let redirectUrl = `${Keystone.adminPath}/${list.path}`; if (state.lists.page.index && state.lists.page.index > 1) { redirectUrl = `${redirectUrl}?page=${state.lists.page.index}`; } router.push(redirectUrl); } // TODO Proper error handling if (err) { alert(err.error || 'Error deleting item, please try again!'); } else { dispatch(loadItems()); } }); }; }
Deletes an item and optionally redirects to the current list URL @param {String} id The ID of the item we want to delete @param {Object} router A react-router router object. If this is passed, we redirect to Keystone.adminPath/currentList.path!
deleteItem
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/actions.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/actions.js
MIT
function reorderItems ({ columns, refList, relationship, relatedItemId, item, prevSortOrder, newSortOrder }) { return (dispatch, getState) => { // Send the item, previous sortOrder and the new sortOrder // we should get the proper list and new page results in return refList.reorderItems( item, prevSortOrder, newSortOrder, { columns: columns, filters: [{ field: refList.fields[relationship.refPath], value: { value: relatedItemId }, }], }, (err, items) => { dispatch(relationshipDataLoaded(relationship.path, items)); // If err, flash the row alert // if (err) { // dispatch(resetItems(item.id)); // // return this.resetItems(this.findItemById[item.id]); // } else { // dispatch(itemsLoaded(items)); // dispatch(setRowAlert({ // success: item.id, // fail: false, // })); // } } ); }; }
Deletes an item and optionally redirects to the current list URL @param {String} id The ID of the item we want to delete @param {Object} router A react-router router object. If this is passed, we redirect to Keystone.adminPath/currentList.path!
reorderItems
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/actions.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/actions.js
MIT
function moveItem ({ prevIndex, newIndex, relationshipPath, newSortOrder }) { return { type: DRAG_MOVE_ITEM, prevIndex, newIndex, relationshipPath, newSortOrder, }; }
Deletes an item and optionally redirects to the current list URL @param {String} id The ID of the item we want to delete @param {Object} router A react-router router object. If this is passed, we redirect to Keystone.adminPath/currentList.path!
moveItem
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/actions.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/actions.js
MIT
function resetItems () { return { type: DRAG_RESET_ITEMS, }; }
Deletes an item and optionally redirects to the current list URL @param {String} id The ID of the item we want to delete @param {Object} router A react-router router object. If this is passed, we redirect to Keystone.adminPath/currentList.path!
resetItems
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/actions.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/actions.js
MIT
getInitialState () { return { createIsOpen: false, }; }
Item View This is the item view, it is rendered when users visit a page of a specific item. This mainly renders the form to edit the item content in.
getInitialState
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/index.js
MIT
componentDidMount () { // When we directly navigate to an item without coming from another client // side routed page before, we need to select the list before initializing the item // We also need to update when the list id has changed if (!this.props.currentList || this.props.currentList.id !== this.props.params.listId) { this.props.dispatch(selectList(this.props.params.listId)); } this.initializeItem(this.props.params.itemId); }
Item View This is the item view, it is rendered when users visit a page of a specific item. This mainly renders the form to edit the item content in.
componentDidMount
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/index.js
MIT
componentWillReceiveProps (nextProps) { // We've opened a new item from the client side routing, so initialize // again with the new item id if (nextProps.params.itemId !== this.props.params.itemId) { this.props.dispatch(selectList(nextProps.params.listId)); this.initializeItem(nextProps.params.itemId); } }
Item View This is the item view, it is rendered when users visit a page of a specific item. This mainly renders the form to edit the item content in.
componentWillReceiveProps
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/index.js
MIT
initializeItem (itemId) { this.props.dispatch(selectItem(itemId)); this.props.dispatch(loadItemData()); }
Item View This is the item view, it is rendered when users visit a page of a specific item. This mainly renders the form to edit the item content in.
initializeItem
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/index.js
MIT
onCreate (item) { // Hide the create form this.toggleCreateModal(false); // Redirect to newly created item path const list = this.props.currentList; this.context.router.push(`${Keystone.adminPath}/${list.path}/${item.id}`); }
Item View This is the item view, it is rendered when users visit a page of a specific item. This mainly renders the form to edit the item content in.
onCreate
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/index.js
MIT
toggleCreateModal (visible) { this.setState({ createIsOpen: visible, }); }
Item View This is the item view, it is rendered when users visit a page of a specific item. This mainly renders the form to edit the item content in.
toggleCreateModal
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/index.js
MIT
renderRelationships () { const { relationships } = this.props.currentList; const keys = Object.keys(relationships); if (!keys.length) return; return ( <div className="Relationships"> <Container> <h2>Relationships</h2> {keys.map(key => { const relationship = relationships[key]; const refList = listsByKey[relationship.ref]; const { currentList, params, relationshipData, drag } = this.props; return ( <RelatedItemsList key={relationship.path} list={currentList} refList={refList} relatedItemId={params.itemId} relationship={relationship} items={relationshipData[relationship.path]} dragNewSortOrder={drag.newSortOrder} dispatch={this.props.dispatch} /> ); })} </Container> </div> ); }
Item View This is the item view, it is rendered when users visit a page of a specific item. This mainly renders the form to edit the item content in.
renderRelationships
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/index.js
MIT
handleError (error) { const detail = error.detail; if (detail) { // Item not found if (detail.name === 'CastError' && detail.path === '_id') { return ( <Container> <Alert color="danger" style={{ marginTop: '2em' }}> No item matching id "{this.props.routeParams.itemId}".&nbsp; <Link to={`${Keystone.adminPath}/${this.props.routeParams.listId}`}> Go back to {this.props.routeParams.listId}? </Link> </Alert> </Container> ); } } if (error.message) { // Server down + possibly other errors if (error.message === 'Internal XMLHttpRequest Error') { return ( <Container> <Alert color="danger" style={{ marginTop: '2em' }}> We encountered some network problems, please refresh. </Alert> </Container> ); } } return ( <Container> <Alert color="danger" style={{ marginTop: '2em' }}> An unknown error has ocurred, please refresh. </Alert> </Container> ); }
Item View This is the item view, it is rendered when users visit a page of a specific item. This mainly renders the form to edit the item content in.
handleError
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/index.js
MIT
render () { // If we don't have any data yet, show the loading indicator if (!this.props.ready) { return ( <Center height="50vh" data-screen-id="item"> <Spinner /> </Center> ); } // When we have the data, render the item view with it return ( <div data-screen-id="item"> {(this.props.error) ? this.handleError(this.props.error) : ( <div> <Container> <EditFormHeader list={this.props.currentList} data={this.props.data} toggleCreate={this.toggleCreateModal} /> <CreateForm list={this.props.currentList} isOpen={this.state.createIsOpen} onCancel={() => this.toggleCreateModal(false)} onCreate={(item) => this.onCreate(item)} /> <EditForm list={this.props.currentList} data={this.props.data} dispatch={this.props.dispatch} router={this.context.router} /> </Container> {this.renderRelationships()} </div> )} </div> ); }
Item View This is the item view, it is rendered when users visit a page of a specific item. This mainly renders the form to edit the item content in.
render
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/index.js
MIT
function item (state = initialState, action) { switch (action.type) { case SELECT_ITEM: return assign({}, state, { ready: false, id: action.id, data: null, }); case LOAD_DATA: return assign({}, state, { loading: true, }); case DATA_LOADING_SUCCESS: Keystone.item = action.data; // Fix keystone filter return assign({}, state, { data: action.data, loading: false, ready: true, error: null, }); case DATA_LOADING_ERROR: return assign({}, state, { data: null, loading: false, ready: true, error: action.error, }); case DRAG_MOVE_ITEM: const currentItems = state.relationshipData[action.relationshipPath].results; // Cache a copy of the current items to reset the items when dismissing a drag and drop if a cached copy doesn't already exist const clonedItems = state.drag.clonedItems || currentItems; const item = currentItems[action.prevIndex]; // Remove item at prevIndex from array and save that array in // itemsWithoutItem let itemsWithoutItem = currentItems .slice(0, action.prevIndex) .concat( currentItems.slice( action.prevIndex + 1, currentItems.length ) ); // Add item back in at new index itemsWithoutItem.splice(action.newIndex, 0, item); const newRelationshipData = assign({}, state.relationshipData[action.relationshipPath], { results: itemsWithoutItem, }); return assign({}, state, { drag: { newSortOrder: action.newSortOrder, clonedItems: clonedItems, relationshipPath: action.relationshipPath, }, relationshipData: { ...state.relationshipData, [action.relationshipPath]: newRelationshipData, }, }); case DRAG_RESET_ITEMS: const originalRelationshipData = assign({}, state.relationshipData[state.drag.relationshipPath], { results: state.drag.clonedItems, }); return assign({}, state, { drag: { newSortOrder: null, clonedItems: false, relationshipPath: false, }, relationshipData: { ...state.relationshipData, [state.drag.relationshipPath]: originalRelationshipData, }, }); case LOAD_RELATIONSHIP_DATA: return assign({}, state, { // Reset drag and drop when relationship data is loaded drag: { newSortOrder: null, clonedItems: false, relationshipPath: false, }, relationshipData: { ...state.relationshipData, [action.relationshipPath]: action.data, }, }); default: return state; } }
Item reducer, handles the item data and loading
item
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/reducer.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/reducer.js
MIT
function dragProps (connect, monitor) { return { connectDragSource: connect.dragSource(), isDragging: monitor.isDragging(), connectDragPreview: connect.dragPreview(), }; }
Specifies the props to inject into your component.
dragProps
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/components/RelatedItemsList/RelatedItemsListRow.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/components/RelatedItemsList/RelatedItemsListRow.js
MIT
function dropProps (connect) { return { connectDropTarget: connect.dropTarget(), }; }
Specifies the props to inject into your component.
dropProps
javascript
keystonejs/keystone-classic
admin/client/App/screens/Item/components/RelatedItemsList/RelatedItemsListRow.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/Item/components/RelatedItemsList/RelatedItemsListRow.js
MIT
getInitialState () { return { confirmationDialog: { isOpen: false, }, checkedItems: {}, constrainTableWidth: true, manageMode: false, showCreateForm: false, showUpdateForm: false, }; }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
getInitialState
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
componentWillMount () { // When we directly navigate to a list without coming from another client // side routed page before, we need to initialize the list and parse // possibly specified query parameters this.props.dispatch(selectList(this.props.params.listId)); const isNoCreate = this.props.lists.data[this.props.params.listId].nocreate; const shouldOpenCreate = this.props.location.search === '?create'; this.setState({ showCreateForm: (shouldOpenCreate && !isNoCreate) || Keystone.createFormErrors, }); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
componentWillMount
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
componentWillReceiveProps (nextProps) { // We've opened a new list from the client side routing, so initialize // again with the new list id const isReady = this.props.lists.ready && nextProps.lists.ready; if (isReady && checkForQueryChange(nextProps, this.props)) { this.props.dispatch(selectList(nextProps.params.listId)); } }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
componentWillReceiveProps
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
onCreate (item) { // Hide the create form this.toggleCreateModal(false); // Redirect to newly created item path const list = this.props.currentList; this.context.router.push(`${Keystone.adminPath}/${list.path}/${item.id}`); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
onCreate
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
createAutocreate () { const list = this.props.currentList; list.createItem(null, (err, data) => { if (err) { // TODO Proper error handling alert('Something went wrong, please try again!'); console.log(err); } else { this.context.router.push(`${Keystone.adminPath}/${list.path}/${data.id}`); } }); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
createAutocreate
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
handleSearchClear () { this.props.dispatch(setActiveSearch('')); // TODO re-implement focus when ready // findDOMNode(this.refs.listSearchInput).focus(); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
handleSearchClear
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
handleSearchKey (e) { // clear on esc if (e.which === ESC_KEY_CODE) { this.handleSearchClear(); } }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
handleSearchKey
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
handlePageSelect (i) { // If the current page index is the same as the index we are intending to pass to redux, bail out. if (i === this.props.lists.page.index) return; return this.props.dispatch(setCurrentPage(i)); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
handlePageSelect
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
toggleManageMode (filter = !this.state.manageMode) { this.setState({ manageMode: filter, checkedItems: {}, }); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
toggleManageMode
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
toggleUpdateModal (filter = !this.state.showUpdateForm) { this.setState({ showUpdateForm: filter, }); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
toggleUpdateModal
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
massUpdate () { // TODO: Implement update multi-item console.log('Update ALL the things!'); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
massUpdate
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
massDelete () { const { checkedItems } = this.state; const list = this.props.currentList; const itemCount = pluralize(checkedItems, ('* ' + list.singular.toLowerCase()), ('* ' + list.plural.toLowerCase())); const itemIds = Object.keys(checkedItems); this.setState({ confirmationDialog: { isOpen: true, label: 'Delete', body: ( <div> Are you sure you want to delete {itemCount}? <br /> <br /> This cannot be undone. </div> ), onConfirmation: () => { this.props.dispatch(deleteItems(itemIds)); this.toggleManageMode(); this.removeConfirmationDialog(); }, }, }); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
massDelete
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
handleManagementSelect (selection) { if (selection === 'all') this.checkAllItems(); if (selection === 'none') this.uncheckAllTableItems(); if (selection === 'visible') this.checkAllTableItems(); return false; }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
handleManagementSelect
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
renderConfirmationDialog () { const props = this.state.confirmationDialog; return ( <ConfirmationDialog confirmationLabel={props.label} isOpen={props.isOpen} onCancel={this.removeConfirmationDialog} onConfirmation={props.onConfirmation} > {props.body} </ConfirmationDialog> ); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
renderConfirmationDialog
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
renderManagement () { const { checkedItems, manageMode, selectAllItemsLoading } = this.state; const { currentList } = this.props; return ( <ListManagement checkedItemCount={Object.keys(checkedItems).length} handleDelete={this.massDelete} handleSelect={this.handleManagementSelect} handleToggle={() => this.toggleManageMode(!manageMode)} isOpen={manageMode} itemCount={this.props.items.count} itemsPerPage={this.props.lists.page.size} nodelete={currentList.nodelete} noedit={currentList.noedit} selectAllItemsLoading={selectAllItemsLoading} /> ); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
renderManagement
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
renderPagination () { const items = this.props.items; if (this.state.manageMode || !items.count) return; const list = this.props.currentList; const currentPage = this.props.lists.page.index; const pageSize = this.props.lists.page.size; return ( <Pagination currentPage={currentPage} onPageSelect={this.handlePageSelect} pageSize={pageSize} plural={list.plural} singular={list.singular} style={{ marginBottom: 0 }} total={items.count} limit={10} /> ); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
renderPagination
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
renderHeader () { const items = this.props.items; const { autocreate, nocreate, plural, singular } = this.props.currentList; return ( <Container style={{ paddingTop: '2em' }}> <ListHeaderTitle activeSort={this.props.active.sort} availableColumns={this.props.currentList.columns} handleSortSelect={this.handleSortSelect} title={` ${numeral(items.count).format()} ${pluralize(items.count, ' ' + singular, ' ' + plural)} `} /> <ListHeaderToolbar // common dispatch={this.props.dispatch} list={listsByPath[this.props.params.listId]} // expand expandIsActive={!this.state.constrainTableWidth} expandOnClick={this.toggleTableWidth} // create createIsAvailable={!nocreate} createListName={singular} createOnClick={autocreate ? this.createAutocreate : this.openCreateModal} // search searchHandleChange={this.updateSearch} searchHandleClear={this.handleSearchClear} searchHandleKeyup={this.handleSearchKey} searchValue={this.props.active.search} // filters filtersActive={this.props.active.filters} filtersAvailable={this.props.currentList.columns.filter((col) => ( col.field && col.field.hasFilterMethod) || col.type === 'heading' )} // columns columnsActive={this.props.active.columns} columnsAvailable={this.props.currentList.columns} /> <ListFilters dispatch={this.props.dispatch} filters={this.props.active.filters} /> </Container> ); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
renderHeader
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
checkTableItem (item, e) { e.preventDefault(); const newCheckedItems = { ...this.state.checkedItems }; const itemId = item.id; if (this.state.checkedItems[itemId]) { delete newCheckedItems[itemId]; } else { newCheckedItems[itemId] = true; } this.setState({ checkedItems: newCheckedItems, }); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
checkTableItem
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
checkAllTableItems () { const checkedItems = {}; this.props.items.results.forEach(item => { checkedItems[item.id] = true; }); this.setState({ checkedItems: checkedItems, }); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
checkAllTableItems
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
checkAllItems () { const checkedItems = { ...this.state.checkedItems }; // Just in case this API call takes a long time, we'll update the select all button with // a spinner. this.setState({ selectAllItemsLoading: true }); var self = this; this.props.currentList.loadItems({ expandRelationshipFilters: false, filters: {} }, function (err, data) { data.results.forEach(item => { checkedItems[item.id] = true; }); self.setState({ checkedItems: checkedItems, selectAllItemsLoading: false, }); }); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
checkAllItems
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
uncheckAllTableItems () { this.setState({ checkedItems: {}, }); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
uncheckAllTableItems
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
deleteTableItem (item, e) { if (e.altKey) { this.props.dispatch(deleteItem(item.id)); return; } e.preventDefault(); this.setState({ confirmationDialog: { isOpen: true, label: 'Delete', body: ( <div> Are you sure you want to delete <strong>{item.name}</strong>? <br /> <br /> This cannot be undone. </div> ), onConfirmation: () => { this.props.dispatch(deleteItem(item.id)); this.removeConfirmationDialog(); }, }, }); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
deleteTableItem
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
removeConfirmationDialog () { this.setState({ confirmationDialog: { isOpen: false, }, }); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
removeConfirmationDialog
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
toggleTableWidth () { this.setState({ constrainTableWidth: !this.state.constrainTableWidth, }); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
toggleTableWidth
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
handleSortSelect (path, inverted) { if (inverted) path = '-' + path; this.props.dispatch(setActiveSort(path)); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
handleSortSelect
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
toggleCreateModal (visible) { this.setState({ showCreateForm: visible, }); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
toggleCreateModal
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
showBlankState () { return !this.props.loading && !this.props.items.results.length && !this.props.active.search && !this.props.active.filters.length; }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
showBlankState
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
renderBlankState () { const { currentList } = this.props; if (!this.showBlankState()) return null; // create and nav directly to the item view, or open the create modal const onClick = currentList.autocreate ? this.createAutocreate : this.openCreateModal; // display the button if create allowed const button = !currentList.nocreate ? ( <GlyphButton color="success" glyph="plus" position="left" onClick={onClick} data-e2e-list-create-button="no-results"> Create {currentList.singular} </GlyphButton> ) : null; return ( <Container> {(this.props.error) ? ( <FlashMessages messages={{ error: [{ title: "There is a problem with the network, we're trying to reconnect...", }] }} /> ) : null} <BlankState heading={`No ${this.props.currentList.plural.toLowerCase()} found...`} style={{ marginTop: 40 }}> {button} </BlankState> </Container> ); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
renderBlankState
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
renderActiveState () { if (this.showBlankState()) return null; const containerStyle = { transition: 'max-width 160ms ease-out', msTransition: 'max-width 160ms ease-out', MozTransition: 'max-width 160ms ease-out', WebkitTransition: 'max-width 160ms ease-out', }; if (!this.state.constrainTableWidth) { containerStyle.maxWidth = '100%'; } return ( <div> {this.renderHeader()} <Container> <div style={{ height: 35, marginBottom: '1em', marginTop: '1em' }}> {this.renderManagement()} {this.renderPagination()} <span style={{ clear: 'both', display: 'table' }} /> </div> </Container> <Container style={containerStyle}> {(this.props.error) ? ( <FlashMessages messages={{ error: [{ title: "There is a problem with the network, we're trying to reconnect..", }] }} /> ) : null} {(this.props.loading) ? ( <Center height="50vh"> <Spinner /> </Center> ) : ( <div> <ItemsTable activeSort={this.props.active.sort} checkedItems={this.state.checkedItems} checkTableItem={this.checkTableItem} columns={this.props.active.columns} deleteTableItem={this.deleteTableItem} handleSortSelect={this.handleSortSelect} items={this.props.items} list={this.props.currentList} manageMode={this.state.manageMode} rowAlert={this.props.rowAlert} currentPage={this.props.lists.page.index} pageSize={this.props.lists.page.size} drag={this.props.lists.drag} dispatch={this.props.dispatch} /> {this.renderNoSearchResults()} </div> )} </Container> </div> ); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
renderActiveState
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
renderNoSearchResults () { if (this.props.items.results.length) return null; let matching = this.props.active.search; if (this.props.active.filters.length) { matching += (matching ? ' and ' : '') + pluralize(this.props.active.filters.length, '* filter', '* filters'); } matching = matching ? ' found matching ' + matching : '.'; return ( <BlankState style={{ marginTop: 20, marginBottom: 20 }}> <Glyph name="search" size="medium" style={{ marginBottom: 20 }} /> <h2 style={{ color: 'inherit' }}> No {this.props.currentList.plural.toLowerCase()}{matching} </h2> </BlankState> ); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
renderNoSearchResults
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
render () { if (!this.props.ready) { return ( <Center height="50vh" data-screen-id="list"> <Spinner /> </Center> ); } return ( <div data-screen-id="list"> {this.renderBlankState()} {this.renderActiveState()} <CreateForm err={Keystone.createFormErrors} isOpen={this.state.showCreateForm} list={this.props.currentList} onCancel={this.closeCreateModal} onCreate={this.onCreate} /> <UpdateForm isOpen={this.state.showUpdateForm} itemIds={Object.keys(this.state.checkedItems)} list={this.props.currentList} onCancel={() => this.toggleUpdateModal(false)} /> {this.renderConfirmationDialog()} </div> ); }
The list view is a paginated table of all items in the list. It can show a variety of information about the individual items in columns.
render
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/index.js
MIT
function selectList (id) { return (dispatch, getState) => { dispatch({ type: SELECT_LIST, id, }); dispatch(setActiveList(getState().lists.data[id], id)); }; }
Select a list, and set it as the active list. Called whenever the main List component mounts or the list changes. @param {String} id The list ID, passed via this.props.params.listId
selectList
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/actions/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/actions/index.js
MIT
function loadInitialItems () { return { type: INITIAL_LIST_LOAD, }; }
Select a list, and set it as the active list. Called whenever the main List component mounts or the list changes. @param {String} id The list ID, passed via this.props.params.listId
loadInitialItems
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/actions/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/actions/index.js
MIT
function setCurrentPage (index) { return { type: SET_CURRENT_PAGE, index: parseInt(index), }; }
Set the current page @param {Number} index The page number we want to be on
setCurrentPage
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/actions/index.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/actions/index.js
MIT
function itemLoadingError () { return (dispatch) => { dispatch({ type: ITEM_LOADING_ERROR, err: 'Network request failed', }); setTimeout(() => { dispatch(loadItems()); }, NETWORK_ERROR_RETRY_DELAY); }; }
Dispatched when unsuccessfully trying to load the items, will redispatch loadItems after NETWORK_ERROR_RETRY_DELAY milliseconds until we get items back
itemLoadingError
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/actions/items.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/actions/items.js
MIT
function deleteItems (ids) { return (dispatch, getState) => { const list = getState().lists.currentList; list.deleteItems(ids, (err, data) => { // TODO ERROR HANDLING dispatch(loadItems()); }); }; }
Dispatched when unsuccessfully trying to load the items, will redispatch loadItems after NETWORK_ERROR_RETRY_DELAY milliseconds until we get items back
deleteItems
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/actions/items.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/actions/items.js
MIT
renderPageDrops () { const { items, currentPage, pageSize } = this.props; const totalPages = Math.ceil(items.count / pageSize); const style = { display: totalPages > 1 ? null : 'none' }; const pages = []; for (let i = 0; i < totalPages; i++) { const page = i + 1; const pageItems = '' + (page * pageSize - (pageSize - 1)) + ' - ' + (page * pageSize); const current = (page === currentPage); const className = classnames('ItemList__dropzone--page', { 'is-active': current, }); pages.push( <DropZoneTarget key={'page_' + page} page={page} className={className} pageItems={pageItems} pageSize={pageSize} currentPage={currentPage} drag={this.props.drag} dispatch={this.props.dispatch} /> ); } let cols = this.props.columns.length; if (this.props.list.sortable) cols++; if (!this.props.list.nodelete) cols++; return ( <tr style={style}> <td colSpan={cols} > <div className="ItemList__dropzone" > {pages} <div className="clearfix" /> </div> </td> </tr> ); }
THIS IS ORPHANED AND ISN'T RENDERED AT THE MOMENT THIS WAS DONE TO FINISH THE REDUX INTEGRATION, WILL REWRITE SOON - @mxstbr
renderPageDrops
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/components/ItemsTable/ItemsTableDragDropZone.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/components/ItemsTable/ItemsTableDragDropZone.js
MIT
render () { return this.renderPageDrops(); }
THIS IS ORPHANED AND ISN'T RENDERED AT THE MOMENT THIS WAS DONE TO FINISH THE REDUX INTEGRATION, WILL REWRITE SOON - @mxstbr
render
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/components/ItemsTable/ItemsTableDragDropZone.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/components/ItemsTable/ItemsTableDragDropZone.js
MIT
componentDidUpdate () { if (timeoutID && !this.props.isOver) { clearTimeout(timeoutID); timeoutID = false; } }
THIS IS ORPHANED AND ISN'T RENDERED AT THE MOMENT THIS WAS DONE TO FINISH THE REDUX INTEGRATION, WILL REWRITE SOON - @mxstbr
componentDidUpdate
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/components/ItemsTable/ItemsTableDragDropZoneTarget.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/components/ItemsTable/ItemsTableDragDropZoneTarget.js
MIT
render () { const { pageItems, page, isOver, dispatch } = this.props; let { className } = this.props; if (isOver) { className += (page === this.props.currentPage) ? ' is-available ' : ' is-waiting '; } return this.props.connectDropTarget( <div className={className} onClick={(e) => { dispatch(setCurrentPage(page)); }} > {pageItems} </div>); }
THIS IS ORPHANED AND ISN'T RENDERED AT THE MOMENT THIS WAS DONE TO FINISH THE REDUX INTEGRATION, WILL REWRITE SOON - @mxstbr
render
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/components/ItemsTable/ItemsTableDragDropZoneTarget.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/components/ItemsTable/ItemsTableDragDropZoneTarget.js
MIT
function dropProps (connect, monitor) { return { connectDropTarget: connect.dropTarget(), isOver: monitor.isOver(), }; }
Specifies the props to inject into your component.
dropProps
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/components/ItemsTable/ItemsTableDragDropZoneTarget.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/components/ItemsTable/ItemsTableDragDropZoneTarget.js
MIT
function dragProps (connect, monitor) { return { connectDragSource: connect.dragSource(), isDragging: monitor.isDragging(), connectDragPreview: connect.dragPreview(), }; }
Specifies the props to inject into your component.
dragProps
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/components/ItemsTable/ItemsTableRow.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/components/ItemsTable/ItemsTableRow.js
MIT
function dropProps (connect) { return { connectDropTarget: connect.dropTarget(), }; }
Specifies the props to inject into your component.
dropProps
javascript
keystonejs/keystone-classic
admin/client/App/screens/List/components/ItemsTable/ItemsTableRow.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/screens/List/components/ItemsTable/ItemsTableRow.js
MIT
getDefaultProps () { return { alerts: {}, }; }
This renders alerts for API success and error responses. Error format: { error: 'validation errors' // The unique error type identifier detail: { ... } // Optional details specific to that error type } Success format: { success: 'item updated', // The unique success type identifier details: { ... } // Optional details specific to that success type } Eventually success and error responses should be handled individually based on their type. For example: validation errors should be displayed next to each invalid field and signin errors should promt the user to sign in.
getDefaultProps
javascript
keystonejs/keystone-classic
admin/client/App/shared/AlertMessages.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/shared/AlertMessages.js
MIT
renderValidationErrors () { let errors = this.props.alerts.error.detail; if (errors.name === 'ValidationError') { errors = errors.errors; } let errorCount = Object.keys(errors).length; let alertContent; let messages = Object.keys(errors).map((path) => { if (errorCount > 1) { return ( <li key={path}> {upcase(errors[path].error || errors[path].message)} </li> ); } else { return ( <div key={path}> {upcase(errors[path].error || errors[path].message)} </div> ); } }); if (errorCount > 1) { alertContent = ( <div> <h4>There were {errorCount} errors creating the new item:</h4> <ul>{messages}</ul> </div> ); } else { alertContent = messages; } return <Alert color="danger">{alertContent}</Alert>; }
This renders alerts for API success and error responses. Error format: { error: 'validation errors' // The unique error type identifier detail: { ... } // Optional details specific to that error type } Success format: { success: 'item updated', // The unique success type identifier details: { ... } // Optional details specific to that success type } Eventually success and error responses should be handled individually based on their type. For example: validation errors should be displayed next to each invalid field and signin errors should promt the user to sign in.
renderValidationErrors
javascript
keystonejs/keystone-classic
admin/client/App/shared/AlertMessages.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/shared/AlertMessages.js
MIT
render () { let { error, success } = this.props.alerts; if (error) { // Render error alerts switch (error.error) { case 'validation errors': return this.renderValidationErrors(); case 'error': if (error.detail.name === 'ValidationError') { return this.renderValidationErrors(); } else { return <Alert color="danger">{upcase(error.error)}</Alert>; } default: return <Alert color="danger">{upcase(error.error)}</Alert>; } } if (success) { // Render success alerts return <Alert color="success">{upcase(success.success)}</Alert>; } return null; // No alerts, render nothing }
This renders alerts for API success and error responses. Error format: { error: 'validation errors' // The unique error type identifier detail: { ... } // Optional details specific to that error type } Success format: { success: 'item updated', // The unique success type identifier details: { ... } // Optional details specific to that success type } Eventually success and error responses should be handled individually based on their type. For example: validation errors should be displayed next to each invalid field and signin errors should promt the user to sign in.
render
javascript
keystonejs/keystone-classic
admin/client/App/shared/AlertMessages.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/shared/AlertMessages.js
MIT
getDefaultProps () { return { err: null, isOpen: false, }; }
The form that's visible when "Create <ItemName>" is clicked on either the List screen or the Item screen
getDefaultProps
javascript
keystonejs/keystone-classic
admin/client/App/shared/CreateForm.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/shared/CreateForm.js
MIT
getInitialState () { // Set the field values to their default values when first rendering the // form. (If they have a default value, that is) var values = {}; Object.keys(this.props.list.fields).forEach(key => { var field = this.props.list.fields[key]; var FieldComponent = Fields[field.type]; values[field.path] = FieldComponent.getDefaultValue(field); }); return { values: values, alerts: {}, }; }
The form that's visible when "Create <ItemName>" is clicked on either the List screen or the Item screen
getInitialState
javascript
keystonejs/keystone-classic
admin/client/App/shared/CreateForm.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/shared/CreateForm.js
MIT
componentDidMount () { document.body.addEventListener('keyup', this.handleKeyPress, false); }
The form that's visible when "Create <ItemName>" is clicked on either the List screen or the Item screen
componentDidMount
javascript
keystonejs/keystone-classic
admin/client/App/shared/CreateForm.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/shared/CreateForm.js
MIT
componentWillUnmount () { document.body.removeEventListener('keyup', this.handleKeyPress, false); }
The form that's visible when "Create <ItemName>" is clicked on either the List screen or the Item screen
componentWillUnmount
javascript
keystonejs/keystone-classic
admin/client/App/shared/CreateForm.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/shared/CreateForm.js
MIT
handleKeyPress (evt) { if (vkey[evt.keyCode] === '<escape>') { this.props.onCancel(); } }
The form that's visible when "Create <ItemName>" is clicked on either the List screen or the Item screen
handleKeyPress
javascript
keystonejs/keystone-classic
admin/client/App/shared/CreateForm.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/shared/CreateForm.js
MIT
handleChange (event) { var values = assign({}, this.state.values); values[event.path] = event.value; this.setState({ values: values, }); }
The form that's visible when "Create <ItemName>" is clicked on either the List screen or the Item screen
handleChange
javascript
keystonejs/keystone-classic
admin/client/App/shared/CreateForm.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/shared/CreateForm.js
MIT
getFieldProps (field) { var props = assign({}, field); props.value = this.state.values[field.path]; props.values = this.state.values; props.onChange = this.handleChange; props.mode = 'create'; props.key = field.path; return props; }
The form that's visible when "Create <ItemName>" is clicked on either the List screen or the Item screen
getFieldProps
javascript
keystonejs/keystone-classic
admin/client/App/shared/CreateForm.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/shared/CreateForm.js
MIT
submitForm (event) { event.preventDefault(); const createForm = event.target; const formData = new FormData(createForm); this.props.list.createItem(formData, (err, data) => { if (data) { if (this.props.onCreate) { this.props.onCreate(data); } else { // Clear form this.setState({ values: {}, alerts: { success: { success: 'Item created', }, }, }); } } else { if (!err) { err = { error: 'connection error', }; } // If we get a database error, show the database error message // instead of only saying "Database error" if (err.error === 'database error') { err.error = err.detail.errmsg; } this.setState({ alerts: { error: err, }, }); } }); }
The form that's visible when "Create <ItemName>" is clicked on either the List screen or the Item screen
submitForm
javascript
keystonejs/keystone-classic
admin/client/App/shared/CreateForm.js
https://github.com/keystonejs/keystone-classic/blob/master/admin/client/App/shared/CreateForm.js
MIT