Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const generalizedError = (payload: GeneralizedError) => {
const badStatus = payload.statusBeforeError == SpecialStatus.SAVING;
if (badStatus) {
/** If, somehow, a `SAVING` status sneaks in, default it to DIRTY. */
payload.statusBeforeError = SpecialStatus.DIRTY;
}
toastErrors(payload);
stopTracking(payload.uuid);
return { type: Actions._RESOURCE_NO, payload };
};
export function getArrayStatus(i: TaggedResource[]): SpecialStatus {
const r = betterCompact(_(i).map(x => x.specialStatus).uniq().value());
if (r.length) {
return (r.includes(SpecialStatus.SAVING)) ?
SpecialStatus.SAVING : SpecialStatus.DIRTY;
} else {
return SpecialStatus.SAVED;
}
}
export function SaveBtn(props: SaveBtnProps) {
const STATUS_TRANSLATION: Partial> = {
[SpecialStatus.DIRTY]: "is-dirty",
[SpecialStatus.SAVING]: "is-saving"
};
const CAPTIONS: Partial> = {
[SpecialStatus.DIRTY]: (props.dirtyText || t("Save") + " *"),
[SpecialStatus.SAVING]: props.savingText || t("Saving")
};
const { savedText, onClick, hidden } = props;
const statusClass = STATUS_TRANSLATION[props.status || ""] || "is-saved";
const klass = `${props.color || "green"} ${statusClass} save-btn fb-button`;
const spinnerEl = (props.status === SpecialStatus.SAVING) ?
spinner : "";
return <button hidden="{!!hidden}">
{CAPTIONS[props.status] || (savedText || t("Saved") + " ✔")} {spinnerEl}
</button>;
.add(Actions.REFRESH_RESOURCE_START, (s, a) => {
mutateSpecialStatus(a.payload, s.index, SpecialStatus.SAVING);
return s;
})
.add(Actions.REFRESH_RESOURCE_NO, (s, { payload }) => {
save = () => {
const numUniqueValues = uniq(Object.values(this.state.form)).length;
switch (numUniqueValues) {
case 1:
error(t("Provided new and old passwords match. Password not changed."),
t("Error"));
this.clearForm();
break;
case 2:
if (confirm(t(Content.ACCOUNT_PASSWORD_CHANGE))) {
this.setState({ status: SpecialStatus.SAVING });
this.sendChange();
}
this.clearForm();
break;
case 3:
error(t("New password and confirmation do not match."), t("Error"));
this.clearForm();
break;
default:
this.clearForm();
throw new Error(trim(`Password change form error:
${numUniqueValues} unique values provided.`));
}
}
export function getArrayStatus(i: TaggedResource[]): SpecialStatus {
const r = betterCompact(chain(i).map(x => x.specialStatus).uniq().value());
if (r.length) {
return (r.includes(SpecialStatus.SAVING)) ?
SpecialStatus.SAVING : SpecialStatus.DIRTY;
} else {
return SpecialStatus.SAVED;
}
}
export function SaveBtn(props: SaveBtnProps) {
const STATUS_TRANSLATION: Partial> = {
[SpecialStatus.DIRTY]: "is-dirty",
[SpecialStatus.SAVING]: "is-saving"
};
const CAPTIONS: Partial> = {
[SpecialStatus.DIRTY]: (props.dirtyText || t("Save") + " *"),
[SpecialStatus.SAVING]: props.savingText || t("Saving")
};
const { savedText, onClick, hidden } = props;
const statusClass = STATUS_TRANSLATION[props.status || ""] || "is-saved";
const klass = `${props.color || "green"} ${statusClass} save-btn fb-button`;
const spinnerEl = (props.status === SpecialStatus.SAVING) ?
spinner : "";
return <button hidden="{!!hidden}">
{CAPTIONS[props.status] || (savedText || t("Saved") + " ✔")} {spinnerEl}
</button>;
export function getArrayStatus(i: TaggedResource[]): SpecialStatus {
const r = betterCompact(_(i).map(x => x.specialStatus).uniq().value());
if (r.length) {
return (r.includes(SpecialStatus.SAVING)) ?
SpecialStatus.SAVING : SpecialStatus.DIRTY;
} else {
return SpecialStatus.SAVED;
}
}
export const generalizedError = (payload: GeneralizedError) => {
const badStatus = payload.statusBeforeError == SpecialStatus.SAVING;
if (badStatus) {
/** If, somehow, a `SAVING` status sneaks in, default it to DIRTY. */
payload.statusBeforeError = SpecialStatus.DIRTY;
}
toastErrors(payload);
stopTracking(payload.uuid);
return { type: Actions._RESOURCE_NO, payload };
};
.add(Actions.SAVE_RESOURCE_START, (s, { payload }) => {
mutateSpecialStatus(payload.uuid, s.index, SpecialStatus.SAVING);
return s;
})
.add(Actions.BATCH_INIT, (s, { payload }) => {