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

Admin Generator (Future): Implement option to set Tooltips for grid column headers #2362

Merged
merged 28 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f46bf34
Add option to generate tooltip for column headers in admin generator
andrearutrecht Jul 31, 2024
a608d5d
Generate Grids with Tooltips
andrearutrecht Jul 31, 2024
abb4d10
Add changeset for admin generator tooltip
andrearutrecht Jul 31, 2024
3a4f71b
Upgrade changeset text
andrearutrecht Jul 31, 2024
2b2cb12
Exchange div with Box
andrearutrecht Aug 1, 2024
653ae01
Do not use renderHeader whe no tooltipMessage ist set
andrearutrecht Aug 1, 2024
ddda3fd
Use 'GridColumnHeaderTitle' instead of 'Typography' ofr column header…
andrearutrecht Aug 1, 2024
0f73b21
Remove button from Tooltip icon and correct its margin
andrearutrecht Aug 1, 2024
03cb6a4
Correct syntax error for variable setting in generator
andrearutrecht Aug 1, 2024
66e8f77
Add regenerated grids
andrearutrecht Aug 1, 2024
4b00ca1
Update tooltip in handmande 'ManufacturersGrid'
andrearutrecht Aug 1, 2024
c69a38a
Remove changeset
andrearutrecht Aug 6, 2024
0d0ff40
Move definition of 'defaultMinWidth'
andrearutrecht Aug 6, 2024
90608bd
Use formatted message for GridColumHeaderTitle label
andrearutrecht Aug 7, 2024
09cdb38
Replace Box with fragment as styling is already default
andrearutrecht Aug 7, 2024
e1d4ee3
Remove unnecessary white space
andrearutrecht Aug 7, 2024
82ff026
Add formattedMessage to handmade grid tooltip label, remove unnecessa…
andrearutrecht Aug 9, 2024
c97969a
Move column width logic
andrearutrecht Aug 9, 2024
cde103a
Change margin to marginLeft for tooltip icon
andrearutrecht Aug 12, 2024
7b37292
Move tooltipMessage prop from GridColumnConfig to DataGridSettings
andrearutrecht Aug 12, 2024
8744a67
Merge branch 'main' into admin-generator-tooltip
andrearutrecht Sep 11, 2024
4b650d2
Re-Add type export due to merge error, rename 'DataGridSettings' to '…
andrearutrecht Sep 11, 2024
cc36848
Merge branch 'main' into admin-generator-tooltip
andrearutrecht Sep 11, 2024
343a20b
Remove styled div from handmade ManufacturersGrid as empty tag is suf…
andrearutrecht Sep 16, 2024
a80883a
Merge branch 'main' into admin-generator-tooltip
andrearutrecht Sep 16, 2024
4529559
Rename 'tooltipMessage' to 'headerInfoTooltip' to better reflect usage
andrearutrecht Sep 17, 2024
0fafd99
Merge branch 'main' into admin-generator-tooltip
andrearutrecht Sep 18, 2024
22abf38
Revert change to next-env in demo/site
andrearutrecht Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions demo/admin/src/products/ManufacturersGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
usePersistentColumnState,
} from "@comet/admin";
import { Add as AddIcon, Edit, Info } from "@comet/admin-icons";
import { Button, IconButton, Typography } from "@mui/material";
import { DataGridPro, GridToolbarQuickFilter } from "@mui/x-data-grid-pro";
import { Button, IconButton } from "@mui/material";
import { DataGridPro, GridColumnHeaderTitle, GridToolbarQuickFilter } from "@mui/x-data-grid-pro";
import {
GQLCreateManufacturerMutation,
GQLCreateManufacturerMutationVariables,
Expand Down Expand Up @@ -64,16 +64,15 @@ export function ManufacturersGrid() {
width: 150,
renderHeader: () => (
<div style={{ display: "flex", alignItems: "center" }}>
<Typography fontWeight={400} fontSize={14}>
<GridColumnHeaderTitle label="ID" columnWidth={150}>
{intl.formatMessage({ id: "manufacturers.id", defaultMessage: "ID" })}
</Typography>
</GridColumnHeaderTitle>

<Tooltip
trigger="click"
trigger="hover"
title={<FormattedMessage id="comet.manufacturers.id.info" defaultMessage="The id of the manufacturer" />}
>
<IconButton>
<Info />
</IconButton>
<Info sx={{ margin: 1 }} />
</Tooltip>
</div>
),
Expand Down
9 changes: 7 additions & 2 deletions demo/admin/src/products/future/ManufacturersGrid.cometGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ export const ManufacturersGrid: GridConfig<GQLManufacturer> = {
{ type: "text", name: "name", headerName: "Name" },
{ type: "text", name: "address.street", headerName: "Street" },
{ type: "number", name: "address.streetNumber", headerName: "Street number" },
{ type: "text", name: "address.alternativeAddress.street", headerName: "Alt-Street" },
{ type: "number", name: "address.alternativeAddress.streetNumber", headerName: "Alt-Street number" },
{ type: "text", name: "address.alternativeAddress.street", headerName: "Alt-Street", tooltipMessage: "Street of alternative address" },
{
type: "number",
name: "address.alternativeAddress.streetNumber",
headerName: "Alt-Street number",
tooltipMessage: "Street number of alternative address",
},
{ type: "text", name: "addressAsEmbeddable.street", headerName: "Street 2" },
{ type: "number", name: "addressAsEmbeddable.streetNumber", headerName: "Street number 2" },
{ type: "text", name: "addressAsEmbeddable.alternativeAddress.street", headerName: "Alt-Street 2" },
Expand Down
2 changes: 1 addition & 1 deletion demo/admin/src/products/future/ProductsGrid.cometGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const ProductsGrid: GridConfig<GQLProduct> = {
{ type: "boolean", name: "inStock", headerName: "In stock", width: 90 },
{ type: "text", name: "title", headerName: "Titel", minWidth: 200, maxWidth: 250 },
{ type: "text", name: "description", headerName: "Description" },
{ type: "number", name: "price", headerName: "Price", maxWidth: 150 },
{ type: "number", name: "price", headerName: "Price", maxWidth: 150, tooltipMessage: "Price in EUR" },
{ type: "staticSelect", name: "type", maxWidth: 150 /*, values: from gql schema (TODO overridable)*/ },
{ type: "date", name: "availableSince", width: 140 },
{ type: "dateTime", name: "createdAt", width: 170 },
Expand Down
52 changes: 48 additions & 4 deletions demo/admin/src/products/future/generated/ManufacturersGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import {
ToolbarActions,
ToolbarFillSpace,
ToolbarItem,
Tooltip,
useBufferedRowCount,
useDataGridRemote,
usePersistentColumnState,
} from "@comet/admin";
import { Add as AddIcon, Edit } from "@comet/admin-icons";
import { Add as AddIcon, Edit, Info } from "@comet/admin-icons";
import { Button, IconButton } from "@mui/material";
import { DataGridPro, GridToolbarQuickFilter } from "@mui/x-data-grid-pro";
import { DataGridPro, GridColumnHeaderTitle, GridToolbarQuickFilter } from "@mui/x-data-grid-pro";
import * as React from "react";
import { FormattedMessage, useIntl } from "react-intl";

Expand Down Expand Up @@ -137,7 +138,27 @@ export function ManufacturersGrid(): React.ReactElement {
},
{
field: "address_alternativeAddress_street",
headerName: intl.formatMessage({ id: "manufacturer.address.alternativeAddress.street", defaultMessage: "Alt-Street" }),
renderHeader: () => (
<>
<GridColumnHeaderTitle
label={intl.formatMessage({ id: "manufacturer.address.alternativeAddress.street", defaultMessage: "Alt-Street" })}
columnWidth={150}
>
{intl.formatMessage({ id: "manufacturer.address.alternativeAddress.street", defaultMessage: "Alt-Street" })}
</GridColumnHeaderTitle>
<Tooltip
trigger="hover"
title={
<FormattedMessage
id="manufacturer.address.alternativeAddress.street.tooltip"
defaultMessage="Street of alternative address"
/>
}
>
<Info sx={{ margin: 1 }} />
</Tooltip>
</>
),
filterable: false,
sortable: false,
valueGetter: ({ row }) => row.address?.alternativeAddress?.street,
Expand All @@ -146,7 +167,30 @@ export function ManufacturersGrid(): React.ReactElement {
},
{
field: "address_alternativeAddress_streetNumber",
headerName: intl.formatMessage({ id: "manufacturer.address.alternativeAddress.streetNumber", defaultMessage: "Alt-Street number" }),
renderHeader: () => (
<>
<GridColumnHeaderTitle
label={intl.formatMessage({
id: "manufacturer.address.alternativeAddress.streetNumber",
defaultMessage: "Alt-Street number",
})}
columnWidth={150}
>
{intl.formatMessage({ id: "manufacturer.address.alternativeAddress.streetNumber", defaultMessage: "Alt-Street number" })}
</GridColumnHeaderTitle>
<Tooltip
trigger="hover"
title={
<FormattedMessage
id="manufacturer.address.alternativeAddress.streetNumber.tooltip"
defaultMessage="Street number of alternative address"
/>
}
>
<Info sx={{ margin: 1 }} />
</Tooltip>
</>
),
type: "number",
filterable: false,
sortable: false,
Expand Down
17 changes: 14 additions & 3 deletions demo/admin/src/products/future/generated/ProductsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ import {
ToolbarActions,
ToolbarFillSpace,
ToolbarItem,
Tooltip,
useBufferedRowCount,
useDataGridRemote,
usePersistentColumnState,
} from "@comet/admin";
import { Info } from "@comet/admin-icons";
import { DamImageBlock } from "@comet/cms-admin";
import { DataGridPro, GridRenderCellParams, GridToolbarQuickFilter } from "@mui/x-data-grid-pro";
import { DataGridPro, GridColumnHeaderTitle, GridRenderCellParams, GridToolbarQuickFilter } from "@mui/x-data-grid-pro";
import { GQLProductFilter } from "@src/graphql.generated";
import * as React from "react";
import { useIntl } from "react-intl";
import { FormattedMessage, useIntl } from "react-intl";

import {
GQLCreateProductMutation,
Expand Down Expand Up @@ -109,7 +111,16 @@ export function ProductsGrid({ filter, toolbarAction, rowAction }: Props): React
},
{
field: "price",
headerName: intl.formatMessage({ id: "product.price", defaultMessage: "Price" }),
renderHeader: () => (
<>
<GridColumnHeaderTitle label={intl.formatMessage({ id: "product.price", defaultMessage: "Price" })} columnWidth={150}>
{intl.formatMessage({ id: "product.price", defaultMessage: "Price" })}
</GridColumnHeaderTitle>
<Tooltip trigger="hover" title={<FormattedMessage id="product.price.tooltip" defaultMessage="Price in EUR" />}>
<Info sx={{ margin: 1 }} />
</Tooltip>
</>
),
type: "number",
flex: 1,
maxWidth: 150,
Expand Down
44 changes: 37 additions & 7 deletions packages/admin/cms-admin/src/generator/future/generateGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export function generateGrid(
minWidth: column.minWidth,
maxWidth: column.maxWidth,
flex: column.flex,
tooltipMessage: column.tooltipMessage,
};
}

Expand All @@ -292,6 +293,7 @@ export function generateGrid(
minWidth: column.minWidth,
maxWidth: column.maxWidth,
flex: column.flex,
tooltipMessage: column.tooltipMessage,
};
});

Expand Down Expand Up @@ -333,14 +335,15 @@ export function generateGrid(
ToolbarActions,
ToolbarFillSpace,
ToolbarItem,
Tooltip,
useBufferedRowCount,
useDataGridRemote,
usePersistentColumnState,
} from "@comet/admin";
import { Add as AddIcon, Edit } from "@comet/admin-icons";
import { Add as AddIcon, Edit, Info } from "@comet/admin-icons";
import { BlockPreviewContent } from "@comet/blocks-admin";
import { Alert, Button, Box, IconButton } from "@mui/material";
import { DataGridPro, GridRenderCellParams, GridToolbarQuickFilter } from "@mui/x-data-grid-pro";
import { Alert, Button, IconButton, Typography } from "@mui/material";
import { DataGridPro, GridColumnHeaderTitle, GridRenderCellParams, GridToolbarQuickFilter } from "@mui/x-data-grid-pro";
import { useContentScope } from "@src/common/ContentScopeProvider";
import {
GQL${gqlTypePlural}GridQuery,
Expand Down Expand Up @@ -471,15 +474,43 @@ export function generateGrid(
const intl = useIntl();
const dataGridProps = { ...useDataGridRemote(), ...usePersistentColumnState("${gqlTypePlural}Grid") };
${hasScope ? `const { scope } = useContentScope();` : ""}


const columns: GridColDef<GQL${fragmentName}Fragment>[] = [
${gridColumnFields
.map((column) => {
const defaultMinWidth = 150;
const columnDefinition: TsCodeRecordToStringObject = {
field: `"${column.name.replace(/\./g, "_")}"`, // field-name is used for api-filter, and api nests with underscore
headerName: `intl.formatMessage({ id: "${instanceGqlType}.${column.name}", defaultMessage: "${
column.headerName || camelCaseToHumanReadable(column.name)
}" })`,
renderHeader: column.tooltipMessage
? `() => (
<>
<GridColumnHeaderTitle label={intl.formatMessage({ id: "${instanceGqlType}.${
column.name
}", defaultMessage: "${column.headerName || camelCaseToHumanReadable(column.name)}"})} columnWidth= {${
column.width ?? defaultMinWidth
}}
>
{intl.formatMessage({ id: "${instanceGqlType}.${column.name}", defaultMessage: "${
column.headerName || camelCaseToHumanReadable(column.name)
}" })}
</GridColumnHeaderTitle>
<Tooltip
trigger="hover"
title={<FormattedMessage id="${instanceGqlType}.${column.name}.tooltip" defaultMessage="${
column.tooltipMessage
}" />}
>
<Info sx={{ margin: 1 }} />
</Tooltip>
</>
)`
: undefined,
headerName: !column.tooltipMessage
? `intl.formatMessage({ id: "${instanceGqlType}.${column.name}", defaultMessage: "${
column.headerName || camelCaseToHumanReadable(column.name)
}" })`
: undefined,
type: column.gridType ? `"${column.gridType}"` : undefined,
filterable: !filterFields.includes(column.name) ? `false` : undefined,
sortable: !sortFields.includes(column.name) ? `false` : undefined,
Expand All @@ -491,7 +522,6 @@ export function generateGrid(
};

if (typeof column.width === "undefined") {
const defaultMinWidth = 150;
columnDefinition.flex = 1;
columnDefinition.maxWidth = column.maxWidth;

Expand Down
3 changes: 2 additions & 1 deletion packages/admin/cms-admin/src/generator/future/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export type GridColumnConfig<T> = (
| { type: "dateTime" }
| { type: "staticSelect"; values?: string[] }
| { type: "block"; block: ImportReference }
) & { name: UsableFields<T> } & DataGridSettings;
) & { name: UsableFields<T>; tooltipMessage?: string } & DataGridSettings;

export type GridConfig<T extends { __typename?: string }> = {
type: "grid";
gqlType: T["__typename"];
Expand Down
Loading