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: search bar in fav activity modal #1799

Draft
wants to merge 1 commit into
base: feat/1637-add-favourite-modal
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import React, { useEffect, useState } from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';

import {
Modal, Table, TableHead, TableRow, TableHeader, Pagination,
TableBody, TableCell, TableContainer, DataTable, TableSelectRow, TableSelectAll
Modal, Table, TableHead, TableRow, TableHeader, Pagination, TableBody,
TableCell, TableContainer, DataTable, TableSelectRow, TableSelectAll,
TextInput, Dropdown, Button, Column, Grid
} from '@carbon/react';
import * as Icons from '@carbon/icons-react';

import { getFavAct, postFavAct, deleteFavAct } from '../../../api-service/favouriteActivitiesAPI';
import { FavActivityPostType } from '../../../types/FavActivityTypes';

import { textConfig, favActHeaders } from './constants';
import ComboBoxEvent from '../../../types/ComboBoxEvent';
import {
HeaderProps, RowProps, FavouriteActivityModalProps, FavActivityTableProps
textConfig, favActHeaders, searchOptions, headerIconMap
} from './constants';
import {
HeaderProps, RowProps, FavouriteActivityModalProps,
FavActivityTableProps, FavActivitySearchMenu
} from './definitions';
import './styles.scss';

Expand All @@ -31,23 +36,24 @@ const allRows: RowProps[] = Object.keys(FavouriteActivityMap).map((key) => {
return null;
}).filter((activity) => activity !== null);

type Department = 'Testing' | 'Administrative' | 'Withdrawal' | 'Processing' | 'Seed and family lot';

const headerIconMap: Record<Department, string> = {
Testing: 'Chemistry',
Administrative: 'Tools',
Withdrawal: 'StayInside',
Processing: 'Industry',
'Seed and family lot': 'SoilMoistureGlobal'
};

const FavouriteActivityModal = ({ open, setOpen }: FavouriteActivityModalProps) => {
const [selectedRows, setSelectedRows] = useState<string[]>([]);
const [initActs, setInitActs] = useState<string[]>([]);
const [searchOption, setSearchOption] = useState<FavActivitySearchMenu>(searchOptions[0]);
const [searchWord, setSearchWord] = useState('');
const [currentPage, setCurrentPage] = useState(1);
const [itemsPerPage, setItemsPerPage] = useState(10);

const currentRows = allRows.slice(
let filteredRows = allRows;
if (searchWord) {
const lowerCaseKeyWord = searchWord.toLowerCase();
filteredRows = allRows.filter((r) => r.activityName.toLowerCase().includes(lowerCaseKeyWord));
if (searchOption.option !== 'All departments') {
filteredRows = filteredRows.filter((row) => row.department === searchOption.option);
}
}

const currentRows = filteredRows.slice(
(currentPage - 1) * itemsPerPage,
currentPage * itemsPerPage
);
Expand Down Expand Up @@ -122,6 +128,38 @@ const FavouriteActivityModal = ({ open, setOpen }: FavouriteActivityModalProps)
<p className="favourite-activity-modal-description">
{textConfig.description}
</p>
<Grid fullWidth className="fav-activity-search-row">
<Column sm={1} md={3} lg={4} xlg={4}>
<Dropdown
id="client-search-dropdown"
label=""
aria-label="Client Search Field Select Dropdown"
titleText=""
items={searchOptions}
selectedItem={searchOption}
onChange={(e: ComboBoxEvent) => {
setSearchOption(e.selectedItem);
}}
/>
</Column>
<Column sm={2} md={3} lg={10} xlg={10}>
<TextInput
id="client-search-input"
labelText=""
aria-label="Favourite Activity Search Input"
placeholder="Search for favourite activity"
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setSearchWord(e.target.value);
}}
/>
</Column>
<Column sm={1} md={2} lg={2} xlg={2}>
<Button size="md" className="fav-activity-search-btn">
Search
<Icons.Search className="fav-activity-search-btn-icon" />
</Button>
</Column>
</Grid>
<DataTable
rows={currentRows}
headers={favActHeaders}
Expand Down Expand Up @@ -174,7 +212,7 @@ const FavouriteActivityModal = ({ open, setOpen }: FavouriteActivityModalProps)
/>

<Pagination
totalItems={allRows.length}
totalItems={filteredRows.length}
pageSize={itemsPerPage}
pageSizes={[5, 10, 15, 20]}
onChange={({ page, pageSize }: { page: number; pageSize: number }) => {
Expand Down
37 changes: 36 additions & 1 deletion frontend/src/views/CONSEP/FavouriteActivity/constants.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HeaderProps } from './definitions';
import { HeaderProps, FavActivitySearchMenu, Department } from './definitions';

export const textConfig = {
title: 'Add favourite activity',
Expand All @@ -18,3 +18,38 @@ export const favActHeaders: HeaderProps[] = [
key: 'department',
header: 'Department'
}];

export const searchOptions: Array<FavActivitySearchMenu> = [
{
label: 'All departments',
option: 'All departments'
},
{
label: 'Testing',
option: 'Testing'
},
{
label: 'Administrative',
option: 'Administrative'
},
{
label: 'Withdrawal',
option: 'Withdrawal'
},
{
label: 'Processing',
option: 'Processing'
},
{
label: 'Seed and family lot',
option: 'Seed and family lot'
}
];

export const headerIconMap: Record<Department, string> = {
Testing: 'Chemistry',
Administrative: 'Tools',
Withdrawal: 'StayInside',
Processing: 'Industry',
'Seed and family lot': 'SoilMoistureGlobal'
};
9 changes: 9 additions & 0 deletions frontend/src/views/CONSEP/FavouriteActivity/definitions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,12 @@ export type FavActivityTableProps = {
getSelectionProps: (props: { row: RowProps }) => any;
getRowProps: (props: { row: RowProps }) => any;
};

export type FavActivitySearchOptions = 'All departments' | 'Testing' | 'Administrative' | 'Withdrawal' | 'Processing' | 'Seed and family lot';

export type FavActivitySearchMenu = {
label: string;
option: FavActivitySearchOptions
};

export type Department = 'Testing' | 'Administrative' | 'Withdrawal' | 'Processing' | 'Seed and family lot';
18 changes: 18 additions & 0 deletions frontend/src/views/CONSEP/FavouriteActivity/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,22 @@ th > .bx--checkbox--inline > .bx--checkbox-label {
margin-top: 2rem;
max-width: 16rem;
}
}

.fav-activity-search-row {
margin: 0 0 1.5rem 0;
padding: 0;

.bx--css-grid-column {
padding: 0;
margin: 0 0.1rem 0 0;
}

.fav-activity-search-btn {
width: 100%;
.fav-activity-search-btn-icon {
color: white;
}
}

}
Loading