Skip to content

Commit

Permalink
First review for Limit naming an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
xrutayisire committed Jan 23, 2024
1 parent da291f4 commit 783b294
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 29 deletions.
5 changes: 4 additions & 1 deletion packages/manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export { createSliceMachineManager } from "./managers/createSliceMachineManager"
export { createSliceMachineManagerMiddleware } from "./managers/createSliceMachineManagerMiddleware";
export type { CreateSliceMachineManagerMiddlewareArgs } from "./managers/createSliceMachineManagerMiddleware";

export type { Environment, Limit } from "./managers/prismicRepository/types";
export type {
Environment,
PushChangesLimit,
} from "./managers/prismicRepository/types";

export type {
PrismicAuthManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import {
BulkBody,
ChangeTypes,
ClientError,
Limit,
LimitType,
PushChangesLimit,
PushChangesLimitType,
PrismicRepository,
PrismicRepositoryRole,
PrismicRepositoryUserAgent,
PrismicRepositoryUserAgents,
RawLimit,
PushChangesRawLimit,
TransactionalMergeArgs,
TransactionalMergeReturnType,
FrameworkWroomTelemetryID,
Expand Down Expand Up @@ -421,7 +421,7 @@ export class PrismicRepositoryManager extends BaseManager {
return this._decodeLimitOrThrow(
await response.json(),
response.status,
LimitType.SOFT,
PushChangesLimitType.SOFT,
);
case 204:
return null;
Expand All @@ -431,7 +431,7 @@ export class PrismicRepositoryManager extends BaseManager {
return this._decodeLimitOrThrow(
await response.json(),
response.status,
LimitType.HARD,
PushChangesLimitType.HARD,
);
case 400:
const text = await response.text();
Expand Down Expand Up @@ -509,9 +509,9 @@ export class PrismicRepositoryManager extends BaseManager {
private _decodeLimitOrThrow(
potentialLimit: unknown,
statusCode: number,
limitType: LimitType,
): Limit | null {
return fold<t.Errors, RawLimit, Limit | null>(
limitType: PushChangesLimitType,
): PushChangesLimit | null {
return fold<t.Errors, PushChangesRawLimit, PushChangesLimit | null>(
() => {
const error: ClientError = {
status: statusCode,
Expand All @@ -521,12 +521,12 @@ export class PrismicRepositoryManager extends BaseManager {
};
throw error;
},
(rawLimit: RawLimit) => {
(rawLimit: PushChangesRawLimit) => {
const limit = { ...rawLimit, type: limitType };

return limit;
},
)(RawLimit.decode(potentialLimit));
)(PushChangesRawLimit.decode(potentialLimit));
}

private async _fetch(args: {
Expand Down
12 changes: 6 additions & 6 deletions packages/manager/src/managers/prismicRepository/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export interface BulkBody extends Record<string, unknown> {
changes: AllChangeTypes[];
}

export const RawLimit = t.type({
export const PushChangesRawLimit = t.type({
details: t.type({
customTypes: t.array(
t.type({
Expand All @@ -96,13 +96,13 @@ export const RawLimit = t.type({
),
}),
});
export type RawLimit = t.TypeOf<typeof RawLimit>;
export enum LimitType {
export type PushChangesRawLimit = t.TypeOf<typeof PushChangesRawLimit>;
export enum PushChangesLimitType {
SOFT = "SOFT",
HARD = "HARD",
}
export type Limit = RawLimit & {
type: LimitType;
export type PushChangesLimit = PushChangesRawLimit & {
type: PushChangesLimitType;
};

export interface ClientError {
Expand Down Expand Up @@ -130,7 +130,7 @@ export type TransactionalMergeArgs = {
changes: (CustomTypeChange | SliceChange)[];
};

export type TransactionalMergeReturnType = Limit | null;
export type TransactionalMergeReturnType = PushChangesLimit | null;

/**
* Framework id sent to Segment from wroom. Property used for the "framework"
Expand Down
4 changes: 2 additions & 2 deletions packages/manager/src/managers/telemetry/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CustomTypeFormat } from "../customTypes/types";
import type { LimitType } from "../prismicRepository/types";
import type { PushChangesLimitType } from "../prismicRepository/types";

export const SegmentEventType = {
command_init_start: "command:init:start",
Expand Down Expand Up @@ -248,7 +248,7 @@ type ChangesPushedSegmentEvent = SegmentEvent<

type ChangesLimitReachSegmentEvent = SegmentEvent<
typeof SegmentEventType.changes_limitReach,
{ limitType: LimitType }
{ limitType: PushChangesLimitType }
>;

type EditorWidgetUsedSegmentEvent = SegmentEvent<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { isRemoteOnly } from "@lib/models/common/ModelData";
import { getModelId } from "@lib/models/common/ModelData";
import { AssociatedDocumentsCard } from "./AssociatedDocumentsCard";
import { SliceMachineDrawerUI } from "@components/SliceMachineDrawer";
import { Limit } from "@slicemachine/manager";
import { PushChangesLimit } from "@slicemachine/manager";

export const HardDeleteDocumentsDrawer: React.FunctionComponent<{
pushChanges: (confirmDeleteDocuments: boolean) => void;
modalData?: Limit;
modalData?: PushChangesLimit;
onClose: () => void;
}> = ({ pushChanges, modalData, onClose }) => {
const { remoteOnlyCustomTypes } = useSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { selectAllCustomTypes } from "@src/modules/availableCustomTypes";
import { getModelId } from "@lib/models/common/ModelData";
import { AssociatedDocumentsCard } from "./AssociatedDocumentsCard";
import { SliceMachineDrawerUI } from "@components/SliceMachineDrawer";
import { Limit } from "@slicemachine/manager";
import { PushChangesLimit } from "@slicemachine/manager";

const ConfirmationDialogue: React.FC<{
isConfirmed: boolean;
Expand Down Expand Up @@ -40,7 +40,7 @@ const ConfirmationDialogue: React.FC<{

export const SoftDeleteDocumentsDrawer: React.FunctionComponent<{
pushChanges: (confirmDeleteDocuments: boolean) => void;
modalData?: Limit;
modalData?: PushChangesLimit;
onClose: () => void;
}> = ({ pushChanges, modalData, onClose }) => {
const [confirmDeleteDocuments, setConfirmDeleteDocuments] = useState(false);
Expand Down
8 changes: 4 additions & 4 deletions packages/slice-machine/pages/changes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
ChangedCustomType,
ChangedSlice,
} from "@lib/models/common/ModelStatus";
import { Limit } from "@slicemachine/manager";
import { PushChangesLimit } from "@slicemachine/manager";
import { pushChanges } from "@src/features/changes/actions/pushChanges";
import { getState } from "@src/apiClient";

Expand Down Expand Up @@ -60,9 +60,9 @@ const Changes: React.FunctionComponent = () => {

const { pushChangesSuccess, refreshState } = useSliceMachineActions();
const [isSyncing, setIsSyncing] = useState(false);
const [openModalData, setOpenModalData] = useState<Limit | undefined>(
undefined,
);
const [openModalData, setOpenModalData] = useState<
PushChangesLimit | undefined
>(undefined);

const numberOfChanges = unSyncedSlices.length + unSyncedCustomTypes.length;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ChangedCustomType,
ChangedSlice,
} from "@lib/models/common/ModelStatus";
import { Limit } from "@slicemachine/manager";
import { PushChangesLimit } from "@slicemachine/manager";

import { trackPushChangesSuccess } from "./trackPushChangesSuccess";

Expand All @@ -15,7 +15,7 @@ type PushChangesArgs = {

export async function pushChanges(
args: PushChangesArgs,
): Promise<Limit | undefined> {
): Promise<PushChangesLimit | undefined> {
const {
changedSlices,
changedCustomTypes,
Expand Down

0 comments on commit 783b294

Please sign in to comment.