Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Jul 20, 2024
1 parent 8e15aa5 commit f2e05c3
Showing 1 changed file with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,32 +84,34 @@ const bulkGetDetail = (

const widthForTypeSelector = 220;
const widthForRightMargin = 4;
const MAX_ITEMS_DISPLAY = 6;

export const RecentWork = (props: { core: CoreStart; workspaceEnabled?: boolean }) => {
const { core, workspaceEnabled } = props;
const recently$Ref = useRef(core.chrome.recentlyAccessed.get$());
const recentAccessed = useObservable(recently$Ref.current, []);
const workspaceList = useObservable(core.workspaces.workspaceList$, []);

const allOptions = useMemo(() => {
const options: string[] = [allOption];
recentAccessed.forEach((recentAccessItem: ChromeRecentlyAccessedHistoryItem) => {
if (
recentAccessItem.extraProps?.type &&
options.indexOf(recentAccessItem.extraProps.type) === -1
) {
options.push(recentAccessItem.extraProps.type);
}
});
return options.map((option: string) => ({ label: option, value: option }));
}, [recentAccessed]);

const [selectedType, setSelectedType] = useState(allOption);
const [selectedSort, setSelectedSort] = useState(recentlyViewed);
const [detailedSavedObjects, setDetailedSavedObjects] = useState<DetailedRecentlyAccessedItem[]>(
[]
);

const allOptions = useMemo(() => {
const options: string[] = [allOption];
detailedSavedObjects
.filter((item) => !item.error)
.forEach((recentAccessItem: ChromeRecentlyAccessedHistoryItem) => {
if (
recentAccessItem.extraProps?.type &&
options.indexOf(recentAccessItem.extraProps.type) === -1
) {
options.push(recentAccessItem.extraProps.type);
}
});
return options.map((option: string) => ({ label: option, value: option }));
}, [detailedSavedObjects]);

const itemsForDisplay = useMemo(() => {
const sortedResult = [...detailedSavedObjects]
.filter((item) => !item.error)
Expand Down Expand Up @@ -210,7 +212,7 @@ export const RecentWork = (props: { core: CoreStart; workspaceEnabled?: boolean
</EuiFlexItem>
</EuiFlexGroup>
<EuiFlexGroup>
{Array.from({ length: 6 }).map((item, itemIndexInRow) => {
{Array.from({ length: MAX_ITEMS_DISPLAY }).map((item, itemIndexInRow) => {
const recentAccessItem = itemsForDisplay[itemIndexInRow];
let content = null;
if (recentAccessItem) {
Expand Down

0 comments on commit f2e05c3

Please sign in to comment.