Skip to content

Commit f2d257f

Browse files
authored
fix(app-headless-cms): add dynamic search placeholder to content entries list (#4682)
1 parent 04668ce commit f2d257f

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

packages/app-aco/src/components/Search/Search.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import { SearchWrapper } from "./styled";
55

66
interface SearchProps {
77
value: string;
8+
placeholder: string;
89
onChange: (value: string) => void;
910
}
1011

11-
export const Search = ({ value, onChange }: SearchProps) => {
12+
export const Search = ({ value, placeholder, onChange }: SearchProps) => {
1213
return (
1314
<SearchWrapper>
14-
<SearchUI value={value} onChange={onChange} />
15+
<SearchUI value={value} inputPlaceholder={placeholder} onChange={onChange} />
1516
</SearchWrapper>
1617
);
1718
};

packages/app-aco/src/contexts/acoList.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useContext, useEffect } from "react";
1+
import React, { useCallback, useContext, useEffect, useMemo } from "react";
22
import dotPropImmutable from "dot-prop-immutable";
33
import pick from "lodash/pick";
44
import { useStateIfMounted } from "@webiny/app-admin";
@@ -23,6 +23,7 @@ import { sortTableItems, validateOrGetDefaultDbSort } from "~/sorting";
2323
import { ROOT_FOLDER } from "~/constants";
2424

2525
export interface AcoListContextData<T> {
26+
currentFolder?: FolderItem;
2627
folders: FolderItem[];
2728
hideFilters: () => void;
2829
isListLoading: boolean;
@@ -389,6 +390,10 @@ export const AcoListProvider = ({ children, ...props }: AcoListProviderProps) =>
389390
state.folderId
390391
]);
391392

393+
const currentFolder = useMemo(() => {
394+
return originalFolders?.find(folder => folder.id === currentFolderId);
395+
}, [originalFolders, currentFolderId]);
396+
392397
const context: AcoListContextData<GenericSearchData> = {
393398
...pick(state, [
394399
"isSearch",
@@ -399,6 +404,7 @@ export const AcoListProvider = ({ children, ...props }: AcoListProviderProps) =>
399404
"isSelectedAll"
400405
]),
401406
folders,
407+
currentFolder,
402408
records,
403409
listTitle,
404410
isListLoading: Boolean(

packages/app-headless-cms/src/admin/components/ContentEntries/Header/Header.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface HeaderProps {
1212
onCreateEntry: (event?: React.SyntheticEvent) => void;
1313
onCreateFolder: (event?: React.SyntheticEvent) => void;
1414
searchValue: string;
15+
searchPlaceholder: string;
1516
onSearchChange: (value: string) => void;
1617
}
1718

@@ -23,6 +24,7 @@ export const Header = (props: HeaderProps) => {
2324
onCreateFolder,
2425
title,
2526
searchValue,
27+
searchPlaceholder,
2628
onSearchChange
2729
} = props;
2830

@@ -33,7 +35,11 @@ export const Header = (props: HeaderProps) => {
3335
</TitleColumn>
3436
<ActionsColumn>
3537
<WrapperActions>
36-
<Search value={searchValue} onChange={onSearchChange} />
38+
<Search
39+
value={searchValue}
40+
placeholder={searchPlaceholder}
41+
onChange={onSearchChange}
42+
/>
3743
<ButtonFilters />
3844
<ButtonsCreate
3945
canCreateFolder={canCreateFolder}

packages/app-headless-cms/src/admin/views/contentEntries/Table/Main.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export const Main = ({ folderId: initialFolderId }: MainProps) => {
9292
onCreateEntry={createEntry}
9393
onCreateFolder={onCreateFolder}
9494
searchValue={list.search}
95+
searchPlaceholder={list.searchPlaceholder}
9596
onSearchChange={list.setSearch}
9697
/>
9798
<BulkActions />

packages/app-headless-cms/src/admin/views/contentEntries/hooks/useContentEntriesList.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface ContentEntriesListProviderContext {
5454
isSelectedAll: boolean;
5555
getWhere: () => Record<string, any>;
5656
searchQuery: string;
57+
searchPlaceholder: string;
5758
}
5859

5960
export const ContentEntriesListContext = React.createContext<
@@ -71,6 +72,7 @@ export const ContentEntriesListProvider = ({ children }: ContentEntriesListProvi
7172

7273
const {
7374
folders: initialFolders,
75+
currentFolder,
7476
isListLoading,
7577
isListLoadingMore,
7678
isSearch,
@@ -185,6 +187,18 @@ export const ContentEntriesListProvider = ({ children }: ContentEntriesListProvi
185187
[currentFolderId, baseUrl]
186188
);
187189

190+
const searchPlaceholder = useMemo(() => {
191+
if (!currentFolder) {
192+
return "Search...";
193+
}
194+
195+
if (currentFolder.id === ROOT_FOLDER) {
196+
return `Search all ${contentModel.pluralApiName}`;
197+
}
198+
199+
return `Search in "${currentFolder.title}"`;
200+
}, [currentFolder, contentModel]);
201+
188202
const context: ContentEntriesListProviderContext = {
189203
modelId: contentModel.modelId,
190204
folderId: currentFolderId || ROOT_FOLDER,
@@ -200,6 +214,7 @@ export const ContentEntriesListProvider = ({ children }: ContentEntriesListProvi
200214
onSelectRow,
201215
records,
202216
search,
217+
searchPlaceholder,
203218
selected,
204219
setSelected,
205220
setSearch,

0 commit comments

Comments
 (0)