Skip to content

Commit

Permalink
Merge pull request #643 from rowyio/rc
Browse files Browse the repository at this point in the history
v2.3.1
  • Loading branch information
notsidney authored Feb 9, 2022
2 parents 2c1e4b0 + 0bd7d81 commit 8842e0f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 51 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Rowy",
"version": "2.3.0",
"version": "2.3.1",
"homepage": "https://rowy.io",
"repository": {
"type": "git",
Expand Down
3 changes: 2 additions & 1 deletion src/components/TableHeader/Extensions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,13 @@ export function emptyExtensionObject(
user: IExtensionEditor
): IExtension {
return {
name: "Untitled extension",
name: `${type} extension`,
active: false,
triggers: [],
type,
extensionBody: extensionBodyTemplate[type] ?? extensionBodyTemplate["task"],
requiredFields: [],
trackedFields: [],
conditions: `const condition: Condition = async({row, change}) => {
// feel free to add your own code logic here
return true;
Expand Down
16 changes: 1 addition & 15 deletions src/components/fields/Status/ConditionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ export default function ConditionModal({
setModal(EMPTY_STATE);
};
const handleAdd = () => {
const labelIsEmpty = Boolean(modal.condition.label.length < 4);
const stringValueIsEmpty = Boolean(
modal.condition.type === "string" && modal.condition.value.length === 0
);
const hasDuplicate = Boolean(_find(conditions, modal.condition));
const validation = Boolean(
labelIsEmpty || stringValueIsEmpty || hasDuplicate
);
if (validation) return;
function setConditionHack(type, condition) {
let rCondition = condition;
if (type === "undefined") rCondition = { ...condition, value: undefined };
Expand Down Expand Up @@ -100,12 +91,7 @@ export default function ConditionModal({
secondary: secondaryAction(modal.index),
}}
children={
<Content
isEditing={modal.index}
condition={modal.condition}
conditions={conditions}
handleUpdate={handleUpdate}
/>
<Content condition={modal.condition} handleUpdate={handleUpdate} />
}
/>
);
Expand Down
37 changes: 7 additions & 30 deletions src/components/fields/Status/ConditionModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,22 @@ import TextField from "@mui/material/TextField";
import Typography from "@mui/material/Typography";
import MultiSelect from "@rowy/multiselect";

interface I_ConditionModalContent {
handleUpdate: () => void;
modal: any;
}

export default function ConditionModalContent({
isEditing,
condition,
conditions,
handleUpdate,
}: any) {
const { label, operator, type, value } = condition;
const labelReqLen = Boolean(condition.label.length < 1);
const onNewHasDuplicate = Boolean(_find(conditions, condition));
const onEditConditions = conditions.filter(
(c) => c.value !== condition.value
); //remove the current condition from list of conditions, to prevent false positive error on duplicate value
const onEditHasDuplicate = Boolean(_find(onEditConditions, condition));

const errorTextType = (isEditing: boolean, error: string) => {
const hasError = isEditing ? onEditHasDuplicate : onNewHasDuplicate;
return hasError ? error : "";
};

return (
<>
<Typography variant="overline">DATA TYPE (input)</Typography>
<MultiSelect
options={[
{ label: "True", value: "true" },
{ label: "False", value: "false" },
{ label: "Boolean", value: "boolean" },
{ label: "Number", value: "number" },
{ label: "String", value: "string" },
{ label: "Undefined", value: "undefined" },
{ label: "Null", value: "null" },
]}
onChange={(v) => handleUpdate("type")(v)}
value={type}
Expand All @@ -46,11 +31,8 @@ export default function ConditionModalContent({
{type === "boolean" && (
<MultiSelect
options={[
{ label: "Boolean", value: "boolean" },
{ label: "Number", value: "number" },
{ label: "String", value: "string" },
{ label: "Undefined", value: "undefined" },
{ label: "Null", value: "null" },
{ label: "True", value: "true" },
{ label: "False", value: "false" },
]}
onChange={(v) => handleUpdate("value")(v === "true")}
value={value ? "true" : "false"}
Expand All @@ -76,27 +58,22 @@ export default function ConditionModalContent({
/>
</div>
<TextField
error={isEditing ? onEditHasDuplicate : onNewHasDuplicate}
type="number"
label="Value"
value={value}
onChange={(e) => handleUpdate("value")(Number(e.target.value))}
helperText={errorTextType(isEditing, "Number value already exists")}
/>
</Grid>
)}
{type === "string" && (
<TextField
error={isEditing ? onEditHasDuplicate : onNewHasDuplicate}
fullWidth
label="Value"
value={value}
onChange={(e) => handleUpdate("value")(e.target.value)}
helperText={errorTextType(isEditing, "String value already exists")}
/>
)}
<TextField
error={labelReqLen}
value={label}
label="Label"
fullWidth
Expand Down
19 changes: 18 additions & 1 deletion src/contexts/ProjectContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,19 @@ export const ProjectContextProvider: React.FC = ({ children }) => {
})
.then(
() => console.log("Field Value deleted"),
(error) => console.error("Failed to delete", error)
(error) => {
if (error.code === "permission-denied") {
enqueueSnackbar(`You don't have permission to delete this field`, {
variant: "error",
anchorOrigin: { horizontal: "center", vertical: "top" },
});
} else {
enqueueSnackbar(error.message, {
variant: "error",
anchorOrigin: { horizontal: "center", vertical: "top" },
});
}
}
);
};

Expand Down Expand Up @@ -335,6 +347,11 @@ export const ProjectContextProvider: React.FC = ({ children }) => {
anchorOrigin: { horizontal: "center", vertical: "top" },
}
);
} else {
enqueueSnackbar(error.message, {
variant: "error",
anchorOrigin: { horizontal: "center", vertical: "top" },
});
}
}
);
Expand Down
15 changes: 12 additions & 3 deletions src/hooks/useTable/useTableConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,30 @@ const useTableConfig = (tableId?: string) => {
});
};
/** remove column by index
* @param index of column.
* @param key of column.
*/
const remove = (key: string) => {
const { columns } = tableConfigState;

let updatedColumns: any = Object.values(columns)
/**
* Filter column, and remove key index
* Sort and reorder column
* Rewrite column index for firestore
*/
const updatedColumns: any = Object.values(columns)
.filter((c: any) => c.key !== key)
.sort((c: any) => c.index)
.reduce((acc: any, curr: any, index: any) => {
acc[curr.key] = { ...curr, index };
return acc;
}, {});

const deleteColumn = { [key]: deleteField() };
const finalColumns = { ...updatedColumns, ...deleteColumn };

documentDispatch({
action: DocActions.update,
data: { columns: updatedColumns },
data: { columns: finalColumns },
});
};
/** reorder columns by key
Expand Down

0 comments on commit 8842e0f

Please sign in to comment.