Skip to content

Commit

Permalink
feat: tags folder experimental (#10)
Browse files Browse the repository at this point in the history
* feat: hide native folders behind experimental flag

* fix: better tags resizing

* fix: merge global window

* style: rename params

* refactor: remove level of indirection in feature toggle
  • Loading branch information
laurentsenta committed Dec 21, 2021
1 parent 8d9170a commit 222363e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
15 changes: 11 additions & 4 deletions app/assets/javascripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ declare global {
_plans_url?: string;
// eslint-disable-next-line camelcase
_dashboard_url?: string;
// eslint-disable-next-line camelcase
_default_sync_server: string;
// eslint-disable-next-line camelcase
_enable_unfinished_features: boolean;
// eslint-disable-next-line camelcase
_websocket_url: string;
startApplication?: StartApplication;
}
}

Expand Down Expand Up @@ -216,11 +223,11 @@ const startApplication: StartApplication = async function startApplication(

if (IsWebPlatform) {
startApplication(
(window as any)._default_sync_server as string,
window._default_sync_server,
new BrowserBridge(AppVersion),
(window as any)._enable_unfinished_features as boolean,
(window as any)._websocket_url as string
window._enable_unfinished_features,
window._websocket_url
);
} else {
(window as any).startApplication = startApplication;
window.startApplication = startApplication;
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,16 @@ const QuickSettingsMenu: FunctionComponent<MenuProps> = observer(
onClose={closeQuickSettingsMenu}
isEnabled={focusModeEnabled}
/>
<TagNestingSwitch
application={application}
onToggle={(x) => {
appState.features.hasFolders = x;
}}
isEnabled={appState.features.hasFolders}
onClose={closeQuickSettingsMenu}
/>
{appState.features.hasUnfinishedFoldersFeature && (
<TagNestingSwitch
application={application}
onToggle={(checked: boolean) => {
appState.features.hasFolders = checked;
}}
isEnabled={appState.features.hasFolders}
onClose={closeQuickSettingsMenu}
/>
)}
<div className="h-1px my-2 bg-border"></div>
<button
className="sn-dropdown-item focus:bg-info-backdrop focus:shadow-none"
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/ui_models/app_state/app_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export enum EventSource {
type ObserverCallback = (event: AppStateEvent, data?: any) => Promise<void>;

export class AppState {
readonly enableUnfinishedFeatures: boolean = (window as any)
?._enable_unfinished_features;
readonly enableUnfinishedFeatures: boolean =
window?._enable_unfinished_features;

$rootScope: ng.IRootScopeService;
$timeout: ng.ITimeoutService;
Expand Down
20 changes: 16 additions & 4 deletions app/assets/javascripts/ui_models/app_state/features_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ import { WebApplication } from '../application';
* and eventually for in-development features (feature flags).
*/
export class FeaturesState {
readonly hasUnfinishedFeatures: boolean = window?._enable_unfinished_features;

_hasFolders = false;
private unsub: () => void;

constructor(private application: WebApplication) {
this._hasFolders = this.hasFolderFeature();
this._hasFolders = this.hasFoldersFeature();

makeObservable(this, {
_hasFolders: observable,
hasFolders: computed,
hasUnfinishedFoldersFeature: computed,
});

this.unsub = this.application.addEventObserver(async () => {
runInAction(() => {
this._hasFolders = this.hasFolderFeature();
this._hasFolders = this.hasFoldersFeature();
});
}, ApplicationEvent.FeaturesUpdated);
}
Expand All @@ -33,10 +36,19 @@ export class FeaturesState {
this.unsub();
}

public hasFolderFeature(): boolean {
public get hasUnfinishedFoldersFeature(): boolean {
return this.hasUnfinishedFeatures;
}

public hasFoldersFeature(): boolean {
if (!this.hasUnfinishedFoldersFeature) {
return false;
}

const status = this.application.getFeatureStatus(
FeatureIdentifier.TagNesting
);

return status === FeatureStatus.Entitled;
}

Expand All @@ -50,7 +62,7 @@ export class FeaturesState {
return;
}

if (!this.hasFolderFeature()) {
if (!this.hasFoldersFeature()) {
this.application.alertService?.alert(
'Tag Folders requires at least a Plus Subscription.'
);
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/_tags.scss
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
cursor: pointer;
text-overflow: ellipsis;
width: 75%;
flex-grow: 1;

// Required for Safari to avoid highlighting when dragging panel resizers
// Make sure to undo if it's selected (for editing)
Expand Down

0 comments on commit 222363e

Please sign in to comment.