|
1 | 1 | import { AzulEntityStaticResponse } from "@clevercanary/data-explorer-ui/lib/apis/azul/common/entities";
|
2 |
| -import { PARAMS_INDEX_UUID } from "@clevercanary/data-explorer-ui/lib/common/constants"; |
| 2 | +import { |
| 3 | + PARAMS_INDEX_TAB, |
| 4 | + PARAMS_INDEX_UUID, |
| 5 | +} from "@clevercanary/data-explorer-ui/lib/common/constants"; |
3 | 6 | import { EntityConfig } from "@clevercanary/data-explorer-ui/lib/config/entities";
|
4 | 7 | import { getEntityConfig } from "@clevercanary/data-explorer-ui/lib/config/utils";
|
5 | 8 | import { getEntityService } from "@clevercanary/data-explorer-ui/lib/hooks/useEntityService";
|
@@ -128,22 +131,25 @@ export const getStaticProps: GetStaticProps<AzulEntityStaticResponse> = async ({
|
128 | 131 | }
|
129 | 132 |
|
130 | 133 | const props: EntityDetailPageProps = { entityListType: entityListType };
|
| 134 | + |
| 135 | + // If the entity detail view is to be "statically loaded", we need to seed the database (for retrieval of the entity), or |
| 136 | + // fetch the entity detail from API. |
131 | 137 | if (entityConfig.detail.staticLoad) {
|
132 | 138 | // Seed database.
|
133 |
| - if ( |
134 |
| - entityConfig && |
135 |
| - entityConfig.staticLoad && |
136 |
| - entityConfig.detail.staticLoad |
137 |
| - ) { |
| 139 | + if (entityConfig.staticLoad) { |
138 | 140 | await seedDatabase(entityConfig.route, entityConfig);
|
139 | 141 | }
|
140 |
| - |
| 142 | + // Grab the entity detail, either from database or API. |
141 | 143 | const { fetchEntityDetail, path } = getEntityService(entityConfig);
|
142 |
| - const data = await fetchEntityDetail( |
| 144 | + // When the entity detail is to be fetched from API, we only do so for the first tab. |
| 145 | + if (!entityConfig.staticLoad && params?.params?.[PARAMS_INDEX_TAB]) { |
| 146 | + return { props }; |
| 147 | + } |
| 148 | + props.data = await fetchEntityDetail( |
143 | 149 | (params as PageUrl).params[PARAMS_INDEX_UUID],
|
144 |
| - path |
| 150 | + path, |
| 151 | + undefined |
145 | 152 | );
|
146 |
| - props.data = data; |
147 | 153 | }
|
148 | 154 | return {
|
149 | 155 | props,
|
|
0 commit comments