Skip to content

Commit

Permalink
feat(cli): upgrade pulumi in 5.17.0 (#2004)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric committed Nov 3, 2021
1 parent 7b97011 commit 945c561
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import Error from "@webiny/error";
import { NotFoundError } from "@webiny/handler-graphql";
import { ContextPlugin } from "@webiny/handler/plugins/ContextPlugin";
import checkBasePermissions from "@webiny/api-page-builder/graphql/crud/utils/checkBasePermissions";
import { PageImportExportTaskStatus, PbPageImportExportContext } from "~/types";
import {
PageImportExportTaskStatus,
PagesImportExportCrud,
PbPageImportExportContext
} from "~/types";
import { invokeHandlerClient } from "~/importPages/client";
import { HandlerArgs as CreateHandlerArgs } from "~/importPages/create";
import { initialStats, zeroPad } from "~/importPages/utils";
Expand All @@ -14,14 +18,8 @@ const EXPORT_PAGES_PROCESS_HANDLER = process.env.EXPORT_PAGES_PROCESS_HANDLER;
const IMPORT_PAGES_CREATE_HANDLER = process.env.IMPORT_PAGES_CREATE_HANDLER;

export default new ContextPlugin<PbPageImportExportContext>(context => {
const importExportCrud = {
async importPages(
categorySlug: string,
data: {
zipFileKey?: string;
zipFileUrl?: string;
}
) {
const importExportCrud: PagesImportExportCrud = {
async importPages({ category: categorySlug, zipFileKey, zipFileUrl }) {
await checkBasePermissions(context, PERMISSION_NAME, {
rwd: "w"
});
Expand All @@ -37,7 +35,8 @@ export default new ContextPlugin<PbPageImportExportContext>(context => {
status: PageImportExportTaskStatus.PENDING,
input: {
category: categorySlug,
data
zipFileKey,
zipFileUrl
}
});

Expand All @@ -46,7 +45,8 @@ export default new ContextPlugin<PbPageImportExportContext>(context => {
name: IMPORT_PAGES_CREATE_HANDLER,
payload: {
category: categorySlug,
data,
zipFileKey,
zipFileUrl,
task,
identity: context.security.getIdentity()
}
Expand All @@ -57,14 +57,33 @@ export default new ContextPlugin<PbPageImportExportContext>(context => {
};
},

async exportPages(pageIds: string[], revisionType) {
async exportPages({ ids: initialPageIds, revisionType, where, sort, search }) {
await checkBasePermissions(context, PERMISSION_NAME, {
rwd: "w"
});
let pageIds = initialPageIds;
// If no ids are provided then it means we want to export all pages
if (!initialPageIds || (Array.isArray(initialPageIds) && initialPageIds.length === 0)) {
pageIds = [];
let pages = [];
let meta = { hasMoreItems: true, cursor: null };
// Paginate pages
while (meta.hasMoreItems) {
[pages, meta] = await context.pageBuilder.pages.listLatest({
after: meta.cursor,
where: where,
sort: sort,
search: search
});
// Save page ids
pages.forEach(page => pageIds.push(page.id));
}
}

if (pageIds.length === 0) {
throw new Error(
"Cannot export page(s) - no page ID(s) were provided.",
"EMPTY_PAGE_IDS_PROVIDED"
"Cannot export pages - no pages found for provided inputs.",
"EMPTY_EXPORT_NO_PAGES_FOUND"
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GraphQLSchemaPlugin } from "@webiny/handler-graphql/types";
import { PageExportRevisionType } from "~/types";
import { ExportPagesParams, ImportPagesParams } from "~/types";
import { PbPageImportExportContext } from "../types";
import resolve from "./utils/resolve";

Expand Down Expand Up @@ -30,42 +30,32 @@ const plugin: GraphQLSchemaPlugin<PbPageImportExportContext> = {
latest
}
input PbImportPageInput {
zipFileKey: String
zipFileUrl: String
}
extend type PbMutation {
# Export pages
exportPages(
ids: [ID]!
revisionType: PbExportPageRevisionType
ids: [ID!]
revisionType: PbExportPageRevisionType!
where: PbListPagesWhereInput
sort: [PbListPagesSort!]
search: PbListPagesSearchInput
): PbExportPageResponse
# Import pages
importPages(category: String!, data: PbImportPageInput!): PbImportPageResponse
importPages(
category: String!
zipFileKey: String
zipFileUrl: String
): PbImportPageResponse
}
`,
resolvers: {
PbMutation: {
exportPages: async (
_,
args: { ids: string[]; revisionType: PageExportRevisionType },
context
) => {
return resolve(() =>
context.pageBuilder.pages.exportPages(args.ids, args.revisionType)
);
exportPages: async (_, args: ExportPagesParams, context) => {
return resolve(() => context.pageBuilder.pages.exportPages(args));
},

importPages: async (
_,
args: { category: string; data: Record<string, any> },
context
) => {
return resolve(() =>
context.pageBuilder.pages.importPages(args.category, args.data)
);
importPages: async (_, args: ImportPagesParams, context) => {
return resolve(() => context.pageBuilder.pages.importPages(args));
}
}
}
Expand Down
29 changes: 21 additions & 8 deletions packages/api-page-builder-import-export/src/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,28 @@ import {
PageImportExportTaskStorageOperationsListParams
} from "~/types";

export interface ExportPagesParams {
ids?: string[];
revisionType: PageExportRevisionType;
where?: {
category?: string;
status?: string;
tags?: { query: string[]; rule?: "any" | "all" };
[key: string]: any;
};
search?: { query?: string };
sort?: string[];
}

export interface ImportPagesParams {
category: string;
zipFileKey?: string;
zipFileUrl?: string;
}

export type PagesImportExportCrud = {
exportPages(
ids: string[],
revisionType: PageExportRevisionType
): Promise<{ task: PageImportExportTask }>;
importPages(
category: string,
data: Record<string, any>
): Promise<{ task: PageImportExportTask }>;
exportPages(params: ExportPagesParams): Promise<{ task: PageImportExportTask }>;
importPages(params: ImportPagesParams): Promise<{ task: PageImportExportTask }>;
};

type PageImportExportTaskCreateData = Omit<PageImportExportTask, "id" | "createdOn" | "createdBy">;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import { mockSecurity } from "~/mockSecurity";

export type HandlerArgs = {
category: string;
data: {
zipFileKey?: string;
zipFileUrl?: string;
};
zipFileKey?: string;
zipFileUrl?: string;
task: PageImportExportTask;
identity: SecurityIdentity;
};
Expand Down Expand Up @@ -47,11 +45,11 @@ export default (
try {
log("RUNNING Import Pages Create");
const { invocationArgs: args, pageBuilder } = context;
const { task, category, data, identity } = args;
const { task, category, zipFileKey, zipFileUrl, identity } = args;
mockSecurity(identity, context);
// Step 1: Read the zip file
const pageImportDataList = await readExtractAndUploadZipFileContents(
data.zipFileKey || data.zipFileUrl
zipFileKey || zipFileUrl
);
// Once we have map we can start processing each page

Expand All @@ -67,7 +65,8 @@ export default (
data: {
pageKey: pagesDirMap.key,
category,
zipFileKey: data.zipFileKey,
zipFileKey,
zipFileUrl,
input: {
fileUploadsData: pagesDirMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#
# Example query - list all users:
{
security {
adminUsers {
listUsers {
data {
login
email
firstName
createdOn
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ stats {
}`;

export const IMPORT_PAGES = gql`
mutation PbImportPage($category: String!, $data: PbImportPageInput!) {
mutation PbImportPage(
$category: String!,
$zipFileKey: String,
$zipFileUrl: String
) {
pageBuilder {
importPages(category: $category, data: $data) {
importPages(
category: $category,
zipFileKey: $zipFileKey,
zipFileUrl: $zipFileUrl
) {
data {
task {
id
Expand All @@ -36,9 +44,21 @@ export const IMPORT_PAGES = gql`
`;

export const EXPORT_PAGES = gql`
mutation PbExportPages($ids: [ID]!, $revisionType: PbExportPageRevisionType) {
mutation PbExportPages(
$ids: [ID!],
$revisionType: PbExportPageRevisionType!,
$where: PbListPagesWhereInput,
$sort: [PbListPagesSort!],
$search: PbListPagesSearchInput
) {
pageBuilder {
exportPages(ids: $ids, revisionType: $revisionType) {
exportPages(
ids: $ids,
revisionType: $revisionType,
where: $where,
sort: $sort,
search: $search
) {
data {
task {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const InlineLoaderWrapper = styled("div")({
const Actions = styled("div")({
display: "flex",
justifyContent: "flex-end",
"& button:not(:first-child)": {
"& button:not(:first-of-type)": {
marginLeft: 16
}
});
Expand Down Expand Up @@ -276,7 +276,12 @@ const PagesDataList = ({ onCreatePage, canCreate, onImportPage }: PagesDataListP
/>
}
multiSelectActions={
<ExportPagesButton getMultiSelected={multiSelectProps.getMultiSelected} />
<ExportPagesButton
getMultiSelected={multiSelectProps.getMultiSelected}
where={where}
sort={sort}
search={search}
/>
}
multiSelectAll={multiSelectProps.multiSelectAll}
isAllMultiSelected={multiSelectProps.isAllMultiSelected}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useCallback } from "react";
import pick from "lodash/pick";
import get from "lodash/get";
import { useMutation } from "@apollo/react-hooks";
import { useSnackbar } from "@webiny/app-admin/hooks/useSnackbar";
Expand All @@ -19,13 +18,7 @@ const useImportPage = ({ setLoadingLabel, clearLoadingLabel, closeDialog }) => {
const res = await importPage({
variables: {
category,
data: pick(
{
zipFileKey: fileKey,
zipFileUrl: fileKey
},
[fileKey.startsWith("http") ? "zipFileUrl" : "zipFileKey"]
)
[fileKey.startsWith("http") ? "zipFileUrl" : "zipFileKey"]: fileKey
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ import React from "react";
import { IconButton } from "@webiny/ui/Button";
import { Tooltip } from "@webiny/ui/Tooltip";
import { i18n } from "@webiny/app/i18n";
import useExportPageDialog from "./useExportPageDialog";
import useExportPageDialog, { ExportPagesDialogProps } from "./useExportPageDialog";
import useExportPageRevisionSelectorDialog from "./useExportPageRevisionSelectorDialog";
// assets
import { ReactComponent as DownloadIcon } from "../icons/file_download.svg";

const t = i18n.ns("app-page-builder/editor/plugins/defaultBar/exportPageButton");

export const ExportPagesButton = ({ getMultiSelected }) => {
interface ExportPagesButtonProps extends ExportPagesDialogProps {
getMultiSelected: any;
}

export const ExportPagesButton: React.FC<ExportPagesButtonProps> = ({
getMultiSelected,
...restProps
}) => {
const selected = getMultiSelected();
const { showExportPageRevisionSelectorDialog } = useExportPageRevisionSelectorDialog();
const { showExportPageInitializeDialog } = useExportPageDialog();
Expand All @@ -22,18 +29,19 @@ export const ExportPagesButton = ({ getMultiSelected }) => {
});
}

return t`Export pages`;
return t`Export all pages`;
};

return (
<Tooltip content={renderExportPagesTooltip(selected)} placement={"bottom"}>
<IconButton
data-testid={"export-page-button"}
icon={<DownloadIcon />}
disabled={selected.length === 0}
onClick={() => {
showExportPageRevisionSelectorDialog({
onAccept: () => showExportPageInitializeDialog({ ids: selected })
onAccept: () =>
showExportPageInitializeDialog({ ids: selected, ...restProps }),
selected
});
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ import { useEffect, useState } from "react";
import get from "lodash/get";
import { useMutation } from "@apollo/react-hooks";
import { useSnackbar } from "@webiny/app-admin/hooks/useSnackbar";
import { useDialog } from "@webiny/app-admin/hooks/useDialog";
import { EXPORT_PAGES } from "~/admin/graphql/pageImportExport.gql";
import useExportPageDialog from "./useExportPageDialog";

const useExportPage = () => {
const [taskId, setTaskId] = useState<string>(null);
const { showSnackbar } = useSnackbar();
const { showExportPageLoadingDialog } = useExportPageDialog();
const { hideDialog } = useDialog();

const [exportPage] = useMutation(EXPORT_PAGES, {
onCompleted: response => {
const { error, data } = get(response, "pageBuilder.exportPages", {});
if (error) {
hideDialog();
return showSnackbar(error.message);
}
setTaskId(data.task.id);
Expand Down

0 comments on commit 945c561

Please sign in to comment.