Skip to content

Commit

Permalink
Release 25 11 24 (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
TCMeldrum authored Nov 25, 2024
2 parents 7efa1e3 + e8ad598 commit 66f6718
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 88 deletions.
2 changes: 1 addition & 1 deletion apps/backend/src/datasources/CallDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ export interface CallDataSource {
getCallsByInstrumentScientist(scientistId: number): Promise<Call[]>;
isCallEnded(callId: number, checkIfInternalEnded: boolean): Promise<boolean>;
isCallEnded(callId: number): Promise<boolean>;
getCallByQuestionId(questionId: string): Promise<Call>;
getCallByAnswerIdProposal(answerId: number): Promise<Call>;
}
2 changes: 1 addition & 1 deletion apps/backend/src/datasources/mockups/CallDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class CallDataSourceMock implements CallDataSource {
async isCallEnded(callId: number): Promise<boolean> {
return callId !== 1;
}
async getCallByQuestionId(questionId: string) {
async getCallByAnswerIdProposal(answer_id: number) {
return dummyCall;
}
}
22 changes: 14 additions & 8 deletions apps/backend/src/datasources/postgres/CallDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,20 +511,26 @@ export default class PostgresCallDataSource implements CallDataSource {
.first()
.then((call: CallRecord) => (call ? false : true));
}
public async getCallByQuestionId(questionId: string): Promise<Call> {
public async getCallByAnswerIdProposal(answerId: number): Promise<Call> {
const records: CallRecord[] = await database('call')
.leftJoin(
.join(
'templates_has_questions',
'templates_has_questions.template_id',
'call.template_id'
)
.leftJoin(
'answers',
'answers.question_id',
.join(
database('answers')
.select()
.where('answers.answer_id', answerId)
.as('a'),
'a.question_id',
'templates_has_questions.question_id'
)
.where('answers.question_id', questionId);
);

if (records.length > 0) {
return createCallObject(records[0]);
}

return createCallObject(records[0]);
throw new GraphQLError(`Call not found for answerId: ${answerId}`);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { logger } from '@user-office-software/duo-logger';
import { GraphQLError } from 'graphql';

Expand Down Expand Up @@ -113,7 +112,7 @@ export default class PostgresStatusActionsLogsDataSource
.select(['sal.*', 'p.*', database.raw('count(*) OVER() AS full_count')])
.from('status_actions_logs as sal')
.distinct('sal.status_actions_log_id')
.leftJoin(
.join(
'status_actions_log_has_proposals as salhp',
'salhp.status_actions_log_id',
'=',
Expand Down
8 changes: 4 additions & 4 deletions apps/backend/src/factory/pdf/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ const addTopicInformation = async (
);
const instruments = await instrumentDataSource.getInstrumentsByIds(ids);

const call = await callDataSource.getCallByQuestionId(
answer.question.id
const call = await callDataSource.getCallByAnswerIdProposal(
answer.answerId
);
answer.value = instrumentPickerAnswer(answer, instruments, call);
}
Expand Down Expand Up @@ -386,9 +386,9 @@ export const collectProposalPDFData = async (
: [Number(answer.value?.instrumentId || '0')];
const instruments =
await baseContext.queries.instrument.getInstrumentsByIds(user, ids);
const call = await baseContext.queries.call.getCallByQuestionId(
const call = await baseContext.queries.call.getCallOfAnswersProposal(
user,
answer.question.id
answer.answerId
);
answer.value = instrumentPickerAnswer(answer, instruments, call);
} else if (answer.question.dataType === DataType.TECHNIQUE_PICKER) {
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/queries/CallQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class CallQueries {
}

@Authorized()
async getCallByQuestionId(user: UserWithRole | null, questionId: string) {
return this.dataSource.getCallByQuestionId(questionId);
async getCallOfAnswersProposal(user: UserWithRole | null, answerId: number) {
return this.dataSource.getCallByAnswerIdProposal(answerId);
}
}
9 changes: 6 additions & 3 deletions apps/backend/src/resolvers/queries/CallQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ export class CallQuery {
}

@Query(() => Call, { nullable: true })
callByQuestionId(
@Arg('questionId', () => String) questionId: string,
getCallByAnswerId(
@Arg('answerId', () => Int) answerId: number,
@Ctx() context: ResolverContext
) {
return context.queries.call.getCallByQuestionId(context.user, questionId);
return context.queries.call.getCallOfAnswersProposal(
context.user,
answerId
);
}
}
2 changes: 0 additions & 2 deletions apps/backend/src/resolvers/types/StatusActionsLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { StatusActionsLog as StatusActionsLogOrigin } from '../../models/StatusA
import { ConnectionStatusAction } from './ConnectionStatusAction';
import { Proposal } from './Proposal';
import { EmailStatusActionRecipients } from './ProposalStatusActionConfig';
import { User } from './User';

@ObjectType()
@Directive('@key(fields: "statusActionsLogId")')
Expand All @@ -36,7 +35,6 @@ export class StatusActionsLog implements Partial<StatusActionsLogOrigin> {
}
@Resolver(() => StatusActionsLog)
export class StatusActionsLogResolver {
@FieldResolver(() => User, { nullable: true })
@FieldResolver(() => ConnectionStatusAction, { nullable: true })
async connectionStatusAction(
@Root() statusActionsLog: StatusActionsLogOrigin,
Expand Down
32 changes: 22 additions & 10 deletions apps/frontend/src/components/common/FileLink.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Link from '@mui/material/Link';
import { SxProps, Theme } from '@mui/system';
import React, { useContext } from 'react';
import React, { useContext, useState } from 'react';

import { DownloadMonitorDialog } from 'context/DownloadContextProvider';
import { UserContext } from 'context/UserContextProvider';

export function FileLink(props: {
Expand All @@ -11,9 +12,12 @@ export function FileLink(props: {
sx?: SxProps<Theme>;
}) {
const { token } = useContext(UserContext);
const [isLoading, setIsLoading] = useState(false);

const AddAuthToLink = (link: string, fileName: string) => {
fetch(link, {
const AddAuthToLink = async (link: string, fileName: string) => {
setIsLoading(true);

return fetch(link, {
method: 'GET',
headers: {
authorization: `Bearer ${token}`,
Expand All @@ -29,16 +33,24 @@ export function FileLink(props: {
link.click();
link.remove();
URL.revokeObjectURL(blobUrl);
setIsLoading(false);
});
};

return (
<Link
download
onClick={() => AddAuthToLink(props.link, props.filename)}
sx={{ cursor: 'pointer', ...props.sx }}
>
{props.children}
</Link>
<>
<Link
download
onClick={() => AddAuthToLink(props.link, props.filename)}
sx={{ cursor: 'pointer', ...props.sx }}
>
{props.children}
</Link>
{isLoading && (
<DownloadMonitorDialog
items={[{ id: props.filename, name: props.filename, total: 1 }]}
/>
)}
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React, { useMemo } from 'react';

import { AnswerRenderer } from 'components/questionary/QuestionaryComponentRegistry';
import { InstrumentPickerConfig } from 'generated/sdk';
import { useQuestionCallData } from 'hooks/call/useQuestionCallData';
import { useAnswerCallData } from 'hooks/call/useQuestionCallData';
import { useInstrumentsByIdsData } from 'hooks/instrument/useInstrumentsByIdsData';
import { toArray } from 'utils/helperFunctions';

const InstrumentPickerAnswerRenderer: AnswerRenderer = ({
answerId,
value,
config,
question,
}) => {
const ids = useMemo(
() =>
Expand All @@ -19,7 +19,7 @@ const InstrumentPickerAnswerRenderer: AnswerRenderer = ({
[value]
);
const { instruments } = useInstrumentsByIdsData(ids);
const data = useQuestionCallData(question.id);
const { callAllocatedTimeUnit } = useAnswerCallData(answerId);
const instrumentPickerConfig = config as InstrumentPickerConfig;
{
if (instrumentPickerConfig.requestTime) {
Expand All @@ -39,7 +39,7 @@ const InstrumentPickerAnswerRenderer: AnswerRenderer = ({
' (' +
filtered.timeRequested +
' ' +
data.call?.allocationTimeUnit +
callAllocatedTimeUnit +
') '
);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import MaterialTableCore, {
Column,
OrderByCollection,
Query,
QueryResult,
} from '@material-table/core';
Expand Down Expand Up @@ -94,7 +95,7 @@ const StatusActionsLogsTable = ({ confirm }: { confirm: WithConfirmType }) => {
if (localStorageValue) {
columns = columns.map((column) => ({
...column,
hidden: localStorageValue?.find(
hidden: localStorageValue.find(
(localStorageValueItem) => localStorageValueItem.title === column.title
)?.hidden,
}));
Expand All @@ -109,6 +110,19 @@ const StatusActionsLogsTable = ({ confirm }: { confirm: WithConfirmType }) => {
});
tableRef.current && tableRef.current.onQueryChange({});
};
const handleSortOrderChange = (orderByCollection: OrderByCollection[]) => {
const [orderBy] = orderByCollection;
setSearchParams((searchParam) => {
searchParam.delete('sortField');
searchParam.delete('sortDirection');
if (orderBy?.orderByField != null && orderBy?.orderDirection != null) {
searchParam.set('sortField', orderBy?.orderByField);
searchParam.set('sortDirection', orderBy?.orderDirection);
}

return searchParam;
});
};
const fetchStatusActionsLogsData = (tableQuery: Query<StatusActionsLog>) =>
new Promise<QueryResult<StatusActionsLog>>(async (resolve, reject) => {
try {
Expand Down Expand Up @@ -293,9 +307,11 @@ const StatusActionsLogsTable = ({ confirm }: { confirm: WithConfirmType }) => {
setLocalStorageValue(proposalColumns);
}}
onPageChange={(page, pageSize) => {
setSearchParams({
page: page.toString(),
pageSize: pageSize.toString(),
setSearchParams((searchParams) => {
searchParams.set('page', page.toString());
searchParams.set('pageSize', pageSize.toString());

return searchParams;
});
}}
onSearchChange={(searchText) => {
Expand All @@ -317,25 +333,7 @@ const StatusActionsLogsTable = ({ confirm }: { confirm: WithConfirmType }) => {
});
}
}}
onOrderCollectionChange={(orderByCollection) => {
const [orderBy] = orderByCollection;

if (!orderBy) {
setSearchParams((searchParams) => {
searchParams.delete('sortField');
searchParams.delete('sortDirection');

return searchParams;
});
} else {
setSearchParams((searchParams) => {
searchParams.set('sortField', orderBy?.orderByField);
searchParams.set('sortDirection', orderBy?.orderDirection);

return searchParams;
});
}
}}
onOrderCollectionChange={handleSortOrderChange}
/>
</div>
</>
Expand Down
12 changes: 7 additions & 5 deletions apps/frontend/src/context/DownloadContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import { downloadBlob } from 'utils/downloadBlob';

import { UserContext } from './UserContextProvider';

const DownloadMonitorDialog = ({
export const DownloadMonitorDialog = ({
items,
cancel,
}: {
items: InProgressItem[];
cancel: (id: string) => void;
cancel?: (id: string) => void;
}) => {
const theme = useTheme();
const [open, setOpen] = useState(true);
Expand Down Expand Up @@ -92,9 +92,11 @@ const DownloadMonitorDialog = ({
)
}
/>
<Button variant="text" onClick={() => cancel(item.id)}>
Cancel
</Button>
{cancel && (
<Button variant="text" onClick={() => cancel(item.id)}>
Cancel
</Button>
)}
</ListItem>
);
})}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query getCallByAnswerId($answerId: Int!) {
getCallByAnswerId(answerId: $answerId) {
allocationTimeUnit
}
}
5 changes: 0 additions & 5 deletions apps/frontend/src/graphql/call/getCallByQuestionId.graphql

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ fragment statusActionsLog on StatusActionsLog {
statusActionsSuccessful
statusActionsTstamp
proposals {
...proposal
}
connectionStatusAction {
action {
name
type
}
proposalId
primaryKey
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ query getStatusActionsLogs($filter: StatusActionsLogsFilter,$searchText: String,
statusActionsLogs(filter: $filter, first: $first, sortField: $sortField, sortDirection: $sortDirection, searchText: $searchText, offset: $offset) {
statusActionsLogs {
...statusActionsLog
connectionStatusAction {
...connectionStatusAction
}
}
totalCount
}
Expand Down
Loading

0 comments on commit 66f6718

Please sign in to comment.