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

Fix missing output checker actions in request sidebar #57

Merged
merged 1 commit into from
Feb 13, 2019
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
2 changes: 2 additions & 0 deletions frontend/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const cookieSecret = config.get('cookieSecret');
const isDevelopment = process.env.NODE_ENV === 'development';
const filesApiHost = config.get('filesApiHost');
const forumSocket = config.get('forumSocket');
const idField = config.get('user.idField');
const memoryStore = new MemoryStore({
checkPeriod: 86400000, // prune expired entries every 24h
});
Expand Down Expand Up @@ -93,6 +94,7 @@ app.get('*', storeUrl, (req, res) => {
filesApiHost: parseApiHost(filesApiHost),
socketHost: parseWsHost(forumSocket),
commit: get(process, 'env.GITHASH', ''),
idField,
});
});

Expand Down
1 change: 1 addition & 0 deletions frontend/server/views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ html
window.FILES_API_HOST = !{JSON.stringify(filesApiHost)};
window.SOCKET_HOST = !{JSON.stringify(socketHost)};
window.COMMIT = !{JSON.stringify(commit)};
window.ID_FIELD = !{JSON.stringify(idField)};

if isDevelopment
script(src="/main.js")
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/modules/discussion/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { camelizeKeys } from 'humps';
import { getToken } from '@src/services/auth';
import has from 'lodash/has';
import get from 'lodash/get';
import { idField } from '@src/services/config';

import { postSchema } from './schemas';

Expand All @@ -16,7 +17,7 @@ function createSocket() {
return socket;
}

function createSocketChannel(socket, email) {
function createSocketChannel(socket, username) {
return eventChannel(emit => {
socket.onmessage = event => {
const parsedJson = JSON.parse(event.data);
Expand All @@ -29,7 +30,7 @@ function createSocketChannel(socket, email) {
if (has(json, 'comment')) {
const { topicId, authorUser } = json.comment;

if (authorUser !== email) {
if (authorUser !== username) {
const payload = normalize(json.comment, postSchema);

emit({
Expand All @@ -52,8 +53,10 @@ function createSocketChannel(socket, email) {
function* authWatcher() {
try {
const socket = yield call(createSocket);
const email = yield select(state => get(state, 'app.auth.user.email'));
const channel = yield call(createSocketChannel, socket, email);
const user = yield select(state => get(state, 'app.auth.user', {}));
const email = get(user, 'email', '');
const username = get(user, idField, email);
const channel = yield call(createSocketChannel, socket, username);

while (true) {
const { payload, meta } = yield take(channel);
Expand Down
25 changes: 13 additions & 12 deletions frontend/src/modules/output-checker/components/request/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ function Sidebar({
<p>{data.author}</p>
<h6>Reviewers</h6>
{data.reviewers.length === 1 && <p>{assignedUser}</p>}
{data.reviewers.length <= 0 && (
<Button
appearance="link"
id="request-sidebar-pickup-button"
iconBefore={<AddCircleIcon primaryColor="green" />}
isDisabled={isSaving}
onClick={() => onPickupRequest(id)}
>
Assign to Me
</Button>
)}
{user.email === assignedUser &&
{data.reviewers.length <= 0 &&
data.state < 3 && (
<Button
appearance="link"
id="request-sidebar-pickup-button"
iconBefore={<AddCircleIcon primaryColor="green" />}
isDisabled={isSaving}
onClick={() => onPickupRequest(id)}
>
Assign to Me
</Button>
)}
{user.username === assignedUser &&
data.state < 4 && (
<React.Fragment>
<h6>Actions</h6>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/modules/output-checker/containers/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ import values from 'lodash/values';
import withRequest from '@src/modules/data/components/data-request';
import { fetchRequests } from '@src/modules/requests/actions';
import { requestsListSchema } from '@src/modules/requests/schemas';
import { idField } from '@src/services/config';

import RequestsList from '../components/requests-list';

const mapStateToProps = (state, { params }) => {
const { filter, search } = state.outputChecker.viewState;
const user = get(state, 'app.auth.user.email');
const username = get(state, ['app', 'auth', 'user', idField]);
const requests = values(state.data.entities.requests);
const data = requests
.filter(d => d.state === params.state)
.filter(d => {
switch (filter) {
case 'mine':
return head(d.reviewers) === user;
return head(d.reviewers) === username;
case 'unassigned':
return d.reviewers.length === 0;
default:
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/services/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ export const limit = 100;

export const version = VERSION;
export const commit = COMMIT;
export const idField = ID_FIELD;

export default {
commit,
limit,
version,
idField,
};