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(DataSource): Allow for dynamic data source configuration and creation #3543

Merged

Conversation

jbocce
Copy link
Collaborator

@jbocce jbocce commented Jul 17, 2023

Context

Addresses the following issues...

Changes & Results

Added interface in ExtensionManager to add and replace/set data sources. DataSource.initialize is now where a data source is configured. Added onConfiguration hook for a data source to dynamically configure a data source via the URL when initialize is called.

Testing

  • Test that each of the existing data sources (i.e. DICOMweb, DICOMJson, local, DICOMWebProxy, ...) continue to work as before.
  • Attempt to add an onConfiguration to a data source to ensure that hook works. The configuration docs has an example which can be followed.
  • From the browser console, attempt to either add (via extensionManager.addDataSource) a data source or set/update (via extensionManager.setDataSource) an existing data source.

Checklist

PR

  • My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

  • My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

  • The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • OS: Windows 11
  • Node version: 16.14.0
  • Browser: Chrome 114.0.5735.199

Added interface in ExtensionManager to add and replace/set data sources.
DataSource.initialize is now where a data source is configured.
Added onConfiguration hook for a data source to dynamically configure a
data source via the URL when initialize is called.
@netlify
Copy link

netlify bot commented Jul 17, 2023

Deploy Preview for ohif-dev ready!

Name Link
🔨 Latest commit a77ca03
🔍 Latest deploy log https://app.netlify.com/sites/ohif-dev/deploys/64b9461c5e1ed6000846986b
😎 Deploy Preview https://deploy-preview-3543--ohif-dev.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Jul 17, 2023

Deploy Preview for ohif-platform-docs ready!

Name Link
🔨 Latest commit a77ca03
🔍 Latest deploy log https://app.netlify.com/sites/ohif-platform-docs/deploys/64b9461c917db20009981d33
😎 Deploy Preview https://deploy-preview-3543--ohif-platform-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@jbocce jbocce requested review from sedghi and igoroctaviano July 17, 2023 19:42
@codecov
Copy link

codecov bot commented Jul 17, 2023

Codecov Report

Merging #3543 (a77ca03) into master (d5cbbb0) will increase coverage by 0.17%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3543      +/-   ##
==========================================
+ Coverage   42.75%   42.93%   +0.17%     
==========================================
  Files          82       80       -2     
  Lines        1450     1444       -6     
  Branches      338      338              
==========================================
  Hits          620      620              
+ Misses        667      661       -6     
  Partials      163      163              
Impacted Files Coverage Δ
platform/core/src/DataSources/IWebApiDataSource.js 9.09% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6d88978...a77ca03. Read the comment docs.

Comment on lines 18 to 20
for (const [key, value] of searchParams) {
lowerCaseSearchParams.set(key.toLowerCase(), value);
}
Copy link
Member

Choose a reason for hiding this comment

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

this lower casing utility probably is usefull for dicom tags too, can we put it in utilties?

Comment on lines 115 to 128
useEffect(() => {
const dataSourceChangedCallback = () => {
setIsDataSourceInitialized(false);
setDataPath('');
setDataSource(extensionManager.getActiveDataSource()[0]);
setData(DEFAULT_DATA);
};

const sub = extensionManager.subscribe(
ExtensionManager.EVENTS.ACTIVE_DATA_SOURCE_CHANGED,
dataSourceChangedCallback
);
return () => sub.unsubscribe();
}, []);
Copy link
Member

Choose a reason for hiding this comment

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

I prefer the [] useEffects at first but I might be weird

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I rearranged this file to have state followed by effects (since effects might have dependencies on state).

Comment on lines 78 to 79
const [dataSource, setDataSource] = useState(getInitialDataSource());
const [isDataSourceInitialized, setIsDataSourceInitialized] = useState(false);
Copy link
Member

Choose a reason for hiding this comment

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

useStates are spread out in the file which makes reading the file hard. Can you please group them to the top? if you need those functions just put them int the useState like

  const [dataSource, setDataSource] = useState(() => {
    const dataSourceName = getInitialDataSourceName();

    if (!dataSourceName) {
      return extensionManager.getActiveDataSource()[0];
    }

    const dataSource = extensionManager.getDataSources(dataSourceName)?.[0];
    if (!dataSource) {
      throw new Error(`No data source found for ${dataSourceName}`);
    }

    return dataSource;
  });

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I rearranged this file to have state followed by effects (since effects might have dependencies on state).

return dataSourceName;
}, []);

const getInitialDataPath = useCallback(() => {
Copy link
Member

Choose a reason for hiding this comment

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

what is DataPath? is it datasourcePath? it requires doc please

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added a comment and renamed it to dataSourcePath

Copy link
Member

@sedghi sedghi left a comment

Choose a reason for hiding this comment

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

see my comments please thanks

…SourceConfiguration.

Arranged DataSourceWrapper to have state followed by effects.
Moved a data source's friendly name from its definition to its configuration.
@james-hanks james-hanks mentioned this pull request Jul 19, 2023
4 tasks
Copy link
Contributor

@igoroctaviano igoroctaviano left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants