Skip to content

Commit 30b3fb9

Browse files
authored
feat: add login nag when not logged in (#3624) (#3629)
1 parent 05cf1de commit 30b3fb9

File tree

6 files changed

+66
-2
lines changed

6 files changed

+66
-2
lines changed

explorer/app/content/anvil-cmg/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export { Section } from "../../components/common/MDXMarkdown/components/Section/
33
export { default as ExportToTerraStart } from "../common/exportToTerraStart.mdx";
44
export { default as ExportToTerraSuccess } from "../common/exportToTerraSuccess.mdx";
55
export { default as DataReleasePolicy } from "./dataReleasePolicy.mdx";
6+
export { default as LoginReminder } from "./loginReminder.mdx";
67
export { default as LoginTermsOfService } from "./loginTermsOfService.mdx";
78
export { default as LoginText } from "./loginText.mdx";
89
export { default as LoginWarning } from "./loginWarning.mdx";
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Link } from "@clevercanary/data-explorer-ui/lib/components/Links/components/Link/link";
2+
3+
<span>
4+
Access to data explorer is limited for unauthorized users.To view all
5+
available data please <Link label="Sign In" url="/login" />
6+
</span>

explorer/app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,21 @@ export const buildDatasetIds = (
256256
};
257257
};
258258

259+
/**
260+
* Build dataset list view list hero warning.
261+
* Warning serves as a reminder for users to log in.
262+
* @returns model to be used as props for Alert component.
263+
*/
264+
export const buildDatasetListViewListHeroWarning = (): React.ComponentProps<
265+
typeof C.Alert
266+
> => {
267+
return {
268+
severity: "warning",
269+
title: MDX.RenderComponent({ Component: MDX.LoginReminder }),
270+
variant: "banner",
271+
};
272+
};
273+
259274
/**
260275
* Build props for StatusBadge component from the given datasets response.
261276
* @param datasetsResponse - Response model return from datasets API.
@@ -827,6 +842,24 @@ function mapCurrentQuery(
827842
];
828843
}
829844

845+
/**
846+
* Renders configuration component children when the given authentication state is not authorized.
847+
* @param _ - Unused.
848+
* @param viewContext - View context.
849+
* @returns model to be used as props for the ConditionalComponent component.
850+
*/
851+
export const renderWhenUnAuthorized = (
852+
_: DatasetsResponse,
853+
viewContext: ViewContext
854+
): React.ComponentProps<typeof C.ConditionalComponent> => {
855+
const {
856+
authState: { isAuthorized },
857+
} = viewContext;
858+
return {
859+
isIn: !isAuthorized,
860+
};
861+
};
862+
830863
/**
831864
* Renders entity related export when the given datasests response is accessible.
832865
* @param datasetsResponse - Response model return from datasets API.

explorer/site-config/anvil-cmg/dev/index/datasetsEntityConfig.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { mainColumn as exportMainColumn } from "../detail/dataset/exportMainColu
1616
import { mainColumn } from "../detail/dataset/overviewMainColumn";
1717
import { sideColumn } from "../detail/dataset/overviewSideColumn";
1818
import { top } from "../detail/dataset/top";
19+
import { listHero } from "../listView/datasetsListHero";
1920

2021
/**
2122
* Entity config object responsible for config related to the /explore/datasets route.
@@ -134,6 +135,9 @@ export const datasetsEntityConfig: EntityConfig<DatasetsResponse> = {
134135
id: ANVIL_CMG_CATEGORY_KEY.DATASET_TITLE,
135136
},
136137
} as ListConfig<DatasetsResponse>,
138+
listView: {
139+
listHero,
140+
},
137141
route: "datasets",
138142
staticLoad: false,
139143
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {
2+
ComponentConfig,
3+
ComponentsConfig,
4+
} from "@clevercanary/data-explorer-ui/lib/config/entities";
5+
import { DatasetsResponse } from "../../../../app/apis/azul/anvil-cmg/common/responses";
6+
import * as C from "../../../../app/components";
7+
import * as V from "../../../../app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders";
8+
9+
export const listHero: ComponentsConfig = [
10+
{
11+
children: [
12+
{
13+
component: C.Alert,
14+
viewBuilder: V.buildDatasetListViewListHeroWarning,
15+
} as ComponentConfig<typeof C.Alert>,
16+
],
17+
component: C.ConditionalComponent,
18+
viewBuilder: V.renderWhenUnAuthorized,
19+
} as ComponentConfig<typeof C.ConditionalComponent, DatasetsResponse>,
20+
];

explorer/site-config/anvil-cmg/dev/listView/listHero.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import {
33
ComponentsConfig,
44
} from "@clevercanary/data-explorer-ui/lib/config/entities";
55
import * as C from "../../../../app/components";
6-
import * as T from "../../../../app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders";
6+
import * as V from "../../../../app/viewModelBuilders/azul/anvil-cmg/common/viewModelBuilders";
77

88
export const listHero: ComponentsConfig = [
99
{
1010
component: C.Alert,
11-
viewBuilder: T.buildListWarning,
11+
viewBuilder: V.buildListWarning,
1212
} as ComponentConfig<typeof C.Alert>,
1313
];

0 commit comments

Comments
 (0)