Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
d317b038
Commit
d317b038
authored
Nov 23, 2023
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add search box in resources dashboard
parent
3e138405
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
11 deletions
+26
-11
en.json
web/src/locales/en.json
+2
-1
Resources.tsx
web/src/pages/Resources.tsx
+24
-10
No files found.
web/src/locales/en.json
View file @
d317b038
...
@@ -62,7 +62,8 @@
...
@@ -62,7 +62,8 @@
"new"
:
"New"
,
"new"
:
"New"
,
"mark"
:
"Mark"
,
"mark"
:
"Mark"
,
"profile"
:
"Profile"
,
"profile"
:
"Profile"
,
"inbox"
:
"Inbox"
"inbox"
:
"Inbox"
,
"search"
:
"Search"
},
},
"router"
:
{
"router"
:
{
"go-to-home"
:
"Go to Home"
,
"go-to-home"
:
"Go to Home"
,
...
...
web/src/pages/Resources.tsx
View file @
d317b038
import
{
Divider
,
IconButton
,
Tooltip
}
from
"@mui/joy"
;
import
{
Divider
,
IconButton
,
Input
,
Tooltip
}
from
"@mui/joy"
;
import
{
includes
}
from
"lodash-es"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
Link
}
from
"react-router-dom"
;
import
{
Link
}
from
"react-router-dom"
;
import
{
showCommonDialog
}
from
"@/components/Dialog/CommonDialog"
;
import
{
showCommonDialog
}
from
"@/components/Dialog/CommonDialog"
;
...
@@ -12,11 +13,6 @@ import i18n from "@/i18n";
...
@@ -12,11 +13,6 @@ import i18n from "@/i18n";
import
{
Resource
}
from
"@/types/proto/api/v2/resource_service"
;
import
{
Resource
}
from
"@/types/proto/api/v2/resource_service"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
import
{
useTranslate
}
from
"@/utils/i18n"
;
const
fetchAllResources
=
async
()
=>
{
const
{
resources
}
=
await
resourceServiceClient
.
listResources
({});
return
resources
;
};
function
groupResourcesByDate
(
resources
:
Resource
[])
{
function
groupResourcesByDate
(
resources
:
Resource
[])
{
const
grouped
=
new
Map
<
number
,
Resource
[]
>
();
const
grouped
=
new
Map
<
number
,
Resource
[]
>
();
resources
.
forEach
((
item
)
=>
{
resources
.
forEach
((
item
)
=>
{
...
@@ -32,15 +28,23 @@ function groupResourcesByDate(resources: Resource[]) {
...
@@ -32,15 +28,23 @@ function groupResourcesByDate(resources: Resource[]) {
return
grouped
;
return
grouped
;
}
}
interface
State
{
searchQuery
:
string
;
}
const
Resources
=
()
=>
{
const
Resources
=
()
=>
{
const
t
=
useTranslate
();
const
t
=
useTranslate
();
const
loadingState
=
useLoading
();
const
loadingState
=
useLoading
();
const
[
state
,
setState
]
=
useState
<
State
>
({
searchQuery
:
""
,
});
const
[
resources
,
setResources
]
=
useState
<
Resource
[]
>
([]);
const
[
resources
,
setResources
]
=
useState
<
Resource
[]
>
([]);
const
groupedResources
=
groupResourcesByDate
(
resources
.
filter
((
resoure
)
=>
resoure
.
memoId
));
const
filteredResources
=
resources
.
filter
((
resource
)
=>
includes
(
resource
.
filename
,
state
.
searchQuery
));
const
unusedResources
=
resources
.
filter
((
resoure
)
=>
!
resoure
.
memoId
);
const
groupedResources
=
groupResourcesByDate
(
filteredResources
.
filter
((
resoure
)
=>
resoure
.
memoId
));
const
unusedResources
=
filteredResources
.
filter
((
resoure
)
=>
!
resoure
.
memoId
);
useEffect
(()
=>
{
useEffect
(()
=>
{
fetchAllResources
().
then
((
resources
)
=>
{
resourceServiceClient
.
listResources
({}).
then
(({
resources
}
)
=>
{
setResources
(
resources
);
setResources
(
resources
);
loadingState
.
setFinish
();
loadingState
.
setFinish
();
});
});
...
@@ -69,6 +73,16 @@ const Resources = () => {
...
@@ -69,6 +73,16 @@ const Resources = () => {
<
p
className=
"px-2 py-1 flex flex-row justify-start items-center select-none opacity-80"
>
<
p
className=
"px-2 py-1 flex flex-row justify-start items-center select-none opacity-80"
>
<
Icon
.
Paperclip
className=
"w-5 h-auto mr-1"
/>
{
t
(
"common.resources"
)
}
<
Icon
.
Paperclip
className=
"w-5 h-auto mr-1"
/>
{
t
(
"common.resources"
)
}
</
p
>
</
p
>
<
div
>
<
Input
className=
"max-w-[8rem]"
variant=
"plain"
placeholder=
{
t
(
"common.search"
)
}
startDecorator=
{
<
Icon
.
Search
className=
"w-4 h-auto"
/>
}
value=
{
state
.
searchQuery
}
onChange=
{
(
e
)
=>
setState
({
...
state
,
searchQuery
:
e
.
target
.
value
})
}
/>
</
div
>
</
div
>
</
div
>
<
div
className=
"w-full flex flex-col justify-start items-start mt-4 mb-6"
>
<
div
className=
"w-full flex flex-col justify-start items-start mt-4 mb-6"
>
{
loadingState
.
isLoading
?
(
{
loadingState
.
isLoading
?
(
...
@@ -77,7 +91,7 @@ const Resources = () => {
...
@@ -77,7 +91,7 @@ const Resources = () => {
</
div
>
</
div
>
)
:
(
)
:
(
<>
<>
{
r
esources
.
length
===
0
?
(
{
filteredR
esources
.
length
===
0
?
(
<
div
className=
"w-full mt-8 mb-8 flex flex-col justify-center items-center italic"
>
<
div
className=
"w-full mt-8 mb-8 flex flex-col justify-center items-center italic"
>
<
Empty
/>
<
Empty
/>
<
p
className=
"mt-4 text-gray-600 dark:text-gray-400"
>
{
t
(
"message.no-data"
)
}
</
p
>
<
p
className=
"mt-4 text-gray-600 dark:text-gray-400"
>
{
t
(
"message.no-data"
)
}
</
p
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment