Skip to content

Commit

Permalink
Move community Github and Board widgets from devgogigs to devhub (#561)
Browse files Browse the repository at this point in the history
* fix solution action

* added required components

* remove unnecessary code

* add hidden btn

* update github configurator

* prettier update

* fix flash error issue

* more improvements

* prettier update

* refactor code

* add comment

* added state for when no configurations exists

* fix pagination error

* handle error

* fix map error

* fix amount issue

* updated UI

* decoupled state

* remove replace fn

* remove title on new column

---------

Co-authored-by: T guntenaar <[email protected]>
  • Loading branch information
2 people authored and elliotBraem committed Jan 9, 2024
1 parent d81cfc5 commit da86a64
Show file tree
Hide file tree
Showing 15 changed files with 1,544 additions and 451 deletions.
30 changes: 0 additions & 30 deletions src/core/adapter/devhub-contract.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,6 @@ function deleteCommunity({ handle }) {
return Near.call("${REPL_DEVHUB_CONTRACT}", "delete_community", { handle });
}

function updateCommunityBoard({ handle, board }) {
return Near.call("${REPL_DEVHUB_CONTRACT}", "update_community_board", {
handle,
board,
});
}

function updateCommunityGithub({ handle, github }) {
return Near.call("${REPL_DEVHUB_CONTRACT}", "update_community_github", {
handle,
github,
});
}

/**
* Sets all addons, for configurating tabs
*/
Expand Down Expand Up @@ -118,18 +104,6 @@ function getAllCommunitiesMetadata() {
);
}

function getCommunityAddons({ handle }) {
return Near.view("${REPL_DEVHUB_CONTRACT}", "get_community_addons", {
handle,
});
}

function getCommunityAddonConfigs({ handle }) {
return Near.view("${REPL_DEVHUB_CONTRACT}", "get_community_addon_configs", {
handle,
});
}

function getAllLabels() {
return Near.view("${REPL_DEVHUB_CONTRACT}", "get_all_labels") ?? null;
}
Expand Down Expand Up @@ -201,16 +175,12 @@ return {
getAccountCommunityPermissions,
updateCommunity,
deleteCommunity,
updateCommunityBoard,
updateCommunityGithub,
setCommunityAddons,
setCommunityAddon,
getAccessControlInfo,
getAllAuthors,
getAllCommunitiesMetadata,
getAllAddons,
getCommunityAddons,
getCommunityAddonConfigs,
getAllLabels,
getPost,
getPostsByAuthor,
Expand Down
35 changes: 35 additions & 0 deletions src/core/lib/data-request.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const DataRequest = {
/**
* Requests all the data from non-empty pages of the paginated API.
*
* **Notice: currently expected to work only with array responses.**
*
* @param {object} parameters
* Request parameters including the number of page to start with,
* and an accumulated response buffer, if it exists.
*
* @param {array | null | undefined} parameters.buffer
* @param {number} parameters.startWith
*
* @param {(pageNumber: number) => array} requestByNumber
*
* @returns {array} The final accumulated response.
*/
paginated: (requestByNumber, { buffer, startWith }) => {
const startPageNumber = startWith ?? 1,
accumulatedResponse = buffer ?? [];

const latestResponse = requestByNumber(startPageNumber) ?? [];

if (latestResponse.length === 0) {
return accumulatedResponse;
} else {
return DataRequest.paginated(requestByNumber, {
buffer: [...accumulatedResponse, ...latestResponse],
startWith: startPageNumber + 1,
});
}
},
};

return { DataRequest };
47 changes: 46 additions & 1 deletion src/core/lib/struct.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,49 @@ const pick = (sourceObject, keysToPick) => {
const typeMatch = (input) =>
input !== null && typeof input === "object" && !Array.isArray(input);

return { deepFieldUpdate, isEqual, pick, toOrdered, typeMatch };
const defaultFieldUpdate = ({
input,
lastKnownValue,
params: { arrayDelimiter },
}) => {
switch (typeof input) {
case "boolean":
return input;

case "object": {
if (Array.isArray(input) && typeof lastKnownValue === "string") {
return input.join(arrayDelimiter ?? ",");
} else {
return Array.isArray(lastKnownValue)
? [...lastKnownValue, ...input]
: { ...lastKnownValue, ...input };
}
}

case "string":
return Array.isArray(lastKnownValue)
? input.split(arrayDelimiter ?? ",").map((string) => string.trim())
: input;

default: {
if ((input ?? null) === null) {
switch (typeof lastKnownValue) {
case "boolean":
return !lastKnownValue;

default:
return lastKnownValue;
}
} else return input;
}
}
};

return {
deepFieldUpdate,
isEqual,
pick,
toOrdered,
typeMatch,
defaultFieldUpdate,
};
17 changes: 17 additions & 0 deletions src/core/lib/uuid.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const uuid = () =>
[Date.now().toString(16)]
.concat(
Array.from(
{ length: 4 },
() => Math.floor(Math.random() * 0xffffffff) & 0xffffffff
).map((value) => value.toString(16))
)
.join("-");

const withUUIDIndex = (data) => {
const id = uuid();

return Object.fromEntries([[id, { ...data, id }]]);
};

return { uuid, withUUIDIndex };
2 changes: 2 additions & 0 deletions src/devhub/components/molecule/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const Button = ({
icon: iconProps,
label,
type,
isHidden,
notRounded,
...restProps
}) => {
Expand All @@ -126,6 +127,7 @@ const Button = ({
"btn d-inline-flex align-items-center gap-2",
classNames?.root ?? "btn-primary",
!notRounded ?? "rounded-pill",
isHidden ?? false ? "d-none" : "",
].join(" ")}
style={{ width: "fit-content" }}
{...restProps}
Expand Down
43 changes: 3 additions & 40 deletions src/devhub/components/organism/Configurator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,6 @@ if (!Struct) {
return <p>Loading modules...</p>;
}

const defaultFieldUpdate = ({
input,
lastKnownValue,
params: { arrayDelimiter },
}) => {
switch (typeof input) {
case "boolean":
return input;

case "object": {
if (Array.isArray(input) && typeof lastKnownValue === "string") {
return input.join(arrayDelimiter ?? ",");
} else {
return Array.isArray(lastKnownValue)
? [...lastKnownValue, ...input]
: { ...lastKnownValue, ...input };
}
}

case "string":
return Array.isArray(lastKnownValue)
? input.split(arrayDelimiter ?? ",").map((string) => string.trim())
: input;

default: {
if ((input ?? null) === null) {
switch (typeof lastKnownValue) {
case "boolean":
return !lastKnownValue;

default:
return lastKnownValue;
}
} else return input;
}
}
};

const useForm = ({ initialValues, onUpdate, stateKey }) => {
const initialFormState = {
hasUnsubmittedChanges: false,
Expand All @@ -68,7 +30,7 @@ const useForm = ({ initialValues, onUpdate, stateKey }) => {
params,
});
} else {
return defaultFieldUpdate({
return Struct.defaultFieldUpdate({
input: fieldInput?.target?.value ?? fieldInput,
lastKnownValue: node,
params,
Expand Down Expand Up @@ -245,6 +207,7 @@ const Configurator = ({
schema,
submitIcon,
submitLabel,
hideSubmitBtn,
}) => {
const fieldsRender = customFieldsRender || defaultFieldsRender;

Expand Down Expand Up @@ -314,7 +277,7 @@ const Configurator = ({
schema,
})}
</div>
{isActive && (
{isActive && !hideSubmitBtn && (
<div className="d-flex align-items-center justify-content-end gap-3 mt-auto">
{actionsAdditional ? (
<div className="me-auto">{actionsAdditional}</div>
Expand Down
Loading

0 comments on commit da86a64

Please sign in to comment.