React + TypeScript: Passing components in an Array as props

I am looking for a solution in TypeScript React to pass multiple components in an array. I have declared interfaces and importing it inside my component. But it gives me an error as ‘Type ‘Element’ has no properties in common with type ‘IDataView”.

I have added code snippet to what steps i am following. I am not sure what am i missing in the below code.

My Parent Component:

    const DataViewContainer:React.FC = () => {
 return (
    <ViewCollection views={[<BarChart />, <LineChart />]} />
 )
}

Child Component :

interface IViewCollection {
 views: IDataView
}
interface IDataView {
 barChartView?: React.ReactNode;
 lineChartView?: React.ReactNode;
}

const ViewCollection = (views: IViewCollection): JSX.Element => {
 return (
    <Carousel>
       {views.map((cmp) => { return (cmp) }}
    </Carousel>
 )
}

casting of js.executeAsyncScript output to Map

I want to cast the output of below script into Map<string,string> but it is showing “java.lang.String cannot be cast to java.util.Map“error.
How can we cast that in map??

final JavascriptExecutor js = (JavascriptExecutor) driver;
            Map<String,String> str = new HashMap<>();
            str = (Map<String, String>) js.executeAsyncScript("var myHeaders = new Headers();n" +
                    "myHeaders.append('client-id', 'LPDP');n" 
                    "let inputEntities = new Map();n" +
                    "inputEntities.set("Commons$customerId", "\"A2ZLDCQRXMMNLG\"")n" +
                    "inputEntities.set("Commons$marketPlaceId", "\"A2XZLSVIQ0F4JT\" +
                    "let entitiesToBeResolved = ["Rewards$APPA$GetAllPromotions$applicablePromotionDetailList"]n" +
                    "n" +
                    "const executeInput = {n" +
                    ""inputEntities": Object.fromEntries(inputEntities),n" +
                    ""entitiesToBeResolved": entitiesToBeResolved,n" +
                    "};n" +
                    "var obj n" +
                    "n" +
                    "fetch("url", {n" +
                    "  method: 'POST',n" +
                    "  headers: myHeaders,n" +
                    "  body: JSON.stringify(executeInput),n" +
                    "})n" +
                    "  .then(response => response.text())n" +
                    "  .then(arguments[0])n" +
                    "    .then(result => obj = result);n" +
                    "n" +
                    "  return obj;");

How can I use google translate directly on sveltekit web pages

I’ve been having issues using google translator directly on my sveltekit web app using the following code

<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
    <script type="text/javascript">
        function googleTranslateElementInit() {
          new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
        }
  // googleTranslateElementInit()
     </script>

I’ve tried several approaches, for example putting the code in svelte:head</svelte:head> but yet it’s kept appearing ad disappearing.
Please how can I achieve this,
Note I’m using Static adapter, thanks in advance

Using onclick in AMP

I have the following which works in HTML:

<a onclick="__tcfapi('displayConsentUi',2, function() {});">Manage Privacy Settings</a>

However, this doesn’t work in AMP since scripts aren’t allowed, which I understand.

I have tried using the following but it’s not working either:

<a on="tap:__tcfapi('displayConsentUi',2, function() {});">Manage Privacy Settings</a>

RBAC in Next Js

heloo everyone, i want to ask about RBAC in Next Js, so i was stuck for 3 days, thanks for help this my code .

what i want is if the roles is admin they can open all menu, and if its not admin only can dashboard

navigation.js

const navigation = [
  {
    path: '/',
    name: 'Dashboard',
    icon: <Icon path={LAYOUT_LINE_WHITE} maxWidth='24px' />
  },
  {
    path: '/statistik',
    name: 'Statistik',
    icon: <Icon path={PIE_CHART_LINE_WHITE} maxWidth='24px' />
  },
  {
    name: 'Settings',
    icon: <Icon path={SETTING_LINE_WHITE} maxWidth='24px' />,
}

How do I write html for form with multiple questions that use radio input type?

I have this quiz in multiple choice format where users can select one option per question and submit their answers at the end. This example shows what I’m trying achieve: [Example code w3school][1]

The problem I’m having is that selecting an option on a question de-selects any previous selection, meaning only one option can be selected for the entire quiz.

This is a section of my form template:

<form @submit.prevent="submit">
<div v-for="question in questions" :key="question.id">
 <jet-label :for="question.question" :value="question.question" class="font-bold text-lg" />
     <div v-for="option in question.options" :key="option.id">
        <jet-label :for="option.option" :value="option.option" />
        <input :id="option.id" type="radio" :value="option.option" 
        :name="option.question_id" v-model="form.options" />
     </div>
</div>
<div class="flex items-center justify-end mt-4">
    <jet-button class="ml-4" :class="{ 'opacity-25': form.processing }" 
     :disabled="form.processing">
       Submit
     </jet-button>
</div>
</form>

And this is the JS to handle user selection binding:

<script setup>
...
import { useForm } from '@inertiajs/inertia-vue3'

defineProps({
    questions: Array
})

const form = useForm({
    options: []
})

...
</script>

The issue probably is that inputs are seen as belonging to one group. How can I group the inputs based on the question id so that the select/deselect radio action is per question?
[1]: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_radio

javascript how to filter various items in array [duplicate]

I need a function that filter some items from array ,like below:

how to make it? Thank you so much in advance !

const users = [
   {id:"1",name:"Jane"},
   {id:"2",name:"Lucy"},
   {id:"3",name:"Li Li"},
   {id:"4",name:"Hilton"},
   {id:"5",name:"Rose"},
   {id:"6",name:"Ha Ha"},
]

//user with this id need to been remove.
const filteredUsers = [
   '1','2','5'
]

function filterUsers(allUsers,filteredUsers){
   //return after filtered list
}

How do I test a single file using yarn workspaces?

I know I can run a single test file using jest

I also know I can run all the tests in a single workspace with

yarn workspace @mycompany/somepackage test

But how would I run a single test file within a workspace?

I have tried:

yarn workspace @mycompany/somepackage test packages/somepackage/src/index.int.test.ts

and also:

yarn workspace @mycompany/somepackage test src/index.int.test.ts

As I am unsure whether the ‘test’ expects paths relative to the workspace or not. Both fail with:

No tests found, exiting with code 1

I am using Yarn v1.22.7 and my tests use jest.

How do I test a single file using yarn workspaces?

check decimal format in .tsx

I’m currently looking for a way to check the format of a number.

I want to accept only conventional decimals such as: { 1 ; 1.1 ; 1.01 ; 15 ; 15.15}.

Currently in my text box I can pass numbers like for example: 102.129.392.12 (like an ip adress indeed) etc…

I had thought to put a regex to check that the format is good:

. .match(/^d+(.d{1,2})?$/) 

but I don’t know how to implement it in a .tsx file

I’m new to react’s technology.

Here’s my code.

const SupplyEvent = () => {

   const handleChangeQuantity = (value: string) => {
       if (chosenSupply) {
          setChosenSupply({
            ...chosenSupply,
            quantity: value.replace(/,/g, '.'),
            // .match(/^d+(.d{1,2})?$/)
          });
       }
  }; 

  return(
     <View style={styles.halfWidth}>
        <Input
           value={chosenSupply?.quantity}
           keyboardType="decimal-pad"
           onChangeText={handleChangeQuantity}
           disabled={mode === FormMode.read}
        />
     </View>
   );
};

I want to add a message in red for the user like ‘This number is not accepted’

Do you guys have any ideas ?

Thanks you

ReactJS – Change CSS Class Properties

How can we dynamically change the properties of a CSS Class in ReactJS. For example, I have several text fields with CSS Classname “important”. I want to change all of them to have flash a red background on click of a button.

I thought I could do this by changing the properties of that CSS Class. How do I alter this class so that all its the text fields with that class will change in a flash.

Or is there another more elegant way of doing this?

Update FeatureCollection Geojson coordinates to mapbox map every 2sec

I am new to Javascript and mapbox and I want some help to solve an issue (code below). I am using some coordinates ({{coords}}) coming from a python script and I am adding them as a geojson to the map (featureCollection). I want these geojson coordinates to be updated every 2 seconds. I have used setData(), but my coordinates are not refreshing on the map. Can you help and give some hints? Thank you very much.

var longLat = {{coords}};
var featureCollection = [];

for(var itemIndex in longLat) {
featureCollection.push({
    "type": "Feature",
    "geometry": {
      "type": "Point",
      "coordinates": longLat[itemIndex]
    },
    "properties": {
      "title": "boat",
      "icon": "ferry"
    }
  });
}
map.on('load', function () {

map.addSource('ship', { type: 'geojson', data: featureCollection });
  map.addLayer({
    "id": "points",
    "type": "symbol",
    "source": {
    "type": "geojson",
      "data": {
        "type": "FeatureCollection",
        "features": featureCollection
      }
    },
    "layout": {
      "icon-image": "{icon}-15",
      "text-field": "{title}",
      "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"],
      "text-offset": [0, 0.6],
      "text-anchor": "top"
    }
  });

window.setInterval(function() {

  map.getSource('ship').setData(featureCollection);
}, 2000);

});

How to import OldSchool scripts into ES6 app

Old scripts designed to be used directly with tag, use various global variables and some features which don’t work inside ES6 with default strict mode.

For Example:

Uncaught TypeError: Failed to execute 'importScripts' on 'WorkerGlobalScope': Module scripts don't support importScripts().

How can we hypothetically do something like this:

var coolModule = magicImport( 'oldstyle_library.js' )

Or better yet:

var coolIsolatedModule = magicImportWrapContain( 'oldstyle_library.js' )

Set the sidebar width data after page reload

Someone could help me on how to set and use the local storage data of the left sidebar width after page reload?
I have created a local storage data and retrieve it using the codes below but after page reload it doesn’t work. I should have an “onload” event attribute or any suggestions please…
Here is the link where I get the codes https://htmldom.dev/create-resizable-split-views/
Credit to: htmldom.dev for sharing this code

const newLeftWidth = ((leftWidth + dx) * 100) / resize.parentNode.getBoundingClientRect().width;
localStorage.setItem(‘newLeftWidth’, newLeftWidth);
const localNewLeftWidth = localStorage.getItem(‘newLeftWidth’);
leftSide.style.width = ${localNewLeftWidth}%;
console.log(‘log: ‘ +${localNewLeftWidth}%);