Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String sorting comparators fixed to use selected locale. #110

Merged
merged 4 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ npm-debug.log
prod/
package-lock.json

/run_server.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { FormattedMessage } from 'react-intl';
import { injectIntl, FormattedMessage } from 'react-intl';

import Icon from 'react-fontawesome';
import { Table } from 'react-bootstrap';
Expand All @@ -28,7 +28,8 @@ const AttachedFilesTable = ({
downloadFile,
uploadId,
HeaderComponent,
RowComponent
RowComponent,
intl
}) =>
<Box title={title} collapsable isOpen>
<div>
Expand Down Expand Up @@ -62,7 +63,7 @@ const AttachedFilesTable = ({
</thead>
<tbody>
{attachments
.sort((a, b) => a.name.localeCompare(b.name))
.sort((a, b) => a.name.localeCompare(b.name, intl.locale))
.map((data, i) =>
<RowComponent
{...data}
Expand Down Expand Up @@ -105,7 +106,8 @@ AttachedFilesTable.propTypes = {
removeFile: PropTypes.func,
downloadFile: PropTypes.func,
HeaderComponent: PropTypes.func.isRequired,
RowComponent: PropTypes.func.isRequired
RowComponent: PropTypes.func.isRequired,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
};

export default AttachedFilesTable;
export default injectIntl(AttachedFilesTable);
26 changes: 12 additions & 14 deletions src/components/Exercises/ExercisesList/ExercisesList.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Table } from 'react-bootstrap';
import { FormattedMessage } from 'react-intl';
import { injectIntl, FormattedMessage } from 'react-intl';

import ExercisesListItem from '../ExercisesListItem';

const ExercisesList = ({ exercises = [], createActions, ...rest }) => (
const ExercisesList = ({ exercises = [], createActions, intl, ...rest }) =>
<Table hover>
<thead>
<tr>
Expand Down Expand Up @@ -44,35 +44,33 @@ const ExercisesList = ({ exercises = [], createActions, ...rest }) => (
.filter(e => e !== null)
.sort(
(a, b) =>
a.name < b.name
? -1
: b.name < a.name ? 1 : b.createdAt - a.createdAt
a.name.localeCompare(b.name, intl.locale) ||
b.createdAt - a.createdAt
)
.map(exercise => (
.map(exercise =>
<ExercisesListItem
{...exercise}
createActions={createActions}
key={exercise.id}
/>
))}
)}

{exercises.length === 0 && (
{exercises.length === 0 &&
<tr>
<td className="text-center" colSpan={6}>
<FormattedMessage
id="app.exercisesList.empty"
defaultMessage="There are no exercises in this list."
/>
</td>
</tr>
)}
</tr>}
</tbody>
</Table>
);
</Table>;

ExercisesList.propTypes = {
exercises: PropTypes.array,
createActions: PropTypes.func
createActions: PropTypes.func,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
};

export default ExercisesList;
export default injectIntl(ExercisesList);
23 changes: 11 additions & 12 deletions src/components/Exercises/ExercisesSimpleList/ExercisesSimpleList.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import { Table } from 'react-bootstrap';
import { FormattedMessage } from 'react-intl';
import { injectIntl, FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types';

import GroupExercisesListItem from '../ExercisesSimpleListItem';

const ExercisesSimpleList = ({ exercises, createActions, ...rest }) => (
const ExercisesSimpleList = ({ exercises, createActions, intl, ...rest }) =>
<Table>
<thead>
<tr>
Expand Down Expand Up @@ -33,38 +33,37 @@ const ExercisesSimpleList = ({ exercises, createActions, ...rest }) => (
<tbody>
{exercises
.sort((a, b) => {
var tmp = a.name.localeCompare(b.name);
var tmp = a.name.localeCompare(b.name, intl.locale);
if (tmp === 0) {
return b.createdAt - a.createdAt;
} else {
return tmp;
}
})
.map(exercise => (
.map(exercise =>
<GroupExercisesListItem
{...exercise}
createActions={createActions}
key={exercise.id}
/>
))}
)}

{exercises.length === 0 && (
{exercises.length === 0 &&
<tr>
<td className="text-center" colSpan={4}>
<FormattedMessage
id="app.exercisesSimpleList.empty"
defaultMessage="There are no exercises in this list."
/>
</td>
</tr>
)}
</tr>}
</tbody>
</Table>
);
</Table>;

ExercisesSimpleList.propTypes = {
exercises: PropTypes.array.isRequired,
createActions: PropTypes.func
createActions: PropTypes.func,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
};

export default ExercisesSimpleList;
export default injectIntl(ExercisesSimpleList);
22 changes: 12 additions & 10 deletions src/components/Instances/InstancesTable/InstancesTable.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { injectIntl, FormattedMessage } from 'react-intl';
import { Table } from 'react-bootstrap';
import { Link } from 'react-router';
import { MaybeSucceededIcon } from '../../icons';
import UsersNameContainer from '../../../containers/UsersNameContainer';

import withLinks from '../../../hoc/withLinks';

const InstancesTable = ({ instances, links: { INSTANCE_URI_FACTORY } }) => (
const InstancesTable = ({ instances, links: { INSTANCE_URI_FACTORY }, intl }) =>
<Table hover>
<thead>
<tr>
Expand All @@ -34,11 +34,13 @@ const InstancesTable = ({ instances, links: { INSTANCE_URI_FACTORY } }) => (
</thead>
<tbody>
{instances
.sort((a, b) => (a.name < b.name ? -1 : 1))
.map(({ id, name, admin, hasValidLicence }) => (
.sort((a, b) => a.name.localeCompare(b.name, intl.locale))
.map(({ id, name, admin, hasValidLicence }) =>
<tr key={id}>
<td>
<Link to={INSTANCE_URI_FACTORY(id)}>{name}</Link>
<Link to={INSTANCE_URI_FACTORY(id)}>
{name}
</Link>
</td>
<td>
<UsersNameContainer userId={admin} />
Expand All @@ -47,14 +49,14 @@ const InstancesTable = ({ instances, links: { INSTANCE_URI_FACTORY } }) => (
<MaybeSucceededIcon success={hasValidLicence} />
</td>
</tr>
))}
)}
</tbody>
</Table>
);
</Table>;

InstancesTable.propTypes = {
instances: PropTypes.array.isRequired,
links: PropTypes.object
links: PropTypes.object,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
};

export default withLinks(InstancesTable);
export default injectIntl(withLinks(InstancesTable));
11 changes: 6 additions & 5 deletions src/components/Pipelines/PipelinesList/PipelinesList.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Table } from 'react-bootstrap';
import { FormattedMessage } from 'react-intl';
import { injectIntl, FormattedMessage } from 'react-intl';

import PipelinesListItem from '../PipelinesListItem';

const PipelinesList = ({ pipelines = [], createActions }) =>
const PipelinesList = ({ pipelines = [], createActions, intl }) =>
<Table hover>
<thead>
<tr>
Expand Down Expand Up @@ -36,7 +36,7 @@ const PipelinesList = ({ pipelines = [], createActions }) =>
<tbody>
{pipelines
.filter(a => a !== null)
.sort((a, b) => a.name.localeCompare(b.name))
.sort((a, b) => a.name.localeCompare(b.name, intl.locale))
.map(pipeline =>
<PipelinesListItem
{...pipeline}
Expand All @@ -59,7 +59,8 @@ const PipelinesList = ({ pipelines = [], createActions }) =>

PipelinesList.propTypes = {
pipelines: PropTypes.array,
createActions: PropTypes.func
createActions: PropTypes.func,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
};

export default PipelinesList;
export default injectIntl(PipelinesList);
22 changes: 10 additions & 12 deletions src/components/Pipelines/PipelinesSimpleList/PipelinesSimpleList.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';
import { Table } from 'react-bootstrap';
import { FormattedMessage } from 'react-intl';
import { injectIntl, FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types';

import ExercisePipelinesListItem from '../PipelinesSimpleListItem';

const PipelinesSimpleList = ({ pipelines, createActions, ...rest }) =>
const PipelinesSimpleList = ({ pipelines, createActions, intl, ...rest }) =>
<Table>
<thead>
<tr>
Expand All @@ -32,14 +32,11 @@ const PipelinesSimpleList = ({ pipelines, createActions, ...rest }) =>
</thead>
<tbody>
{pipelines
.sort((a, b) => {
var tmp = a.name.localeCompare(b.name);
if (tmp === 0) {
return b.createdAt - a.createdAt;
} else {
return tmp;
}
})
.sort(
(a, b) =>
a.name.localeCompare(b.name, intl.locale) ||
b.createdAt - a.createdAt
)
.map((pipeline, i) =>
<ExercisePipelinesListItem
{...pipeline}
Expand All @@ -62,7 +59,8 @@ const PipelinesSimpleList = ({ pipelines, createActions, ...rest }) =>

PipelinesSimpleList.propTypes = {
pipelines: PropTypes.array.isRequired,
createActions: PropTypes.func
createActions: PropTypes.func,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
};

export default PipelinesSimpleList;
export default injectIntl(PipelinesSimpleList);
11 changes: 6 additions & 5 deletions src/components/Users/UsersList/UsersList.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Table } from 'react-bootstrap';
import { FormattedMessage } from 'react-intl';
import { injectIntl, FormattedMessage } from 'react-intl';
import UsersListItem from '../UsersListItem';

const UsersList = ({ users = [], createActions, ...rest }) =>
const UsersList = ({ users = [], createActions, intl, ...rest }) =>
<Table hover>
<tbody>
{users
.sort((a, b) => {
const aName = a.name.lastName + ' ' + a.name.firstName;
const bName = b.name.lastName + ' ' + b.name.firstName;
return aName.localeCompare(bName);
return aName.localeCompare(bName, intl.locale);
})
.map(user =>
<UsersListItem
Expand All @@ -35,7 +35,8 @@ const UsersList = ({ users = [], createActions, ...rest }) =>

UsersList.propTypes = {
users: PropTypes.array,
createActions: PropTypes.func
createActions: PropTypes.func,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
};

export default UsersList;
export default injectIntl(UsersList);
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { injectIntl } from 'react-intl';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { Field } from 'redux-form';
Expand All @@ -12,7 +13,8 @@ const EditExerciseConfigTest = ({
supplementaryFiles,
pipelines,
runtimeEnvironmentIndex,
fetchVariables
fetchVariables,
intl
}) =>
<tbody>
{tests.map((test, index) => [
Expand All @@ -30,7 +32,7 @@ const EditExerciseConfigTest = ({
component={SelectField}
options={[{ key: '', name: '...' }].concat(
pipelines
.sort((a, b) => a.name.localeCompare(b.name))
.sort((a, b) => a.name.localeCompare(b.name, intl.locale))
.map(data => {
const obj = {};
obj['key'] = data.id;
Expand Down Expand Up @@ -67,7 +69,7 @@ const EditExerciseConfigTest = ({
component={SelectField}
options={[{ key: '', name: '...' }].concat(
pipelines
.sort((a, b) => a.name.localeCompare(b.name))
.sort((a, b) => a.name.localeCompare(b.name, intl.locale))
.map(data => {
const obj = {};
obj['key'] = data.id;
Expand Down Expand Up @@ -104,7 +106,8 @@ EditExerciseConfigTest.propTypes = {
supplementaryFiles: ImmutablePropTypes.map,
pipelines: ImmutablePropTypes.map,
runtimeEnvironmentIndex: PropTypes.number.isRequired,
fetchVariables: PropTypes.func
fetchVariables: PropTypes.func,
intl: PropTypes.shape({ locale: PropTypes.string.isRequired }).isRequired
};

export default EditExerciseConfigTest;
export default injectIntl(EditExerciseConfigTest);
Loading