Skip to content

Commit

Permalink
feat(core, admin): Channel aware Assets
Browse files Browse the repository at this point in the history
Relates to vendure-ecommerce#677

BREAKING CHANGE: New DB relation Asset to Channel. Mutations deleteAsset and deleteAssets changed
  • Loading branch information
martijnvdbrug committed Feb 10, 2021
1 parent 0a1fadd commit f335116
Show file tree
Hide file tree
Showing 24 changed files with 787 additions and 201 deletions.
36 changes: 30 additions & 6 deletions packages/admin-ui/src/lib/core/src/common/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ export type Mutation = {
addNoteToOrder: Order;
/** Add an OptionGroup to a Product */
addOptionGroupToProduct: Product;
/** Assign assets to channel */
assignAssetsToChannel: Array<Asset>;
/** Assigns ProductVariants to the specified Channel */
assignProductVariantsToChannel: Array<ProductVariant>;
/** Assigns all ProductVariants of Product to the specified Channel */
Expand Down Expand Up @@ -542,6 +544,11 @@ export type MutationAddOptionGroupToProductArgs = {
};


export type MutationAssignAssetsToChannelArgs = {
input: AssignAssetsToChannelInput;
};


export type MutationAssignProductVariantsToChannelArgs = {
input: AssignProductVariantsToChannelInput;
};
Expand Down Expand Up @@ -687,14 +694,12 @@ export type MutationDeleteAdministratorArgs = {


export type MutationDeleteAssetArgs = {
id: Scalars['ID'];
force?: Maybe<Scalars['Boolean']>;
input: DeleteAssetInput;
};


export type MutationDeleteAssetsArgs = {
ids: Array<Scalars['ID']>;
force?: Maybe<Scalars['Boolean']>;
input: DeleteAssetsInput;
};


Expand Down Expand Up @@ -1124,13 +1129,30 @@ export type CoordinateInput = {
y: Scalars['Float'];
};

export type DeleteAssetInput = {
assetId: Scalars['ID'];
force?: Maybe<Scalars['Boolean']>;
deleteFromAllChannels?: Maybe<Scalars['Boolean']>;
};

export type DeleteAssetsInput = {
assetIds: Array<Scalars['ID']>;
force?: Maybe<Scalars['Boolean']>;
deleteFromAllChannels?: Maybe<Scalars['Boolean']>;
};

export type UpdateAssetInput = {
id: Scalars['ID'];
name?: Maybe<Scalars['String']>;
focalPoint?: Maybe<CoordinateInput>;
tags?: Maybe<Array<Scalars['String']>>;
};

export type AssignAssetsToChannelInput = {
assetIds: Array<Scalars['ID']>;
channelId: Scalars['ID'];
};

export type NativeAuthenticationResult = CurrentUser | InvalidCredentialsError | NativeAuthStrategyError;

export type AuthenticationResult = CurrentUser | InvalidCredentialsError;
Expand All @@ -1143,6 +1165,7 @@ export type CreateChannelInput = {
currencyCode: CurrencyCode;
defaultTaxZoneId: Scalars['ID'];
defaultShippingZoneId: Scalars['ID'];
customFields?: Maybe<Scalars['JSON']>;
};

export type UpdateChannelInput = {
Expand All @@ -1154,6 +1177,7 @@ export type UpdateChannelInput = {
currencyCode?: Maybe<CurrencyCode>;
defaultTaxZoneId?: Maybe<Scalars['ID']>;
defaultShippingZoneId?: Maybe<Scalars['ID']>;
customFields?: Maybe<Scalars['JSON']>;
};

/** Returned if attempting to set a Channel's defaultLanguageCode to a language which is not enabled in GlobalSettings */
Expand Down Expand Up @@ -2489,6 +2513,7 @@ export type Channel = Node & {
defaultLanguageCode: LanguageCode;
currencyCode: CurrencyCode;
pricesIncludeTax: Scalars['Boolean'];
customFields?: Maybe<Scalars['JSON']>;
};

export type CollectionBreadcrumb = {
Expand Down Expand Up @@ -6346,8 +6371,7 @@ export type UpdateAssetMutation = { updateAsset: (
) };

export type DeleteAssetsMutationVariables = Exact<{
ids: Array<Scalars['ID']>;
force?: Maybe<Scalars['Boolean']>;
input: DeleteAssetsInput;
}>;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ export const UPDATE_ASSET = gql`
`;

export const DELETE_ASSETS = gql`
mutation DeleteAssets($ids: [ID!]!, $force: Boolean) {
deleteAssets(ids: $ids, force: $force) {
mutation DeleteAssets($input: DeleteAssetsInput!) {
deleteAssets(input: $input) {
result
message
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,10 @@ export class ProductDataService {

deleteAssets(ids: string[], force: boolean) {
return this.baseDataService.mutate<DeleteAssets.Mutation, DeleteAssets.Variables>(DELETE_ASSETS, {
ids,
force,
input: {
assetIds: ids,
force,
},
});
}

Expand Down
8 changes: 8 additions & 0 deletions packages/admin-ui/src/lib/core/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export * from './data/server-config';
export * from './data/utils/add-custom-fields';
export * from './data/utils/get-server-location';
export * from './data/utils/remove-readonly-custom-fields';
export * from './data/utils/transform-relation-custom-field-inputs';
export * from './providers/auth/auth.service';
export * from './providers/component-registry/component-registry.service';
export * from './providers/custom-field-component/custom-field-component.service';
Expand Down Expand Up @@ -175,6 +176,13 @@ export * from './shared/dynamic-form-inputs/number-form-input/number-form-input.
export * from './shared/dynamic-form-inputs/password-form-input/password-form-input.component';
export * from './shared/dynamic-form-inputs/product-selector-form-input/product-selector-form-input.component';
export * from './shared/dynamic-form-inputs/register-dynamic-input-components';
export * from './shared/dynamic-form-inputs/relation-form-input/asset/relation-asset-input.component';
export * from './shared/dynamic-form-inputs/relation-form-input/customer/relation-customer-input.component';
export * from './shared/dynamic-form-inputs/relation-form-input/product/relation-product-input.component';
export * from './shared/dynamic-form-inputs/relation-form-input/product-variant/relation-product-variant-input.component';
export * from './shared/dynamic-form-inputs/relation-form-input/relation-card/relation-card.component';
export * from './shared/dynamic-form-inputs/relation-form-input/relation-form-input.component';
export * from './shared/dynamic-form-inputs/relation-form-input/relation-selector-dialog/relation-selector-dialog.component';
export * from './shared/dynamic-form-inputs/select-form-input/select-form-input.component';
export * from './shared/dynamic-form-inputs/text-form-input/text-form-input.component';
export * from './shared/pipes/asset-preview.pipe';
Expand Down
12 changes: 7 additions & 5 deletions packages/asset-server-plugin/e2e/asset-server-plugin.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import fetch from 'node-fetch';
import path from 'path';

import { initialData } from '../../../e2e-common/e2e-initial-data';
import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config';
import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config';
import { AssetServerPlugin } from '../src/plugin';

import { CreateAssets, DeleteAsset, DeletionResult } from './graphql/generated-e2e-asset-server-plugin-types';
Expand Down Expand Up @@ -172,8 +172,10 @@ describe('AssetServerPlugin', () => {
const { deleteAsset } = await adminClient.query<DeleteAsset.Mutation, DeleteAsset.Variables>(
DELETE_ASSET,
{
id: asset.id,
force: true,
input: {
assetId: asset.id,
force: true,
},
},
);

Expand Down Expand Up @@ -254,8 +256,8 @@ export const CREATE_ASSETS = gql`
`;

export const DELETE_ASSET = gql`
mutation DeleteAsset($id: ID!, $force: Boolean!) {
deleteAsset(id: $id, force: $force) {
mutation DeleteAsset($input: DeleteAssetInput!) {
deleteAsset(input: $input) {
result
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ export type Mutation = {
deleteAsset: DeletionResponse;
/** Delete multiple Assets */
deleteAssets: DeletionResponse;
/** Assign assets to channel */
assignAssetsToChannel: Array<Asset>;
/** Authenticates the user using the native authentication strategy. This mutation is an alias for `authenticate({ native: { ... }})` */
login: NativeAuthenticationResult;
/** Authenticates the user using a named authentication strategy */
Expand Down Expand Up @@ -476,13 +478,15 @@ export type MutationUpdateAssetArgs = {
};

export type MutationDeleteAssetArgs = {
id: Scalars['ID'];
force?: Maybe<Scalars['Boolean']>;
input: DeleteAssetInput;
};

export type MutationDeleteAssetsArgs = {
ids: Array<Scalars['ID']>;
force?: Maybe<Scalars['Boolean']>;
input: DeleteAssetsInput;
};

export type MutationAssignAssetsToChannelArgs = {
input: AssignAssetsToChannelInput;
};

export type MutationLoginArgs = {
Expand Down Expand Up @@ -940,13 +944,30 @@ export type CoordinateInput = {
y: Scalars['Float'];
};

export type DeleteAssetInput = {
assetId: Scalars['ID'];
force?: Maybe<Scalars['Boolean']>;
deleteFromAllChannels?: Maybe<Scalars['Boolean']>;
};

export type DeleteAssetsInput = {
assetIds: Array<Scalars['ID']>;
force?: Maybe<Scalars['Boolean']>;
deleteFromAllChannels?: Maybe<Scalars['Boolean']>;
};

export type UpdateAssetInput = {
id: Scalars['ID'];
name?: Maybe<Scalars['String']>;
focalPoint?: Maybe<CoordinateInput>;
tags?: Maybe<Array<Scalars['String']>>;
};

export type AssignAssetsToChannelInput = {
assetIds: Array<Scalars['ID']>;
channelId: Scalars['ID'];
};

export type NativeAuthenticationResult = CurrentUser | InvalidCredentialsError | NativeAuthStrategyError;

export type AuthenticationResult = CurrentUser | InvalidCredentialsError;
Expand All @@ -959,6 +980,7 @@ export type CreateChannelInput = {
currencyCode: CurrencyCode;
defaultTaxZoneId: Scalars['ID'];
defaultShippingZoneId: Scalars['ID'];
customFields?: Maybe<Scalars['JSON']>;
};

export type UpdateChannelInput = {
Expand All @@ -970,6 +992,7 @@ export type UpdateChannelInput = {
currencyCode?: Maybe<CurrencyCode>;
defaultTaxZoneId?: Maybe<Scalars['ID']>;
defaultShippingZoneId?: Maybe<Scalars['ID']>;
customFields?: Maybe<Scalars['JSON']>;
};

/** Returned if attempting to set a Channel's defaultLanguageCode to a language which is not enabled in GlobalSettings */
Expand Down Expand Up @@ -2279,6 +2302,7 @@ export type Channel = Node & {
defaultLanguageCode: LanguageCode;
currencyCode: CurrencyCode;
pricesIncludeTax: Scalars['Boolean'];
customFields?: Maybe<Scalars['JSON']>;
};

export type CollectionBreadcrumb = {
Expand Down Expand Up @@ -4431,6 +4455,7 @@ export type NativeAuthInput = {

export type CustomFields = {
Address: Array<CustomFieldConfig>;
Channel: Array<CustomFieldConfig>;
Collection: Array<CustomFieldConfig>;
Customer: Array<CustomFieldConfig>;
Facet: Array<CustomFieldConfig>;
Expand Down Expand Up @@ -4460,8 +4485,7 @@ export type CreateAssetsMutation = {
};

export type DeleteAssetMutationVariables = Exact<{
id: Scalars['ID'];
force: Scalars['Boolean'];
input: DeleteAssetInput;
}>;

export type DeleteAssetMutation = { deleteAsset: Pick<DeletionResponse, 'result'> };
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ export type Channel = Node & {
defaultLanguageCode: LanguageCode;
currencyCode: CurrencyCode;
pricesIncludeTax: Scalars['Boolean'];
customFields?: Maybe<Scalars['JSON']>;
};

export type Collection = Node & {
Expand Down
Loading

0 comments on commit f335116

Please sign in to comment.