Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(feature-toggles): Add feature object to standardize feature toggles #1477

Merged
merged 4 commits into from
Jun 2, 2023

Conversation

JChan106
Copy link
Contributor

@JChan106 JChan106 commented Jun 1, 2023

Purpose is to enhance the Preview SDK to standardize the usage of feature toggles. This takes in a features object passed in from the options object and sets to the Preview options field. This allows Preview items to have access to the features passed in from the Preview SDK caller.

@JChan106 JChan106 requested a review from a team as a code owner June 1, 2023 01:45
Copy link
Collaborator

@jstoffan jstoffan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid introducing global variables into the SDK. Let's discuss the approach.

// Features
// This makes features available everywhere that features is passed in, which includes
// all of the viewers for different files
this.options.features = options.features;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this before the enable/disable viewer logic? Should it have a default value, such as an empty object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will do

@@ -38,6 +38,8 @@ let preview;
let containerEl;

describe('lib/Preview', () => {
const features = { shouldUseBatman: { enabled: true } };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best to avoid copyrighted characters. 😄

@@ -0,0 +1,34 @@
import { getFeatureConfig, isFeatureEnabled } from '../featureChecking';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be converted to a TS file, as well?

@@ -0,0 +1,34 @@
import { getFeatureConfig, isFeatureEnabled } from '../featureChecking';

const Box = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the Box wrapper?

[key: string]: FeatureOptions;
};

const isFeatureEnabled = (features: FeatureConfig, featureName: string): boolean => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we still want a singleton style implementation rather than passing the value around, something like the following would work:

let features = {};

const setFeatures = value => {
    features = value || {};
}

const isFeatureEnabled = (featureName: string): boolean => {
    return !!get(features, featureName, false);
}

// Preview.js
features.setFeatures(options.features);

return get(features, featureName, {});
};

export { isFeatureEnabled, getFeatureConfig };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we export inline?

export const getFeatureConfig ...

jstoffan
jstoffan previously approved these changes Jun 1, 2023
},
};

describe('isFeatureEnabled', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but we typically maintain one top-level describe per test file. Can we wrap these two?

@@ -102,7 +102,7 @@ export const PDFJS_WIDTH_PADDING_PX = 40; // Should match SCROLLBAR_PADDING in p
export const PDFJS_HEIGHT_PADDING_PX = 5; // Should match VERTICAL_PADDING in pdf_viewer.js

export const DOC_LEGACY_STATIC_ASSETS_VERSION = '2.76.0'; // IE11 only
export const DOC_STATIC_ASSETS_VERSION = '2.93.0'; // Modern browsers
export const DOC_STATIC_ASSETS_VERSION = '2.90.0'; // Modern browsers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this change as a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mergify mergify bot merged commit 27792bb into box:master Jun 2, 2023
@JChan106 JChan106 deleted the feature-toggles branch June 2, 2023 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants