forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeaderNavigations.tsx
More file actions
119 lines (111 loc) · 3.14 KB
/
HeaderNavigations.tsx
File metadata and controls
119 lines (111 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { useIntl } from '@edx/frontend-platform/i18n';
import {
Button,
ButtonGroup,
Stack,
} from '@openedx/paragon';
import {
Add,
Edit as EditIcon,
FindInPage,
InfoOutline,
} from '@openedx/paragon/icons';
import { COURSE_BLOCK_NAMES } from '@src/constants';
import messages from './messages';
import { isUnitPageNewDesignEnabled } from '../utils';
import { useUnitSidebarContext } from '../unit-sidebar/UnitSidebarContext';
export type HeaderNavigationActions = {
handleViewLive: () => void;
handlePreview: () => void;
handleEdit: () => void;
};
type HeaderNavigationsProps = {
headerNavigationsActions: HeaderNavigationActions;
category: string;
isPublished?: boolean;
};
/**
* Generic header navigations to be used in this pages:
* - Unit page
* - Legacy library content page
* - Split test page
*/
const HeaderNavigations = ({
headerNavigationsActions,
category,
isPublished = true,
}: HeaderNavigationsProps) => {
const intl = useIntl();
const {
handleViewLive,
handlePreview,
handleEdit,
} = headerNavigationsActions;
const { setCurrentPageKey, readOnly } = useUnitSidebarContext();
const showNewDesignButtons = isUnitPageNewDesignEnabled();
return (
<nav className="header-navigations ml-auto flex-shrink-0">
{
/**
* Action buttons used in the unit page
*/
}
{category === COURSE_BLOCK_NAMES.vertical.id && (
<Stack direction="horizontal" gap={3}>
{showNewDesignButtons && (
<>
<Button
variant="outline-primary"
iconBefore={InfoOutline}
onClick={() => setCurrentPageKey('info', null)}
>
{intl.formatMessage(messages.infoButton)}
</Button>
{!readOnly && (
<Button
variant="outline-primary"
iconBefore={Add}
onClick={() => setCurrentPageKey('add', null)}
>
{intl.formatMessage(messages.addButton)}
</Button>
)}
</>
)}
<ButtonGroup>
<Button
variant="outline-primary"
onClick={handlePreview}
iconBefore={FindInPage}
>
{intl.formatMessage(messages.previewButton)}
</Button>
<Button
variant="outline-primary"
onClick={handleViewLive}
disabled={!isPublished}
>
{intl.formatMessage(messages.viewLiveButton)}
</Button>
</ButtonGroup>
</Stack>
)}
{
/**
* Action buttons used in legacy libraries content page and split test page
*/
}
{[COURSE_BLOCK_NAMES.libraryContent.id, COURSE_BLOCK_NAMES.splitTest.id].includes(category) && (
<Button
iconBefore={EditIcon}
variant="outline-primary"
onClick={handleEdit}
data-testid="header-edit-button"
>
{intl.formatMessage(messages.editButton)}
</Button>
)}
</nav>
);
};
export default HeaderNavigations;