function isDirty(val, initVal) { if (typeof val === 'boolean') { return val !== initVal; } else { return !isEqual(sortBy(val), sortBy(initVal)); } }
export function orderLinks (links) { const [provided, unknown] = partition(links, isProvided); return [ ...sortBy(provided, link => PROVIDED_TYPES.indexOf(link.type)), ...sortBy(unknown, link => link.name.toLowerCase()) ]; }
function sortMeasures (measures, order) { const [known, unknown] = partition(measures, measure => order.includes(measure.metric.key)); return [ ...sortBy(known, measure => order.indexOf(measure.metric.key)), ...sortBy(unknown, measure => getLocalizedMetricName(measure.metric)) ]; }
export default function AllMeasuresDomain ({ domain, component, displayLeakHeader, leakPeriodLabel }) { const hasLeak = !!leakPeriodLabel; const { measures } = domain; const knownMetrics = domains[domain.name] || []; const [knownMeasures, otherMeasures] = partition(measures, measure => knownMetrics.indexOf(measure.metric.key) !== -1); const finalMeasures = [ ...sortBy(knownMeasures, measure => knownMetrics.indexOf(measure.metric.key)), ...sortBy(otherMeasures, measure => measure.metric.name) ]; return ( <li> <header className="page-header"> <h3 className="page-title">{domain.name}</h3> {displayLeakHeader && hasLeak && ( <div className="measures-domains-leak-header"> {translateWithParameters('overview.leak_period_x', leakPeriodLabel)} </div> )} </header> <ul className="domain-measures"> {finalMeasures.map(measure => ( <li key={measure.metric.key} id={`measure-${measure.metric.key}`}> <Link to={{ pathname: measure.metric.key, query: { id: component.key } }}> <div className="domain-measures-name"> <span id={`measure-${measure.metric.key}-name`}> {measure.metric.name} </span> </div> <div className="domain-measures-value"> {measure.value != null && ( <span id={`measure-${measure.metric.key}-value`}> {formatMeasure(measure.value, measure.metric.type)} </span> )} </div> {hasLeak && measure.leak != null && ( <div className="domain-measures-value domain-measures-leak"> <span id={`measure-${measure.metric.key}-leak`}> {formatLeak(measure.leak, measure.metric)} </span> </div> )} </Link> </li> ))} </ul> </li> ); }
function sortRelations(obj) { if (obj instanceof Person) { obj.movies = sortBy(obj.movies, 'name'); } if (obj instanceof Animal) { obj.peopleWhoseFavoriteIAm = sortBy(obj.peopleWhoseFavoriteIAm, 'name'); } return obj; }
/** * @private * @description * Builds the query object passed to the API instance. * The object includes all the parameters added via with*() methods * and the filters added via addDataFilter(), addPeriodFilter(), addOrgUnitFilter(), addFilter(). * The filters are handled by the API instance when building the final URL. * Used internally. * * @param {Object} options Optional configurations * * @returns {Object} Query parameters */ buildQuery(options) { let filters = this.filters; if (options && options.sorted) { filters = sortBy(filters, 'dimension'); } const encodedFilters = filters.map(({ dimension, items }) => { if (Array.isArray(items) && items.length) { const encodedItems = items.map(customEncodeURIComponent); if (options && options.sorted) { encodedItems.sort(); } return `${dimension}:${encodedItems.join(';')}`; } return dimension; }); if (filters.length) { this.parameters.filter = encodedFilters; } return this.parameters; }
/** * @private * @description * Builds the URL to pass to the Api object. * The URL includes the dimension(s) parameters. * Used internally. * * @param {Object} options Optional configurations * * @returns {String} URL URL for the request with dimensions included */ buildUrl(options) { // at least 1 dimension is required let dimensions = this.dimensions; if (options && options.sorted) { dimensions = sortBy(dimensions, 'dimension'); } const encodedDimensions = dimensions.map(({ dimension, items }) => { if (Array.isArray(items) && items.length) { const encodedItems = items.map(customEncodeURIComponent); if (options && options.sorted) { encodedItems.sort(); } return `${dimension}:${encodedItems.join(';')}`; } return dimension; }); const endPoint = [this.endPoint, this.path, this.program].filter(e => !!e).join('/'); return ( `${endPoint}.${this.format}?dimension=${encodedDimensions.join('&dimension=')}` ); }
function getIcons() { if (typeof document === 'undefined') { return null; } return ( <section> Import: <p className="code">Icon = require ‘../icon/Icon’</p> <br /> <div style={{ columnWidth: '20em', columnGap: '2em', columnCount: 4, }} > {sortBy( [].slice.call(document.getElementsByTagName('symbol')), symbol => symbol.id, ).map(symbol => getIcon(symbol.id))} </div> <div> <Icon className="large-icon" img="icon-icon_subway-live" /> <span className="code">.large-icon</span> <br /> <Icon className="large-icon" img="icon-icon_user" /> <span className="code">.large-icon</span> <br /> </div> </section> ); }
function sortByRender(events) { const sortedByTime = sortBy(events, ['start', e => -e.end]) const sorted = [] while (sortedByTime.length > 0) { const event = sortedByTime.shift() sorted.push(event) for (let i = 0; i < sortedByTime.length; i++) { const test = sortedByTime[i] // Still inside this event, look for next. if (event.end > test.start) { continue } // We've found the first event of the next event group. // If that event is not right next to our current event, we have to // move it here. if (i > 0) { const [event] = sortedByTime.splice(i, 1) sorted.push(event) } // We've already found the next event group, so stop looking. break } } return sorted }
render () { const { component, periods } = this.props; const { loading, conditions } = this.state; if (loading) { return null; } const sortedConditions = sortBy( conditions, condition => LEVEL_ORDER.indexOf(condition.level), condition => condition.metric.name ); return ( <ul className="overview-quality-gate-conditions-list" id="overview-quality-gate-conditions-list"> {sortedConditions.map(condition => ( <QualityGateCondition key={condition.measure.metric.key} component={component} periods={periods} condition={condition}/> ))} </ul> ); }
.then((d) => { if (!Array.isArray(d.posL)) { console.error('d', d) const err = new Error('invalid response') err.shouldRetry = true throw err } const byDuration = [] let i = 0, lastDuration = NaN for (const pos of sortBy(d.posL, 'dur')) { const loc = d.locations[pos.locX] if (!loc) continue if (pos.dur !== lastDuration) { lastDuration = pos.dur i = byDuration.length byDuration.push({ duration: pos.dur, stations: [loc] }) } else { byDuration[i].stations.push(loc) } } return byDuration })
export const sortKeys = (keys, breakpoints) => ( // sort the keys sortBy(keys, (key) => { // if the key is a custom style if (key[0] !== '_') { // deal with it first return 0 } // otherwise the key is a responsive style // grab the data for the style const {comparison, size} = parsePattern(key) // DRY const nBreakpoints = breakpoints.length // start off sorting by ascending order to match breakpoints let sortValue = breakpoints.indexOf(size) + nBreakpoints // make sure equals checks come last if (comparison === 'equal') { // offset it by a lot /* eslint-disable space-infix-ops, space-unary-ops */ sortValue =+ 3 * nBreakpoints /* eslint-enable space-infix-ops space-unary-ops */ // make sure lessThans come after greaterThans } else if (comparison === 'lessThan') { // by offsetting them all and inverting the placement sortValue = 2 * nBreakpoints - sortValue } // return the sort index return sortValue }) )
componentWillReceiveProps(nextProps) { const sortedContacts = sortBy( nextProps.contacts.edges, ['node.lastName', 'node.firstName'] ) this.props.initActiveItem(sortedContacts[0].node.id) }
var initLayers = function () { var $select = $('.wv-debug-gibs-layerlist'); $select.empty(); var sortedLayers = lodashSortBy(config.layers, ['title', 'subtitle']); lodashEach(sortedLayers, function (layer) { if (acceptLayer(layer)) { var names = models.layers.getTitles(layer.id); var text = names.title + '; ' + names.subtitle; if (text.length > 65) { text = text.substr(0, 65) + '...'; } console.log(layer.id); var $option = $('<option></option>') .val(encodeURIComponent(layer.id)) .html(text); $select.append($option); } }); models.layers.clear(); if (type !== 'gibs' && config.layers.Land_Water_Map) { models.layers.add('Land_Water_Map'); } updateLayers.apply($select); if (type === 'dataDownload') { models.data.activate(); } };
export function createAdjustedScheduleOptions(timezone, day) { const format = 'HH:mm'; const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']; const idx = days.indexOf(day.toLowerCase()); let list = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22].map((hour) => { const start = moment.utc({ hour }) .day(idx) .add(moment.duration({ hours: 1 })) .tz(timezone); const finish = moment.utc({ hour }) .day(idx) .add(moment.duration({ hours: 3 })) .tz(timezone); return { start, finish, label: `${start.format(format)} - ${finish.format(format)}`, value: `W${shift(moment.utc({ hour }).format('H'))}`, }; }); list = sortBy(list, (i) => i.label); list.unshift({ label: 'Choose a time', value: '' }); return list; }
(layers, layerTypes, filtersSource) => sortBy(layers, layer => layer.order) .map(({ filters, ...layer }) => ({ ...layer, ...layerTypes[layer.type], filters: pick(filtersSource, filters) }))
export const getSlugsForTrendingPosts = (pages, count) => { let eligiblePages = pages .filter(isEligiblePage) // prevent cases where we're just moving up a deep pit at the bottom .filter(page => getRecentPageViews(page) > 30) // don't include things posted in the last 30 days .filter(page => getRecentPageViews(page) !== getPageViews(page)); let rankByPopular = sortBy(pages, getPageViews); let rankByRecentlyPopular = sortBy(eligiblePages, getRecentPageViews); let rankByTrending = sortBy(eligiblePages, page => { let getRankInList = list => findIndex(list, popPage => getSlug(popPage) === getSlug(page)); return getRankInList(rankByPopular) - getRankInList(rankByRecentlyPopular); }); return take(rankByTrending.map(getSlug), count); };
module.exports = async () => { const paths = await find('*.md', { cwd: 'content/blog' }); const posts = await Promise.all(paths.map(findPost)); const sortedPosts = reverse(sortBy(posts, p => new Date(p.date))); return sortedPosts; };
render () { const pageLinks = [] // Sort pages. const sortedPages = sortBy(this.props.route.pages, (page) => access(page, "data.date") ).reverse(); sortedPages.forEach((page) => { if (access(page, "file.ext") === "md") { pageLinks.push( <HomeItem key={page.path} page={page}/> ) } }); return ( <DocumentTitle title={config.blogTitle}> <div> <Header></Header> <ul className="homelist"> {pageLinks} </ul> </div> </DocumentTitle> ) }
export const getSortedPosts = ( pages, count = Infinity, includeReviews = false ) => { let mostPopular = getSlugsForMostPopularPosts(pages, 10); let trending = getSlugsForTrendingPosts(pages, 10); const buildPage = rawPage => { let path = getSlug(rawPage); let data = rawPage.node.frontmatter; data.isTrending = includes(trending, path); data.isPopular = includes(mostPopular, path); return { data, path }; }; let pageTypes = ['post']; if (includeReviews) { pageTypes.push('review'); } return take( sortBy(pages, page => new Date(get(page, 'node.frontmatter.date'))) .reverse() .filter( page => includes(pageTypes, get(page, 'node.frontmatter.layout')) && !isDraft(page) && !get(page, 'node.frontmatter.dontfeature') ) .map(buildPage), count ); };
render() { if (this.props.loading) { return <LoadingScreen /> } else { const sortedContacts = sortBy( this.props.contacts.edges, ['node.lastName', 'node.firstName'] ) return ( <div id="main-container" className="container row"> <div className="list-detail-container"> <ContactDetailContainer /> <ContactListContainer contacts={sortedContacts} /> </div> <AddUserFormContainer /> <EditUserFormContainer /> <DeleteConfirmationContainer /> <hr className="contact-app" /> <Button className="add-contact" bsStyle="primary" onClick={this.props.toggleAddForm} > <span className="glyphicon glyphicon-plus" /> </Button> </div> ) } }
render () { const pageLinks = [] // Sort pages. const sortedPages = sortBy(this.props.route.pages, (page) => access(page, 'data.date') ).reverse() sortedPages.forEach((page) => { if (access(page, 'file.ext') === 'md' && !include(page.path, '/404')) { const title = access(page, 'data.title') || page.path pageLinks.push( <li key={page.path} style={{ marginBottom: rhythm(1/4), }} > <Link style={{boxShadow: 'none'}} to={prefixLink(page.path)}>{title}</Link> </li> ) } }) return ( <DocumentTitle title={config.blogTitle}> <div> <Bio /> <ul> {pageLinks} </ul> </div> </DocumentTitle> ) }
kernelOptions() { const { kernels } = this.props; return sortBy(map(kernels.kernels, kernel => ({ ...kernel, value: kernel.id, })), 'version').reverse(); }
searchRules(data).then(r => { if (this.mounted) { this.setState({ latestRules: sortBy(parseRules(r), 'langName'), latestRulesTotal: r.total }); } });
function groupByDomains (measures) { const KNOWN_DOMAINS = ['Releasability', 'Reliability', 'Security', 'Maintainability', 'Coverage', 'Duplications', 'Size', 'Complexity']; const domains = sortBy(toPairs(groupBy(measures, measure => measure.metric.domain)).map(r => { const [name, measures] = r; const sortedMeasures = sortBy(measures, measure => getLocalizedMetricName(measure.metric)); return { name, measures: sortedMeasures }; }), 'name'); const [knownDomains, unknownDomains] = partition(domains, domain => KNOWN_DOMAINS.includes(domain.name)); return [ ...sortBy(knownDomains, domain => KNOWN_DOMAINS.indexOf(domain.name)), ...sortBy(unknownDomains, domain => domain.name) ]; }
export const getWeeklyLinks = (pages, count = Infinity) => take( sortBy(pages, page => get(page, 'node.frontmatter.date')) .reverse() .filter(page => get(page, 'node.frontmatter.layout') === 'weekly-links') .map(p => ({ data: p.node.frontmatter, path: p.node.fields.slug })), count );
export default function getPosts(allPages) { const posts = filter(allPages, page => { const data = page.data; return page.path && page.path !== '/' && data && data.body && !data.draft; }); return sortBy(posts, page => page.data.date).reverse(); }
export const getSlugsForMostPopularPosts = (pages, count) => take( sortBy(pages, getPageViews) .reverse() .filter(isEligiblePage) .map(getSlug), count );
parse (datas){ datas = _sortBy( datas, (movie) => movie.name.toLowerCase() ); return _extend( this.datas, { allMovies: datas, movies: datas } ); }
const Controls = controls => ( <div className="node-details-property-list-controls"> {sortBy(controls, 'rank').map(control => (<NodeDetailsControlButton nodeId={control.nodeId} control={control} key={control.id} />))} </div> );