Skip to content

Commit

Permalink
Restructure builder (customFilters) to accept custom options (honestb…
Browse files Browse the repository at this point in the history
…leeps#4797)

* Restructure builder (customFilters) to accept custom options

- The builder is less coupled with customFilter options (`ondemand`)
- Custom options is necessary for future comment filter options
- ondemand name field is now visible

* Prevent unknown types from breaking the builder

* move name from case conditions to filter

* Improve coupling between filter sources and external filters

* customFilter id

Needed as relying on the name as type can break references to on-demand
cases

* Retrieve case value on construction

* Tweak group case

* add 'name' parameter to adHoc cases

* on-demand filters default to state false
  • Loading branch information
larsjohnsen committed Jul 13, 2018
1 parent f55fe9f commit b4527e3
Show file tree
Hide file tree
Showing 25 changed files with 467 additions and 393 deletions.
14 changes: 14 additions & 0 deletions lib/core/migrate/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,20 @@ const migrations = [

// TODO Next stable: Remove `RESmodules.filteReddit` and option filteReddit customFilters
},
}, {
versionNumber: '5.11.1-settingsConsole-builder-tweak',
async go() {
const { customFiltersP, customFiltersC } = await Options.loadRaw('filteReddit') || {};
let i = Date.now();
for (const v of [...(customFiltersP.value || []), ...(customFiltersC.value || [])]) {
const { body: { name }, ondemand } = v;
v.opts = { ondemand, name };
v.id = `customFilter-${String(i++)}`;
// The trash values will be ignored by the builder, so no need to remove them
}
if (customFiltersP) await Options.set('filteReddit', 'customFiltersP', customFiltersP.value);
if (customFiltersC) await Options.set('filteReddit', 'customFiltersC', customFiltersC.value);
},
},

]; // ^^ Add new migrations ^^
Expand Down
26 changes: 19 additions & 7 deletions lib/core/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,20 @@ export type BuilderOption<Ctx> = {|
defaultTemplate: () => BuilderRootValue,
cases: { [string]: BuilderCase<*> },
value: BuilderRootValue[],
customOptionsFields: Array<Array<BuilderField | string>>,
...CommonOptionProps<Ctx>,
|};

export type BuilderRootValue = {|
note: string,
ver: number,
id: string,
body: BuilderValue,
ondemand?: boolean,
opts?: {
[string]: mixed,
// Some typed (reserved) values in order to simplify type checking
name?: string,
},
|};

export type BuilderValue = {
Expand All @@ -241,7 +247,7 @@ type BuilderCase = {
fields: Array<BuilderField | string>,
};

type BuilderField = BuilderSelectField | BuilderMultiField | BuilderTextField | BuilderDurationField | BuilderChecksetField | BuilderNumberField;
type BuilderField = BuilderSelectField | BuilderMultiField | BuilderDurationField | BuilderChecksetField | BuilderNumberField | BuilderCheckboxField | BuilderGenericInputField;

type PredefinedSelectChoice = 'COMPARISON';

Expand All @@ -257,11 +263,6 @@ type BuilderMultiField = {|
id: string,
|};

type BuilderTextField = {|
type: 'text',
id: string,
|};

type BuilderDurationField = {|
type: 'duration',
id: string,
Expand All @@ -277,3 +278,14 @@ type BuilderNumberField = {|
type: 'number',
id: string,
|};

type BuilderCheckboxField = {|
type: 'check',
id: string,
label: string,
|};

type BuilderGenericInputField = {|
type: string,
id: string,
|};
8 changes: 8 additions & 0 deletions lib/css/res.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,10 @@ body.RESScrollLock {
display: flex;
margin-bottom: 5px;

> .builderCustomOptions {
margin-left: 10px;
}

> .builderControls {
padding: .3em .2em;
}
Expand All @@ -1433,6 +1437,10 @@ body.RESScrollLock {
&.handle { font-size: 27px; }
}
}

input[type='checkbox'] {
vertical-align: text-bottom !important;
}
}

.builderWrap {
Expand Down
Loading

0 comments on commit b4527e3

Please sign in to comment.