Skip to content

Commit

Permalink
Don't allow making a view global if one already exists with the same …
Browse files Browse the repository at this point in the history
…name.
  • Loading branch information
lbwexler committed Jan 6, 2025
1 parent b5cc8db commit c84d714
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
20 changes: 14 additions & 6 deletions desktop/cmp/viewmanager/dialog/ManageDialogModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,21 @@ export class ManageDialogModel extends HoistModel {
}

private async doMakeGlobalAsync(view: ViewInfo) {
const {globalDisplayName, typeDisplayName} = this.viewManagerModel,
{typedName} = view,
msgs = [
`The ${typedName} will become a ${globalDisplayName} ${typeDisplayName} visible to all other ${XH.appName} users.`,
strong('Are you sure you want to proceed?')
];
const {globalDisplayName, typeDisplayName, globalViews} = this.viewManagerModel,
{typedName} = view;

if (some(globalViews, {name: view.name})) {
XH.alert({
title: 'Alert',
message: `There is already a ${globalDisplayName} ${typedName}. Please rename or edit it instead.`
});
return;
}

const msgs = [
`The ${typedName} will become a ${globalDisplayName} ${typeDisplayName} visible to all other ${XH.appName} users.`,
strong('Are you sure you want to proceed?')
];
const confirmed = await XH.confirm({
message: fragment(msgs.map(m => p(m))),
confirmProps: {
Expand Down
5 changes: 3 additions & 2 deletions desktop/cmp/viewmanager/dialog/ViewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {ViewPanelModel} from '@xh/hoist/desktop/cmp/viewmanager/dialog/ViewPanel
import {getGroupOptions} from '@xh/hoist/desktop/cmp/viewmanager/dialog/Utils';
import {fmtDateTime} from '@xh/hoist/format';
import {Icon} from '@xh/hoist/icon';
import {capitalize} from 'lodash';
import {capitalize, some} from 'lodash';

/**
* Form to edit or view details on a single saved view within the ViewManager manage dialog.
Expand Down Expand Up @@ -128,7 +128,7 @@ const formButtons = hoistCmp.factory<ViewPanelModel>({
});
}

const {enableGlobal, globalDisplayName, manageGlobal, typeDisplayName} =
const {enableGlobal, globalDisplayName, manageGlobal, typeDisplayName, globalViews} =
parent.viewManagerModel;
return vbox({
style: {gap: 10, alignItems: 'center'},
Expand All @@ -148,6 +148,7 @@ const formButtons = hoistCmp.factory<ViewPanelModel>({
icon: Icon.globe(),
width: 200,
outlined: true,
disabled: some(globalViews, {name: view.name}),
omit: readonly || view.isGlobal || !enableGlobal || !manageGlobal,
onClick: () => parent.makeGlobalAsync(view)
}),
Expand Down

0 comments on commit c84d714

Please sign in to comment.