Skip to content

Commit

Permalink
[frontend]Moved models.py changes to UI and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhibhatg committed Jul 27, 2023
1 parent a748265 commit ca1973f
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
${ render_bundle(bundle) | n,unicode }
% endfor

<script type="text/javascript">
(function () {
window.createReactComponents('#embeddable_filebrowser');
})();
</script>

<div>
<StorageBrowserPage data-reactcomponent='StorageBrowserPage'></StorageBrowserPage>
</div>
Expand Down
2 changes: 2 additions & 0 deletions desktop/core/src/desktop/api2.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from desktop import appmanager
from desktop.auth.backend import is_admin
from desktop.conf import ENABLE_CONNECTORS, ENABLE_GIST_PREVIEW, CUSTOM, get_clusters, IS_K8S_ONLY, ENABLE_SHARING
from desktop.conf import ENABLE_NEW_STORAGE_BROWSER
from desktop.lib.conf import BoundContainer, GLOBAL_CONFIG, is_anonymous
from desktop.lib.django_util import JsonResponse, login_notrequired, render
from desktop.lib.exceptions_renderable import PopupException
Expand Down Expand Up @@ -99,6 +100,7 @@ def get_config(request):
config = get_cluster_config(request.user)
config['hue_config']['is_admin'] = is_admin(request.user)
config['hue_config']['is_yarn_enabled'] = is_yarn()
config['hue_config']['enable_new_storage_browser'] = ENABLE_NEW_STORAGE_BROWSER.get()
config['clusters'] = list(get_clusters(request.user).values())
config['documents'] = {
'types': list(Document2.objects.documents(user=request.user).order_by().values_list('type', flat=True).distinct())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ import React from 'react';
import { i18nReact } from '../../../utils/i18nReact';

import CommonHeader from '../../../reactComponents/CommonHeader/CommonHeader';
//TODO: substitute for file browser icon
import ABFSIcon from '../../../components/icons/AdlsIcon';
import DataBrowserIcon from '@cloudera/cuix-core/icons/react/DataBrowserIcon';

const StorageBrowserPage = (): JSX.Element => {
const StorageBrowserPage: React.FC = (): JSX.Element => {
const { t } = i18nReact.useTranslation();

return (
<>
<CommonHeader title={t('Storage Browser')} icon={<ABFSIcon />} />
</>
<div className="hue-storage-browser">
<CommonHeader title={t('Storage Browser')} icon={<DataBrowserIcon />} />
</div>
);
};

Expand Down
8 changes: 8 additions & 0 deletions desktop/core/src/desktop/js/apps/storageBrowser/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import huePubSub from '../../utils/huePubSub';

huePubSub.subscribe('app.dom.loaded', app => {
if (app !== 'filebrowser') {
return;
}
window.createReactComponents('#embeddable_filebrowser');
});
36 changes: 35 additions & 1 deletion desktop/core/src/desktop/js/components/sidebar/HueSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@
database: string;
}
interface BrowserInterpreter {
buttonName: string;
displayName: string;
page: string;
tooltip: string;
type: string;
}
const APP_ICON_INDEX: { [name: string]: string } = {
abfs: `<svg class="hi hi-fw"><use xlink:href="#hi-adls"></use></svg>`,
adls: `<svg class="hi hi-fw"><use xlink:href="#hi-adls"></use></svg>`,
Expand Down Expand Up @@ -484,7 +492,33 @@
});
}
if (appConfig.browser && appConfig.browser.interpreters) {
appConfig.browser.interpreters.forEach(browser => {
// Replace old file browser entries with the new storage browser if the feature flag is enabled.
let browserInterpreters: BrowserInterpreter[] = [];
if (clusterConfig.hue_config.enable_new_storage_browser) {
let firstFileBrowserFound = false;
appConfig.browser.interpreters.forEach(browser => {
const isFileBrowser = /\/filebrowser/.test(browser.page);
if (isFileBrowser) {
if (!firstFileBrowserFound) {
browserInterpreters.push({
buttonName: 'Browse',
displayName: 'Storage Browser',
//by default the first filesystem's url in the config is used.
page: browser.page,
tooltip: 'Storage Browser',
type: 'storageBrowser'
});
}
firstFileBrowserFound = true;
} else {
browserInterpreters.push(browser);
}
});
} else {
browserInterpreters = appConfig.browser.interpreters;
}
browserInterpreters.forEach(browser => {
if (browser.type === 'tables') {
browserItems.push({
type: 'navigation',
Expand Down
6 changes: 3 additions & 3 deletions desktop/core/src/desktop/js/reactComponents/imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export async function loadComponent(name) {
case 'ReactExample':
return (await import('../apps/editor/components/result/reactExample/ReactExample')).default;

case 'StorageBrowserPage':
return (await import('../apps/storageBrowser/StorageBrowserPage/StorageBrowserPage')).default;

// Application global components here
case 'AppBanner':
return (await import('./AppBanner/AppBanner')).default;
Expand All @@ -17,9 +20,6 @@ export async function loadComponent(name) {
case 'FileChooserWithButton':
return (await import('./FileChooser/FileChooserWithButton/FileChooserWithButton')).default;

case 'StorageBrowserPage':
return (await import('../apps/storageBrowser/StorageBrowserPage/StorageBrowserPage')).default;

default:
console.error(`A placeholder component is rendered because you probably forgot to include your new component in the
loadComponent function of reactComponents/imports.js`);
Expand Down
109 changes: 48 additions & 61 deletions desktop/core/src/desktop/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
from desktop.lib.paths import get_run_root, SAFE_CHARACTERS_URI_COMPONENTS
from desktop.redaction import global_redaction_engine
from desktop.settings import DOCUMENT2_SEARCH_MAX_LENGTH, HUE_DESKTOP_VERSION
from desktop.conf import ENABLE_NEW_STORAGE_BROWSER

from filebrowser.conf import REMOTE_STORAGE_HOME

Expand Down Expand Up @@ -2009,73 +2008,61 @@ def _get_browser(self):

remote_home_storage = get_remote_home_storage(self.user)

#TODO: handle all file systems
if ENABLE_NEW_STORAGE_BROWSER.get():
for hdfs_connector in hdfs_connectors:
force_home = remote_home_storage and not remote_home_storage.startswith('/')
home_path = self.user.get_home_directory(force_home=force_home).encode('utf-8')
interpreters.append({
'type': 'hdfs',
'displayName': hdfs_connector,
'buttonName': _('Browse'),
'tooltip': hdfs_connector,
'page': '/filebrowser/' + (
not self.user.is_anonymous and
'view=' + urllib_quote(home_path, safe=SAFE_CHARACTERS_URI_COMPONENTS) or ''
)
})

if 'filebrowser' in self.apps and fsmanager.is_enabled_and_has_access('s3a', self.user):
home_path = remote_home_storage if remote_home_storage else 's3a://'.encode('utf-8')
interpreters.append({
'type': 's3',
'displayName': _('S3'),
'buttonName': _('Browse'),
'tooltip': _('S3'),
'page': '/filebrowser/view=' + urllib_quote(home_path, safe=SAFE_CHARACTERS_URI_COMPONENTS)
})

if 'filebrowser' in self.apps and fsmanager.is_enabled_and_has_access('adl', self.user):
home_path = remote_home_storage if remote_home_storage else 'adl:/'.encode('utf-8')
interpreters.append({
'type': 'adls',
'displayName': _('ADLS'),
'buttonName': _('Browse'),
'tooltip': _('ADLS'),
'page': '/filebrowser/view=' + urllib_quote(home_path, safe=SAFE_CHARACTERS_URI_COMPONENTS)
})

if 'filebrowser' in self.apps and fsmanager.is_enabled_and_has_access('abfs', self.user):
from azure.abfs.__init__ import get_home_dir_for_abfs
home_path = remote_home_storage if remote_home_storage else get_home_dir_for_abfs(self.user).encode('utf-8')
interpreters.append({
'type': 'abfs',
'displayName': 'Storage Browser',
'buttonName': 'Storage Browser',
'tooltip': 'Storage Browser',
'displayName': _('ABFS'),
'buttonName': _('Browse'),
'tooltip': _('ABFS'),
'page': '/filebrowser/view=' + urllib_quote(home_path, safe=SAFE_CHARACTERS_URI_COMPONENTS)
})
else:
for hdfs_connector in hdfs_connectors:
force_home = remote_home_storage and not remote_home_storage.startswith('/')
home_path = self.user.get_home_directory(force_home=force_home).encode('utf-8')
interpreters.append({
'type': 'hdfs',
'displayName': hdfs_connector,
'buttonName': _('Browse'),
'tooltip': hdfs_connector,
'page': '/filebrowser/' + (
not self.user.is_anonymous and
'view=' + urllib_quote(home_path, safe=SAFE_CHARACTERS_URI_COMPONENTS) or ''
)
})

if 'filebrowser' in self.apps and fsmanager.is_enabled_and_has_access('s3a', self.user):
home_path = remote_home_storage if remote_home_storage else 's3a://'.encode('utf-8')
interpreters.append({
'type': 's3',
'displayName': _('S3'),
'buttonName': _('Browse'),
'tooltip': _('S3'),
'page': '/filebrowser/view=' + urllib_quote(home_path, safe=SAFE_CHARACTERS_URI_COMPONENTS)
})

if 'filebrowser' in self.apps and fsmanager.is_enabled_and_has_access('adl', self.user):
home_path = remote_home_storage if remote_home_storage else 'adl:/'.encode('utf-8')
interpreters.append({
'type': 'adls',
'displayName': _('ADLS'),
'buttonName': _('Browse'),
'tooltip': _('ADLS'),
'page': '/filebrowser/view=' + urllib_quote(home_path, safe=SAFE_CHARACTERS_URI_COMPONENTS)
})

if 'filebrowser' in self.apps and fsmanager.is_enabled_and_has_access('abfs', self.user):
from azure.abfs.__init__ import get_home_dir_for_abfs
home_path = remote_home_storage if remote_home_storage else get_home_dir_for_abfs(self.user).encode('utf-8')
interpreters.append({
'type': 'abfs',
'displayName': _('ABFS'),
'buttonName': _('Browse'),
'tooltip': _('ABFS'),
'page': '/filebrowser/view=' + urllib_quote(home_path, safe=SAFE_CHARACTERS_URI_COMPONENTS)
})

if 'filebrowser' in self.apps and fsmanager.is_enabled_and_has_access('ofs', self.user):
from desktop.lib.fs.ozone.ofs import get_ofs_home_directory
home_path = get_ofs_home_directory().encode('utf-8')
interpreters.append({
'type': 'ofs',
'displayName': _('Ozone'),
'buttonName': _('Browse'),
'tooltip': _('Ozone'),
'page': '/filebrowser/view=' + urllib_quote(home_path, safe=SAFE_CHARACTERS_URI_COMPONENTS)
})
if 'filebrowser' in self.apps and fsmanager.is_enabled_and_has_access('ofs', self.user):
from desktop.lib.fs.ozone.ofs import get_ofs_home_directory
home_path = get_ofs_home_directory().encode('utf-8')
interpreters.append({
'type': 'ofs',
'displayName': _('Ozone'),
'buttonName': _('Browse'),
'tooltip': _('Ozone'),
'page': '/filebrowser/view=' + urllib_quote(home_path, safe=SAFE_CHARACTERS_URI_COMPONENTS)
})

if 'metastore' in self.apps:
interpreters.append({
Expand Down

0 comments on commit ca1973f

Please sign in to comment.