Skip to content
Closed
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
4 changes: 3 additions & 1 deletion packages/api-aco/src/filter/filter.so.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { pickEntryFieldValues } from "~/utils/pickEntryFieldValues.js";
import type { AcoFilterStorageOperations, Filter } from "./filter.types.js";
import { ENTRY_META_FIELDS } from "@webiny/api-headless-cms/constants.js";
import { CmsSortMapper, CmsWhereMapper } from "@webiny/api-headless-cms";
import type { UpdateCmsEntryInput } from "@webiny/api-headless-cms/types/index.js";

export const createFilterOperations = (
params: CreateAcoStorageOperationsParams
Expand Down Expand Up @@ -72,12 +73,13 @@ export const createFilterOperations = (
return withModel(async model => {
const original = await cms.getEntryById(model, id);

const input = {
const input: UpdateCmsEntryInput = {
/**
* We are omitting the standard entry meta fields:
* we don't want to override them with the ones coming from the `original` entry.
*/
...omit(original, ENTRY_META_FIELDS),
expiresAt: null,
values: {
...original.values,
...data
Expand Down
2 changes: 1 addition & 1 deletion packages/api-headless-cms-ddb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"@webiny/feature": "0.0.0",
"@webiny/handler": "0.0.0",
"@webiny/handler-db": "0.0.0",
"@webiny/stdlib": "^0.0.3",
"@webiny/utils": "0.0.0",
"dataloader": "^2.2.3",
"dot-object": "^2.1.5",
"dot-prop": "^10.1.0",
"lodash": "^4.18.1"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CmsEntry, CmsEntryValues, CmsModel } from "@webiny/api-headless-cms/types/index.js";
import WebinyError from "@webiny/error";
import * as dotProp from "dot-prop";
import { immutableGet } from "@webiny/stdlib";
import lodashSortBy from "lodash/sortBy.js";
import { extractSort } from "./extractSort.js";
import type { Field } from "./types.js";
Expand Down Expand Up @@ -53,7 +53,7 @@ export const sort = <T extends CmsEntryValues = CmsEntryValues>(
const itemsToSort = items.map(item => {
return {
id: item.id,
value: field.transform(dotProp.getProperty(item, valuePath))
value: field.transform(immutableGet(item, valuePath))
};
});
const sortedItems: SortedItem[] = lodashSortBy(itemsToSort, "value");
Expand Down
2 changes: 1 addition & 1 deletion packages/api-headless-cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"@webiny/handler-graphql": "0.0.0",
"@webiny/plugins": "0.0.0",
"@webiny/project": "0.0.0",
"@webiny/stdlib": "^0.0.3",
"@webiny/utils": "0.0.0",
"@webiny/validation": "0.0.0",
"dot-prop-immutable": "^2.1.1",
"graphql": "^16.14.0",
"graphql-tag": "^2.12.6",
"lodash": "^4.18.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dotPropImmutable from "dot-prop-immutable";
import { immutableSet, immutableGet } from "@webiny/stdlib";
import { parseIdentifier } from "@webiny/utils";
import type { CmsContext, CmsEntryValues, CmsModel } from "~/types/index.js";
import { buildReferenceFieldPaths } from "./references/buildPaths.js";
Expand Down Expand Up @@ -54,7 +54,7 @@ export const referenceFieldsMapping = async <TValues extends CmsEntryValues = Cm
*/
for (const path of referenceFieldPaths) {
// It is safe to cast here, because `referenceFieldPaths` array is generated from the `input`.
const refValue = dotPropImmutable.get(values, path) as CmsRefEntry | undefined;
const refValue = immutableGet(values, path) as CmsRefEntry | undefined;
if (!refValue) {
continue;
}
Expand All @@ -71,7 +71,7 @@ export const referenceFieldsMapping = async <TValues extends CmsEntryValues = Cm
id: entryId
});

output = dotPropImmutable.set(output, path, {
output = immutableSet(output, path, {
id,
entryId,
modelId: refValue.modelId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { CmsDynamicZoneTemplate, CmsEntryValues, CmsModelField } from "~/types/index.js";
import dotPropImmutable from "dot-prop-immutable";
import { immutableGet } from "@webiny/stdlib";
import { getBaseFieldType } from "~/utils/getBaseFieldType.js";
import type { GenericRecord } from "@webiny/api/types.js";

type INarrowedCmsModelField = Pick<CmsModelField, "fieldId" | "list" | "type" | "settings">;

Expand All @@ -18,7 +19,7 @@ const resolveBaseRef = <TValues extends CmsEntryValues = CmsEntryValues>(
const { field, parentPaths, input, collection, isMultipleValues } = params;
const parentPathsValue = parentPaths.length > 0 ? `${parentPaths.join(".")}.` : "";
if (field.list) {
const inputValue = dotPropImmutable.get(input, `${field.fieldId}`, []);
const inputValue = immutableGet(input, `${field.fieldId}`, []);
if (!Array.isArray(inputValue)) {
return collection;
}
Expand Down Expand Up @@ -79,7 +80,7 @@ export const buildReferenceFieldPaths = <TValues extends CmsEntryValues = CmsEnt
const templates: CmsDynamicZoneTemplate[] = field.settings?.templates || [];

if (field.list) {
const values = dotPropImmutable.get(input, field.fieldId, []);
const values = immutableGet(input, field.fieldId, []);
if (!Array.isArray(values)) {
return collection;
}
Expand All @@ -102,12 +103,14 @@ export const buildReferenceFieldPaths = <TValues extends CmsEntryValues = CmsEnt
return collection;
}

const value = dotPropImmutable.get(input, field.fieldId, {});
const value = immutableGet<GenericRecord>(input, field.fieldId, {});
if (!value) {
return collection;
}

const template = templates.find(tpl => tpl.id === value["_templateId"]);
const template = templates.find(tpl => {
return tpl.id === value["_templateId"];
});

if (!template) {
return collection;
Expand Down Expand Up @@ -139,7 +142,7 @@ export const buildReferenceFieldPaths = <TValues extends CmsEntryValues = CmsEnt
}

const objFieldPath = `${field.fieldId}`;
const objFieldInputValue = dotPropImmutable.get(input, objFieldPath, []);
const objFieldInputValue = immutableGet(input, objFieldPath, []);

/**
* If field is multiple values one, we need to go through the input and use the existing keys.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CmsContext } from "~/types/index.js";
import dotPropImmutable from "dot-prop-immutable";
import { immutableGet } from "@webiny/stdlib";
import { WebinyError } from "@webiny/error";

interface ReferenceObject {
Expand Down Expand Up @@ -33,7 +33,7 @@ export const validateReferencedEntries = async ({
* Group references by modelId.
*/
for (const path of referenceFieldPaths) {
const ref = dotPropImmutable.get(output, path) as ReferenceObject | any;
const ref = immutableGet<ReferenceObject>(output, path);

const result = getReferenceFieldValue(ref);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import set from "lodash/set.js";
import { mutableSet } from "@webiny/stdlib";
import type { Resolvers } from "@webiny/handler-graphql/types.js";
import WebinyError from "@webiny/error";
import type { ApiEndpoint, CmsContext, CmsModel, CmsModelField } from "~/types/index.js";
Expand Down Expand Up @@ -117,7 +117,7 @@ export const createFieldResolversFactory = (factoryParams: CreateFieldResolversF
value
});

set(
mutableSet(
valueIsRoot && parent.values ? parent.values : parent,
fieldId,
transformedValue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import set from "lodash/set.js";
import { mutableSet } from "@webiny/stdlib";
import type { GenericRecord } from "@webiny/api/types.js";
import type { CmsEntryResolverFactory, CmsModel } from "~/types/index.js";
import type { IContentEntryTraverser } from "~/features/contentEntry/ContentEntryTraverser/ContentEntryTraverser.js";
Expand Down Expand Up @@ -57,7 +57,7 @@ class GraphQlInputNormalizer {
input: value
});

set(values, path, normalizedValue);
mutableSet(values, path, normalizedValue);
}
});

Expand Down
2 changes: 1 addition & 1 deletion packages/api-headless-cms/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ export interface UpdateCmsEntryInput<TValues extends CmsEntryValues = CmsEntryVa

values?: Partial<TValues>;

expiresAt?: Date | undefined;
expiresAt?: Date | null | undefined;
}

export interface UpdateCmsEntryOptionsInput {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-aco/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"@webiny/plugins": "0.0.0",
"@webiny/react-properties": "0.0.0",
"@webiny/shared-aco": "0.0.0",
"@webiny/stdlib": "^0.0.3",
"@webiny/utils": "0.0.0",
"@webiny/validation": "0.0.0",
"dot-prop-immutable": "^2.1.1",
"graphql": "^16.14.0",
"graphql-tag": "^2.12.6",
"lodash": "^4.18.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import get from "lodash/get.js";
import { immutableGet } from "@webiny/stdlib";
import type { FilterDTO } from "~/components/AdvancedSearch/domain/index.js";

interface NestedObject {
Expand Down Expand Up @@ -27,7 +27,7 @@ export class GraphQLInputMapper {
const values = JSON.parse(value);
return this.createNestedObject(
this.createKeys(field, condition),
this.convertToBooleanOrString(get(values, keys))
this.convertToBooleanOrString(immutableGet(values, keys.join(".")))
);
} catch {
return this.createNestedObject(
Expand Down
13 changes: 6 additions & 7 deletions packages/app-aco/src/contexts/acoList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useContext, useEffect, useMemo } from "react";
import dotPropImmutable from "dot-prop-immutable";
import { immutableSet, immutableGet } from "@webiny/stdlib";
import pick from "lodash/pick.js";
import { useStateIfMounted } from "@webiny/app-admin";
import { useSecurity } from "@webiny/app-admin";
Expand Down Expand Up @@ -109,10 +109,9 @@ const getCurrentRecordList = <T extends GenericSearchData = GenericSearchData>(
return records;
}

return records.filter(
(record): record is SearchRecordItem<T> =>
dotPropImmutable.get(record, folderIdPath) === currentFolderId
);
return records.filter((record): record is SearchRecordItem<T> => {
return immutableGet(record, folderIdPath) === currentFolderId;
});
};

export interface AcoListProviderProps {
Expand Down Expand Up @@ -263,7 +262,7 @@ export const AcoListProvider = ({ children, ...props }: AcoListProviderProps) =>
);

// Set the locationWhere object with descendant folder IDs
where = dotPropImmutable.set({}, folderIdInPath, descendantFolderIds);
where = immutableSet({}, folderIdInPath, descendantFolderIds);
}

return {
Expand All @@ -286,7 +285,7 @@ export const AcoListProvider = ({ children, ...props }: AcoListProviderProps) =>
(state.filters && Object.values(state.filters).filter(Boolean).length)
);

let where = dotPropImmutable.set({}, folderIdPath, state.folderId);
let where = immutableSet({}, folderIdPath, state.folderId);

// In case of a search or filters applied, let's get the where condition based on the current folder ID,
// ownership status, and other existing filters in the state.
Expand Down
8 changes: 4 additions & 4 deletions packages/app-aco/src/hooks/useRecords.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dotPropImmutable from "dot-prop-immutable";
import { immutableSet, immutableGet } from "@webiny/stdlib";
import { useContext, useEffect, useMemo } from "react";
import { makeDecoratable } from "@webiny/app-admin";
import type { ListRecordsParams } from "~/contexts/records.js";
Expand Down Expand Up @@ -45,7 +45,7 @@ export const useRecords = makeDecoratable((folderId?: string) => {
if (!folderId) {
return;
}
const where = dotPropImmutable.set({}, folderIdPath, folderId);
const where = immutableSet({}, folderIdPath, folderId);
listRecords({
where
});
Expand All @@ -61,11 +61,11 @@ export const useRecords = makeDecoratable((folderId?: string) => {
loading,
meta,
records: records.filter(record => {
const recordFolderId = dotPropImmutable.get(record, folderIdPath);
const recordFolderId = immutableGet(record, folderIdPath);
return recordFolderId === folderId || recordFolderId === currentFolderId;
}),
listRecords(params: ListRecordsParams) {
const where = dotPropImmutable.set(params.where || {}, folderIdPath, folderId);
const where = immutableSet(params.where || {}, folderIdPath, folderId);
return listRecords({
...params,
where
Expand Down
2 changes: 1 addition & 1 deletion packages/app-file-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
"@webiny/react-composition": "0.0.0",
"@webiny/react-properties": "0.0.0",
"@webiny/sdk": "0.0.0",
"@webiny/stdlib": "^0.0.3",
"@webiny/validation": "0.0.0",
"apollo-cache": "^1.3.5",
"apollo-client": "^2.6.10",
"apollo-link": "^1.2.14",
"apollo-utilities": "^1.3.4",
"bytes": "^3.1.2",
"dayjs": "^1.11.20",
"dot-prop-immutable": "^2.1.1",
"graphql": "^16.14.0",
"graphql-tag": "^2.12.6",
"lodash": "^4.18.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import dotProp from "dot-prop-immutable";
import { immutableDelete } from "@webiny/stdlib";
import type {
CmsModelFieldRendererPlugin,
CmsModelFieldRendererProps
Expand Down Expand Up @@ -60,9 +60,9 @@ const FieldRenderer = ({ getBind }: CmsModelFieldRendererProps) => {
values={values}
onSelectItem={() => selectFiles()}
onReplaceItem={(_, index) => selectFiles(index)}
onRemoveItem={(_, index) =>
onChange(dotProp.delete(values, index))
}
onRemoveItem={(_, index) => {
return onChange(immutableDelete(values, index));
}}
placeholder={field.placeholder}
type={"compact"}
data-testid={`fr.input.filefields.${field.label}`}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import { Button, Grid, Input, Link, OverlayLoader, Text, Heading } from "@webiny/admin-ui";
import { Button, Grid, Heading, Input, Link, OverlayLoader, Text } from "@webiny/admin-ui";
import { Form, useBind } from "@webiny/form";
import { Mutation, Query } from "@apollo/react-components";
import {
Expand All @@ -13,7 +13,6 @@ import {
} from "@webiny/app-admin";
import type { GetSettingsResponse } from "../graphql.js";
import graphql from "../graphql.js";
import get from "lodash/get.js";
import { validation } from "@webiny/validation";
import type { QueryGetSettingsResult, Settings } from "~/domain/types.js";
import type { MutationFunction, MutationResult } from "@apollo/react-common";
Expand Down Expand Up @@ -76,8 +75,7 @@ export const FileManagerSettings = () => {
{({ data, loading: queryInProgress }: MutationResult<QueryGetSettingsResult>) => (
<Mutation mutation={graphql.UPDATE_SETTINGS}>
{(update: MutationFunction, result: MutationResult) => {
const settings = (get(data, "fileManager.getSettings.data") ||
{}) as Settings;
const settings = data?.fileManager?.getSettings?.data;
const { loading: mutationInProgress } = result;

const onSubmit = async (data: Settings): Promise<void> => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import set from "lodash/set.js";
import get from "lodash/get.js";
import { immutableGet, mutableSet } from "@webiny/stdlib";
import type { FileItem } from "~/domain/types.js";
import type { BatchDTO } from "~/presentation/FileList/components/BulkActions/domain/index.js";
import { OperatorType } from "~/presentation/FileList/components/BulkActions/domain/index.js";
Expand All @@ -10,26 +9,26 @@ export class GraphQLInputMapper {

batch.operations.forEach(operation => {
const { field, operator, value } = operation;
const fieldValue = get(value, field);
const fieldValue = immutableGet(value, field);

switch (operator) {
case OperatorType.OVERRIDE:
if (!fieldValue) {
return;
}

set(update, field, fieldValue);
mutableSet(update, field, fieldValue);
break;
case OperatorType.REMOVE:
set(update, field, null);
mutableSet(update, field, null);
break;
case OperatorType.APPEND:
if (!value || !fieldValue || !Array.isArray(fieldValue)) {
return;
}

const oldData = (data && get(data, field)) ?? [];
set(update, field, [...oldData, ...fieldValue]);
const oldData = immutableGet(data, field, []);
mutableSet(update, field, [...oldData, ...fieldValue]);

break;
default:
Expand Down
Loading