Skip to content

Commit 9dbbf51

Browse files
committed
temp: prototyping file picker
1 parent 1efd559 commit 9dbbf51

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

src/files-and-videos/generic/table-components/TableActions.jsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import React, { useContext, useEffect } from 'react';
2-
import { isEmpty } from 'lodash';
3-
import { PropTypes } from 'prop-types';
4-
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
51
import { getConfig } from '@edx/frontend-platform';
6-
import {
7-
Button,
8-
DataTableContext,
9-
Dropdown,
10-
useToggle,
11-
} from '@openedx/paragon';
2+
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
3+
import { Button, DataTableContext, Dropdown, useToggle, } from '@openedx/paragon';
124
import { Add, Tune } from '@openedx/paragon/icons';
5+
import { isEmpty } from 'lodash';
6+
import { PropTypes } from 'prop-types';
7+
import React, { useContext, useEffect } from 'react';
138
import messages from '../messages';
149
import SortAndFilterModal from './sort-and-filter-modal';
1510

@@ -26,12 +21,15 @@ const TableActions = ({
2621
const intl = useIntl();
2722
const [isSortOpen, openSort, closeSort] = useToggle(false);
2823
const { state, clearSelection } = useContext(DataTableContext);
24+
const filePickerParams = new URLSearchParams(window.location.search);
2925

26+
const showFilePicker = Boolean(filePickerParams.get('filePicker')) && Boolean(window.opener);
3027
// This useEffect saves DataTable state so it can persist after table re-renders due to data reload.
3128
useEffect(() => {
3229
setInitialState(state);
3330
}, [state]);
3431

32+
3533
const handleOpenFileSelector = () => {
3634
fileInputControl.click();
3735
clearSelection();
@@ -78,6 +76,18 @@ const TableActions = ({
7876
<Button iconBefore={Add} onClick={handleOpenFileSelector}>
7977
{intl.formatMessage(messages.addFilesButtonLabel, { fileType })}
8078
</Button>
79+
{showFilePicker && (
80+
<Button
81+
className="ml-2"
82+
onClick={async () => {
83+
window.opener.postMessage({ type: 'org.openedx.assets.selected.v1', data: selectedFlatRows.map(({ original }) => original) }, '*');
84+
window.close();
85+
}}
86+
disabled={selectedFlatRows.length === 0}
87+
>
88+
Select File(s)
89+
</Button>
90+
)}
8191
<SortAndFilterModal {...{ isSortOpen, closeSort, handleSort }} />
8292
</>
8393
);

0 commit comments

Comments
 (0)