-
Notifications
You must be signed in to change notification settings - Fork 283
(feat)O3-4564: Support for single extension slot #1400
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
Open
chibongho
wants to merge
7
commits into
main
Choose a base branch
from
singular-extension-slot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b674826
(feat) O3-4564 support for singular extension slot
chibongho b69cf39
address PR feedback
chibongho ccd70dc
Merge branch 'main' into singular-extension-slot
chibongho 9c3a31c
Merge remote-tracking branch 'origin/main' into singular-extension-slot
chibongho e4110a7
Merge remote-tracking branch 'origin/main' into singular-extension-slot
chibongho 4d5639f
Merge branch 'main' into singular-extension-slot
ibacher 5b4ea7a
Merge branch 'main' into singular-extension-slot
chibongho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,31 +42,12 @@ const slotsConfigStore = getExtensionSlotsConfigStore(); | |
| const extensionsConfigStore = getExtensionsConfigStore(); | ||
|
|
||
| // Keep the output store updated | ||
| function updateExtensionOutputStore( | ||
| internalState: ExtensionInternalStore, | ||
| extensionSlotConfigs: ExtensionSlotsConfigStore, | ||
| extensionsConfigStore: ExtensionsConfigStore, | ||
| featureFlagStore: FeatureFlagsStore, | ||
| sessionStore: SessionStore, | ||
| ) { | ||
| function updateExtensionOutputStore() { | ||
| const slots: Record<string, ExtensionSlotState> = {}; | ||
|
|
||
| const isOnline = isOnlineFn(); | ||
| const enabledFeatureFlags = Object.entries(featureFlagStore.flags) | ||
| .filter(([, { enabled }]) => enabled) | ||
| .map(([name]) => name); | ||
|
|
||
| const internalState = extensionInternalStore.getState(); | ||
| for (let [slotName, slot] of Object.entries(internalState.slots)) { | ||
| const { config } = getExtensionSlotConfigFromStore(extensionSlotConfigs, slot.name); | ||
| const assignedExtensions = getAssignedExtensionsFromSlotData( | ||
| slotName, | ||
| internalState, | ||
| config, | ||
| extensionsConfigStore, | ||
| enabledFeatureFlags, | ||
| isOnline, | ||
| sessionStore.session, | ||
| ); | ||
| const assignedExtensions = getAssignedExtensions(slotName); | ||
| slots[slotName] = { moduleName: slot.moduleName, assignedExtensions }; | ||
| } | ||
|
|
||
|
|
@@ -75,68 +56,14 @@ function updateExtensionOutputStore( | |
| } | ||
| } | ||
|
|
||
| extensionInternalStore.subscribe((internalStore) => { | ||
| updateExtensionOutputStore( | ||
| internalStore, | ||
| slotsConfigStore.getState(), | ||
| extensionsConfigStore.getState(), | ||
| featureFlagsStore.getState(), | ||
| sessionStore.getState(), | ||
| ); | ||
| }); | ||
|
|
||
| slotsConfigStore.subscribe((slotConfigs) => { | ||
| updateExtensionOutputStore( | ||
| extensionInternalStore.getState(), | ||
| slotConfigs, | ||
| extensionsConfigStore.getState(), | ||
| featureFlagsStore.getState(), | ||
| sessionStore.getState(), | ||
| ); | ||
| }); | ||
|
|
||
| extensionsConfigStore.subscribe((extensionConfigs) => { | ||
| updateExtensionOutputStore( | ||
| extensionInternalStore.getState(), | ||
| slotsConfigStore.getState(), | ||
| extensionConfigs, | ||
| featureFlagsStore.getState(), | ||
| sessionStore.getState(), | ||
| ); | ||
| }); | ||
|
|
||
| featureFlagsStore.subscribe((featureFlagStore) => { | ||
| updateExtensionOutputStore( | ||
| extensionInternalStore.getState(), | ||
| slotsConfigStore.getState(), | ||
| extensionsConfigStore.getState(), | ||
| featureFlagStore, | ||
| sessionStore.getState(), | ||
| ); | ||
| }); | ||
|
|
||
| sessionStore.subscribe((session) => { | ||
| updateExtensionOutputStore( | ||
| extensionInternalStore.getState(), | ||
| slotsConfigStore.getState(), | ||
| extensionsConfigStore.getState(), | ||
| featureFlagsStore.getState(), | ||
| session, | ||
| ); | ||
| }); | ||
|
|
||
| function updateOutputStoreToCurrent() { | ||
| updateExtensionOutputStore( | ||
| extensionInternalStore.getState(), | ||
| slotsConfigStore.getState(), | ||
| extensionsConfigStore.getState(), | ||
| featureFlagsStore.getState(), | ||
| sessionStore.getState(), | ||
| ); | ||
| } | ||
| extensionInternalStore.subscribe(updateExtensionOutputStore); | ||
| slotsConfigStore.subscribe(updateExtensionOutputStore); | ||
| extensionsConfigStore.subscribe(updateExtensionOutputStore); | ||
| featureFlagsStore.subscribe(updateExtensionOutputStore); | ||
| sessionStore.subscribe(updateExtensionOutputStore); | ||
|
|
||
| updateOutputStoreToCurrent(); | ||
| subscribeConnectivityChanged(updateOutputStoreToCurrent); | ||
| updateExtensionOutputStore(); | ||
| subscribeConnectivityChanged(updateExtensionOutputStore); | ||
|
|
||
| function createNewExtensionSlotInfo(slotName: string, moduleName?: string): ExtensionSlotInfo { | ||
| return { | ||
|
|
@@ -319,21 +246,29 @@ function getOrder( | |
| } | ||
| } | ||
|
|
||
| function getAssignedExtensionsFromSlotData( | ||
| slotName: string, | ||
| internalState: ExtensionInternalStore, | ||
| config: ExtensionSlotConfigObject, | ||
| extensionConfigStoreState: ExtensionsConfigStore, | ||
| enabledFeatureFlags: Array<string>, | ||
| isOnline: boolean, | ||
| session: Session | null, | ||
| ): Array<AssignedExtension> { | ||
| const attachedIds = internalState.slots[slotName].attachedIds; | ||
| const assignedIds = calculateAssignedIds(config, attachedIds); | ||
| const extensions: Array<AssignedExtension> = []; | ||
| /** | ||
| * Create a list of AssignedExtensions for a given slot. This function further | ||
| * filters out extensions that fail 'Display conditions', privilege, feature flag or | ||
| * online / offline checks | ||
| * @see AssignedExtension | ||
| * @param slotName the name of the slot | ||
| * @param extensionIds a list of extensionIds that are slotted into the slot | ||
| * @returns a list of AssignedExtensions | ||
| */ | ||
| function getAssignedExtensionsByExtensionIds(slotName: string, extensionIds: string[]): Array<AssignedExtension> { | ||
| const internalState = extensionInternalStore.getState(); | ||
| const extensionStoreState = extensionsConfigStore.getState(); | ||
| const featureFlagState = featureFlagsStore.getState(); | ||
| const { session } = sessionStore.getState(); | ||
| const isOnline = isOnlineFn(); | ||
| const enabledFeatureFlags = Object.entries(featureFlagState.flags) | ||
| .filter(([, { enabled }]) => enabled) | ||
| .map(([name]) => name); | ||
|
|
||
| const assignedExtensions: Array<AssignedExtension> = []; | ||
|
|
||
| for (let id of assignedIds) { | ||
| const { config: extensionConfig } = getExtensionConfigFromStore(extensionConfigStoreState, slotName, id); | ||
| for (let id of extensionIds) { | ||
| const { config: extensionConfig } = getExtensionConfigFromStore(extensionStoreState, slotName, id); | ||
|
||
| const name = getExtensionNameFromId(id); | ||
| const extension = internalState.extensions[name]; | ||
|
|
||
|
|
@@ -374,7 +309,7 @@ function getAssignedExtensionsFromSlotData( | |
| continue; | ||
| } | ||
|
|
||
| extensions.push({ | ||
| assignedExtensions.push({ | ||
| id, | ||
| name, | ||
| moduleName: extension.moduleName, | ||
|
|
@@ -387,38 +322,45 @@ function getAssignedExtensionsFromSlotData( | |
| } | ||
| } | ||
|
|
||
| return extensions; | ||
| return assignedExtensions; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the list of extensions assigned to a given slot | ||
| * | ||
| * Gets the list of AssignedExtensions for a given slot | ||
| * @see AssignedExtension | ||
| * @param slotName The slot to load the assigned extensions for | ||
| * @returns An array of extensions assigned to the named slot | ||
| */ | ||
| export function getAssignedExtensions(slotName: string): Array<AssignedExtension> { | ||
| const internalState = extensionInternalStore.getState(); | ||
| const { config: slotConfig } = getExtensionSlotConfig(slotName); | ||
| const extensionStoreState = extensionsConfigStore.getState(); | ||
| const featureFlagState = featureFlagsStore.getState(); | ||
| const sessionState = sessionStore.getState(); | ||
| const isOnline = isOnlineFn(); | ||
| const enabledFeatureFlags = Object.entries(featureFlagState.flags) | ||
| .filter(([, { enabled }]) => enabled) | ||
| .map(([name]) => name); | ||
| const extensionIds = getExtensionIds(slotName); | ||
| return getAssignedExtensionsByExtensionIds(slotName, extensionIds); | ||
| } | ||
|
|
||
| return getAssignedExtensionsFromSlotData( | ||
| slotName, | ||
| internalState, | ||
| slotConfig, | ||
| extensionStoreState, | ||
| enabledFeatureFlags, | ||
| isOnline, | ||
| sessionState.session, | ||
| ); | ||
| /** | ||
| * Get an single assigned extension, as if it is assigned to the 'global' extension slot, by extensionId | ||
| * @see AssignedExtension | ||
| * @param extensionId | ||
| */ | ||
| export function getSingularAssignedExtension(extensionId: string): AssignedExtension | null { | ||
| const ret = getAssignedExtensionsByExtensionIds('global', [extensionId]); | ||
| return ret.length > 0 ? ret[0] : null; | ||
| } | ||
|
|
||
| function calculateAssignedIds(config: ExtensionSlotConfigObject, attachedIds: Array<string>) { | ||
| /** | ||
| * Calculate a list of extension ids that are slotted into the specified slot | ||
| * either via: | ||
| * - the "slot" attribute in the extension declaration in routes.json, or | ||
| * - calling attach(), or | ||
| * - the "add" attribute in the configuration of the slot | ||
| * @param slotName the name of the slot | ||
| * @returns a list of extensions ids slotted into the specified slot | ||
| */ | ||
| function getExtensionIds(slotName: string) { | ||
| const internalState = extensionInternalStore.getState(); | ||
| const { config } = getExtensionSlotConfig(slotName); | ||
|
|
||
| const attachedIds = internalState.slots[slotName].attachedIds; | ||
|
|
||
| const addedIds = config.add || []; | ||
| const removedIds = config.remove || []; | ||
| const idOrder = config.order || []; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern of passing in the new store state to the
updateExtensionOutputStoreshould be unnecessary. As a test, I toggled therdefeature flag and confirmed that the patient charts visit notes workspace shows / hides the visit context switcher accordingly.