Skip to content

Commit 5e44248

Browse files
committed
wip
1 parent bdb58e6 commit 5e44248

File tree

11 files changed

+124
-39
lines changed

11 files changed

+124
-39
lines changed
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import React from "react";
2-
import { PageListConfig } from "@webiny/app-website-builder/modules/pages/configs/index.js";
2+
import { PageListConfig } from "@webiny/app-website-builder";
33
import { PagesListContentReviews } from "./PagesListContentReviews.js";
4+
import { PageListChangeStatus } from "./PageListChangeStatus.js";
5+
import { UseDocumentListHookDecorator } from "./UseDocumentListHookDecorator.js";
46

57
export const PageList = () => {
68
return (
79
<PageListConfig>
10+
{/* Attach the decorator for useDocumentList - need it to make pages with states unselectable */}
11+
<UseDocumentListHookDecorator />
12+
{/* Add a Content Reviews button to footer in sidebar */}
813
<PagesListContentReviews />
14+
{/* Decorate the Change Status action in row options to hide it for pages in certain workflow states */}
15+
<PageListChangeStatus />
916
</PageListConfig>
1017
);
1118
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from "react";
2+
import { PageListConfig } from "@webiny/app-website-builder";
3+
import { WorkflowStateValue } from "@webiny/app-workflows/types.js";
4+
import type { WithWorkflowState } from "~/types.js";
5+
import type { PageDto } from "@webiny/app-website-builder/domain/Page/index.js";
6+
import { usePage } from "@webiny/app-website-builder/modules/pages/PagesList/hooks/usePage.js";
7+
8+
const { Browser } = PageListConfig;
9+
10+
const decoratePage = (page: PageDto): WithWorkflowState<PageDto> => {
11+
return {
12+
...page,
13+
// @ts-expect-error
14+
state: page.state
15+
};
16+
};
17+
18+
export const PageListChangeStatus = Browser.Page.Action.createDecorator(Original => {
19+
return function PageListChangeStatusAction(props) {
20+
const { page } = usePage();
21+
const { state } = decoratePage(page);
22+
if (
23+
props.name !== "changeStatus" ||
24+
!state?.state ||
25+
state.state === WorkflowStateValue.approved
26+
) {
27+
return <Original {...props} />;
28+
}
29+
30+
return null;
31+
};
32+
});

packages/app-website-builder-workflows/src/Components/PagesList/PagesListContentReviews.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ const PageListContentReviewsButton = () => {
1818
<Sidebar.Item
1919
className={"w-full"}
2020
onClick={showOverlay}
21-
text={"Workflow States"}
21+
text={"Content Reviews"}
2222
icon={
2323
<Sidebar.Item.Icon
2424
element={<WorkflowStateListIcon />}
25-
label={"Workflow States"}
25+
label={"Content Reviews"}
2626
/>
2727
}
2828
/>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useDocumentList } from "@webiny/app-website-builder/modules/pages/PagesList/useDocumentList.js";
2+
3+
export const UseDocumentListHookDecorator = useDocumentList.createDecorator(original => {
4+
return function useDocumentListWorkflows() {
5+
const hook = original();
6+
7+
return {
8+
...hook,
9+
vm: {
10+
...hook.vm
11+
// data: hook.vm.data.map(item => {
12+
// return item;
13+
// })
14+
}
15+
};
16+
};
17+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { WorkflowStateValue } from "@webiny/app-workflows/types.js";
2+
3+
export interface IRecordWorkflowStateIdentity {
4+
id: string;
5+
displayName: string;
6+
type: string;
7+
}
8+
9+
export interface IRecordWorkflowState {
10+
workflowId: string;
11+
stepId: string;
12+
state: WorkflowStateValue;
13+
savedBy?: IRecordWorkflowStateIdentity | null;
14+
}
15+
16+
export type WithWorkflowState<T> = T & {
17+
state?: IRecordWorkflowState | null;
18+
};

packages/app-website-builder/src/modules/pages/PagesList/components/Table/Cells/CellActions.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FolderProvider, useAcoConfig } from "@webiny/app-aco";
33
import { makeDecoratable, OptionsMenu } from "@webiny/app-admin";
44
import { PageListConfig } from "~/modules/pages/configs/index.js";
55
import { PageProvider } from "~/modules/pages/PagesList/hooks/usePage.js";
6+
67
const DefaultCellActions = () => {
78
const { useTableRow, isFolderRow } = PageListConfig.Browser.Table.Column;
89
const { row } = useTableRow();
@@ -20,6 +21,10 @@ const DefaultCellActions = () => {
2021
</FolderProvider>
2122
);
2223
}
24+
25+
console.log({
26+
...documentConfig.actions
27+
});
2328

2429
return (
2530
<PageProvider page={row.data}>
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import React, { createContext, useContext, useMemo } from "react";
22
import { DocumentListPresenter } from "./DocumentListPresenter.js";
3+
import { makeDecoratableHook } from "@webiny/react-composition";
34

45
const DocumentListPresenterContext = createContext<DocumentListPresenter | null>(null);
56

6-
export const DocumentListPresenterProvider: React.FC<{ children: React.ReactNode }> = ({
7+
interface IDocumentListPresenterProviderProps {
8+
children: React.ReactNode;
9+
}
10+
11+
export const DocumentListPresenterProvider = ({
712
children
8-
}) => {
13+
}: IDocumentListPresenterProviderProps) => {
914
const presenter = useMemo(() => new DocumentListPresenter(), []);
1015
return (
1116
<DocumentListPresenterContext.Provider value={presenter}>
@@ -14,12 +19,12 @@ export const DocumentListPresenterProvider: React.FC<{ children: React.ReactNode
1419
);
1520
};
1621

17-
export function useDocumentListPresenter() {
22+
export const useDocumentListPresenter = makeDecoratableHook(() => {
1823
const presenter = useContext(DocumentListPresenterContext);
1924
if (!presenter) {
2025
throw new Error(
2126
"useDocumentListPresenter must be used within a DocumentListPresenterProvider"
2227
);
2328
}
2429
return presenter;
25-
}
30+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from "./DocumentListPresenter.js";
2+
export { useDocumentListPresenter } from "./DocumentListPresenterContext.js";

packages/app-website-builder/src/modules/pages/PagesList/useDocumentList.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useState, useMemo, useEffect, useRef } from "react";
1+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
22
import { autorun } from "mobx";
33
import {
44
useGetFolderHierarchy,
@@ -8,8 +8,9 @@ import {
88
import { useDocumentListPresenter } from "./presenters/DocumentListPresenterContext.js";
99
import { useFilterPages, useLoadPages } from "~/features/pages/index.js";
1010
import { useSelectPages } from "~/features/pages/selectPages/useSelectPages.js";
11+
import { makeDecoratableHook } from "@webiny/react-composition";
1112

12-
export const useDocumentList = () => {
13+
export const useDocumentList = makeDecoratableHook(() => {
1314
const isFirstLoad = useRef(true);
1415
const { folders, getFolderHierarchy } = useGetFolderHierarchy();
1516
const { listFoldersByParentIds } = useListFoldersByParentIds();
@@ -77,4 +78,4 @@ export const useDocumentList = () => {
7778
vm,
7879
showFilters
7980
};
80-
};
81+
});

packages/app-website-builder/src/modules/pages/configs/list/Browser/BulkAction.tsx

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useDocumentList } from "~/modules/pages/PagesList/useDocumentList.js";
66
import { useSelectPages } from "~/features/pages/selectPages/useSelectPages.js";
77
import { Page, type PageDto, PageDtoMapper } from "~/domain/Page/index.js";
88
import type { TableRow } from "~/modules/pages/types.js";
9+
import { makeDecoratable } from "@webiny/react-composition";
910

1011
export interface BulkActionConfig {
1112
name: string;
@@ -20,36 +21,33 @@ export interface BulkActionProps {
2021
element?: React.ReactElement;
2122
}
2223

23-
export const BaseBulkAction = ({
24-
name,
25-
after = undefined,
26-
before = undefined,
27-
remove = false,
28-
element
29-
}: BulkActionProps) => {
30-
const getId = useIdGenerator("bulkAction");
24+
export const BaseBulkAction = makeDecoratable(
25+
"BulkAction",
26+
({ name, after = undefined, before = undefined, remove = false, element }: BulkActionProps) => {
27+
const getId = useIdGenerator("bulkAction");
3128

32-
const placeAfter = after !== undefined ? getId(after) : undefined;
33-
const placeBefore = before !== undefined ? getId(before) : undefined;
29+
const placeAfter = after !== undefined ? getId(after) : undefined;
30+
const placeBefore = before !== undefined ? getId(before) : undefined;
3431

35-
return (
36-
<Property id="browser" name={"browser"}>
37-
<Property
38-
id={getId(name)}
39-
name={"bulkActions"}
40-
remove={remove}
41-
array={true}
42-
before={placeBefore}
43-
after={placeAfter}
44-
>
45-
<Property id={getId(name, "name")} name={"name"} value={name} />
46-
{element ? (
47-
<Property id={getId(name, "element")} name={"element"} value={element} />
48-
) : null}
32+
return (
33+
<Property id="browser" name={"browser"}>
34+
<Property
35+
id={getId(name)}
36+
name={"bulkActions"}
37+
remove={remove}
38+
array={true}
39+
before={placeBefore}
40+
after={placeAfter}
41+
>
42+
<Property id={getId(name, "name")} name={"name"} value={name} />
43+
{element ? (
44+
<Property id={getId(name, "element")} name={"element"} value={element} />
45+
) : null}
46+
</Property>
4947
</Property>
50-
</Property>
51-
);
52-
};
48+
);
49+
}
50+
);
5351

5452
const useWorker = () => {
5553
const { vm } = useDocumentList();

0 commit comments

Comments
 (0)