-
Notifications
You must be signed in to change notification settings - Fork 0
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: support unifying export views #4102 #312
Merged
Merged
Changes from all commits
Commits
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 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 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 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ExportConfig } from "../config/entities"; | ||
import { useConfig } from "./useConfig"; | ||
|
||
/** | ||
* Returns the export configuration for the given entity. | ||
* @returns export configuration. | ||
*/ | ||
export const useEntityExportConfig = (): ExportConfig => { | ||
const { entityConfig } = useConfig(); | ||
|
||
if (!entityConfig.export) { | ||
throw new Error("This entity config does not have an export field set"); | ||
} | ||
|
||
return entityConfig.export; | ||
}; |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes here are specific to tab-hide functionality. |
This file contains 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
67 changes: 67 additions & 0 deletions
67
src/views/EntityExportMethodView/entityExportMethodView.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { useRouter } from "next/router"; | ||
import type { ParsedUrlQuery } from "querystring"; | ||
import React from "react"; | ||
import { EntityDetailViewProps } from "views/EntityDetailView/entityDetailView"; | ||
import { PARAMS_INDEX_EXPORT_METHOD } from "../../common/constants"; | ||
import { ComponentCreator } from "../../components/ComponentCreator/ComponentCreator"; | ||
import { BackPageView } from "../../components/Layout/components/BackPage/backPageView"; | ||
import { ExportMethodConfig } from "../../config/entities"; | ||
import { useEntityExportConfig } from "../../hooks/useEntityExportConfig"; | ||
import { useFetchEntity } from "../../hooks/useFetchEntity"; | ||
import { useUpdateURLCatalogParams } from "../../hooks/useUpdateURLCatalogParam"; | ||
|
||
export const EntityExportMethodView = ( | ||
props: EntityDetailViewProps | ||
): JSX.Element => { | ||
// Update the catalog param if necessary. | ||
useUpdateURLCatalogParams(); | ||
|
||
// Grab the entity to be exported. | ||
const { response } = useFetchEntity(props); | ||
|
||
// Get the column definitions for the entity export. | ||
const { query } = useRouter(); | ||
const { exportMethods, tabs } = useEntityExportConfig(); | ||
const { sideColumn } = tabs[0]; | ||
const { mainColumn, top } = getExportMethodConfig(exportMethods, query) || {}; | ||
|
||
// Wait for the entity to be fetched. | ||
if (!response) { | ||
return <span></span>; | ||
} | ||
|
||
return ( | ||
<BackPageView | ||
mainColumn={ | ||
<ComponentCreator components={mainColumn || []} response={response} /> | ||
} | ||
sideColumn={ | ||
sideColumn ? ( | ||
<ComponentCreator components={sideColumn} response={response} /> | ||
) : undefined | ||
} | ||
top={<ComponentCreator components={top || []} response={response} />} | ||
/> | ||
); | ||
}; | ||
|
||
/** | ||
* Returns the export method configuration for the given pathname. | ||
* @param exportMethods - Export methods config. | ||
* @param query - Router query object. | ||
* @returns export method configuration. | ||
*/ | ||
function getExportMethodConfig( | ||
exportMethods: ExportMethodConfig[], | ||
query: ParsedUrlQuery | ||
): ExportMethodConfig | undefined { | ||
// Determine the selected export method from the URL. | ||
const exportMethodRoute = query.params?.[PARAMS_INDEX_EXPORT_METHOD]; | ||
if (!exportMethodRoute) { | ||
return; | ||
} | ||
// Find the config for the selected export method. | ||
return exportMethods.find(({ route }) => { | ||
return route.includes(exportMethodRoute); | ||
}); | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from "react"; | ||
import { EntityDetailViewProps } from "views/EntityDetailView/entityDetailView"; | ||
import { ComponentCreator } from "../../components/ComponentCreator/ComponentCreator"; | ||
import { BackPageView } from "../../components/Layout/components/BackPage/backPageView"; | ||
import { useEntityExportConfig } from "../../hooks/useEntityExportConfig"; | ||
import { useFetchEntity } from "../../hooks/useFetchEntity"; | ||
import { useUpdateURLCatalogParams } from "../../hooks/useUpdateURLCatalogParam"; | ||
|
||
export const EntityExportView = (props: EntityDetailViewProps): JSX.Element => { | ||
// Update the catalog param if necessary. | ||
useUpdateURLCatalogParams(); | ||
|
||
// Grab the entity to be exported. | ||
const { response } = useFetchEntity(props); | ||
|
||
// Get the column definitions for the entity export. | ||
const { tabs, top } = useEntityExportConfig(); | ||
const currentTab = tabs[0]; | ||
const { mainColumn, sideColumn } = currentTab; | ||
|
||
// Wait for the entity to be fetched. | ||
if (!response) { | ||
return <span></span>; | ||
} | ||
|
||
return ( | ||
<BackPageView | ||
mainColumn={ | ||
<ComponentCreator components={mainColumn} response={response} /> | ||
} | ||
sideColumn={ | ||
sideColumn ? ( | ||
<ComponentCreator components={sideColumn} response={response} /> | ||
) : undefined | ||
} | ||
top={<ComponentCreator components={top} response={response} />} | ||
/> | ||
); | ||
}; |
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.
Hook for easily grabbing entity-specific export config (with related error handling). Matches existing useExportConfig for cohort export functionality.