-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[FEATURE] Update Algolia components to make them easier to understand and use #14984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
components/algolia/actions/browse-records/browse-records.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import app from "../../algolia.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "algolia-browse-records", | ||
| name: "Browse Records", | ||
| description: "Browse for records in the given index. [See the documentation](https://www.algolia.com/doc/libraries/javascript/v5/methods/search/browse/?client=javascript).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| indexName: { | ||
| propDefinition: [ | ||
| app, | ||
| "indexName", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| browse(args) { | ||
| return this.app._client().browse(args); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| browse, | ||
| indexName, | ||
| } = this; | ||
|
|
||
| const response = await browse({ | ||
| indexName, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully fetched records from ${indexName} index.`); | ||
|
|
||
| return response; | ||
| }, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
54 changes: 0 additions & 54 deletions
54
components/algolia/actions/create-objects/create-objects.mjs
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
components/algolia/actions/delete-objects/delete-objects.mjs
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
components/algolia/actions/delete-records/delete-records.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import app from "../../algolia.app.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "algolia-delete-records", | ||
| name: "Delete Records", | ||
| description: "Delete records from the given index. [See the documentation](https://www.algolia.com/doc/libraries/javascript/v5/helpers/#delete-records)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| indexName: { | ||
| propDefinition: [ | ||
| app, | ||
| "indexName", | ||
| ], | ||
| }, | ||
| recordIds: { | ||
| type: "string[]", | ||
| label: "Record IDs", | ||
| description: "IDs of the records to delete also known as `objectIDs`. Eg. `[\"1\", \"2\"]`. If you don't know the IDs, you can use the **Browse Records** action to find them, then map them and then use them here as a custom expression. Eg. `{{steps.map_records_to_objectids.$return_value}}`.", | ||
| }, | ||
| }, | ||
| methods: { | ||
| deleteRecords(args = {}) { | ||
| return this.app._client().deleteObjects(args); | ||
| }, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| deleteRecords, | ||
| indexName, | ||
| recordIds, | ||
| } = this; | ||
|
|
||
| const response = await deleteRecords({ | ||
| indexName, | ||
| objectIDs: utils.parseArray(recordIds), | ||
| waitForTasks: true, | ||
| }); | ||
|
|
||
| $.export("$summary", "Successfully deleted records."); | ||
|
|
||
| return response; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import app from "../../algolia.app.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "algolia-save-records", | ||
| name: "Save Records", | ||
| description: "Adds records to an index. [See the documentation](https://www.algolia.com/doc/libraries/javascript/v5/helpers/#save-records).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| indexName: { | ||
| propDefinition: [ | ||
| app, | ||
| "indexName", | ||
| ], | ||
| }, | ||
| records: { | ||
| type: "string[]", | ||
| label: "Records From JSON Objects", | ||
| description: "The records to add to the index. Each record should be a JSON object. Eg. `{\"objectID\": \"1\", \"name\": \"Jane Doe\"}`. For a better user experience, you can use the [**CSV File To Objects**](https://pipedream.com/apps/helper-functions/actions/csv-file-to-objects) **Helper Function** action to convert a CSV file to an array of objects and then map the objects to the records field here as a **Custom Expression**. Eg. `{{steps.csv_file_to_objects.$return_value}}`.", | ||
| }, | ||
| }, | ||
| methods: { | ||
| saveRecords(args = {}) { | ||
| return this.app._client().saveObjects(args); | ||
| }, | ||
| }, | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async run({ $ }) { | ||
| const { | ||
| saveRecords, | ||
| indexName, | ||
| records, | ||
| } = this; | ||
|
|
||
| const response = await saveRecords({ | ||
| indexName, | ||
| objects: utils.parseArrayAndMap(records), | ||
| waitForTasks: true, | ||
| }); | ||
|
|
||
| $.export("$summary", "Successfully created records."); | ||
| return response; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
|
|
||
| const parseJson = (input) => { | ||
| const parse = (value) => { | ||
| if (typeof(value) === "string") { | ||
| try { | ||
| return parseJson(JSON.parse(value)); | ||
| } catch (e) { | ||
| return value; | ||
| } | ||
| } else if (typeof(value) === "object" && value !== null) { | ||
| return Object.entries(value) | ||
| .reduce((acc, [ | ||
| key, | ||
| val, | ||
| ]) => Object.assign(acc, { | ||
| [key]: parse(val), | ||
| }), {}); | ||
| } | ||
| return value; | ||
| }; | ||
|
|
||
| return parse(input); | ||
| }; | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| function parseArray(value) { | ||
| try { | ||
| if (!value) { | ||
| return []; | ||
| } | ||
|
|
||
| if (Array.isArray(value)) { | ||
| return value; | ||
| } | ||
|
|
||
| const parsedValue = JSON.parse(value); | ||
|
|
||
| if (!Array.isArray(parsedValue)) { | ||
| throw new Error("Not an array"); | ||
| } | ||
|
|
||
| return parsedValue; | ||
|
|
||
| } catch (e) { | ||
| throw new ConfigurationError("Make sure the custom expression contains a valid JSON array object"); | ||
| } | ||
| } | ||
|
|
||
| export default { | ||
| parseArray, | ||
| parseArrayAndMap: (value) => parseArray(value)?.map(parseJson), | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.