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

Feat/add sorting to requests #1793

Merged
merged 3 commits into from
Oct 19, 2023
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
46 changes: 23 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions src/api/community-api/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,22 @@ export const extractTopicsFromSearch = (
return uniqueTopics;
};

export const searchCommunityRequests = (queryTerm: string) => {
export const searchCommunityRequests = (
queryTerm: string,
sortOption?: string
) => {
if (queryTerm.length > 0) {
return axios
.get(
`${FDK_COMMUNITY_BASE_URI}/api/search?term=${queryTerm}&in=titles&matchWords=all&category=6`
`${FDK_COMMUNITY_BASE_URI}/api/search?term=${queryTerm}&in=titles&matchWords=all&categories[]=6&sortBy=${sortOption}&sortDirection=desc`
)
.then(({ data }) => data);
} else {
return axios
.get(`${FDK_COMMUNITY_BASE_URI}/api/search?&category=6`)
.then(({ data }) => data);
}
return axios
.get(
`${FDK_COMMUNITY_BASE_URI}/api/search?&categories[]=6&sortBy=${sortOption}&sortDirection=desc`
)
.then(({ data }) => data);
};

export const pruneNodebbTemplateTags = (raw_text: string) =>
Expand Down
4 changes: 2 additions & 2 deletions src/components/filter-box/filter-box.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import localization from '../../lib/localization';
import { FilterOption } from '../filter-option/filter-option.component';
import './filter-box.scss';

import { FilterSearchOption } from '../../types';
import { SelectOption } from '../../types';

interface Props {
htmlKey?: number;
Expand Down Expand Up @@ -197,7 +197,7 @@ export class FilterBox extends React.Component<Props, State> {
label: label || localization.facet.formatType.UNKNOWN
};
})
.sort((a: FilterSearchOption, b: FilterSearchOption) =>
.sort((a: SelectOption, b: SelectOption) =>
a.label.localeCompare(b.label)
);

Expand Down
8 changes: 6 additions & 2 deletions src/components/with-community/redux/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ export function searchTopicsFailed(message: string) {
};
}

export function searchRequestsRequested(queryTerm: string) {
export function searchRequestsRequested(
queryTerm: string,
sortOption?: string
) {
return {
type: SEARCH_REQUESTS_REQUESTED,
payload: {
queryTerm
queryTerm,
sortOption
}
};
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/with-community/redux/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ function* searchTopicsRequested({
}

function* searchRequestsRequested({
payload: { queryTerm }
payload: { queryTerm, sortOption }
}: ReturnType<typeof actions.searchRequestsRequested>) {
try {
const postHits: CommunityPost = yield call(
searchCommunityRequests,
queryTerm
queryTerm,
sortOption
);
const { multiplePages } = postHits;
const topics: CommunityTopic[] = (
Expand Down
6 changes: 5 additions & 1 deletion src/l10n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,10 @@
"views": "Number of Views",
"createRequest": "Create request",
"requestData": "Request data",
"requestDataInfo": "Do you want to request data, APIs, or anything else you can do it here. You will be redirected to datalandsbyen.no."
"requestDataInfo": "Do you want to request data, APIs, or anything else you can do it here. You will be redirected to datalandsbyen.no.",
"newestToOldest": "Newest to Oldest",
"mostVotes": "Most Votes",
"mostViews": "Most Views",
"view": "View"
}
}
6 changes: 5 additions & 1 deletion src/l10n/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,10 @@
"views": "Antall visninger",
"createRequest": "Lag etterspørsel",
"requestData": "Etterspør data",
"requestDataInfo": "Ønsker du å etterspørre data, APIer eller annet du kan gjøre det her. Du blir sendt til datalandsbyen.no."
"requestDataInfo": "Ønsker du å etterspørre data, APIer eller annet du kan gjøre det her. Du blir sendt til datalandsbyen.no.",
"newestToOldest": "Nyeste til eldste",
"mostVotes": "Flest stemmer",
"mostViews": "Flest visninger",
"view": "Visning"
}
}
6 changes: 5 additions & 1 deletion src/l10n/nn.json
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,10 @@
"views": "Antall visningar",
"createRequest": "Lag etterspurnad",
"requestData": "Etterspør data",
"requestDataInfo": "Ynskjer du å etterspørre data, APIer eller anna kan du gjere det her. Du blir sendt til datalandsbyen.no."
"requestDataInfo": "Ynskjer du å etterspørre data, APIer eller anna kan du gjere det her. Du blir sendt til datalandsbyen.no.",
"newestToOldest": "Nyeste til eldste",
"mostVotes": "Flest stemmer",
"mostViews": "Flest visningar",
"view": "Visning"
}
}
50 changes: 41 additions & 9 deletions src/pages/requests/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { FC, useEffect, useState } from 'react';
import { compose } from 'redux';
import Link from '@fellesdatakatalog/link';
import Button from '@fellesdatakatalog/button';
import Select from 'react-select';
import withCommunity, {
Props as CommunityProps
} from '../../components/with-community';
Expand All @@ -12,6 +13,7 @@ import { formatDate } from '../../lib/date-utils';
import Banner from '../../components/banner';
import localization from '../../lib/localization';
import env from '../../env';
import { SelectOption } from '../../types';

const { FDK_COMMUNITY_BASE_URI } = env;
interface Props extends CommunityProps {}
Expand All @@ -27,11 +29,26 @@ const RequestsPage: FC<Props> = ({
const notDeletedRequests = topics?.filter(topic => topic.deleted === 0);
const [search, setSearch] = useState('');

const sortOptions: SelectOption[] = [
{
value: 'timestamp',
label: localization.requestsPage.newestToOldest
},
{
value: 'upvotes',
label: localization.requestsPage.mostVotes
},
{
value: 'topic.viewcount',
label: localization.requestsPage.mostViews
}
];

return (
<>
<Banner title={localization.requestsPage.title} />
<main id='content' className='container'>
<SC.Row>
<SC.FirstRow>
<SC.InfoText>
<p>
{localization.formatString(localization.requestsPage.ingress, {
Expand All @@ -52,14 +69,29 @@ const RequestsPage: FC<Props> = ({
{localization.requestsPage.createRequest}
</Button>
</SC.Button>
</SC.Row>
<SC.Button>
<input
type='text'
onChange={event => setSearch(event.target.value)}
></input>
<Button onClick={() => searchRequestsRequested(search)}>Søk</Button>
</SC.Button>
</SC.FirstRow>
<SC.FirstRow>
<div>
<p>{localization.requestsPage.view}</p>
<Select
options={sortOptions}
onChange={value => searchRequestsRequested(search, value?.value)}
defaultValue={sortOptions[0]}
/>
</div>
<div>
<p>Fritekssøk i titler</p>
<SC.Row>
<input
type='text'
onChange={event => setSearch(event.target.value)}
/>
<Button onClick={() => searchRequestsRequested(search)}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Her vil vel ikke valgt sortering bli tatt med?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fikses i PR #1795

Søk
</Button>
</SC.Row>
</div>
</SC.FirstRow>
<SC.RequestsTitleRow>
<SC.RequestTitle>
{localization.requestsPage.requests}
Expand Down
11 changes: 8 additions & 3 deletions src/pages/requests/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ const InfoText = styled.div`
margin-bottom: 50px;
`;

const Row = styled.div`
const FirstRow = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 17px;
`;

const Row = styled.div`
display: flex;
`;

const Button = styled.div`
height: fit-content;
display: flex;
`;

const InfoBox = styled.div`
Expand All @@ -83,5 +87,6 @@ export default {
Row,
Button,
InfoBox,
Text
Text,
FirstRow
};
6 changes: 3 additions & 3 deletions src/pages/search-page/filter-tree/filter-tree.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import localization from '../../../lib/localization';
import { getTranslateText } from '../../../lib/translateText';
import './filter-tree.scss';

import type { FilterSearchOption } from '../../../types';
import type { SelectOption } from '../../../types';
import type { FilterChange } from '../../../components/filter-box/filter-box.component';
import TreeView from '../../../components/treeview';

Expand Down Expand Up @@ -271,13 +271,13 @@ export const FilterTree: FC<Props> = ({
label: `${getNameFromNode(node, referenceDataItems)}`
});

const mapNodeToFilterSearchOptions = (node: any): FilterSearchOption[] =>
const mapNodeToFilterSearchOptions = (node: any): SelectOption[] =>
node.children
? [
getFilterSearchOption(node),
...(node.children.flatMap(
mapNodeToFilterSearchOptions
) as FilterSearchOption[])
) as SelectOption[])
]
: [getFilterSearchOption(node)];

Expand Down
2 changes: 1 addition & 1 deletion src/types/domain.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ export interface CommentThread {
timestamp: string;
content: string;
}
export interface FilterSearchOption {
export interface SelectOption {
value: string;
label: string;
}
Expand Down