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

COM-357: Add import source as column in DAM grid #1756

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions .changeset/light-candles-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"@comet/cms-admin": minor
---

Show DAM import source in grid

To show the "Source" column in the DAM's data grid, provide `importSources` in `DamConfigProvider`:

```tsx
<DamConfigProvider
value={{
...
importSources: {
unsplash: {
label: <FormattedMessage id="dam.importSource.unsplash.label" defaultMessage="Unsplash" />,
},
},
johnnyomair marked this conversation as resolved.
Show resolved Hide resolved
}}
>
...
</DamConfigProvider>
```
14 changes: 12 additions & 2 deletions demo/admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import * as React from "react";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import * as ReactDOM from "react-dom";
import { IntlProvider } from "react-intl";
import { FormattedMessage, IntlProvider } from "react-intl";
import { Route, Switch } from "react-router-dom";

import MasterHeader from "./common/MasterHeader";
Expand Down Expand Up @@ -65,7 +65,17 @@ class App extends React.Component {
resolveSiteConfigForScope: (configs, scope: ContentScope) => configs[scope.domain],
}}
>
<DamConfigProvider value={{ scopeParts: ["domain"], additionalToolbarItems: <ImportFromUnsplash /> }}>
<DamConfigProvider
value={{
scopeParts: ["domain"],
additionalToolbarItems: <ImportFromUnsplash />,
importSources: {
unsplash: {
label: <FormattedMessage id="dam.importSource.unsplash.label" defaultMessage="Unsplash" />,
},
},
}}
>
<IntlProvider locale="en" messages={getMessages()}>
<LocaleProvider resolveLocaleForScope={(scope: ContentScope) => scope.domain}>
<MuiThemeProvider theme={theme}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const damFileTableFragment = gql`
...DamFileThumbnail
}
updatedAt
importSourceType
}
${damFileThumbnailFragment}
`;
Expand Down
23 changes: 22 additions & 1 deletion packages/admin/cms-admin/src/dam/DataGrid/FolderDataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useDebouncedCallback } from "use-debounce";

import { GQLDamItemType } from "../../graphql.generated";
import { useDamAcceptedMimeTypes } from "../config/useDamAcceptedMimeTypes";
import { useDamConfig } from "../config/useDamConfig";
import { useDamScope } from "../config/useDamScope";
import { DamConfig, DamFilter } from "../DamTable";
import AddFolder from "../FolderForm/AddFolder";
Expand All @@ -30,8 +31,10 @@ import DamContextMenu from "./DamContextMenu";
import { useDamFileUpload } from "./fileUpload/useDamFileUpload";
import { damFolderQuery, damItemListPosition, damItemsListQuery } from "./FolderDataGrid.gql";
import {
GQLDamFileTableFragment,
GQLDamFolderQuery,
GQLDamFolderQueryVariables,
GQLDamFolderTableFragment,
GQLDamItemListPositionQuery,
GQLDamItemListPositionQueryVariables,
GQLDamItemsListQuery,
Expand Down Expand Up @@ -84,6 +87,7 @@ const FolderDataGrid = ({
const damSelectionActionsApi = useDamSelectionApi();
const scope = useDamScope();
const snackbarApi = useSnackbarApi();
const { importSources } = useDamConfig();

const [redirectedToId, setRedirectedToId] = useStoredState<string | null>("FolderDataGrid-redirectedToId", null, window.sessionStorage);

Expand Down Expand Up @@ -338,7 +342,7 @@ const FolderDataGrid = ({
return "";
};

const dataGridColumns: GridColumns = [
const dataGridColumns: GridColumns<GQLDamFileTableFragment | GQLDamFolderTableFragment> = [
{
field: "name",
headerName: intl.formatMessage({
Expand Down Expand Up @@ -372,6 +376,22 @@ const FolderDataGrid = ({
hideSortIcons: true,
disableColumnMenu: true,
},
{
field: "importSourceType",
headerName: intl.formatMessage({
id: "comet.dam.file.importSourceType",
defaultMessage: "Source",
}),
renderCell: ({ row }) => {
if (isFile(row) && row.importSourceType && importSources?.[row.importSourceType]) {
return importSources[row.importSourceType].label;
}
},
// TODO enable sorting/filtering in API
sortable: false,
hideSortIcons: true,
disableColumnMenu: true,
},
{
field: "size",
headerName: intl.formatMessage({
Expand Down Expand Up @@ -463,6 +483,7 @@ const FolderDataGrid = ({
selectionModel={Array.from(damSelectionActionsApi.selectionMap.keys())}
onSelectionModelChange={handleSelectionModelChange}
autoHeight={true}
initialState={{ columns: { columnVisibilityModel: { importSourceType: importSources !== undefined } } }}
/>
</sc.FolderOuterHoverHighlight>
<DamSelectionFooter open={damSelectionActionsApi.selectionMap.size > 0} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface DamConfig {
enableLicenseFeature?: boolean;
requireLicense?: boolean;
additionalToolbarItems?: React.ReactNode;
importSources?: Record<string, { label: React.ReactNode }>;
}

export const DamConfigContext = React.createContext<DamConfig | undefined>(undefined);
Loading