Skip to content

Commit

Permalink
chore: merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem committed Oct 10, 2023
1 parent f557121 commit c2682bd
Show file tree
Hide file tree
Showing 24 changed files with 215 additions and 160 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"fmt": "prettier --write '**/*.{js,jsx,ts,tsx,json}'",
"fmt:check": "prettier --check '**/*.{js,jsx,ts,tsx,json}'",
"build": "npm run fmt && node ./module/include.js",
"dev": "~/.cargo/bin/bos-loader devgovgigs.near --path src",
"dev": "~/.cargo/bin/bos-loader devhub.efiz.testnet --path src",
"test": "npx playwright test"
},
"repository": {
Expand Down
22 changes: 17 additions & 5 deletions src/gigs-board/components/organism/addon-configurator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,15 @@ const defaultFieldUpdate = ({
case "boolean":
return input;

case "object":
return Array.isArray(input) && typeof lastKnownValue === "string"
? input.join(arrayDelimiter ?? ",")
: 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)
Expand All @@ -136,7 +141,7 @@ const defaultFieldUpdate = ({
}
};

const useForm = ({ initialValues, stateKey, uninitialized }) => {
const useForm = ({ initialValues, onUpdate, stateKey, uninitialized }) => {
const initialFormState = {
hasUnsubmittedChanges: false,
values: initialValues ?? {},
Expand Down Expand Up @@ -182,6 +187,13 @@ const useForm = ({ initialValues, stateKey, uninitialized }) => {
values: updatedValues,
},
}));

if (
typeof onUpdate === "function" &&
!Struct.isEqual(updatedValues, initialFormState.values)
) {
onUpdate(updatedValues);
}
};

if (
Expand Down
2 changes: 1 addition & 1 deletion src/gigs-board/entity/addon/wiki-viewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const DevHub = {
}),

remove_community_addon: ({ handle, config_id }) =>
Near.call(devHubAccountId, "update_community_addon", {
Near.call(devHubAccountId, "remove_community_addon", {
community_handle: handle,
config_id,
}),
Expand Down
109 changes: 69 additions & 40 deletions src/gigs-board/entity/community/configurator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -377,44 +377,48 @@ if (community.isLoading) {
const [communityData, setCommunityData] = useState(community.data);
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);

if (permissions.can_configure) {
// START MIGRATION MODULE (withMigrate)
const needsMigration = (data) => {
if (data.github || data.board || data.wiki1 || data.wiki2) {
return "253"; // Issue #253
// MIGRATION MODULE
const withMigrate = (scenarios, data) => {
for (let scenario of scenarios) {
if (scenario.condition(data)) {
return {
identifier: scenario.identifier,
migrate: () => scenario.migrate(data),
output: scenario.output,
};
}
return null;
};

const migrationScenario = needsMigration(communityData);

const handleMigrate = () => {
switch (migrationScenario) {
case "253": // Issue #253
// TODO: Handle migration to features
console.log("Migrate with scenario 253");
return;
// default is not available in VM
}
console.log("No migration or unknown scenario");
};
}
console.log("No migration or unknown scenario");
return null;
};

if (migrationScenario) {
return (
const migrationScenarios = [
{
identifier: "253", // Issue #253
condition: (data) => data.github || data.board || data.wiki1 || data.wiki2,
// condition: (data) => true,
migrate: (data) => console.log("Migrate with scenario 253: ", data),
output: (data, migrate) => (
<>
<button onClick={handleMigrate}>Migrate</button>
{permissions.can_configure && (
<button onClick={() => migrate(data)}>Migrate</button>
)}
{widget("entity.community.configurator.old", { handle, link })}
</>
);
}
),
},
];

const MigrationResponse = withMigrate(migrationScenarios, communityData);

if (MigrationResponse) {
const { output: Component, migrate } = MigrationResponse;
return <Component data={communityData} migrate={migrate} />;
}

const availableAddons = DevHub.get_available_addons();
const communityAddonConfigs = DevHub.get_community_addon_configs({ handle });

console.log("availableAddons", availableAddons);
console.log("communityAddonConfigs", communityAddonConfigs);

const sectionSubmit = (sectionData) => {
const updatedCommunityData = {
...Object.entries(sectionData).reduce(
Expand All @@ -439,12 +443,26 @@ const changesSave = () =>

const onDeleteCommunity = () => DevHub.delete_community({ handle });

const UUID = {
generate: (template) => {
if (typeof template !== "string") {
template = "xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx";
}
return template.replace(/[xy]/g, (c) => {
var r = (Math.random() * 16) | 0;
var v = c === "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
},
};

const handleCreateAddon = (addon_id, values) => {
const uuid = UUID.generate("xxxxxxx");
DevHub.add_community_addon({
handle,
config: {
name: "Wiki",
config_id: "123",
config_id: uuid,
addon_id,
parameters: JSON.stringify(values),
enabled: true,
Expand All @@ -461,7 +479,10 @@ const handleUpdateCommunityAddonConfig = (config) => {
};

return (
<div className="d-flex flex-column align-items-center gap-4">
<div
className="d-flex flex-column align-items-center gap-4 w-100"
style={{ maxWidth: 960 }}
>
{widget("entity.community.branding-configurator", {
isUnlocked: permissions.can_configure,
link,
Expand All @@ -471,7 +492,8 @@ return (

{widget("components.organism.configurator", {
heading: "Community information",
data: communityData,
externalState: communityData,
fullWidth: true,
isSubform: true,
isUnlocked: permissions.can_configure,
onSubmit: sectionSubmit,
Expand All @@ -480,7 +502,8 @@ return (
})}
{widget("components.organism.configurator", {
heading: "About",
data: communityData,
externalState: communityData,
fullWidth: true,
isSubform: true,
isUnlocked: permissions.can_configure,
onSubmit: sectionSubmit,
Expand All @@ -490,7 +513,8 @@ return (

{widget("components.organism.configurator", {
heading: "Access control",
data: communityData,
externalState: communityData,
fullWidth: true,
formatter: communityAccessControlFormatter,
isSubform: true,
isUnlocked: permissions.can_configure,
Expand All @@ -508,7 +532,9 @@ return (
{widget("entity.community.configurator.section", {
heading: addon.name,
hasPermissionToConfgure: permissions.can_configure,
configurator: (p) =>
configurator: (
p // TODO: Add support for changing the name and enable/disable, and delete if not created yet
) =>
widget(match.configurator, {
data: JSON.parse(addon.parameters),
onSubmit: (value) =>
Expand All @@ -535,9 +561,9 @@ return (
}
})}

{/* {state.selectedAddon &&
{state.selectedAddon &&
widget("entity.community.configurator.section", {
heading: "New " + state.selectedAddon.title, // TODO: This should swap out with an input
heading: "New " + state.selectedAddon.title,
headerSlotRight: widget("components.molecule.button", {
classNames: { root: "btn-sm btn-secondary" },
icon: {
Expand All @@ -549,22 +575,25 @@ return (
}),
isEditActive: true,
hasPermissionToConfgure: permissions.can_configure,
configurator: (p) =>
configurator: (
p // TODO: Add support for changing the name and enable/disable
) =>
widget(state.selectedAddon.configurator, {
data: communityData.newAddon,
onSubmit: (value) =>
handleCreateAddon(state.selectedAddon.id, value),
...p,
}),
})} */}
})}

{availableAddons &&
permissions.can_configure &&
widget("components.molecule.tile", {
heading: "Add new addon",
children: (
<Widget
src="discom.testnet/widget/DIG.InputSelect" // if mainnet, replace discom.testnet with "near"
src={`${
context.networkId === "mainnet" ? "near" : "discom.testnet"
}/widget/DIG.InputSelect`} // if mainnet, replace discom.testnet with "near"
props={{
groups: [
{
Expand Down
Loading

0 comments on commit c2682bd

Please sign in to comment.