Skip to content

Commit 0b7fee0

Browse files
committed
temp: prototyping file picker
1 parent cc1af47 commit 0b7fee0

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();
@@ -80,6 +78,18 @@ const TableActions = ({
8078
<Button iconBefore={Add} onClick={handleOpenFileSelector}>
8179
{intl.formatMessage(messages.addFilesButtonLabel, { fileType })}
8280
</Button>
81+
{showFilePicker && (
82+
<Button
83+
className="ml-2"
84+
onClick={async () => {
85+
window.opener.postMessage({ type: 'org.openedx.assets.selected.v1', data: selectedFlatRows.map(({ original }) => original) }, '*');
86+
window.close();
87+
}}
88+
disabled={selectedFlatRows.length === 0}
89+
>
90+
Select File(s)
91+
</Button>
92+
)}
8393
<SortAndFilterModal {...{ isSortOpen, closeSort, handleSort }} />
8494
</>
8595
);

0 commit comments

Comments
 (0)