-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding filters for environments and tags to paginated exercise list.
- Loading branch information
Martin Krulis
committed
Nov 25, 2019
1 parent
2a39e0e
commit 1df1bd2
Showing
18 changed files
with
497 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/components/forms/EditEnvironmentSimpleForm/EditEnvironmentList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Field } from 'redux-form'; | ||
import { FormattedMessage, intlShape, injectIntl } from 'react-intl'; | ||
import { Grid, Row, Col, OverlayTrigger, Tooltip } from 'react-bootstrap'; | ||
|
||
import { CheckboxField } from '../Fields'; | ||
import Icon, { InfoIcon } from '../../icons'; | ||
import { STANDALONE_ENVIRONMENTS } from '../../../helpers/exercise/environments'; | ||
|
||
const EditEnvironmentList = ({ | ||
runtimeEnvironments, | ||
namePrefix = '', | ||
showExclusive = false, | ||
fullWidth = false, | ||
intl: { locale }, | ||
}) => ( | ||
<Grid fluid> | ||
<Row> | ||
{runtimeEnvironments | ||
.sort((a, b) => a.longName.localeCompare(b.longName, locale)) | ||
.map(environment => ( | ||
<Col key={environment.id} xs={12} sm={6} md={fullWidth ? 4 : 6} lg={fullWidth ? 3 : 6}> | ||
<Field | ||
name={`${namePrefix}${environment.id}`} | ||
component={CheckboxField} | ||
onOff | ||
label={ | ||
<span> | ||
{environment.longName} | ||
|
||
<OverlayTrigger | ||
placement="bottom" | ||
overlay={ | ||
<Tooltip id={`environment-${environment.id}`}> | ||
{environment.description} {environment.extensions} | ||
</Tooltip> | ||
}> | ||
<InfoIcon gapLeft className="text-primary" timid /> | ||
</OverlayTrigger> | ||
|
||
{showExclusive && STANDALONE_ENVIRONMENTS.includes(environment.id) && ( | ||
<OverlayTrigger | ||
placement="bottom" | ||
overlay={ | ||
<Tooltip id={`environment-standalone-${environment.id}`}> | ||
<FormattedMessage | ||
id="app.editEnvironmentSimpleForm.exclusiveEnvironment" | ||
defaultMessage="Exclusive runtime environment" | ||
/> | ||
</Tooltip> | ||
}> | ||
<Icon icon={['far', 'star']} smallGapLeft className="text-warning half-opaque" /> | ||
</OverlayTrigger> | ||
)} | ||
</span> | ||
} | ||
/> | ||
</Col> | ||
))} | ||
</Row> | ||
</Grid> | ||
); | ||
|
||
EditEnvironmentList.propTypes = { | ||
runtimeEnvironments: PropTypes.array, | ||
namePrefix: PropTypes.string, | ||
showExclusive: PropTypes.bool, | ||
fullWidth: PropTypes.bool, | ||
intl: intlShape.isRequired, | ||
}; | ||
|
||
export default injectIntl(EditEnvironmentList); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { ControlLabel, Label } from 'react-bootstrap'; | ||
import { defaultMemoize } from 'reselect'; | ||
import classnames from 'classnames'; | ||
|
||
import { AddIcon, CloseIcon } from '../../icons'; | ||
import { getTagStyle } from '../../../helpers/exercise/tags'; | ||
|
||
const activeTagsIndex = defaultMemoize(fields => { | ||
const res = {}; | ||
fields.forEach((_, index) => (res[fields.get(index)] = index)); | ||
return res; | ||
}); | ||
|
||
const TagsSelectorField = ({ tags = [], fields, label = null }) => { | ||
const active = activeTagsIndex(fields); | ||
|
||
return ( | ||
<React.Fragment> | ||
{Boolean(label) && <ControlLabel>{label}</ControlLabel>} | ||
<div className="larger"> | ||
{tags.sort().map(tag => ( | ||
<Label | ||
key={tag} | ||
bsSize="lg" | ||
style={getTagStyle(tag)} | ||
className={classnames({ | ||
'tag-margin': true, | ||
'halfem-padding': true, | ||
timid: active[tag] === undefined, | ||
clickable: true, | ||
})} | ||
onClick={() => (active[tag] === undefined ? fields.push(tag) : fields.remove(active[tag]))}> | ||
{tag} | ||
{active[tag] === undefined ? <AddIcon gapLeft /> : <CloseIcon gapLeft />} | ||
</Label> | ||
))} | ||
</div> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
TagsSelectorField.propTypes = { | ||
tags: PropTypes.array, | ||
fields: PropTypes.object.isRequired, | ||
meta: PropTypes.shape({ | ||
active: PropTypes.bool, | ||
dirty: PropTypes.bool, | ||
error: PropTypes.any, | ||
warning: PropTypes.any, | ||
}).isRequired, | ||
label: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.element, | ||
PropTypes.shape({ type: PropTypes.oneOf([FormattedMessage]) }), | ||
]), | ||
noItems: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.element, | ||
PropTypes.shape({ type: PropTypes.oneOf([FormattedMessage]) }), | ||
]), | ||
validateEach: PropTypes.func, | ||
}; | ||
|
||
export default TagsSelectorField; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.