Fakultas Ilmu Komputer UI

Commit 56a812c2 authored by Fadhlan Hazmi's avatar Fadhlan Hazmi
Browse files

1606834604 26 FItur sorting lowongan pekerjaan berdasarkan nama

parent ffa09baa
import React from 'react';
import { Segment, Button } from 'semantic-ui-react';
import { Segment, Button, Dropdown } from 'semantic-ui-react';
import { Link } from 'react-router';
import Tabs from './components/Tabs';
import Pane from './components/Pane';
......@@ -31,7 +31,9 @@ export default class VacancyPage extends React.Component {
this.state = {
vacancies: [],
id: VacancyPage.getId(this.props.user),
sort: '',
};
this.handleChange = this.handleChange.bind(this);
}
......@@ -48,6 +50,7 @@ export default class VacancyPage extends React.Component {
user={this.props.user}
key={1}
userId={this.state.id}
sort={this.state.sort}
/>
}
/>
......@@ -167,9 +170,20 @@ export default class VacancyPage extends React.Component {
return '';
}
handleChange = (e, data) => {
this.setState({ sort: data.value });
};
render() {
return (
<div className="applicant">
<Dropdown
placeholder="Urutkan Berdasarkan"
className="dropdownApplicant"
selection
options={this.state.sortBy}
onChange={this.handleChange}
/>
{this.props.user.role === 'student' || (
<div className="administrationButtons" style={{ display: 'inline-block' }}>
{ this.companyHeader() }
......
......@@ -99,5 +99,13 @@ describe('VacancyPage', () => {
<VacancyPage user={errorUser} />);
expect(vacancyPage).to.exist;
});
it('renders sort feature without problem', () => {
const vacancyPage = ReactTestUtils.renderIntoDocument(
<VacancyPage user={errorUser} />);
vacancyPage.handleChange({}, { value: 'ASC' });
expect(vacancyPage).to.exist;
expect(vacancyPage.state.sort).to.equals('ASC');
});
});
......@@ -11,6 +11,7 @@ export default class VacancyList extends React.Component {
user: React.PropTypes.object.isRequired,
userId: React.PropTypes.number.isRequired,
items: React.PropTypes.array,
sort: React.PropTypes.string.isRequired,
};
static defaultProps = {
......@@ -61,7 +62,7 @@ export default class VacancyList extends React.Component {
);
}
if (this.props.user.role === 'student') {
return this.state.vacancies.map(vacancy =>
const vacancies = this.state.vacancies.map(vacancy =>
(
<Vacancy
key={vacancy.id}
......@@ -74,6 +75,16 @@ export default class VacancyList extends React.Component {
/>
),
);
if (this.props.sort === 'ASC') {
return vacancies.sort((vac1, vac2) => {
return vac1.props.data.name.localeCompare(vac2.props.data.name);
});
} else if (this.props.sort === 'DESC') {
return vacancies.sort((vac1, vac2) => {
return vac2.props.data.name.localeCompare(vac1.props.data.name);
});
}
return vacancies;
} else if ((this.props.user.role === 'admin' && this.props.user.data.company != null)
|| this.props.user.role === 'company') {
return this.state.vacancies.map(vacancy => (
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.17 on 2019-10-08 23:54
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('core', '0017_vacancy_amount'),
('core', '0019_merge_20191006_0852'),
('core', '0014_auto_20191004_1340'),
]
operations = [
]
# -*- coding: utf-8 -*-
# Generated by Django 1.11.17 on 2019-10-08 23:54
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0020_merge_20191009_0654'),
]
operations = [
migrations.AlterField(
model_name='student',
name='phone_number',
field=models.CharField(blank=True, db_index=True, max_length=12, null=True, validators=[django.core.validators.RegexValidator(b'^0\\d{1,11}$')]),
),
]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment