-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76bbc66
commit 1e653dc
Showing
12 changed files
with
175 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { cadtApi } from '../'; | ||
// @ts-ignore | ||
import { BaseQueryResult } from '@reduxjs/toolkit/dist/query/baseQueryTypes'; | ||
|
||
const host: string = 'http://localhost:31310'; | ||
|
||
interface BaseQueryResult { | ||
[key: string]: string[]; | ||
} | ||
|
||
interface DescriptionItem { | ||
header: string; | ||
definition: string; | ||
} | ||
|
||
interface GlossaryItem { | ||
term: string; | ||
description: DescriptionItem[]; | ||
} | ||
|
||
const governanceApi = cadtApi.injectEndpoints({ | ||
endpoints: (builder) => ({ | ||
getGlossary: builder.query<GlossaryItem[], void>({ | ||
query: () => ({ | ||
url: `${host}/v1/governance/meta/glossary`, | ||
method: 'GET', | ||
}), | ||
transformResponse: (baseQueryReturnValue: BaseQueryResult): GlossaryItem[] => { | ||
return Object.entries(baseQueryReturnValue).map(([key, valueArray]) => { | ||
// Map each value in the value array to a DescriptionItem by splitting by ";" to separate header and definition | ||
const description: DescriptionItem[] = valueArray.map((item) => { | ||
const [header, definition] = item.split(';').map((part) => part.trim()); | ||
return { header, definition }; | ||
}); | ||
|
||
return { term: key, description }; | ||
}); | ||
}, | ||
}), | ||
}), | ||
}); | ||
|
||
export const { useGetGlossaryQuery } = governanceApi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './governance.api'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { useMemo } from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { DataTable } from '@/components'; | ||
|
||
interface TableProps { | ||
data: any[]; | ||
isLoading: boolean; | ||
order: string; | ||
setOrder: (sort: string) => void; | ||
} | ||
|
||
const GlossaryTable: React.FC<TableProps> = ({ data, isLoading, order, setOrder }) => { | ||
const columns = useMemo( | ||
() => [ | ||
{ | ||
title: <FormattedMessage id={'term'} />, | ||
key: 'term', | ||
}, | ||
{ | ||
title: <FormattedMessage id={'description'} />, | ||
key: 'description', | ||
render: (row: any) => { | ||
return ( | ||
<div className="text-gray-600 dark:text-white"> | ||
{row.description.map((item, index) => ( | ||
<div key={`${item.header}-${index}`} className="mb-4 last:mb-0 text-left"> | ||
<div className="font-bold items-start">{item.header}</div> | ||
<div className="items-start">{item.definition}</div> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}, | ||
}, | ||
], | ||
[], | ||
); | ||
|
||
return ( | ||
<div className="relative"> | ||
<DataTable columns={columns} data={data} primaryKey="term" isLoading={isLoading} order={order} onChangeOrder={setOrder}/> | ||
</div> | ||
); | ||
}; | ||
|
||
export { GlossaryTable }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './ProjectsListTable'; | ||
export * from './SkeletonTable'; | ||
export * from './UnitsListTable'; | ||
export * from './UnitsListTable'; | ||
export * from './GlossaryTable'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { useMemo, useCallback } from 'react'; | ||
import { useGetGlossaryQuery } from '@/api/cadt/v1/governance'; | ||
import { SkeletonTable, GlossaryTable, SearchBox } from '@/components'; | ||
import { useQueryParamState, useColumnOrderHandler } from '@/hooks'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { debounce } from 'lodash'; | ||
|
||
const GlossaryPage: React.FC = () => { | ||
const { data: glossaryData, isLoading: glossaryLoading, error: glossaryError } = useGetGlossaryQuery(); | ||
const [search, setSearch] = useQueryParamState('search', ''); // Fixed the state name to 'search' | ||
const [order, setOrder] = useQueryParamState('order', undefined); | ||
const handleSetOrder = useColumnOrderHandler(order, setOrder); | ||
|
||
// Memoized ordered data based on the `order` variable | ||
const orderedData = useMemo(() => { | ||
if (!order || !glossaryData) return glossaryData; | ||
|
||
const [orderBy, direction] = order.split(':'); | ||
return [...glossaryData].sort((a, b) => { | ||
if (a[orderBy] < b[orderBy]) return direction === 'ASC' ? -1 : 1; | ||
if (a[orderBy] > b[orderBy]) return direction === 'ASC' ? 1 : -1; | ||
return 0; | ||
}); | ||
}, [glossaryData, order]); | ||
|
||
// Filter the ordered data based on the search term | ||
const filteredData = useMemo(() => { | ||
if (!search.trim()) return orderedData; | ||
return orderedData?.filter(item => item.term.toLowerCase().includes(search.toLowerCase())); | ||
}, [orderedData, search]); | ||
|
||
const handleSearchChange = useCallback( | ||
debounce((event: React.ChangeEvent<HTMLInputElement>) => { | ||
setSearch(event.target.value); | ||
}, 800), | ||
[] // Removed dependencies on `setSearch` and `debounce` as they are not expected to change | ||
); | ||
|
||
if (glossaryLoading) { | ||
return <SkeletonTable />; | ||
} | ||
|
||
if (glossaryError) { | ||
return <FormattedMessage id={'unable-to-load-contents'} />; | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="flex flex-col md:flex-row gap-6 pl-1 my-2.5 relative z-30"> | ||
<SearchBox defaultValue={search} onChange={handleSearchChange} /> | ||
</div> | ||
<GlossaryTable data={filteredData || []} isLoading={glossaryLoading} order={order} setOrder={handleSetOrder} /> | ||
</> | ||
); | ||
}; | ||
|
||
export { GlossaryPage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './GlossaryPage' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './Error'; | ||
export * from './ProjectsList'; | ||
export * from './UnitsList'; | ||
export * from './Glossary'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export default { | ||
PROJECTS_LIST: '/projects', | ||
UNITS_LIST: '/units' | ||
UNITS_LIST: '/units', | ||
GLOSSARY: '/glossary', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters